* [PATCH] virtio: Fix virtio_mmio_read()/virtio_mmio_write()
@ 2021-03-14 20:03 Laurent Vivier
2021-03-17 14:18 ` Laurent Vivier
2021-03-19 9:24 ` Stefano Garzarella
0 siblings, 2 replies; 3+ messages in thread
From: Laurent Vivier @ 2021-03-14 20:03 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier, Michael S. Tsirkin
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>
---
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 6990b9879cf0..342c918ea7b7 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,
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] virtio: Fix virtio_mmio_read()/virtio_mmio_write()
2021-03-14 20:03 [PATCH] virtio: Fix virtio_mmio_read()/virtio_mmio_write() Laurent Vivier
@ 2021-03-17 14:18 ` Laurent Vivier
2021-03-19 9:24 ` Stefano Garzarella
1 sibling, 0 replies; 3+ messages in thread
From: Laurent Vivier @ 2021-03-17 14:18 UTC (permalink / raw)
To: qemu-devel; +Cc: Michael S. Tsirkin
Hi,
could this fix be merged in QEMU 6.0?
Thanks,
Laurent
Le 14/03/2021 à 21:03, Laurent Vivier a écrit :
> 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>
> ---
> 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 6990b9879cf0..342c918ea7b7 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,
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] virtio: Fix virtio_mmio_read()/virtio_mmio_write()
2021-03-14 20:03 [PATCH] virtio: Fix virtio_mmio_read()/virtio_mmio_write() Laurent Vivier
2021-03-17 14:18 ` Laurent Vivier
@ 2021-03-19 9:24 ` Stefano Garzarella
1 sibling, 0 replies; 3+ messages in thread
From: Stefano Garzarella @ 2021-03-19 9:24 UTC (permalink / raw)
To: Laurent Vivier; +Cc: qemu-devel, Michael S. Tsirkin
On Sun, Mar 14, 2021 at 09:03:00PM +0100, Laurent Vivier wrote:
>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>
>---
> hw/virtio/virtio-mmio.c | 74 +++++++++++++++++++++++++++++------------
> 1 file changed, 52 insertions(+), 22 deletions(-)
>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-03-19 9:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-14 20:03 [PATCH] virtio: Fix virtio_mmio_read()/virtio_mmio_write() Laurent Vivier
2021-03-17 14:18 ` Laurent Vivier
2021-03-19 9:24 ` Stefano Garzarella
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.