virtio_ring: expose virtio barriers for use in vringh.
The host side of ring needs this logic too. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
73640c991e
commit
a9a0fef779
2 changed files with 63 additions and 27 deletions
|
@ -4,6 +4,63 @@
|
|||
#include <linux/irqreturn.h>
|
||||
#include <uapi/linux/virtio_ring.h>
|
||||
|
||||
/*
|
||||
* Barriers in virtio are tricky. Non-SMP virtio guests can't assume
|
||||
* they're not on an SMP host system, so they need to assume real
|
||||
* barriers. Non-SMP virtio hosts could skip the barriers, but does
|
||||
* 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
|
||||
* sufficient.
|
||||
*
|
||||
* For using virtio to talk to real devices (eg. other heterogeneous
|
||||
* CPUs) we do need real barriers. In theory, we could be using both
|
||||
* kinds of virtio, so it's a runtime decision, and the branch is
|
||||
* actually quite cheap.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
static inline void virtio_mb(bool weak_barriers)
|
||||
{
|
||||
if (weak_barriers)
|
||||
smp_mb();
|
||||
else
|
||||
mb();
|
||||
}
|
||||
|
||||
static inline void virtio_rmb(bool weak_barriers)
|
||||
{
|
||||
if (weak_barriers)
|
||||
smp_rmb();
|
||||
else
|
||||
rmb();
|
||||
}
|
||||
|
||||
static inline void virtio_wmb(bool weak_barriers)
|
||||
{
|
||||
if (weak_barriers)
|
||||
smp_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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue