[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 11/20] virtio: use virtio accessor to access packed descriptor fla
From: |
Michael S. Tsirkin |
Subject: |
[PULL 11/20] virtio: use virtio accessor to access packed descriptor flags |
Date: |
Mon, 15 Nov 2021 11:38:23 -0500 |
From: Jason Wang <jasowang@redhat.com>
We used to access packed descriptor flags via
address_space_{write|read}_cached(). When we hit the cache, memcpy()
is used which is not an atomic operation which may lead a wrong value
is read or wrote.
So this patch switches to use virito_{stw|lduw}_phys_cached() to make
sure the aceess is atomic.
Fixes: 86044b24e865f ("virtio: basic packed virtqueue support")
Cc: qemu-stable@nongnu.org
Signed-off-by: Jason Wang <jasowang@redhat.com>
Message-Id: <20211111063854.29060-1-jasowang@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/virtio/virtio.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index cc69a9b881..939bcbfeb9 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -507,11 +507,9 @@ static void vring_packed_desc_read_flags(VirtIODevice
*vdev,
MemoryRegionCache *cache,
int i)
{
- address_space_read_cached(cache,
- i * sizeof(VRingPackedDesc) +
- offsetof(VRingPackedDesc, flags),
- flags, sizeof(*flags));
- virtio_tswap16s(vdev, flags);
+ hwaddr off = i * sizeof(VRingPackedDesc) + offsetof(VRingPackedDesc,
flags);
+
+ *flags = virtio_lduw_phys_cached(vdev, cache, off);
}
static void vring_packed_desc_read(VirtIODevice *vdev,
@@ -564,8 +562,7 @@ static void vring_packed_desc_write_flags(VirtIODevice
*vdev,
{
hwaddr off = i * sizeof(VRingPackedDesc) + offsetof(VRingPackedDesc,
flags);
- virtio_tswap16s(vdev, &desc->flags);
- address_space_write_cached(cache, off, &desc->flags, sizeof(desc->flags));
+ virtio_stw_phys_cached(vdev, cache, off, desc->flags);
address_space_cache_invalidate(cache, off, sizeof(desc->flags));
}
--
MST
- [PULL 00/20] pci,pc,virtio: bugfixes, Michael S. Tsirkin, 2021/11/15
- [PULL 01/20] net/vhost-vdpa: fix memory leak in vhost_vdpa_get_max_queue_pairs(), Michael S. Tsirkin, 2021/11/15
- [PULL 02/20] softmmu/qdev-monitor: fix use-after-free in qdev_set_id(), Michael S. Tsirkin, 2021/11/15
- [PULL 04/20] vhost: Fix last vq queue index of devices with no cvq, Michael S. Tsirkin, 2021/11/15
- [PULL 06/20] pcie: rename 'native-hotplug' to 'x-native-hotplug', Michael S. Tsirkin, 2021/11/15
- [PULL 05/20] hw/mem/pc-dimm: Restrict NUMA-specific code to NUMA machines, Michael S. Tsirkin, 2021/11/15
- [PULL 07/20] hw/acpi/ich9: Add compat prop to keep HPC bit set for 6.1 machine type, Michael S. Tsirkin, 2021/11/15
- [PULL 08/20] bios-tables-test: Allow changes in DSDT ACPI tables, Michael S. Tsirkin, 2021/11/15
- [PULL 09/20] hw/i386/acpi-build: Deny control on PCIe Native Hot-plug in _OSC, Michael S. Tsirkin, 2021/11/15
- [PULL 10/20] tests: bios-tables-test update expected blobs, Michael S. Tsirkin, 2021/11/15
- [PULL 11/20] virtio: use virtio accessor to access packed descriptor flags,
Michael S. Tsirkin <=
- [PULL 12/20] virtio: use virtio accessor to access packed event, Michael S. Tsirkin, 2021/11/15
- [PULL 13/20] vdpa: Replace qemu_open_old by qemu_open at, Michael S. Tsirkin, 2021/11/15
- [PULL 14/20] vdpa: Check for existence of opts.vhostdev, Michael S. Tsirkin, 2021/11/15
- [PULL 15/20] pci: implement power state, Michael S. Tsirkin, 2021/11/15
- [PULL 16/20] pcie: implement slot power control for pcie root ports, Michael S. Tsirkin, 2021/11/15
- [PULL 17/20] pcie: add power indicator blink check, Michael S. Tsirkin, 2021/11/15
- [PULL 18/20] pcie: factor out pcie_cap_slot_unplug(), Michael S. Tsirkin, 2021/11/15
- [PULL 19/20] pcie: fast unplug when slot power is off, Michael S. Tsirkin, 2021/11/15
- [PULL 20/20] pcie: expire pending delete, Michael S. Tsirkin, 2021/11/15