From: Ingo Molnar <mingo@elte.hu>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: penberg@kernel.org, asias.hejun@gmail.com, gorcunov@gmail.com,
prasadjoshi124@gmail.com, kvm@vger.kernel.org
Subject: Re: [PATCH 1/2] kvm tools: Fix virt_queue__set_used_elem
Date: Tue, 3 May 2011 21:44:37 +0200 [thread overview]
Message-ID: <20110503194437.GA23144@elte.hu> (raw)
In-Reply-To: <1304437058-15651-1-git-send-email-levinsasha928@gmail.com>
* Sasha Levin <levinsasha928@gmail.com> wrote:
> Increase idx only after updating the used element.
> Not doing so may mark a buffer as used without having
> it's head and length updated.
>
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> ---
> tools/kvm/virtio.c | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/tools/kvm/virtio.c b/tools/kvm/virtio.c
> index 6249521..b2d2407 100644
> --- a/tools/kvm/virtio.c
> +++ b/tools/kvm/virtio.c
> @@ -7,9 +7,10 @@
> struct vring_used_elem *virt_queue__set_used_elem(struct virt_queue *queue, uint32_t head, uint32_t len)
> {
> struct vring_used_elem *used_elem;
> - used_elem = &queue->vring.used->ring[queue->vring.used->idx++ % queue->vring.num];
> + used_elem = &queue->vring.used->ring[queue->vring.used->idx % queue->vring.num];
> used_elem->id = head;
> used_elem->len = len;
> + queue->vring.used->idx++;
> return used_elem;
> }
Note that both the compiler and the CPU can reorder this code arbitrarily, so
your patch does not address the problem.
As mentioned in earlier discussions, you need memory barriers (which also act
as compiler barriers) to express this dependency in the order of updates to
these data structures.
Thanks,
Ingo
prev parent reply other threads:[~2011-05-03 19:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-03 15:37 [PATCH 1/2] kvm tools: Fix virt_queue__set_used_elem Sasha Levin
2011-05-03 15:37 ` [PATCH 2/2] kvm tools: Protect from dup definitions in kernel header Sasha Levin
2011-05-03 19:49 ` Ingo Molnar
2011-05-03 19:56 ` Sasha Levin
2011-05-03 19:59 ` Ingo Molnar
2011-05-03 20:10 ` Cyrill Gorcunov
2011-05-03 20:27 ` Cyrill Gorcunov
2011-05-03 19:44 ` Ingo Molnar [this message]
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=20110503194437.GA23144@elte.hu \
--to=mingo@elte.hu \
--cc=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=levinsasha928@gmail.com \
--cc=penberg@kernel.org \
--cc=prasadjoshi124@gmail.com \
/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