qtests/libqos: Allow PCI tests to be run with virt-machine
v3 cover qtests/libqos: Allow PCI tests to be run with virt-machine
Up to now the virt-machine node only contains a virtio-mmio driver node but no driver that eventually produces any pci-bus interface.
Hence, PCI libqos tests cannot be run with aarch64 binary.
This series brings the pieces needed to be able to run PCI tests with the aarch64 binary: a generic-pcihost driver node gets instantiated by the machine. This later contains a pci-bus-generic driver which produces a pci-bus interface. Then all tests consuming the pci-bus interface can be run with the libqos arm virt machine.
One of the first goal was to be able to run the virtio-iommu-pci tests as the virtio-iommu was initially targetting ARM and it was awkard to be run the test with the pc machine. This is now possible.
Only the tests doing hotplug cannot be run yet as hotplug is not possible on the root bus. This will be dealt with separately by adding a root port to the object tree.
Also I have some trouble with 2 of the vhost-user-blk-tests. I am obliged to hack them in "tests/qtest/vhost-user-blk-test: Temporary hack to get tests passing on aarch64". Looks like a memory allocation issue, which at first sight seems unrelated to the aarch64 pci libqos enablement but we are never sure. Calling for help on this issue, if some vhost-user specialists can dedicate some cycles on this. Otherwise I will try my best to further debug.
To reproduce the issue, revert the above hack and run
QTEST_QEMU_STORAGE_DAEMON_BINARY=build/storage-daemon/qemu-storage-daemon QTEST_QEMU_BINARY=build/aarch64-softmmu/qemu-system-aarch64 build/tests/qtest/qos-test
you should get:
ERROR:../tests/qtest/libqos/virtio.c:224:qvirtio_wait_used_elem:
assertion failed (got_desc_idx == desc_idx): (50331648 == 0)
Bail out! ERROR:../tests/qtest/libqos/virtio.c:224: qvirtio_wait_used_elem:
assertion failed (got_desc_idx == desc_idx): (50331648 == 0)Best Regards
Eric
This series can be found at:
https://github.com/eauger/qemu/tree/libqos-pci-arm-v3
History
v2 -> v3:
- force -cpu=max along with aarch64/virt
- reduced the vhost-user-block-pci issue workaround to a single guest_alloc() instead of enabling MSIs. Call for help on this specific issue. The 2 tests which fail otherwise
are: test_basic and indirect.
v1 -> v2:
- copyright updated to 2022
- QPCIBusARM renamed into QGenericPCIBus
- QGenericPCIHost declarations and definitions moved in the same place as the generic pci implementation
- rename pci-arm.c/h in generic-pcihost.c/h and remove any ref to ARM there
- remove qos_node_produces_opts, qpci_new_arm, qpci_free_arm
- ecam_alloc_ptr now is a field of QGenericPCIBus and not QPCIBus
- new libqos_init to create generic-pcihost driver that contains pci-bus-generic
- QGenericPCIHost moved in the same place as the generic pci bindings
- collected Thomas A-b/R-b
Eric Auger (5):
tests/qtest/vhost-user-test.c: Use vhostforce=on tests/qtest/libqos/pci: Introduce pio_limit tests/qtest/libqos: Skip hotplug tests if pci root bus is not
hotpluggable
tests/qtest/vhost-user-blk-test: Temporary hack to get tests passing
on aarch64
tests/qtest/libqos: Add generic pci host bridge in arm-virt machine
tests/qtest/e1000e-test.c | 6 + tests/qtest/libqos/arm-virt-machine.c | 19 ++- tests/qtest/libqos/generic-pcihost.c | 231 ++++++++++++++++++++++++++ tests/qtest/libqos/generic-pcihost.h | 54 ++++++ tests/qtest/libqos/meson.build | 1 + tests/qtest/libqos/pci-pc.c | 1 + tests/qtest/libqos/pci-spapr.c | 1 + tests/qtest/libqos/pci.c | 78 +++++---- tests/qtest/libqos/pci.h | 6 +- tests/qtest/vhost-user-blk-test.c | 16 ++ tests/qtest/vhost-user-test.c | 2 +- tests/qtest/virtio-blk-test.c | 5 + tests/qtest/virtio-net-test.c | 5 + tests/qtest/virtio-rng-test.c | 5 + 14 files changed, 394 insertions(+), 36 deletions(-) create mode 100644 tests/qtest/libqos/generic-pcihost.c create mode 100644 tests/qtest/libqos/generic-pcihost.h
Signature · 1 line
2.26.3
PATCH v3 1/5 tests/qtest/vhost-user-test.c: Use vhostforce=on
-netdev vhost-user,vhostforce is deprecated and vhostforce=on should be used instead.
--- tests/qtest/vhost-user-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/vhost-user-test.c +1 -1
@@ -42,7 +42,7 @@#define QEMU_CMD_MEMFD " -m %d -object memory-backend-memfd,id=mem,size=%dM," \ " -numa node,memdev=mem"#define QEMU_CMD_CHR " -chardev socket,id=%s,path=%s%s" -#define QEMU_CMD_NETDEV " -netdev vhost-user,id=hs0,chardev=%s,vhostforce" +#define QEMU_CMD_NETDEV " -netdev vhost-user,id=hs0,chardev=%s,vhostforce=on"#define HUGETLBFS_MAGIC 0x958458f6
Signature · 1 line
2.26.3
PATCH v3 2/5 tests/qtest/libqos/pci: Introduce pio_limit
In reply to Eric AugerAt the moment the IO space limit is hardcoded to QPCI_PIO_LIMIT = 0x10000. When accesses are performed to a bar, the base address of this latter is compared against the limit to decide whether we perform an IO or a memory access.
On ARM, we cannot keep this PIO limit as the arm-virt machine uses [0x3eff0000, 0x3f000000 ] for the IO space map and we are mandated to allocate at 0x0.
Add a new flag in QPCIBar indicating whether it is an IO bar or a memory bar. This flag is set on QPCIBar allocation and provisionned based on the BAR configuration. Then the new flag is used in access functions and in iomap() function.
--- tests/qtest/libqos/pci-pc.c | 1 + tests/qtest/libqos/pci-spapr.c | 1 + tests/qtest/libqos/pci.c | 78 ++++++++++++++++++++++------------ tests/qtest/libqos/pci.h | 5 +-- 4 files changed, 54 insertions(+), 31 deletions(-)
tests/qtest/libqos/pci-pc.c +1 -0
@@ -150,6 +150,7 @@ void qpci_init_pc(QPCIBusPC *qpci, QTestState *qts, QGuestAllocator *alloc) qpci->bus.qts = qts; qpci->bus.pio_alloc_ptr =0xc000 ; + qpci->bus.pio_limit =0x10000 ; qpci->bus.mmio_alloc_ptr =0xE0000000 ; qpci->bus.mmio_limit =0x100000000ULL ;
tests/qtest/libqos/pci-spapr.c +1 -0
@@ -197,6 +197,7 @@ void qpci_init_spapr(QPCIBusSPAPR *qpci, QTestState *qts, qpci->bus.qts = qts; qpci->bus.pio_alloc_ptr =0xc000 ; + qpci->bus.pio_limit =0x10000 ; qpci->bus.mmio_alloc_ptr = qpci->mmio32.pci_base; qpci->bus.mmio_limit = qpci->mmio32.pci_base + qpci->mmio32.size;
tests/qtest/libqos/pci.c +50 -28
173 lines not on this page · raw message
tests/qtest/libqos/pci.h +2 -3
@@ -16,8 +16,6 @@#include "libqtest.h" #include "qgraph.h" -#define QPCI_PIO_LIMIT 0x10000 -#define QPCI_DEVFN (dev, fn) (((dev) << 3) | (fn))typedef struct QPCIDevice QPCIDevice ;
@@ -51,7 +49,7 @@ struct QPCIBus { uint8_t offset, uint32_t value);QTestState *qts; -uint16_t pio_alloc_ptr; +uint64_t pio_alloc_ptr, pio_limit;uint64_t mmio_alloc_ptr, mmio_limit;bool has_buggy_msi;/* TRUE for spapr, FALSE for pci */
@@ -59,6 +57,7 @@ struct QPCIBus {struct QPCIBar {uint64_t addr; +bool is_io; };struct QPCIDevice
Signature · 1 line
2.26.3
Re: [PATCH v3 2/5] tests/qtest/libqos/pci: Introduce pio_limit
Quoted 9 lines · Eric Auger
At the moment the IO space limit is hardcoded to
QPCI_PIO_LIMIT=0x10000. When accesses are performed to a bar, the base address of this latter is compared against the limit to decide whether we perform an IO or a memory access.On ARM, we cannot keep this PIO limit as the arm-virt machine uses [
0x3eff0000,0x3f000000] for the IO space map and we are mandated to allocate at0x0.
Quoted 7 lines
Add a new flag in QPCIBar indicating whether it is an IO bar or a memory bar. This flag is set on QPCIBar allocation and provisionned based on the BAR configuration. Then the new flag is used in access functions and in
iomap()function.Signed-off-by Eric Auger <[email protected]>Reviewed-by Thomas Huth <[email protected]>
Signature · 1 line
Alex Bennée
PATCH v3 3/5 tests/qtest/libqos: Skip hotplug tests if pci root bus is not hotpluggable
In reply to Eric AugerARM does not not support hotplug on pcie.0. Add a flag on the bus which tells if devices can be hotplugged and skip hotplug tests if the bus cannot be hotplugged. This is a temporary solution to enable the other pci tests on aarch64.
---
v1 ->v2:
- reword g_test_skip msg into "pci bus does not support hotplug"
--- tests/qtest/e1000e-test.c | 6 ++++++ tests/qtest/libqos/pci.h | 1 + tests/qtest/vhost-user-blk-test.c | 10 ++++++++++ tests/qtest/virtio-blk-test.c | 5 +++++ tests/qtest/virtio-net-test.c | 5 +++++ tests/qtest/virtio-rng-test.c | 5 +++++ 6 files changed, 32 insertions(+)
tests/qtest/e1000e-test.c +6 -0
@@ -235,6 +235,12 @@ static void test_e1000e_multiple_transfers(void *obj, void *data,static void test_e1000e_hotplug (void *obj,void *data,QGuestAllocator * alloc) {QTestState *qts = global_qtest;/* TODO: get rid of global_qtest here */ +QE1000E_PCI *dev = obj; + +if (dev->pci_dev.bus->not_hotpluggable) { +g_test_skip ("pci bus does not support hotplug" ); +return ; + }qtest_qmp_device_add (qts,"e1000e" ,"e1000e_net" ,"{'addr': '0x06'}" );qpci_unplug_acpi_device_test (qts,"e1000e_net" ,0x06 );
tests/qtest/libqos/pci.h +1 -0
@@ -52,6 +52,7 @@ struct QPCIBus {uint64_t pio_alloc_ptr, pio_limit;uint64_t mmio_alloc_ptr, mmio_limit;bool has_buggy_msi;/* TRUE for spapr, FALSE for pci */ +bool not_hotpluggable;/* TRUE if devices cannot be hotplugged */ };
tests/qtest/vhost-user-blk-test.c +10 -0
@@ -676,6 +676,11 @@ static void pci_hotplug(void *obj, void *data, QGuestAllocator *t_alloc)QVirtioPCIDevice *dev;QTestState *qts = dev1->pdev->bus->qts; +if (dev1->pdev->bus->not_hotpluggable) { +g_test_skip ("pci bus does not support hotplug" ); +return ; + } +/* plug secondary disk */ qtest_qmp_device_add(qts, "vhost-user-blk-pci", "drv1", "{'addr': %s, 'chardev': 'char2'}",
@@ -703,6 +708,11 @@ static void multiqueue(void *obj, void *data, QGuestAllocator *t_alloc)uint64_t features;uint16_t num_queues; +if (pdev1->pdev->bus->not_hotpluggable) { +g_test_skip ("bus pci.0 does not support hotplug" ); +return ; + } +/* * The primary device has 1 queue and VIRTIO_BLK_F_MQ is not enabled. The * VIRTIO specification allows VIRTIO_BLK_F_MQ to be enabled when there is
tests/qtest/virtio-blk-test.c +5 -0
@@ -701,6 +701,11 @@ static void pci_hotplug(void *obj, void *data, QGuestAllocator *t_alloc)QVirtioPCIDevice *dev;QTestState *qts = dev1->pdev->bus->qts; +if (dev1->pdev->bus->not_hotpluggable) { +g_test_skip ("pci bus does not support hotplug" ); +return ; + } +/* plug secondary disk */ qtest_qmp_device_add(qts, "virtio-blk-pci", "drv1", "{'addr': %s, 'drive': 'drive1'}",
tests/qtest/virtio-net-test.c +5 -0
@@ -174,6 +174,11 @@ static void hotplug(void *obj, void *data, QGuestAllocator *t_alloc)QTestState *qts = dev->pdev->bus->qts;const char *arch =qtest_get_arch (); +if (dev->pdev->bus->not_hotpluggable) { +g_test_skip ("pci bus does not support hotplug" ); +return ; + } +qtest_qmp_device_add (qts,"virtio-net-pci" ,"net1" ,"{'addr': %s}" ,stringify (PCI_SLOT_HP ));
tests/qtest/virtio-rng-test.c +5 -0
@@ -20,6 +20,11 @@ static void rng_hotplug(void *obj, void *data, QGuestAllocator *alloc)QVirtioPCIDevice *dev = obj;QTestState *qts = dev->pdev->bus->qts; +if (dev->pdev->bus->not_hotpluggable) { +g_test_skip ("pci bus does not support hotplug" ); +return ; + } +const char *arch =qtest_get_arch (); qtest_qmp_device_add(qts, "virtio-rng-pci", "rng1",
Signature · 1 line
2.26.3
Re: [PATCH v3 3/5] tests/qtest/libqos: Skip hotplug tests if pci root bus is not hotpluggable
Quoted 7 lines · Eric Auger
ARM does not not support hotplug on pcie.0. Add a flag on the bus which tells if devices can be hotplugged and skip hotplug tests if the bus cannot be hotplugged. This is a temporary solution to enable the other pci tests on aarch64.
Signed-off-by Eric Auger <[email protected]>Acked-by Thomas Huth <[email protected]>
<snip>
Signature · 1 line
Alex Bennée
PATCH v3 4/5 tests/qtest/vhost-user-blk-test: Temporary hack to get tests passing on aarch64
In reply to Eric AugerWhen run on ARM, basic and indirect tests currently fail with the following error:
ERROR:../tests/qtest/libqos/virtio.c:224:qvirtio_wait_used_elem:
assertion failed (got_desc_idx == desc_idx): (50331648 == 0) Bail out! ERROR:../tests/qtest/libqos/virtio.c:224: qvirtio_wait_used_elem:
assertion failed (got_desc_idx == desc_idx): (50331648 == 0)
I noticed it worked when I set up MSI and I further reduced the code to a simple guest_alloc() that removes the error. At the moment I am not able to identify where ths issue is and this blocks the whole pci/aarch64 enablement.
--- tests/qtest/vhost-user-blk-test.c | 6 ++++++ 1 file changed, 6 insertions(+)
tests/qtest/vhost-user-blk-test.c +6 -0
@@ -225,6 +225,9 @@ static QVirtQueue *test_basic(QVirtioDevice *dev, QGuestAllocator *alloc)QTestState *qts = global_qtest;QVirtQueue *vq; +/* temporary hack to let the test pass on aarch64 */ +guest_alloc (alloc,4 ); + features =qvirtio_get_features (dev); features = features & ~(QVIRTIO_F_BAD_FEATURE | (1u << VIRTIO_RING_F_INDIRECT_DESC) |
@@ -469,6 +472,9 @@ static void indirect(void *obj, void *u_data, QGuestAllocator *t_alloc)char *data;QTestState *qts = global_qtest; +/* temporary hack to let the test pass on aarch64 */ +guest_alloc (t_alloc,4 ); + features =qvirtio_get_features (dev); g_assert_cmphex(features & (1u << VIRTIO_RING_F_INDIRECT_DESC), !=, 0); features = features & ~(QVIRTIO_F_BAD_FEATURE |
Signature · 1 line
2.26.3
Re: [PATCH v3 4/5] tests/qtest/vhost-user-blk-test: Temporary hack to get tests passing on aarch64
Quoted 8 lines · Eric Auger
When run on ARM, basic and indirect tests currently fail with the following error:
ERROR:../tests/qtest/libqos/virtio.c:224:qvirtio_wait_used_elem:
assertion failed (got_desc_idx==desc_idx): (50331648 == 0) Bail out! ERROR:../tests/qtest/libqos/virtio.c:224:qvirtio_wait_used_elem:
assertion failed (got_desc_idx==desc_idx): (50331648 == 0)
Quoted 6 lines
I noticed it worked when I set up MSI and I further reduced the code to a simple
guest_alloc()that removes the error. At the moment I am not able to identify where ths issue is and this blocks the whole pci/aarch64 enablement.Signed-off-by Eric Auger <[email protected]>
Hi Eric,
I sent a RFC patch which I think avoids the need for this hack:
Subject: [RFC PATCH] tests/qtest: properly initialise the vring used idx
Date: Wed, 6 Apr 2022 18:33:56 +0100
Message-Id: <[email protected]>
Signature · 1 line
Alex Bennée
Re: [PATCH v3 4/5] tests/qtest/vhost-user-blk-test: Temporary hack to get tests passing on aarch64
Hi Alex,
Quoted 15 lines · Alex Bennée
Quoted 13 lines · Eric Auger
When run on ARM, basic and indirect tests currently fail with the following error:
ERROR:../tests/qtest/libqos/virtio.c:224:qvirtio_wait_used_elem:
assertion failed (got_desc_idx==desc_idx): (50331648 == 0) Bail out! ERROR:../tests/qtest/libqos/virtio.c:224:qvirtio_wait_used_elem:
assertion failed (got_desc_idx==desc_idx): (50331648 == 0)I noticed it worked when I set up MSI and I further reduced the code to a simple
guest_alloc()that removes the error. At the moment I am not able to identify where ths issue is and this blocks the whole pci/aarch64 enablement.
Quoted 9 lines
Quoted 1 line
Signed-off-by Eric Auger <[email protected]>Hi Eric,
I sent a RFC patch which I think avoids the need for this hack:
Subject: [RFC PATCH] tests/qtest: properly initialise the vring used idx
Date: Wed, 6 Apr 2022 18:33:56 +0100
Message-Id: <[email protected]>
Indeed this fixes my issue! Many thanks for the debug & fix.
I will respin with your R-b's.
Eric
PATCH v3 5/5 tests/qtest/libqos: Add generic pci host bridge in arm-virt machine
In reply to Eric AugerUp to now the virt-machine node contains a virtio-mmio node. However no driver produces any PCI interface node. Hence, PCI tests cannot be run with aarch64 binary.
Add a GPEX driver node that produces a pci interface node. This latter then can be consumed by all the pci tests. One of the first motivation was to be able to run the virtio-iommu-pci tests.
We still face an issue with pci hotplug tests as hotplug cannot happen on the pcie root bus and require a generic root port. This will be addressed later on.
We force cpu=max along with aarch64/virt machine as some PCI tests require high MMIO regions to be available.
---
v2 -> v3:
- force cpu=max with aarch64/virt
v1 -> v2:
- copyright updated to 2022
- QPCIBusARM renamed into QGenericPCIBus
- QGenericPCIHost declarations and definitions moved in the same place as the generic pci implementation
- rename pci-arm.c/h in generic-pcihost.c/h and remove any ref to ARM there
- remove qos_node_produces_opts, qpci_new_arm, qpci_free_arm
- ecam_alloc_ptr now is a field of QGenericPCIBus and not QPCIBus
- new libqos_init to create generic-pcihost driver that contains pci-bus-generic
- QGenericPCIHost moved in the same place as the generic pci bindings
--- tests/qtest/libqos/arm-virt-machine.c | 19 ++- tests/qtest/libqos/generic-pcihost.c | 231 ++++++++++++++++++++++++++ tests/qtest/libqos/generic-pcihost.h | 54 ++++++ tests/qtest/libqos/meson.build | 1 + 4 files changed, 301 insertions(+), 4 deletions(-) create mode 100644 tests/qtest/libqos/generic-pcihost.c create mode 100644 tests/qtest/libqos/generic-pcihost.h
tests/qtest/libqos/arm-virt-machine.c +15 -4
@@ -22,6 +22,8 @@#include "malloc.h" #include "qgraph.h" #include "virtio-mmio.h" +#include "generic-pcihost.h" +#include "hw/pci/pci_regs.h" #define ARM_PAGE_SIZE 4096#define VIRTIO_MMIO_BASE_ADDR 0x0A003E00
@@ -35,6 +37,7 @@ struct QVirtMachine {QOSGraphObject obj;QGuestAllocator alloc;QVirtioMMIODevice virtio_mmio; +QGenericPCIHost bridge; };static void virt_destructor (QOSGraphObject *obj)
@@ -57,11 +60,13 @@ static void *virt_get_driver(void *object, const char *interface)static QOSGraphObject *virt_get_device (void *obj,const char *device) {QVirtMachine *machine = obj; -if (!g_strcmp0 (device,"virtio-mmio" )) { +if (!g_strcmp0 (device,"generic-pcihost" )) { +return &machine->bridge.obj; + }else if (!g_strcmp0 (device,"virtio-mmio" )) {return &machine->virtio_mmio.obj; } -fprintf (stderr,"%s not present in arm/virtio\n" , device); +fprintf (stderr,"%s not present in arm/virt\n" , device);g_assert_not_reached (); }
@@ -76,16 +81,22 @@ static void *qos_create_machine_arm_virt(QTestState *qts)qvirtio_mmio_init_device (&machine->virtio_mmio, qts,VIRTIO_MMIO_BASE_ADDR ,VIRTIO_MMIO_SIZE ); +qos_create_generic_pcihost (&machine->bridge, qts, &machine->alloc); + machine->obj.get_device = virt_get_device; machine->obj.get_driver = virt_get_driver; machine->obj.destructor = virt_destructor;return machine; } -static void virtio_mmio_register_nodes (void ) +static void virt_machine_register_nodes (void ) {qos_node_create_machine ("arm/virt" , qos_create_machine_arm_virt);qos_node_contains ("arm/virt" ,"virtio-mmio" ,NULL ); + +qos_node_create_machine_args ("aarch64/virt" , qos_create_machine_arm_virt, +" -cpu max" ); +qos_node_contains ("aarch64/virt" ,"generic-pcihost" ,NULL ); } -libqos_init (virtio_mmio_register_nodes); +libqos_init (virt_machine_register_nodes);
tests/qtest/libqos/generic-pcihost.c new file +231 -0
231 lines not on this page · raw message
tests/qtest/libqos/generic-pcihost.h new file +54 -0
54 lines not on this page · raw message
tests/qtest/libqos/meson.build +1 -0
@@ -42,6 +42,7 @@ libqos_srcs = files('../libqtest.c', 'virtio-scsi.c', 'virtio-serial.c', 'virtio-iommu.c', + 'generic-pcihost.c', # qgraph machines: 'aarch64-xlnx-zcu102-machine.c',
Signature · 1 line
2.26.3
Re: [PATCH v3 5/5] tests/qtest/libqos: Add generic pci host bridge in arm-virt machine
Quoted 269 lines · Eric Auger
Up to now the virt-machine node contains a virtio-mmio node. However no driver produces any PCI interface node. Hence, PCI tests cannot be run with aarch64 binary.
Add a GPEX driver node that produces a pci interface node. This latter then can be consumed by all the pci tests. One of the first motivation was to be able to run the virtio-iommu-pci tests.
We still face an issue with pci hotplug tests as hotplug cannot happen on the pcie root bus and require a generic root port. This will be addressed later on.
We force cpu=max along with aarch64/virt machine as some PCI tests require high MMIO regions to be available.
Signed-off-by Eric Auger <[email protected]>---
v2 -> v3:
- force cpu=max with aarch64/virtv1 -> v2:
- copyright updated to 2022
- QPCIBusARM renamed into QGenericPCIBus
- QGenericPCIHost declarations and definitions moved in the same place as the generic pci implementation
- rename pci-arm.c/h in generic-pcihost.c/h and remove any ref to ARM there
- removeqos_node_produces_opts,qpci_new_arm,qpci_free_arm
-ecam_alloc_ptrnow is a field of QGenericPCIBus and not QPCIBus
- newlibqos_initto create generic-pcihost driver that contains pci-bus-generic
- QGenericPCIHost moved in the same place as the generic pci bindingsSigned-off-by Eric Auger <[email protected]>--- tests/qtest/libqos/arm-virt-machine.c | 19 ++- tests/qtest/libqos/generic-pcihost.c | 231 ++++++++++++++++++++++++++ tests/qtest/libqos/generic-pcihost.h | 54 ++++++ tests/qtest/libqos/meson.build | 1 + 4 files changed, 301 insertions(+), 4 deletions(-) create mode 100644 tests/qtest/libqos/generic-pcihost.c create mode 100644 tests/qtest/libqos/generic-pcihost.htests/qtest/libqos/arm-virt-machine.c +15
-4@@ -22,6 +22,8 @@#include "malloc.h" #include "qgraph.h" #include "virtio-mmio.h" +#include "generic-pcihost.h" +#include "hw/pci/pci_regs.h" #define ARM_PAGE_SIZE 4096#define VIRTIO_MMIO_BASE_ADDR 0x0A003E00@@ -35,6 +37,7 @@ struct QVirtMachine {QOSGraphObject obj;QGuestAllocator alloc;QVirtioMMIODevice virtio_mmio; +QGenericPCIHost bridge; };static void virt_destructor (QOSGraphObject *obj)@@ -57,11 +60,13 @@ static void *virt_get_driver(void *object, const char *interface)static QOSGraphObject *virt_get_device (void *obj,const char *device) {QVirtMachine *machine = obj; -if (!g_strcmp0 (device,"virtio-mmio" )) { +if (!g_strcmp0 (device,"generic-pcihost" )) { +return &machine->bridge.obj; + }else if (!g_strcmp0 (device,"virtio-mmio" )) {return &machine->virtio_mmio.obj; } -fprintf (stderr,"%s not present in arm/virtio\n" , device); +fprintf (stderr,"%s not present in arm/virt\n" , device);g_assert_not_reached (); }@@ -76,16 +81,22 @@ static void *qos_create_machine_arm_virt(QTestState *qts)qvirtio_mmio_init_device (&machine->virtio_mmio, qts,VIRTIO_MMIO_BASE_ADDR ,VIRTIO_MMIO_SIZE ); +qos_create_generic_pcihost (&machine->bridge, qts, &machine->alloc); + machine->obj.get_device = virt_get_device; machine->obj.get_driver = virt_get_driver; machine->obj.destructor = virt_destructor;return machine; } -static void virtio_mmio_register_nodes (void ) +static void virt_machine_register_nodes (void ) {qos_node_create_machine ("arm/virt" , qos_create_machine_arm_virt);qos_node_contains ("arm/virt" ,"virtio-mmio" ,NULL ); + +qos_node_create_machine_args ("aarch64/virt" , qos_create_machine_arm_virt, +" -cpu max" ); +qos_node_contains ("aarch64/virt" ,"generic-pcihost" ,NULL ); } -libqos_init (virtio_mmio_register_nodes); +libqos_init (virt_machine_register_nodes);tests/qtest/libqos/generic-pcihost.c new file +156
-0@@ -0,0 +1,231 @@ +/* +* libqos PCI bindings for generic PCI +* +* Copyright Red Hat Inc., 2022 +* +* Authors: +* Eric Auger <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "generic-pcihost.h" +#include "qapi/qmp/qdict.h" +#include "hw/pci/pci_regs.h" + +#include "qemu/module.h" + +/* QGenericPCIHost */ + +QOSGraphObject *generic_pcihost_get_device (void *obj,const char *device) +{ +QGenericPCIHost *host = obj; +if (!g_strcmp0 (device,"pci-bus-generic" )) { +return &host->pci.obj; + } +fprintf (stderr,"%s not present in generic-pcihost\n" , device); +g_assert_not_reached (); +} + +void qos_create_generic_pcihost (QGenericPCIHost *host, +QTestState *qts, +QGuestAllocator *alloc) +{ + host->obj.get_device = generic_pcihost_get_device; +qpci_init_generic (&host->pci, qts, alloc, false); +} + +static uint8_t qpci_generic_pio_readb (QPCIBus *bus,uint32_t addr) +{ +QGenericPCIBus *s =container_of (bus, QGenericPCIBus, bus); + +return qtest_readb (bus->qts, s->gpex_pio_base + addr); +} + +static void qpci_generic_pio_writeb (QPCIBus *bus,uint32_t addr,uint8_t val) +{ +QGenericPCIBus *s =container_of (bus, QGenericPCIBus, bus); + +qtest_writeb (bus->qts, s->gpex_pio_base + addr, val); +} + +static uint16_t qpci_generic_pio_readw (QPCIBus *bus,uint32_t addr) +{ +QGenericPCIBus *s =container_of (bus, QGenericPCIBus, bus); + +return qtest_readw (bus->qts, s->gpex_pio_base + addr); +} + +static void qpci_generic_pio_writew (QPCIBus *bus,uint32_t addr,uint16_t val) +{ +QGenericPCIBus *s =container_of (bus, QGenericPCIBus, bus); + +qtest_writew (bus->qts, s->gpex_pio_base + addr, val); +} + +static uint32_t qpci_generic_pio_readl (QPCIBus *bus,uint32_t addr) +{ +QGenericPCIBus *s =container_of (bus, QGenericPCIBus, bus); + +return qtest_readl (bus->qts, s->gpex_pio_base + addr); +} + +static void qpci_generic_pio_writel (QPCIBus *bus,uint32_t addr,uint32_t val) +{ +QGenericPCIBus *s =container_of (bus, QGenericPCIBus, bus); + +qtest_writel (bus->qts, s->gpex_pio_base + addr, val); +} + +static uint64_t qpci_generic_pio_readq (QPCIBus *bus,uint32_t addr) +{ +QGenericPCIBus *s =container_of (bus, QGenericPCIBus, bus); + +return qtest_readq (bus->qts, s->gpex_pio_base + addr); +} + +static void qpci_generic_pio_writeq (QPCIBus *bus,uint32_t addr,uint64_t val) +{ +QGenericPCIBus *s =container_of (bus, QGenericPCIBus, bus); + +qtest_writeq (bus->qts, s->gpex_pio_base + addr, val); +} + +static void qpci_generic_memread (QPCIBus *bus,uint32_t addr,void *buf,size_t len) +{ +qtest_memread (bus->qts, addr, buf, len); +} + +static void qpci_generic_memwrite (QPCIBus *bus,uint32_t addr, +const void *buf,size_t len) +{ +qtest_memwrite (bus->qts, addr, buf, len); +} + +static uint8_t qpci_generic_config_readb (QPCIBus *bus,int devfn,uint8_t offset) +{ +QGenericPCIBus *gbus =container_of (bus, QGenericPCIBus, bus); +uint64_t addr = gbus->ecam_alloc_ptr + ((0 <<20 ) | (devfn <<12 ) | offset); +uint8_t val; + +qtest_memread (bus->qts, addr, &val,1 ); +return val; +} + +static uint16_t qpci_generic_config_readw (QPCIBus *bus,int devfn,uint8_t offset) +{ +QGenericPCIBus *gbus =container_of (bus, QGenericPCIBus, bus); +uint64_t addr = gbus->ecam_alloc_ptr + ((0 <<20 ) | (devfn <<12 ) | offset); +uint16_t val; + +qtest_memread (bus->qts, addr, &val,2 ); +return val; +} + +static uint32_t qpci_generic_config_readl (QPCIBus *bus,int devfn,uint8_t offset) +{ +QGenericPCIBus *gbus =container_of (bus, QGenericPCIBus, bus); +uint64_t addr = gbus->ecam_alloc_ptr + ((0 <<20 ) | (devfn <<12 ) | offset); +uint32_t val; + +qtest_memread (bus->qts, addr, &val,4 ); +return val; +} + +static void +qpci_generic_config_writeb (QPCIBus *bus,int devfn,uint8_t offset,uint8_t value) +{ +QGenericPCIBus *gbus =container_of (bus, QGenericPCIBus, bus); +uint64_t addr = gbus->ecam_alloc_ptr + ((0 <<20 ) | (devfn <<12 ) | offset); +uint32_t val = value; + +qtest_memwrite (bus->qts, addr, &val,1 ); +} + +static void +qpci_generic_config_writew (QPCIBus *bus,int devfn,uint8_t offset,uint16_t value) +{ +QGenericPCIBus *gbus =container_of (bus, QGenericPCIBus, bus); +uint64_t addr = gbus->ecam_alloc_ptr + ((0 <<20 ) | (devfn <<12 ) | offset); +uint32_t val = value; + +qtest_memwrite (bus->qts, addr, &val,2 ); +}
tests/qtest/libqos/generic-pcihost.c line 166
Quoted 10 lines
tests/qtest/libqos/generic-pcihost.c new file +10
-0+ +static void +qpci_generic_config_writel (QPCIBus *bus,int devfn,uint8_t offset,uint32_t value) +{ +QGenericPCIBus *gbus =container_of (bus, QGenericPCIBus, bus); +uint64_t addr = gbus->ecam_alloc_ptr + ((0 <<20 ) | (devfn <<12 ) | offset); +uint32_t val = value; + +qtest_memwrite (bus->qts, addr, &val,4 ); +}
It does not looks like there's any treatment of endian-ness here, I suspect (not sure, this is just from a quick look) that this is why it fails on powerpc.
Quoted 139 lines
tests/qtest/libqos/generic-pcihost.c new file +65
-0+ +static void *qpci_generic_get_driver (void *obj,const char *interface) +{ +QGenericPCIBus *qpci = obj; +if (!g_strcmp0 (interface,"pci-bus" )) { +return &qpci->bus; + } +fprintf (stderr,"%s not present in pci-bus-generic\n" , interface); +g_assert_not_reached (); +} + +void qpci_init_generic (QGenericPCIBus *qpci,QTestState *qts, +QGuestAllocator *alloc,bool hotpluggable) +{ +assert (qts); + + qpci->gpex_pio_base =0x3eff0000 ; + qpci->bus.not_hotpluggable = !hotpluggable; + qpci->bus.has_buggy_msi = false; + + qpci->bus.pio_readb = qpci_generic_pio_readb; + qpci->bus.pio_readw = qpci_generic_pio_readw; + qpci->bus.pio_readl = qpci_generic_pio_readl; + qpci->bus.pio_readq = qpci_generic_pio_readq; + + qpci->bus.pio_writeb = qpci_generic_pio_writeb; + qpci->bus.pio_writew = qpci_generic_pio_writew; + qpci->bus.pio_writel = qpci_generic_pio_writel; + qpci->bus.pio_writeq = qpci_generic_pio_writeq; + + qpci->bus.memread = qpci_generic_memread; + qpci->bus.memwrite = qpci_generic_memwrite; + + qpci->bus.config_readb = qpci_generic_config_readb; + qpci->bus.config_readw = qpci_generic_config_readw; + qpci->bus.config_readl = qpci_generic_config_readl; + + qpci->bus.config_writeb = qpci_generic_config_writeb; + qpci->bus.config_writew = qpci_generic_config_writew; + qpci->bus.config_writel = qpci_generic_config_writel; + + qpci->bus.qts = qts; + qpci->bus.pio_alloc_ptr =0x0000 ; + qpci->bus.pio_limit =0x10000 ; + qpci->bus.mmio_alloc_ptr =0x10000000 ; + qpci->bus.mmio_limit =0x2eff0000 ; + qpci->ecam_alloc_ptr =0x4010000000 ; + + qpci->obj.get_driver = qpci_generic_get_driver; +} + +static void qpci_generic_register_nodes (void ) +{ +qos_node_create_driver ("pci-bus-generic" ,NULL ); +qos_node_produces ("pci-bus-generic" ,"pci-bus" ); +} + +static void qpci_generic_pci_register_nodes (void ) +{ +qos_node_create_driver ("generic-pcihost" ,NULL ); +qos_node_contains ("generic-pcihost" ,"pci-bus-generic" ,NULL ); +} + +libqos_init (qpci_generic_register_nodes); +libqos_init (qpci_generic_pci_register_nodes);tests/qtest/libqos/generic-pcihost.h new file +54
-0@@ -0,0 +1,54 @@ +/* +* libqos Generic PCI bindings and generic pci host bridge +* +* Copyright Red Hat Inc., 2022 +* +* Authors: +* Eric Auger <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef LIBQOS_GENERIC_PCIHOST_H +#define LIBQOS_GENERIC_PCIHOST_H + +#include "pci.h" +#include "malloc.h" +#include "qgraph.h" + +typedef struct QGenericPCIBus { +QOSGraphObject obj; +QPCIBus bus; +uint64_t gpex_pio_base; +uint64_t ecam_alloc_ptr; +}QGenericPCIBus ; + +/* +* qpci_init_generic(): +* @ret: A valid QGenericPCIBus * pointer +* @qts: The %QTestState +* @alloc: A previously initialized @alloc providing memory for @qts +* @bool: devices can be hotplugged on this bus +* +* This function initializes an already allocated +* QGenericPCIBus object. +*/ +void qpci_init_generic (QGenericPCIBus *ret,QTestState *qts, +QGuestAllocator *alloc,bool hotpluggable); + +/* QGenericPCIHost */ + +typedef struct QGenericPCIHost QGenericPCIHost ; + +struct QGenericPCIHost { +QOSGraphObject obj; +QGenericPCIBus pci; +}; + +QOSGraphObject *generic_pcihost_get_device (void *obj,const char *device); +void qos_create_generic_pcihost (QGenericPCIHost *host, +QTestState *qts, +QGuestAllocator *alloc); + +#endif tests/qtest/libqos/meson.build +1
-0@@ -42,6 +42,7 @@ libqos_srcs = files('../libqtest.c', 'virtio-scsi.c', 'virtio-serial.c', 'virtio-iommu.c', + 'generic-pcihost.c', # qgraph machines: 'aarch64-xlnx-zcu102-machine.c',Signature · 1 line
2.26.3
Quoted 41 lines · Eric Auger
Up to now the virt-machine node only contains a virtio-mmio driver node but no driver that eventually produces any pci-bus interface.
Hence, PCI libqos tests cannot be run with aarch64 binary.
This series brings the pieces needed to be able to run PCI tests with the aarch64 binary: a generic-pcihost driver node gets instantiated by the machine. This later contains a pci-bus-generic driver which produces a pci-bus interface. Then all tests consuming the pci-bus interface can be run with the libqos arm virt machine.
One of the first goal was to be able to run the virtio-iommu-pci tests as the virtio-iommu was initially targetting ARM and it was awkard to be run the test with the pc machine. This is now possible.
Only the tests doing hotplug cannot be run yet as hotplug is not possible on the root bus. This will be dealt with separately by adding a root port to the object tree.
Also I have some trouble with 2 of the vhost-user-blk-tests. I am obliged to hack them in "tests/qtest/vhost-user-blk-test: Temporary hack to get tests passing on aarch64". Looks like a memory allocation issue, which at first sight seems unrelated to the aarch64 pci libqos enablement but we are never sure. Calling for help on this issue, if some vhost-user specialists can dedicate some cycles on this. Otherwise I will try my best to further debug.
To reproduce the issue, revert the above hack and run
QTEST_QEMU_STORAGE_DAEMON_BINARY=build/storage-daemon/qemu-storage-daemon QTEST_QEMU_BINARY=build/aarch64-softmmu/qemu-system-aarch64 build/tests/qtest/qos-test
you should get:
ERROR:../tests/qtest/libqos/virtio.c:224:qvirtio_wait_used_elem: assertion failed (got_desc_idx == desc_idx): (50331648 == 0) Bail out! ERROR:../tests/qtest/libqos/virtio.c:224: qvirtio_wait_used_elem: assertion failed (got_desc_idx == desc_idx): (50331648 == 0)
Quoted 6 lines
Best Regards
Eric
This series can be found at:
https://github.com/eauger/qemu/tree/libqos-pci-arm-v3
Seems to cause issues when run on a powerpc host (see Peter's response to the pull request).
Dropped from pull for now.
Quoted 53 lines
History
v2 -> v3:
- force -cpu=max along with aarch64/virt
- reduced the vhost-user-block-pci issue workaround to a singleguest_alloc()instead of enabling MSIs. Call for help on this specific issue. The 2 tests which fail otherwise
are:test_basicand indirect.v1 -> v2:
- copyright updated to 2022
- QPCIBusARM renamed into QGenericPCIBus
- QGenericPCIHost declarations and definitions moved in the same place as the generic pci implementation
- rename pci-arm.c/h in generic-pcihost.c/h and remove any ref to ARM there
- removeqos_node_produces_opts,qpci_new_arm,qpci_free_arm
-ecam_alloc_ptrnow is a field of QGenericPCIBus and not QPCIBus
- newlibqos_initto create generic-pcihost driver that contains pci-bus-generic
- QGenericPCIHost moved in the same place as the generic pci bindings
- collected Thomas A-b/R-bEric Auger (5):
tests/qtest/vhost-user-test.c: Use vhostforce=on tests/qtest/libqos/pci: Introducepio_limittests/qtest/libqos: Skip hotplug tests if pci root bus is not
hotpluggable
tests/qtest/vhost-user-blk-test: Temporary hack to get tests passing
on aarch64
tests/qtest/libqos: Add generic pci host bridge in arm-virt machinetests/qtest/e1000e-test.c | 6 + tests/qtest/libqos/arm-virt-machine.c | 19 ++- tests/qtest/libqos/generic-pcihost.c | 231 ++++++++++++++++++++++++++ tests/qtest/libqos/generic-pcihost.h | 54 ++++++ tests/qtest/libqos/meson.build | 1 + tests/qtest/libqos/pci-pc.c | 1 + tests/qtest/libqos/pci-spapr.c | 1 + tests/qtest/libqos/pci.c | 78 +++++---- tests/qtest/libqos/pci.h | 6 +- tests/qtest/vhost-user-blk-test.c | 16 ++ tests/qtest/vhost-user-test.c | 2 +- tests/qtest/virtio-blk-test.c | 5 + tests/qtest/virtio-net-test.c | 5 + tests/qtest/virtio-rng-test.c | 5 + 14 files changed, 394 insertions(+), 36 deletions(-) create mode 100644 tests/qtest/libqos/generic-pcihost.c create mode 100644 tests/qtest/libqos/generic-pcihost.hSignature · 1 line
2.26.3