qemu/virtio: make wmb compiler barrier + comments
authorMichael S. Tsirkin <mst@redhat.com>
Mon, 26 Oct 2009 13:17:15 +0000 (15:17 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Fri, 30 Oct 2009 13:39:34 +0000 (08:39 -0500)
wmb must be at least a compiler barrier, even without SMP.
Further, we likely need some rmb()/mb() as well:
I have not audited the code but lguest has mb(),
add a comment for now.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/virtio.c

index 337ff27..1f92171 100644 (file)
 /* QEMU doesn't strictly need write barriers since everything runs in
  * lock-step.  We'll leave the calls to wmb() in though to make it obvious for
  * KVM or if kqemu gets SMP support.
+ * In any case, we must prevent the compiler from reordering the code.
+ * TODO: we likely need some rmb()/mb() as well.
  */
-#define wmb() do { } while (0)
+
+#define wmb() __asm__ __volatile__("": : :"memory")
 
 typedef struct VRingDesc
 {