LKML Archive on
help / color / mirror / Atom feed
From: Sasha Levin <>
Cc: Neeraj Upadhyay <>,
	Jason Wang <>,
	Stefano Garzarella <>,
	"Michael S . Tsirkin" <>,
	Sasha Levin <>,,,
Subject: [PATCH AUTOSEL 4.9 2/3] vringh: Use wiov->used to check for read/write desc order
Date: Mon, 23 Aug 2021 20:55:38 -0400	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

From: Neeraj Upadhyay <>

[ Upstream commit e74cfa91f42c50f7f649b0eca46aa049754ccdbd ]

As __vringh_iov() traverses a descriptor chain, it populates
each descriptor entry into either read or write vring iov
and increments that iov's ->used member. So, as we iterate
over a descriptor chain, at any point, (riov/wriov)->used
value gives the number of descriptor enteries available,
which are to be read or written by the device. As all read
iovs must precede the write iovs, wiov->used should be zero
when we are traversing a read descriptor. Current code checks
for wiov->i, to figure out whether any previous entry in the
current descriptor chain was a write descriptor. However,
iov->i is only incremented, when these vring iovs are consumed,
at a later point, and remain 0 in __vringh_iov(). So, correct
the check for read and write descriptor order, to use

Acked-by: Jason Wang <>
Reviewed-by: Stefano Garzarella <>
Signed-off-by: Neeraj Upadhyay <>
Signed-off-by: Michael S. Tsirkin <>
Signed-off-by: Sasha Levin <>
 drivers/vhost/vringh.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
index d56736655dec..da47542496cc 100644
--- a/drivers/vhost/vringh.c
+++ b/drivers/vhost/vringh.c
@@ -329,7 +329,7 @@ __vringh_iov(struct vringh *vrh, u16 i,
 			iov = wiov;
 		else {
 			iov = riov;
-			if (unlikely(wiov && wiov->i)) {
+			if (unlikely(wiov && wiov->used)) {
 				vringh_bad("Readable desc %p after writable",
 				err = -EINVAL;

  reply	other threads:[~2021-08-24  1:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-24  0:55 [PATCH AUTOSEL 4.9 1/3] virtio: Improve vq->broken access to avoid any compiler optimization Sasha Levin
2021-08-24  0:55 ` Sasha Levin [this message]
2021-08-24  0:55 ` [PATCH AUTOSEL 4.9 3/3] net/rds: dma_map_sg is entitled to merge entries Sasha Levin

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:

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

  git send-email \ \ \ \ \ \ \ \ \ \ \ \
    --subject='Re: [PATCH AUTOSEL 4.9 2/3] vringh: Use wiov->used to check for read/write desc order' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).