[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL v2 01/19] virtio: Fix virtio_mmio_read()/virtio_mmio_write()
From: |
Michael S. Tsirkin |
Subject: |
[PULL v2 01/19] virtio: Fix virtio_mmio_read()/virtio_mmio_write() |
Date: |
Mon, 22 Mar 2021 18:59:55 -0400 |
From: Laurent Vivier <laurent@vivier.eu>
Both functions don't check the personality of the interface (legacy or
modern) before accessing the configuration memory and always use
virtio_config_readX()/virtio_config_writeX().
With this patch, they now check the personality and in legacy mode
call virtio_config_readX()/virtio_config_writeX(), otherwise call
virtio_config_modern_readX()/virtio_config_modern_writeX().
This change has been tested with virtio-mmio guests (virt stretch/armhf and
virt sid/m68k) and virtio-pci guests (pseries RHEL-7.3/ppc64 and /ppc64le).
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20210314200300.3259170-1-laurent@vivier.eu>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/virtio/virtio-mmio.c | 74 +++++++++++++++++++++++++++++------------
1 file changed, 52 insertions(+), 22 deletions(-)
diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
index 6990b9879c..342c918ea7 100644
--- a/hw/virtio/virtio-mmio.c
+++ b/hw/virtio/virtio-mmio.c
@@ -112,15 +112,28 @@ static uint64_t virtio_mmio_read(void *opaque, hwaddr
offset, unsigned size)
if (offset >= VIRTIO_MMIO_CONFIG) {
offset -= VIRTIO_MMIO_CONFIG;
- switch (size) {
- case 1:
- return virtio_config_readb(vdev, offset);
- case 2:
- return virtio_config_readw(vdev, offset);
- case 4:
- return virtio_config_readl(vdev, offset);
- default:
- abort();
+ if (proxy->legacy) {
+ switch (size) {
+ case 1:
+ return virtio_config_readb(vdev, offset);
+ case 2:
+ return virtio_config_readw(vdev, offset);
+ case 4:
+ return virtio_config_readl(vdev, offset);
+ default:
+ abort();
+ }
+ } else {
+ switch (size) {
+ case 1:
+ return virtio_config_modern_readb(vdev, offset);
+ case 2:
+ return virtio_config_modern_readw(vdev, offset);
+ case 4:
+ return virtio_config_modern_readl(vdev, offset);
+ default:
+ abort();
+ }
}
}
if (size != 4) {
@@ -245,20 +258,37 @@ static void virtio_mmio_write(void *opaque, hwaddr
offset, uint64_t value,
if (offset >= VIRTIO_MMIO_CONFIG) {
offset -= VIRTIO_MMIO_CONFIG;
- switch (size) {
- case 1:
- virtio_config_writeb(vdev, offset, value);
- break;
- case 2:
- virtio_config_writew(vdev, offset, value);
- break;
- case 4:
- virtio_config_writel(vdev, offset, value);
- break;
- default:
- abort();
+ if (proxy->legacy) {
+ switch (size) {
+ case 1:
+ virtio_config_writeb(vdev, offset, value);
+ break;
+ case 2:
+ virtio_config_writew(vdev, offset, value);
+ break;
+ case 4:
+ virtio_config_writel(vdev, offset, value);
+ break;
+ default:
+ abort();
+ }
+ return;
+ } else {
+ switch (size) {
+ case 1:
+ virtio_config_modern_writeb(vdev, offset, value);
+ break;
+ case 2:
+ virtio_config_modern_writew(vdev, offset, value);
+ break;
+ case 4:
+ virtio_config_modern_writel(vdev, offset, value);
+ break;
+ default:
+ abort();
+ }
+ return;
}
- return;
}
if (size != 4) {
qemu_log_mask(LOG_GUEST_ERROR,
--
MST
- [PULL v2 00/19] pc,virtio,pci: fixes, features, Michael S. Tsirkin, 2021/03/22
- [PULL v2 02/19] vhost-user: Drop misleading EAGAIN checks in slave_read(), Michael S. Tsirkin, 2021/03/22
- [PULL v2 01/19] virtio: Fix virtio_mmio_read()/virtio_mmio_write(),
Michael S. Tsirkin <=
- [PULL v2 04/19] vhost-user: Factor out duplicated slave_fd teardown code, Michael S. Tsirkin, 2021/03/22
- [PULL v2 03/19] vhost-user: Fix double-close on slave_read() error path, Michael S. Tsirkin, 2021/03/22
- [PULL v2 05/19] vhost-user: Convert slave channel to QIOChannelSocket, Michael S. Tsirkin, 2021/03/22
- [PULL v2 06/19] vhost-user: Introduce nested event loop in vhost_user_read(), Michael S. Tsirkin, 2021/03/22
- [PULL v2 07/19] vhost-user: Monitor slave channel in vhost_user_read(), Michael S. Tsirkin, 2021/03/22
- [PULL v2 08/19] virtio-pmem: fix virtio_pmem_resp assign problem, Michael S. Tsirkin, 2021/03/22
- [PULL v2 09/19] tests: acpi: temporary whitelist DSDT changes, Michael S. Tsirkin, 2021/03/22
- [PULL v2 10/19] pci: introduce acpi-index property for PCI device, Michael S. Tsirkin, 2021/03/22
- [PULL v2 12/19] acpi: add aml_to_decimalstring() and aml_call6() helpers, Michael S. Tsirkin, 2021/03/22
- [PULL v2 11/19] pci: acpi: ensure that acpi-index is unique, Michael S. Tsirkin, 2021/03/22