Blame SOURCES/kvm-vdpa-Avoid-compiler-to-squash-reads-to-used-idx.patch

29b115
From df06ce560ddfefde98bef822ec2020382059921f Mon Sep 17 00:00:00 2001
29b115
From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= <eperezma@redhat.com>
29b115
Date: Thu, 21 Jul 2022 15:38:55 +0200
29b115
Subject: [PATCH 10/32] vdpa: Avoid compiler to squash reads to used idx
29b115
MIME-Version: 1.0
29b115
Content-Type: text/plain; charset=UTF-8
29b115
Content-Transfer-Encoding: 8bit
29b115
29b115
RH-Author: Eugenio Pérez <eperezma@redhat.com>
29b115
RH-MergeRequest: 108: Net Control Virtqueue shadow Support
29b115
RH-Commit: [10/27] b28789302d4f64749da26f413763f918161d9b70 (eperezmartin/qemu-kvm)
29b115
RH-Bugzilla: 1939363
29b115
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
29b115
RH-Acked-by: Cindy Lu <lulu@redhat.com>
29b115
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
29b115
29b115
Bugzilla: https://bugzilla.redhat.com/1939363
29b115
29b115
Upstream Status: git://git.qemu.org/qemu.git
29b115
29b115
commit c381abc37f0aba42ed2e3b41cdace8f8438829e4
29b115
Author: Eugenio Pérez <eperezma@redhat.com>
29b115
Date:   Wed Jul 20 08:59:29 2022 +0200
29b115
29b115
    vdpa: Avoid compiler to squash reads to used idx
29b115
29b115
    In the next patch we will allow busypolling of this value. The compiler
29b115
    have a running path where shadow_used_idx, last_used_idx, and vring used
29b115
    idx are not modified within the same thread busypolling.
29b115
29b115
    This was not an issue before since we always cleared device event
29b115
    notifier before checking it, and that could act as memory barrier.
29b115
    However, the busypoll needs something similar to kernel READ_ONCE.
29b115
29b115
    Let's add it here, sepparated from the polling.
29b115
29b115
    Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
29b115
    Signed-off-by: Jason Wang <jasowang@redhat.com>
29b115
29b115
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
29b115
---
29b115
 hw/virtio/vhost-shadow-virtqueue.c | 3 ++-
29b115
 1 file changed, 2 insertions(+), 1 deletion(-)
29b115
29b115
diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
29b115
index 3fbda1e3d4..9c46c3a8fa 100644
29b115
--- a/hw/virtio/vhost-shadow-virtqueue.c
29b115
+++ b/hw/virtio/vhost-shadow-virtqueue.c
29b115
@@ -327,11 +327,12 @@ static void vhost_handle_guest_kick_notifier(EventNotifier *n)
29b115
 
29b115
 static bool vhost_svq_more_used(VhostShadowVirtqueue *svq)
29b115
 {
29b115
+    uint16_t *used_idx = &svq->vring.used->idx;
29b115
     if (svq->last_used_idx != svq->shadow_used_idx) {
29b115
         return true;
29b115
     }
29b115
 
29b115
-    svq->shadow_used_idx = cpu_to_le16(svq->vring.used->idx);
29b115
+    svq->shadow_used_idx = cpu_to_le16(*(volatile uint16_t *)used_idx);
29b115
 
29b115
     return svq->last_used_idx != svq->shadow_used_idx;
29b115
 }
29b115
-- 
29b115
2.31.1
29b115