Skip to content

Commit 41cff02

Browse files
Dongli Zhangmstsirkin
authored andcommitted
vhost: modify vhost_log_write() for broader users
Currently, the only user of vhost_log_write() is vhost-net. The 'len' argument prevents logging of pages that are not tainted by the RX path. Adjustments are needed since more drivers (i.e. vhost-scsi) begin using vhost_log_write(). So far vhost-net RX path may only partially use pages shared via the last vring descriptor. Unlike vhost-net, vhost-scsi always logs all pages shared via vring descriptors. To accommodate this, use (len == U64_MAX) to indicate whether the driver would log all pages of vring descriptors, or only pages that are tainted by the driver. In addition, removes BUG(). Suggested-by: Joao Martins <joao.m.martins@oracle.com> Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com> Message-Id: <20250403063028.16045-5-dongli.zhang@oracle.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent a5806cd commit 41cff02

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

drivers/vhost/vhost.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,6 +2304,19 @@ static int log_used(struct vhost_virtqueue *vq, u64 used_offset, u64 len)
23042304
return 0;
23052305
}
23062306

2307+
/*
2308+
* vhost_log_write() - Log in dirty page bitmap
2309+
* @vq: vhost virtqueue.
2310+
* @log: Array of dirty memory in GPA.
2311+
* @log_num: Size of vhost_log arrary.
2312+
* @len: The total length of memory buffer to log in the dirty bitmap.
2313+
* Some drivers may only partially use pages shared via the last
2314+
* vring descriptor (i.e. vhost-net RX buffer).
2315+
* Use (len == U64_MAX) to indicate the driver would log all
2316+
* pages of vring descriptors.
2317+
* @iov: Array of dirty memory in HVA.
2318+
* @count: Size of iovec array.
2319+
*/
23072320
int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
23082321
unsigned int log_num, u64 len, struct iovec *iov, int count)
23092322
{
@@ -2327,15 +2340,14 @@ int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log,
23272340
r = log_write(vq->log_base, log[i].addr, l);
23282341
if (r < 0)
23292342
return r;
2330-
len -= l;
2331-
if (!len) {
2332-
if (vq->log_ctx)
2333-
eventfd_signal(vq->log_ctx);
2334-
return 0;
2335-
}
2343+
2344+
if (len != U64_MAX)
2345+
len -= l;
23362346
}
2337-
/* Length written exceeds what we have stored. This is a bug. */
2338-
BUG();
2347+
2348+
if (vq->log_ctx)
2349+
eventfd_signal(vq->log_ctx);
2350+
23392351
return 0;
23402352
}
23412353
EXPORT_SYMBOL_GPL(vhost_log_write);

0 commit comments

Comments
 (0)