thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 6 months ago
Clone

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

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