Signed-off-by: Jason Wang <jasowang at redhat.com> --- drivers/virtio/virtio_ring.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 79e1b29..78428a8 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -35,7 +35,7 @@ #define virtio_rmb(vq) \ do { if ((vq)->weak_barriers) smp_rmb(); else rmb(); } while(0) #define virtio_wmb(vq) \ - do { if ((vq)->weak_barriers) smp_rmb(); else rmb(); } while(0) + do { if ((vq)->weak_barriers) smp_wmb(); else wmb(); } while(0) #else /* We must force memory ordering even if guest is UP since host could be * running on another CPU, but SMP barriers are defined to barrier() in that
Jason Wang
2012-Jan-20 08:17 UTC
[PATCH 2/2] virtio: correct the memory barrier in virtqueue_kick_prepare()
Use virtio_mb() to make sure the available index to be exposed before checking the the avail event. Otherwise we may get stale value of avail event in guest and never kick the host after. Signed-off-by: Jason Wang <jasowang at redhat.com> --- drivers/virtio/virtio_ring.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 78428a8..07d9360 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -308,9 +308,9 @@ bool virtqueue_kick_prepare(struct virtqueue *_vq) bool needs_kick; START_USE(vq); - /* Descriptors and available array need to be set before we expose the - * new available array entries. */ - virtio_wmb(vq); + /* We need expose available array entries before checking avail + * event. */ + virtio_mb(vq); old = vq->vring.avail->idx - vq->num_added; new = vq->vring.avail->idx;
On Fri, Jan 20, 2012 at 04:16:59PM +0800, Jason Wang wrote:> Signed-off-by: Jason Wang <jasowang at redhat.com>Good catch. Note: this fixes a bug introduced by 7b21e34fd1c272e3a8c3846168f2f6287a4cd72b. It's probably a good idea to mention this is the commit log. Acked-by: Michael S. Tsirkin <mst at redhat.com>> --- > drivers/virtio/virtio_ring.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index 79e1b29..78428a8 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -35,7 +35,7 @@ > #define virtio_rmb(vq) \ > do { if ((vq)->weak_barriers) smp_rmb(); else rmb(); } while(0) > #define virtio_wmb(vq) \ > - do { if ((vq)->weak_barriers) smp_rmb(); else rmb(); } while(0) > + do { if ((vq)->weak_barriers) smp_wmb(); else wmb(); } while(0) > #else > /* We must force memory ordering even if guest is UP since host could be > * running on another CPU, but SMP barriers are defined to barrier() in that
Michael S. Tsirkin
2012-Jan-22 11:47 UTC
[PATCH 2/2] virtio: correct the memory barrier in virtqueue_kick_prepare()
On Fri, Jan 20, 2012 at 04:17:08PM +0800, Jason Wang wrote:> Use virtio_mb() to make sure the available index to be exposed before > checking the the avail event. Otherwise we may get stale value of > avail event in guest and never kick the host after. > > Signed-off-by: Jason Wang <jasowang at redhat.com>Good catch. Note: this fixes a bug introduced by ee7cd8981e15bcb365fc762afe3fc47b8242f630. Acked-by: Michael S. Tsirkin <mst at redhat.com>> --- > drivers/virtio/virtio_ring.c | 6 +++--- > 1 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index 78428a8..07d9360 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -308,9 +308,9 @@ bool virtqueue_kick_prepare(struct virtqueue *_vq) > bool needs_kick; > > START_USE(vq); > - /* Descriptors and available array need to be set before we expose the > - * new available array entries. */ > - virtio_wmb(vq); > + /* We need expose available array entries before checking availNit: We need expose -> Need to expose> + * event. */ > + virtio_mb(vq); > > old = vq->vring.avail->idx - vq->num_added; > new = vq->vring.avail->idx;
Maybe Matching Threads
- [PATCH 1/2] virtio: fix typos of memory barriers
- [PATCH] virtio_ring: Update weak barriers to use dma_wmb/rmb
- [PATCH] virtio_ring: Update weak barriers to use dma_wmb/rmb
- [PATCH net-next v2 4/5] virtio_ring: add event idx support in packed ring
- [RFC v3 4/5] virtio_ring: add event idx support in packed ring