aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugenio Pérez <eperezma@redhat.com>2022-07-20 08:59:29 +0200
committerJason Wang <jasowang@redhat.com>2022-07-20 16:58:08 +0800
commitc381abc37f0aba42ed2e3b41cdace8f8438829e4 (patch)
tree7a73dc1b35f5601acfd5ea1c4b6928dc54226182
parent640b8a1c588b56349b3307d88459ea1cd86181fb (diff)
downloadqemu-c381abc37f0aba42ed2e3b41cdace8f8438829e4.zip
qemu-c381abc37f0aba42ed2e3b41cdace8f8438829e4.tar.gz
qemu-c381abc37f0aba42ed2e3b41cdace8f8438829e4.tar.bz2
vdpa: Avoid compiler to squash reads to used idx
In the next patch we will allow busypolling of this value. The compiler have a running path where shadow_used_idx, last_used_idx, and vring used idx are not modified within the same thread busypolling. This was not an issue before since we always cleared device event notifier before checking it, and that could act as memory barrier. However, the busypoll needs something similar to kernel READ_ONCE. Let's add it here, sepparated from the polling. Signed-off-by: Eugenio Pérez <eperezma@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
-rw-r--r--hw/virtio/vhost-shadow-virtqueue.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/hw/virtio/vhost-shadow-virtqueue.c b/hw/virtio/vhost-shadow-virtqueue.c
index e2184a4..560d07a 100644
--- a/hw/virtio/vhost-shadow-virtqueue.c
+++ b/hw/virtio/vhost-shadow-virtqueue.c
@@ -327,11 +327,12 @@ static void vhost_handle_guest_kick_notifier(EventNotifier *n)
static bool vhost_svq_more_used(VhostShadowVirtqueue *svq)
{
+ uint16_t *used_idx = &svq->vring.used->idx;
if (svq->last_used_idx != svq->shadow_used_idx) {
return true;
}
- svq->shadow_used_idx = cpu_to_le16(svq->vring.used->idx);
+ svq->shadow_used_idx = cpu_to_le16(*(volatile uint16_t *)used_idx);
return svq->last_used_idx != svq->shadow_used_idx;
}