virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] vhost: cache avail index in vhost_enable_notify()
@ 2022-01-13 14:56 Stefano Garzarella
  2022-01-13 15:19 ` Michael S. Tsirkin
  2022-01-14  6:18 ` Jason Wang
  0 siblings, 2 replies; 6+ messages in thread
From: Stefano Garzarella @ 2022-01-13 14:56 UTC (permalink / raw)
  To: virtualization; +Cc: kvm, Michael S. Tsirkin, netdev, linux-kernel, stefanha

In vhost_enable_notify() we enable the notifications and we read
the avail index to check if new buffers have become available in
the meantime. In this case, the device would go to re-read avail
index to access the descriptor.

As we already do in other place, we can cache the value in `avail_idx`
and compare it with `last_avail_idx` to check if there are new
buffers available.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
 drivers/vhost/vhost.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 59edb5a1ffe2..07363dff559e 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -2543,8 +2543,9 @@ bool vhost_enable_notify(struct vhost_dev *dev, struct vhost_virtqueue *vq)
 		       &vq->avail->idx, r);
 		return false;
 	}
+	vq->avail_idx = vhost16_to_cpu(vq, avail_idx);
 
-	return vhost16_to_cpu(vq, avail_idx) != vq->avail_idx;
+	return vq->avail_idx != vq->last_avail_idx;
 }
 EXPORT_SYMBOL_GPL(vhost_enable_notify);
 
-- 
2.31.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-01-14  8:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-01-13 14:56 [RFC PATCH] vhost: cache avail index in vhost_enable_notify() Stefano Garzarella
2022-01-13 15:19 ` Michael S. Tsirkin
2022-01-13 15:44   ` Stefano Garzarella
2022-01-13 16:05     ` Michael S. Tsirkin
2022-01-14  6:18 ` Jason Wang
2022-01-14  8:02   ` Stefano Garzarella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).