mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guo Zhi <qtxuning1999@sjtu.edu.cn>
To: eperezma@redhat.com, jasowang@redhat.com, sgarzare@redhat.com,
	mst@redhat.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, virtualization@lists.linux-foundation.org,
	Guo Zhi <qtxuning1999@sjtu.edu.cn>
Subject: [RFC v3 1/7] vhost: expose used buffers
Date: Thu,  1 Sep 2022 13:54:28 +0800	[thread overview]
Message-ID: <20220901055434.824-2-qtxuning1999@sjtu.edu.cn> (raw)
In-Reply-To: <20220901055434.824-1-qtxuning1999@sjtu.edu.cn>

Follow VIRTIO 1.1 spec, only writing out a single used ring for a batch
of descriptors.

Signed-off-by: Guo Zhi <qtxuning1999@sjtu.edu.cn>
---
 drivers/vhost/vhost.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 40097826cff0..26862c8bf751 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -2376,10 +2376,20 @@ static int __vhost_add_used_n(struct vhost_virtqueue *vq,
 	vring_used_elem_t __user *used;
 	u16 old, new;
 	int start;
+	int copy_n = count;
 
+	/**
+	 * If in order feature negotiated, devices can notify the use of a batch of buffers to
+	 * the driver by only writing out a single used ring entry with the id corresponding
+	 * to the head entry of the descriptor chain describing the last buffer in the batch.
+	 */
+	if (vhost_has_feature(vq, VIRTIO_F_IN_ORDER)) {
+		copy_n = 1;
+		heads = &heads[count - 1];
+	}
 	start = vq->last_used_idx & (vq->num - 1);
 	used = vq->used->ring + start;
-	if (vhost_put_used(vq, heads, start, count)) {
+	if (vhost_put_used(vq, heads, start, copy_n)) {
 		vq_err(vq, "Failed to write used");
 		return -EFAULT;
 	}
@@ -2388,7 +2398,7 @@ static int __vhost_add_used_n(struct vhost_virtqueue *vq,
 		smp_wmb();
 		/* Log used ring entry write. */
 		log_used(vq, ((void __user *)used - (void __user *)vq->used),
-			 count * sizeof *used);
+			 copy_n * sizeof(*used));
 	}
 	old = vq->last_used_idx;
 	new = (vq->last_used_idx += count);
@@ -2410,7 +2420,7 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vring_used_elem *heads,
 
 	start = vq->last_used_idx & (vq->num - 1);
 	n = vq->num - start;
-	if (n < count) {
+	if (n < count && !vhost_has_feature(vq, VIRTIO_F_IN_ORDER)) {
 		r = __vhost_add_used_n(vq, heads, n);
 		if (r < 0)
 			return r;
-- 
2.17.1


  reply	other threads:[~2022-09-01  5:55 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-01  5:54 [RFC v3 0/7] In order support for virtio_ring, vhost and vsock Guo Zhi
2022-09-01  5:54 ` Guo Zhi [this message]
2022-09-01  8:55   ` [RFC v3 1/7] vhost: expose used buffers Eugenio Perez Martin
2022-09-07  4:21   ` Jason Wang
2022-09-08  8:43     ` Guo Zhi
2022-09-01  5:54 ` [RFC v3 2/7] vhost_test: batch used buffer Guo Zhi
2022-09-01  5:54 ` [RFC v3 3/7] vsock: batch buffers in tx Guo Zhi
2022-09-01  9:00   ` Eugenio Perez Martin
2022-09-07  4:27   ` Jason Wang
2022-09-08  8:41     ` Guo Zhi
2022-09-01  5:54 ` [RFC v3 4/7] vsock: announce VIRTIO_F_IN_ORDER in vsock Guo Zhi
2022-09-01  5:54 ` [RFC v3 5/7] virtio: unmask F_NEXT flag in desc_extra Guo Zhi
2022-09-01  6:07   ` Xuan Zhuo
2022-09-01  6:14     ` Guo Zhi
2022-09-01  5:54 ` [RFC v3 6/7] virtio: in order support for virtio_ring Guo Zhi
2022-09-01  6:10   ` Xuan Zhuo
2022-09-07  5:38   ` Jason Wang
2022-09-08  8:47     ` Guo Zhi
2022-09-08  9:36     ` Guo Zhi
2022-10-03 11:32     ` Guo Zhi
2022-09-01  5:54 ` [RFC v3 7/7] virtio: announce VIRTIO_F_IN_ORDER support Guo Zhi
2022-09-07  4:13 ` [RFC v3 0/7] In order support for virtio_ring, vhost and vsock Jason Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220901055434.824-2-qtxuning1999@sjtu.edu.cn \
    --to=qtxuning1999@sjtu.edu.cn \
    --cc=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=sgarzare@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®