Skip to content

Commit

Permalink
virtio_ring: update weak barriers to use virt_xxx
Browse files Browse the repository at this point in the history
virtio ring uses smp_wmb on SMP and wmb on !SMP,
the reason for the later being that it might be
talking to another kernel on the same SMP machine.

This is exactly what virt_xxx barriers do,
so switch to these instead of homegrown ifdef hacks.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Alexander Duyck <alexander.duyck@gmail.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
  • Loading branch information
Michael S. Tsirkin committed Jan 12, 2016
1 parent d307fb1 commit a659612
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions include/linux/virtio_ring.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* anyone care?
*
* For virtio_pci on SMP, we don't need to order with respect to MMIO
* accesses through relaxed memory I/O windows, so smp_mb() et al are
* accesses through relaxed memory I/O windows, so virt_mb() et al are
* sufficient.
*
* For using virtio to talk to real devices (eg. other heterogeneous
Expand All @@ -21,46 +21,29 @@
* actually quite cheap.
*/

#ifdef CONFIG_SMP
static inline void virtio_mb(bool weak_barriers)
{
if (weak_barriers)
smp_mb();
virt_mb();
else
mb();
}

static inline void virtio_rmb(bool weak_barriers)
{
if (weak_barriers)
smp_rmb();
virt_rmb();
else
rmb();
}

static inline void virtio_wmb(bool weak_barriers)
{
if (weak_barriers)
smp_wmb();
virt_wmb();
else
wmb();
}
#else
static inline void virtio_mb(bool weak_barriers)
{
mb();
}

static inline void virtio_rmb(bool weak_barriers)
{
rmb();
}

static inline void virtio_wmb(bool weak_barriers)
{
wmb();
}
#endif

struct virtio_device;
struct virtqueue;
Expand Down

0 comments on commit a659612

Please sign in to comment.