tests: qtest: Add virtio-iommu test
PATCH v2 1/1 tests: qtest: Add virtio-iommu test
Add the framework to test the virtio-iommu-pci device and tests exercising the attach/detach, map/unmap API.
---
This applies on top of jean-Philippe's
[PATCH v4 00/11] virtio-iommu: Add ACPI support
branch can be found at:
https://github.com/eauger/qemu.git
branch qtest-virtio-iommu-v2
To run the tests:
make tests/qtest/qos-test
cd build
QTEST_QEMU_STORAGE_DAEMON_BINARY=./storage-daemon/qemu-storage-daemon QTEST_QEMU_BINARY=x86_64-softmmu/qemu-system-x86_64 tests/qtest/qos-test
v1 -> v2:
- fix the license info (Thomas)
- use UINT64_MAX (Philippe)
--- tests/qtest/libqos/meson.build | 1 + tests/qtest/libqos/virtio-iommu.c | 172 +++++++++++++++++ tests/qtest/libqos/virtio-iommu.h | 40 ++++ tests/qtest/meson.build | 1 + tests/qtest/virtio-iommu-test.c | 299 ++++++++++++++++++++++++++++++ 5 files changed, 513 insertions(+) create mode 100644 tests/qtest/libqos/virtio-iommu.c create mode 100644 tests/qtest/libqos/virtio-iommu.h create mode 100644 tests/qtest/virtio-iommu-test.c
tests/qtest/libqos/meson.build +1 -0
@@ -40,6 +40,7 @@ libqos_srcs = files('../libqtest.c', 'virtio-rng.c', 'virtio-scsi.c', 'virtio-serial.c', + 'virtio-iommu.c', # qgraph machines: 'aarch64-xlnx-zcu102-machine.c',
tests/qtest/libqos/virtio-iommu.c new file +172 -0
172 lines not on this page · raw message
tests/qtest/libqos/virtio-iommu.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* libqos driver virtio-iommu-pci framework +* +* Copyright (c) 2021 Red Hat, Inc. +* +* Authors: +* Eric Auger <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or (at your +* option) any later version. See the COPYING file in the top-level directory. +* +*/ + +#ifndef TESTS_LIBQOS_VIRTIO_IOMMU_H +#define TESTS_LIBQOS_VIRTIO_IOMMU_H + +#include "qgraph.h" +#include "virtio.h" +#include "virtio-pci.h" + +typedef struct QVirtioIOMMU QVirtioIOMMU ; +typedef struct QVirtioIOMMUPCI QVirtioIOMMUPCI ; +typedef struct QVirtioIOMMUDevice QVirtioIOMMUDevice ; + +struct QVirtioIOMMU { +QVirtioDevice *vdev; +QVirtQueue *vq; +}; + +struct QVirtioIOMMUPCI { +QVirtioPCIDevice pci_vdev; +QVirtioIOMMU iommu; +}; + +struct QVirtioIOMMUDevice { +QOSGraphObject obj; +QVirtioIOMMU iommu; +}; + +#endif
tests/qtest/meson.build +1 -0
@@ -230,6 +230,7 @@ qos_test_ss.add( 'virtio-rng-test.c', 'virtio-scsi-test.c', 'virtio-serial-test.c', + 'virtio-iommu-test.c', 'vmxnet3-test.c', ) if have_virtfs
tests/qtest/virtio-iommu-test.c new file +299 -0
299 lines not on this page · raw message
Signature · 1 line
2.26.3
Quoted 6 lines · Eric Auger
Add the framework to test the virtio-iommu-pci device and tests exercising the attach/detach, map/unmap API.
Signed-off-by Eric Auger <[email protected]>---
...
Quoted 29 lines
tests/qtest/virtio-iommu-test.c new file +29
-0+/** +* send_map - Send a map command to the device +* @domain: domain the new binding is attached to +* @virt_start: iova start +* @virt_end: iova end +* @phys_start: base physical address +* @flags: mapping flags +*/ +static int send_map (QTestState *qts,QVirtioIOMMU *v_iommu, +uint32_t domain,uint64_t virt_start,uint64_t virt_end, +uint64_t phys_start,uint32_t flags) +{ +QVirtioDevice *dev = v_iommu->vdev; +QVirtQueue *vq = v_iommu->vq; +uint64_t ro_addr, wr_addr; +uint32_t free_head; +struct virtio_iommu_req_map req; +size_t ro_size =sizeof (req) -sizeof (struct virtio_iommu_req_tail ); +size_t wr_size =sizeof (struct virtio_iommu_req_tail ); +char buffer[64 ]; +int ret; + + req.head.type =VIRTIO_IOMMU_T_MAP ; + req.domain = domain; + req.virt_start = virt_start; + req.virt_end = virt_end; + req.phys_start = phys_start; + req.flags = flags; +
tests/qtest/virtio-iommu-test.c line 118
Quoted 10 lines
tests/qtest/virtio-iommu-test.c new file +10
-0+ ro_addr =guest_alloc (alloc, ro_size); + wr_addr =guest_alloc (alloc, wr_size); + +qtest_memwrite (qts, ro_addr, &req, ro_size); + free_head =qvirtqueue_add (qts, vq, ro_addr, ro_size, false, true); +qvirtqueue_add (qts, vq, wr_addr, wr_size, true, false); +qvirtqueue_kick (qts, dev, vq, free_head); +qvirtio_wait_used_elem (qts, dev, vq, free_head,NULL , +QVIRTIO_IOMMU_TIMEOUT_US ); +memread (wr_addr, buffer, wr_size);
qtest_memread() please.
Quoted 30 lines
tests/qtest/virtio-iommu-test.c new file +30
-0+ ret = ((struct virtio_iommu_req_tail *)buffer)->status; +guest_free (alloc, ro_addr); +guest_free (alloc, wr_addr); +return ret; +} + +/** +* send_unmap - Send an unmap command to the device +* @domain: domain the new binding is attached to +* @virt_start: iova start +* @virt_end: iova end +*/ +static int send_unmap (QTestState *qts,QVirtioIOMMU *v_iommu, +uint32_t domain,uint64_t virt_start,uint64_t virt_end) +{ +QVirtioDevice *dev = v_iommu->vdev; +QVirtQueue *vq = v_iommu->vq; +uint64_t ro_addr, wr_addr; +uint32_t free_head; +struct virtio_iommu_req_unmap req; +size_t ro_size =sizeof (req) -sizeof (struct virtio_iommu_req_tail ); +size_t wr_size =sizeof (struct virtio_iommu_req_tail ); +char buffer[64 ]; +int ret; + + req.head.type =VIRTIO_IOMMU_T_UNMAP ; + req.domain = domain; + req.virt_start = virt_start; + req.virt_end = virt_end; +
tests/qtest/virtio-iommu-test.c line 158
Quoted 10 lines
tests/qtest/virtio-iommu-test.c new file +10
-0+ ro_addr =guest_alloc (alloc, ro_size); + wr_addr =guest_alloc (alloc, wr_size); + +qtest_memwrite (qts, ro_addr, &req, ro_size); + free_head =qvirtqueue_add (qts, vq, ro_addr, ro_size, false, true); +qvirtqueue_add (qts, vq, wr_addr, wr_size, true, false); +qvirtqueue_kick (qts, dev, vq, free_head); +qvirtio_wait_used_elem (qts, dev, vq, free_head,NULL , +QVIRTIO_IOMMU_TIMEOUT_US ); +memread (wr_addr, buffer, wr_size);
qtest_memread() please.
tests/qtest/virtio-iommu-test.c line 78
Quoted 5 lines
tests/qtest/virtio-iommu-test.c new file +5
-0+ ret = ((struct virtio_iommu_req_tail *)buffer)->status; +guest_free (alloc, ro_addr); +guest_free (alloc, wr_addr); +return ret; +}
With the two memread()s changed into qtest_memread()s:
Hi Thomas,
Quoted 43 lines · Thomas Huth
Quoted 6 lines · Eric Auger
Add the framework to test the virtio-iommu-pci device and tests exercising the attach/detach, map/unmap API.
Signed-off-by Eric Auger <[email protected]>---
...
Quoted 35 lines
tests/qtest/virtio-iommu-test.c new file +10
-0+/** +* send_map - Send a map command to the device +* @domain: domain the new binding is attached to +* @virt_start: iova start +* @virt_end: iova end +* @phys_start: base physical address +* @flags: mapping flags +*/ +static int send_map (QTestState *qts,QVirtioIOMMU *v_iommu, + uint32_t domain, uint64_t virt_start, uint64_t
virt_end,
+uint64_tphys_start,uint32_tflags) +{
+ QVirtioDevice *dev =v_iommu->vdev;
+ QVirtQueue *vq =v_iommu->vq;
+uint64_tro_addr,wr_addr;
+uint32_tfree_head;
+ structvirtio_iommu_req_mapreq;
+size_tro_size= sizeof(req) -sizeof(struct virtio_iommu_req_tail);
+size_twr_size=sizeof(struct virtio_iommu_req_tail); + char buffer[64];
+ int ret;tests/qtest/virtio-iommu-test.c new file +12
-0+ + req.head.type = VIRTIO_IOMMU_T_MAP; + req.domain = domain; + req.virt_start = virt_start; + req.virt_end = virt_end; + req.phys_start = phys_start; + req.flags = flags; + + ro_addr = guest_alloc(alloc, ro_size); + wr_addr = guest_alloc(alloc, wr_size); + + qtest_memwrite(qts, ro_addr, &req, ro_size);
Quoted 8 lines
Quoted 6 lines
+
free_head=qvirtqueue_add(qts, vq, ro_addr, ro_size, false, true); +qvirtqueue_add(qts, vq, wr_addr, wr_size, true, false); +qvirtqueue_kick(qts, dev, vq, free_head);
+ qvirtio_wait_used_elem(qts, dev, vq,free_head, NULL,
+QVIRTIO_IOMMU_TIMEOUT_US);
+memread(wr_addr, buffer, wr_size);
qtest_memread()please.
My apologies, I forgot those qtest_memread() comment and the char buffer[64] replacement too :-(
Quoted 52 lines
Quoted 33 lines
+ ret = ((struct
virtio_iommu_req_tail*)buffer)->status; +guest_free(alloc, ro_addr);
+guest_free(alloc, wr_addr);
+ return ret;tests/qtest/virtio-iommu-test.c new file +10
-0+} + +/** +* send_unmap - Send an unmap command to the device +* @domain: domain the new binding is attached to +* @virt_start: iova start +* @virt_end: iova end +*/ +static int send_unmap (QTestState *qts,QVirtioIOMMU *v_iommu, + uint32_t domain, uint64_t virt_start, uint64_t
virt_end)
+{
+ QVirtioDevice *dev =v_iommu->vdev;
+ QVirtQueue *vq =v_iommu->vq;
+uint64_tro_addr,wr_addr;
+uint32_tfree_head;
+ structvirtio_iommu_req_unmapreq;
+size_tro_size= sizeof(req) -sizeof(struct virtio_iommu_req_tail);
+size_twr_size=sizeof(struct virtio_iommu_req_tail); + char buffer[64];
+ int ret;tests/qtest/virtio-iommu-test.c new file +6
-0+ + req.head.type = VIRTIO_IOMMU_T_UNMAP; + req.domain = domain; + req.virt_start = virt_start; + req.virt_end = virt_end; +tests/qtest/virtio-iommu-test.c line 158
Quoted 10 lines
tests/qtest/virtio-iommu-test.c new file +10
-0+ ro_addr = guest_alloc(alloc, ro_size); + wr_addr = guest_alloc(alloc, wr_size); + + qtest_memwrite(qts, ro_addr, &req, ro_size); + free_head = qvirtqueue_add(qts, vq, ro_addr, ro_size, false, true); + qvirtqueue_add(qts, vq, wr_addr, wr_size, true, false); + qvirtqueue_kick(qts, dev, vq, free_head); + qvirtio_wait_used_elem(qts, dev, vq, free_head, NULL, + QVIRTIO_IOMMU_TIMEOUT_US); + memread(wr_addr, buffer, wr_size);
qtest_memread()please.Quoted 5 lines
+ ret = ((struct
virtio_iommu_req_tail*)buffer)->status; +guest_free(alloc, ro_addr);
+guest_free(alloc, wr_addr);
+ return ret;
+}
Quoted 3 lines
With the two memread()s changed into qtest_memread()s:
Acked-by Thomas Huth <[email protected]>
Thank you for your patience!
Eric