[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 04/24] vdpa: Avoid compiler to squash reads to used idx
From: |
Jason Wang |
Subject: |
[PULL 04/24] vdpa: Avoid compiler to squash reads to used idx |
Date: |
Tue, 19 Jul 2022 21:16:17 +0800 |
From: Eugenio Pérez <eperezma@redhat.com>
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, separated from the polling.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
hw/virtio/vhost-shadow-virtqueue.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
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;
}
--
2.7.4
- [PULL 00/24] Net Patches, Jason Wang, 2022/07/19
- [PULL 01/24] vhost: move descriptor translation to vhost_svq_vring_write_descs, Jason Wang, 2022/07/19
- [PULL 02/24] virtio-net: Expose MAC_TABLE_ENTRIES, Jason Wang, 2022/07/19
- [PULL 03/24] virtio-net: Expose ctrl virtqueue logic, Jason Wang, 2022/07/19
- [PULL 04/24] vdpa: Avoid compiler to squash reads to used idx,
Jason Wang <=
- [PULL 05/24] vhost: Reorder vhost_svq_kick, Jason Wang, 2022/07/19
- [PULL 06/24] vhost: Move vhost_svq_kick call to vhost_svq_add, Jason Wang, 2022/07/19
- [PULL 07/24] vhost: Check for queue full at vhost_svq_add, Jason Wang, 2022/07/19
- [PULL 08/24] vhost: Decouple vhost_svq_add from VirtQueueElement, Jason Wang, 2022/07/19
- [PULL 09/24] vhost: Add SVQDescState, Jason Wang, 2022/07/19
- [PULL 10/24] vhost: Track number of descs in SVQDescState, Jason Wang, 2022/07/19
- [PULL 12/24] vhost: Expose vhost_svq_add, Jason Wang, 2022/07/19
- [PULL 13/24] vhost: add vhost_svq_poll, Jason Wang, 2022/07/19
- [PULL 11/24] vhost: add vhost_svq_push_elem, Jason Wang, 2022/07/19
- [PULL 15/24] vdpa: Export vhost_vdpa_dma_map and unmap calls, Jason Wang, 2022/07/19