libqos: Virtio MMIO driver
v3 cover libqos: Virtio MMIO driver
Add virtio-mmio support to libqos and test case for virtio-blk.
This series depends on patch "libqos: Convert malloc-pc allocator to a generic allocator"
Changes from version 2:
- Fix leaks and minor bugs
- Extract basic test case to a function
Marc Marí (5):
libqos: Change use of pointers to uint64_t in virtio
tests: Prepare virtio-blk-test for multi-arch implementation
libqos: Remove PCI assumptions in constants of virtio driver
libqos: Add malloc generic
libqos: Add virtio MMIO support
tests/Makefile | 4 +- tests/libqos/malloc-generic.c | 50 +++++++++ tests/libqos/malloc-generic.h | 21 ++++ tests/libqos/virtio-mmio.c | 190 +++++++++++++++++++++++++++++++ tests/libqos/virtio-mmio.h | 46 ++++++++ tests/libqos/virtio-pci.c | 50 +++++---- tests/libqos/virtio-pci.h | 24 ++-- tests/libqos/virtio.c | 8 +- tests/libqos/virtio.h | 16 +-- tests/virtio-blk-test.c | 249 ++++++++++++++++++++++++++++------------- 10 files changed, 534 insertions(+), 124 deletions(-) create mode 100644 tests/libqos/malloc-generic.c create mode 100644 tests/libqos/malloc-generic.h create mode 100644 tests/libqos/virtio-mmio.c create mode 100644 tests/libqos/virtio-mmio.h
Signature · 1 line
1.7.10.4
PATCH v3 1/5 libqos: Change use of pointers to uint64_t in virtio
Convert use of pointers in functions of virtio to uint64_t in order to make it platform-independent.
Add casting from pointers (in PCI functions) to uint64_t and vice versa through uintptr_t.
--- tests/libqos/virtio-pci.c | 20 +++++++++++--------- tests/libqos/virtio.c | 8 ++++---- tests/libqos/virtio.h | 16 ++++++++-------- tests/virtio-blk-test.c | 21 ++++++++++++++------- 4 files changed, 37 insertions(+), 28 deletions(-)
tests/libqos/virtio-pci.c +11 -9
@@ -60,25 +60,25 @@ static void qvirtio_pci_assign_device(QVirtioDevice *d, void *data) *vpcidev = (QVirtioPCIDevice *)d; } -static uint8_t qvirtio_pci_config_readb (QVirtioDevice *d,void *addr) +static uint8_t qvirtio_pci_config_readb (QVirtioDevice *d,uint64_t addr) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -return qpci_io_readb (dev->pdev, addr); +return qpci_io_readb (dev->pdev, (void *)(uintptr_t )addr); } -static uint16_t qvirtio_pci_config_readw (QVirtioDevice *d,void *addr) +static uint16_t qvirtio_pci_config_readw (QVirtioDevice *d,uint64_t addr) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -return qpci_io_readw (dev->pdev, addr); +return qpci_io_readw (dev->pdev, (void *)(uintptr_t )addr); } -static uint32_t qvirtio_pci_config_readl (QVirtioDevice *d,void *addr) +static uint32_t qvirtio_pci_config_readl (QVirtioDevice *d,uint64_t addr) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -return qpci_io_readl (dev->pdev, addr); +return qpci_io_readl (dev->pdev, (void *)(uintptr_t )addr); } -static uint64_t qvirtio_pci_config_readq (QVirtioDevice *d,void *addr) +static uint64_t qvirtio_pci_config_readq (QVirtioDevice *d,uint64_t addr) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d;int i;
@@ -86,11 +86,13 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, void *addr)if (qtest_big_endian ()) {for (i =0 ; i <8 ; ++i) { - u64 |= (uint64_t )qpci_io_readb (dev->pdev, addr + i) << (7 - i) *8 ; + u64 |= (uint64_t )qpci_io_readb (dev->pdev, + (void *)(uintptr_t )addr + i) << (7 - i) *8 ; } }else {for (i =0 ; i <8 ; ++i) { - u64 |= (uint64_t )qpci_io_readb (dev->pdev, addr + i) << i *8 ; + u64 |= (uint64_t )qpci_io_readb (dev->pdev, + (void *)(uintptr_t )addr + i) << i *8 ; } }
tests/libqos/virtio.c +4 -4
@@ -12,25 +12,25 @@#include "libqos/virtio.h" uint8_t qvirtio_config_readb (const QVirtioBus *bus,QVirtioDevice *d, -void *addr) +uint64_t addr) {return bus->config_readb (d, addr); }uint16_t qvirtio_config_readw (const QVirtioBus *bus,QVirtioDevice *d, -void *addr) +uint64_t addr) {return bus->config_readw (d, addr); }uint32_t qvirtio_config_readl (const QVirtioBus *bus,QVirtioDevice *d, -void *addr) +uint64_t addr) {return bus->config_readl (d, addr); }uint64_t qvirtio_config_readq (const QVirtioBus *bus,QVirtioDevice *d, -void *addr) +uint64_t addr) {return bus->config_readq (d, addr); }
tests/libqos/virtio.h +8 -8
@@ -93,10 +93,10 @@ typedef struct QVRingIndirectDesc { } QVRingIndirectDesc; typedef struct QVirtioBus { - uint8_t (*config_readb)(QVirtioDevice *d, void *addr); - uint16_t (*config_readw)(QVirtioDevice *d, void *addr); - uint32_t (*config_readl)(QVirtioDevice *d, void *addr); - uint64_t (*config_readq)(QVirtioDevice *d, void *addr); + uint8_t (*config_readb)(QVirtioDevice *d, uint64_t addr); + uint16_t (*config_readw)(QVirtioDevice *d, uint64_t addr); + uint32_t (*config_readl)(QVirtioDevice *d, uint64_t addr); + uint64_t (*config_readq)(QVirtioDevice *d, uint64_t addr); /* Get features of the device */ uint32_t (*get_features)(QVirtioDevice *d);
@@ -144,13 +144,13 @@ static inline uint32_t qvring_size(uint32_t num, uint32_t align) }uint8_t qvirtio_config_readb (const QVirtioBus *bus,QVirtioDevice *d, -void *addr); +uint64_t addr);uint16_t qvirtio_config_readw (const QVirtioBus *bus,QVirtioDevice *d, -void *addr); +uint64_t addr);uint32_t qvirtio_config_readl (const QVirtioBus *bus,QVirtioDevice *d, -void *addr); +uint64_t addr);uint64_t qvirtio_config_readq (const QVirtioBus *bus,QVirtioDevice *d, -void *addr); +uint64_t addr);uint32_t qvirtio_get_features (const QVirtioBus *bus,QVirtioDevice *d);void qvirtio_set_features (const QVirtioBus *bus,QVirtioDevice *d,uint32_t features);
tests/virtio-blk-test.c +14 -7
@@ -157,7 +157,8 @@ static void pci_basic(void)/* MSI-X is not enabled */ addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_NO_MSIX ; - capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, addr); + capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, + (uint64_t )(uintptr_t )addr); g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); features =qvirtio_get_features (&qvirtio_pci, &dev->vdev);
@@ -303,7 +304,8 @@ static void pci_indirect(void)/* MSI-X is not enabled */ addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_NO_MSIX ; - capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, addr); + capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, + (uint64_t )(uintptr_t )addr); g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); features =qvirtio_get_features (&qvirtio_pci, &dev->vdev);
@@ -394,7 +396,8 @@ static void pci_config(void)/* MSI-X is not enabled */ addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_NO_MSIX ; - capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, addr); + capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, + (uint64_t )(uintptr_t )addr); g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512);qvirtio_set_driver_ok (&qvirtio_pci, &dev->vdev);
@@ -403,7 +406,8 @@ static void pci_config(void) " 'size': %d } }", n_size);qvirtio_wait_config_isr (&qvirtio_pci, &dev->vdev,QVIRTIO_BLK_TIMEOUT_US ); - capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, addr); + capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, + (uint64_t )(uintptr_t )addr); g_assert_cmpint(capacity, ==, n_size / 512);qvirtio_pci_device_disable (dev);
@@ -438,7 +442,8 @@ static void pci_msix(void)/* MSI-X is enabled */ addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_MSIX ; - capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, addr); + capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, + (uint64_t )(uintptr_t )addr); g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); features =qvirtio_get_features (&qvirtio_pci, &dev->vdev);
@@ -458,7 +463,8 @@ static void pci_msix(void)qvirtio_wait_config_isr (&qvirtio_pci, &dev->vdev,QVIRTIO_BLK_TIMEOUT_US ); - capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, addr); + capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, + (uint64_t )(uintptr_t )addr); g_assert_cmpint(capacity, ==, n_size / 512);/* Write request */
@@ -547,7 +553,8 @@ static void pci_idx(void)/* MSI-X is enabled */ addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_MSIX ; - capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, addr); + capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, + (uint64_t )(uintptr_t )addr); g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); features =qvirtio_get_features (&qvirtio_pci, &dev->vdev);
Signature · 1 line
1.7.10.4
PATCH v3 2/5 tests: Prepare virtio-blk-test for multi-arch implementation
In reply to Marc MaríModularize functions in virtio-blk-test and add PCI suffix for PCI specific components.
--- tests/virtio-blk-test.c | 146 +++++++++++++++++++++++++++-------------------- 1 file changed, 85 insertions(+), 61 deletions(-)
tests/virtio-blk-test.c +85 -61
@@ -55,11 +55,10 @@ typedef struct QVirtioBlkReq {uint8_t status; } QVirtioBlkReq; -static QPCIBus *test_start (void ) +static char *drive_create (void ) { -char *cmdline; -char tmp_path[] ="/tmp/qtest.XXXXXX" ;int fd, ret; +char *tmp_path =g_strdup ("/tmp/qtest.XXXXXX" );/* Create a temporary raw image */ fd =mkstemp (tmp_path);
@@ -68,6 +67,16 @@ static QPCIBus *test_start(void) g_assert_cmpint(ret, ==, 0);close (fd); +return tmp_path; +} + +static QPCIBus *pci_test_start (void ) +{ +char *cmdline; +char *tmp_path; + + tmp_path =drive_create (); + cmdline =g_strdup_printf ("-drive if=none,id=drive0,file=%s " "-drive if=none,id=drive1,file=/dev/null " "-device virtio-blk-pci,id=drv0,drive=drive0,"
@@ -75,6 +84,7 @@ static QPCIBus *test_start(void) tmp_path, PCI_SLOT, PCI_FN);qtest_start (cmdline);unlink (tmp_path); +g_free (tmp_path);g_free (cmdline);return qpci_init_pc ();
@@ -85,7 +95,7 @@ static void test_end(void)qtest_end (); } -static QVirtioPCIDevice *virtio_blk_init (QPCIBus *bus,int slot) +static QVirtioPCIDevice *virtio_blk_pci_init (QPCIBus *bus,int slot) {QVirtioPCIDevice *dev;
@@ -135,14 +145,10 @@ static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioBlkReq *req,return addr; } -static void pci_basic (void ) +static void test_basic (const QVirtioBus *bus,QVirtioDevice *dev, +QGuestAllocator *alloc,QVirtQueue *vq,uint64_t device_specific) { -QVirtioPCIDevice *dev; -QPCIBus *bus; -QVirtQueuePCI *vqpci; -QGuestAllocator *alloc;QVirtioBlkReq req; -void *addr;uint64_t req_addr;uint64_t capacity;uint32_t features;
@@ -150,28 +156,16 @@ static void pci_basic(void)uint8_t status;char *data; - bus =test_start (); - - dev =virtio_blk_init (bus,PCI_SLOT ); - -/* MSI-X is not enabled */ - addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_NO_MSIX ; - - capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, - (uint64_t )(uintptr_t )addr); + capacity =qvirtio_config_readq (bus, dev, device_specific); g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); - features =qvirtio_get_features (&qvirtio_pci, &dev->vdev); + features =qvirtio_get_features (bus, dev); features = features & ~(QVIRTIO_F_BAD_FEATURE |QVIRTIO_F_RING_INDIRECT_DESC |QVIRTIO_F_RING_EVENT_IDX |QVIRTIO_BLK_F_SCSI ); -qvirtio_set_features (&qvirtio_pci, &dev->vdev, features); +qvirtio_set_features (bus, dev, features); - alloc =pc_alloc_init (); - vqpci = (QVirtQueuePCI *)qvirtqueue_setup (&qvirtio_pci, &dev->vdev, - alloc,0 ); - -qvirtio_set_driver_ok (&qvirtio_pci, &dev->vdev); +qvirtio_set_driver_ok (bus, dev);/* Write and read with 2 descriptor layout */ /* Write request */
@@ -185,12 +179,11 @@ static void pci_basic(void)g_free (req.data); - free_head =qvirtqueue_add (&vqpci->vq, req_addr,528 , false, true); -qvirtqueue_add (&vqpci->vq, req_addr +528 ,1 , true, false); -qvirtqueue_kick (&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head); + free_head =qvirtqueue_add (vq, req_addr,528 , false, true); +qvirtqueue_add (vq, req_addr +528 ,1 , true, false); +qvirtqueue_kick (bus, dev, vq, free_head); -qvirtio_wait_queue_isr (&qvirtio_pci, &dev->vdev, &vqpci->vq, -QVIRTIO_BLK_TIMEOUT_US ); +qvirtio_wait_queue_isr (bus, dev, vq,QVIRTIO_BLK_TIMEOUT_US ); status =readb (req_addr +528 ); g_assert_cmpint(status, ==, 0);
@@ -206,13 +199,12 @@ static void pci_basic(void)g_free (req.data); - free_head =qvirtqueue_add (&vqpci->vq, req_addr,16 , false, true); -qvirtqueue_add (&vqpci->vq, req_addr +16 ,513 , true, false); + free_head =qvirtqueue_add (vq, req_addr,16 , false, true); +qvirtqueue_add (vq, req_addr +16 ,513 , true, false); -qvirtqueue_kick (&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head); +qvirtqueue_kick (bus, dev, vq, free_head); -qvirtio_wait_queue_isr (&qvirtio_pci, &dev->vdev, &vqpci->vq, -QVIRTIO_BLK_TIMEOUT_US ); +qvirtio_wait_queue_isr (bus, dev, vq,QVIRTIO_BLK_TIMEOUT_US ); status =readb (req_addr +528 ); g_assert_cmpint(status, ==, 0);
@@ -233,14 +225,15 @@ static void pci_basic(void) req_addr =virtio_blk_request (alloc, &req,512 ); - free_head =qvirtqueue_add (&vqpci->vq, req_addr,16 , false, true); -qvirtqueue_add (&vqpci->vq, req_addr +16 ,512 , false, true); -qvirtqueue_add (&vqpci->vq, req_addr +528 ,1 , true, false); +g_free (req.data); -qvirtqueue_kick (&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head); + free_head =qvirtqueue_add (vq, req_addr,16 , false, true); +qvirtqueue_add (vq, req_addr +16 ,512 , false, true); +qvirtqueue_add (vq, req_addr +528 ,1 , true, false); -qvirtio_wait_queue_isr (&qvirtio_pci, &dev->vdev, &vqpci->vq, -QVIRTIO_BLK_TIMEOUT_US ); +qvirtqueue_kick (bus, dev, vq, free_head); + +qvirtio_wait_queue_isr (bus, dev, vq,QVIRTIO_BLK_TIMEOUT_US ); status =readb (req_addr +528 ); g_assert_cmpint(status, ==, 0);
@@ -256,14 +249,13 @@ static void pci_basic(void)g_free (req.data); - free_head =qvirtqueue_add (&vqpci->vq, req_addr,16 , false, true); -qvirtqueue_add (&vqpci->vq, req_addr +16 ,512 , true, true); -qvirtqueue_add (&vqpci->vq, req_addr +528 ,1 , true, false); + free_head =qvirtqueue_add (vq, req_addr,16 , false, true); +qvirtqueue_add (vq, req_addr +16 ,512 , true, true); +qvirtqueue_add (vq, req_addr +528 ,1 , true, false); -qvirtqueue_kick (&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head); +qvirtqueue_kick (bus, dev, vq, free_head); -qvirtio_wait_queue_isr (&qvirtio_pci, &dev->vdev, &vqpci->vq, -QVIRTIO_BLK_TIMEOUT_US ); +qvirtio_wait_queue_isr (bus, dev, vq,QVIRTIO_BLK_TIMEOUT_US ); status =readb (req_addr +528 ); g_assert_cmpint(status, ==, 0);
@@ -273,11 +265,35 @@ static void pci_basic(void)g_free (data);guest_free (alloc, req_addr); +} + +static void pci_basic (void ) +{ +QVirtioPCIDevice *dev; +QPCIBus *bus; +QVirtQueuePCI *vqpci; +QGuestAllocator *alloc; +void *addr; + + bus =pci_test_start (); + dev =virtio_blk_pci_init (bus,PCI_SLOT ); + + alloc =pc_alloc_init (); + vqpci = (QVirtQueuePCI *)qvirtqueue_setup (&qvirtio_pci, &dev->vdev, + alloc,0 ); + +/* MSI-X is not enabled */ + addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_NO_MSIX ; + +test_basic (&qvirtio_pci, &dev->vdev, alloc, &vqpci->vq, + (uint64_t )(uintptr_t )addr);/* End test */ guest_free (alloc, vqpci->vq.desc); +pc_alloc_uninit (alloc);qvirtio_pci_device_disable (dev);g_free (dev); +qpci_free_pc (bus);test_end (); }
@@ -297,9 +313,9 @@ static void pci_indirect(void)uint8_t status;char *data; - bus =test_start (); + bus =pci_test_start (); - dev =virtio_blk_init (bus,PCI_SLOT ); + dev =virtio_blk_pci_init (bus,PCI_SLOT );/* MSI-X is not enabled */ addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_NO_MSIX ;
@@ -376,8 +392,10 @@ static void pci_indirect(void)/* End test */ guest_free (alloc, vqpci->vq.desc); +pc_alloc_uninit (alloc);qvirtio_pci_device_disable (dev);g_free (dev); +qpci_free_pc (bus);test_end (); }
@@ -389,9 +407,9 @@ static void pci_config(void)void *addr;uint64_t capacity; - bus =test_start (); + bus =pci_test_start (); - dev =virtio_blk_init (bus,PCI_SLOT ); + dev =virtio_blk_pci_init (bus,PCI_SLOT );/* MSI-X is not enabled */ addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_NO_MSIX ;
@@ -412,6 +430,7 @@ static void pci_config(void)qvirtio_pci_device_disable (dev);g_free (dev); +qpci_free_pc (bus);test_end (); }
@@ -431,10 +450,10 @@ static void pci_msix(void)uint8_t status;char *data; - bus =test_start (); + bus =pci_test_start (); alloc =pc_alloc_init (); - dev =virtio_blk_init (bus,PCI_SLOT ); + dev =virtio_blk_pci_init (bus,PCI_SLOT );qpci_msix_enable (dev->pdev);qvirtio_pci_set_msix_configuration_vector (dev, alloc,0 );
@@ -520,10 +539,12 @@ static void pci_msix(void)guest_free (alloc, req_addr);/* End test */ -guest_free (alloc, (uint64_t )vqpci->vq.desc); +guest_free (alloc, vqpci->vq.desc); +pc_alloc_uninit (alloc);qpci_msix_disable (dev->pdev);qvirtio_pci_device_disable (dev);g_free (dev); +qpci_free_pc (bus);test_end (); }
@@ -542,10 +563,10 @@ static void pci_idx(void)uint8_t status;char *data; - bus =test_start (); + bus =pci_test_start (); alloc =pc_alloc_init (); - dev =virtio_blk_init (bus,PCI_SLOT ); + dev =virtio_blk_pci_init (bus,PCI_SLOT );qpci_msix_enable (dev->pdev);qvirtio_pci_set_msix_configuration_vector (dev, alloc,0 );
@@ -643,30 +664,33 @@ static void pci_idx(void)/* End test */ guest_free (alloc, vqpci->vq.desc); +pc_alloc_uninit (alloc);qpci_msix_disable (dev->pdev);qvirtio_pci_device_disable (dev);g_free (dev); +qpci_free_pc (bus);test_end (); } -static void hotplug (void ) +static void pci_hotplug (void ) {QPCIBus *bus;QVirtioPCIDevice *dev; - bus =test_start (); + bus =pci_test_start ();/* plug secondary disk */ qpci_plug_device_test ("virtio-blk-pci" ,"drv1" ,PCI_SLOT_HP ,"'drive': 'drive1'" ); - dev =virtio_blk_init (bus,PCI_SLOT_HP ); + dev =virtio_blk_pci_init (bus,PCI_SLOT_HP );g_assert (dev);qvirtio_pci_device_disable (dev);g_free (dev);/* unplug secondary disk */ qpci_unplug_acpi_device_test ("drv1" ,PCI_SLOT_HP ); +qpci_free_pc (bus);test_end (); }
@@ -681,7 +705,7 @@ int main(int argc, char **argv)g_test_add_func ("/virtio/blk/pci/config" , pci_config);g_test_add_func ("/virtio/blk/pci/msix" , pci_msix);g_test_add_func ("/virtio/blk/pci/idx" , pci_idx); -g_test_add_func ("/virtio/blk/pci/hotplug" , hotplug); +g_test_add_func ("/virtio/blk/pci/hotplug" , pci_hotplug); ret =g_test_run ();
Signature · 1 line
1.7.10.4
PATCH v3 3/5 libqos: Remove PCI assumptions in constants of virtio driver
In reply to Marc MaríConvert PCI-specific constants names of libqos virtio driver.
--- tests/libqos/virtio-pci.c | 30 +++++++++++++++--------------- tests/libqos/virtio-pci.h | 24 ++++++++++++------------ tests/virtio-blk-test.c | 11 ++++++----- 3 files changed, 33 insertions(+), 32 deletions(-)
tests/libqos/virtio-pci.c +15 -15
@@ -102,31 +102,31 @@ static uint64_t qvirtio_pci_config_readq(QVirtioDevice *d, uint64_t addr)static uint32_t qvirtio_pci_get_features (QVirtioDevice *d) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -return qpci_io_readl (dev->pdev, dev->addr +QVIRTIO_DEVICE_FEATURES ); +return qpci_io_readl (dev->pdev, dev->addr +QVIRTIO_PCI_DEVICE_FEATURES ); }static void qvirtio_pci_set_features (QVirtioDevice *d,uint32_t features) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -qpci_io_writel (dev->pdev, dev->addr +QVIRTIO_GUEST_FEATURES , features); +qpci_io_writel (dev->pdev, dev->addr +QVIRTIO_PCI_GUEST_FEATURES , features); }static uint32_t qvirtio_pci_get_guest_features (QVirtioDevice *d) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -return qpci_io_readl (dev->pdev, dev->addr +QVIRTIO_GUEST_FEATURES ); +return qpci_io_readl (dev->pdev, dev->addr +QVIRTIO_PCI_GUEST_FEATURES ); }static uint8_t qvirtio_pci_get_status (QVirtioDevice *d) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -return qpci_io_readb (dev->pdev, dev->addr +QVIRTIO_DEVICE_STATUS ); +return qpci_io_readb (dev->pdev, dev->addr +QVIRTIO_PCI_DEVICE_STATUS ); }static void qvirtio_pci_set_status (QVirtioDevice *d,uint8_t status) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -qpci_io_writeb (dev->pdev, dev->addr +QVIRTIO_DEVICE_STATUS , status); +qpci_io_writeb (dev->pdev, dev->addr +QVIRTIO_PCI_DEVICE_STATUS , status); }static bool qvirtio_pci_get_queue_isr_status (QVirtioDevice *d,QVirtQueue *vq)
@@ -146,7 +146,7 @@ static bool qvirtio_pci_get_queue_isr_status(QVirtioDevice *d, QVirtQueue *vq)return data == vqpci->msix_data; } }else { -return qpci_io_readb (dev->pdev, dev->addr +QVIRTIO_ISR_STATUS ) &1 ; +return qpci_io_readb (dev->pdev, dev->addr +QVIRTIO_PCI_ISR_STATUS ) &1 ; } }
@@ -166,26 +166,26 @@ static bool qvirtio_pci_get_config_isr_status(QVirtioDevice *d)return data == dev->config_msix_data; } }else { -return qpci_io_readb (dev->pdev, dev->addr +QVIRTIO_ISR_STATUS ) &2 ; +return qpci_io_readb (dev->pdev, dev->addr +QVIRTIO_PCI_ISR_STATUS ) &2 ; } }static void qvirtio_pci_queue_select (QVirtioDevice *d,uint16_t index) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -qpci_io_writeb (dev->pdev, dev->addr +QVIRTIO_QUEUE_SELECT , index); +qpci_io_writeb (dev->pdev, dev->addr +QVIRTIO_PCI_QUEUE_SELECT , index); }static uint16_t qvirtio_pci_get_queue_size (QVirtioDevice *d) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -return qpci_io_readw (dev->pdev, dev->addr +QVIRTIO_QUEUE_SIZE ); +return qpci_io_readw (dev->pdev, dev->addr +QVIRTIO_PCI_QUEUE_SIZE ); }static void qvirtio_pci_set_queue_address (QVirtioDevice *d,uint32_t pfn) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -qpci_io_writel (dev->pdev, dev->addr +QVIRTIO_QUEUE_ADDRESS , pfn); +qpci_io_writel (dev->pdev, dev->addr +QVIRTIO_PCI_QUEUE_ADDRESS , pfn); } static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d,
@@ -227,7 +227,7 @@ static QVirtQueue *qvirtio_pci_virtqueue_setup(QVirtioDevice *d,static void qvirtio_pci_virtqueue_kick (QVirtioDevice *d,QVirtQueue *vq) {QVirtioPCIDevice *dev = (QVirtioPCIDevice *)d; -qpci_io_writew (dev->pdev, dev->addr +QVIRTIO_QUEUE_NOTIFY , vq->index); +qpci_io_writew (dev->pdev, dev->addr +QVIRTIO_PCI_QUEUE_NOTIFY , vq->index); }const QVirtioBus qvirtio_pci = {
@@ -307,8 +307,8 @@ void qvirtqueue_pci_msix_setup(QVirtioPCIDevice *d, QVirtQueuePCI *vqpci, control & ~PCI_MSIX_ENTRY_CTRL_MASKBIT);qvirtio_pci_queue_select (&d->vdev, vqpci->vq.index); -qpci_io_writew (d->pdev, d->addr +QVIRTIO_MSIX_QUEUE_VECTOR , entry); - vector =qpci_io_readw (d->pdev, d->addr +QVIRTIO_MSIX_QUEUE_VECTOR ); +qpci_io_writew (d->pdev, d->addr +QVIRTIO_PCI_MSIX_QUEUE_VECTOR , entry); + vector =qpci_io_readw (d->pdev, d->addr +QVIRTIO_PCI_MSIX_QUEUE_VECTOR ); g_assert_cmphex(vector, !=, QVIRTIO_MSI_NO_VECTOR); }
@@ -339,7 +339,7 @@ void qvirtio_pci_set_msix_configuration_vector(QVirtioPCIDevice *d,qpci_io_writel (d->pdev, addr +PCI_MSIX_ENTRY_VECTOR_CTRL , control & ~PCI_MSIX_ENTRY_CTRL_MASKBIT ); -qpci_io_writew (d->pdev, d->addr +QVIRTIO_MSIX_CONF_VECTOR , entry); - vector =qpci_io_readw (d->pdev, d->addr +QVIRTIO_MSIX_CONF_VECTOR ); +qpci_io_writew (d->pdev, d->addr +QVIRTIO_PCI_MSIX_CONF_VECTOR , entry); + vector =qpci_io_readw (d->pdev, d->addr +QVIRTIO_PCI_MSIX_CONF_VECTOR ); g_assert_cmphex(vector, !=, QVIRTIO_MSI_NO_VECTOR); }
tests/libqos/virtio-pci.h +12 -12
@@ -13,18 +13,18 @@#include "libqos/virtio.h" #include "libqos/pci.h" -#define QVIRTIO_DEVICE_FEATURES 0x00 -#define QVIRTIO_GUEST_FEATURES 0x04 -#define QVIRTIO_QUEUE_ADDRESS 0x08 -#define QVIRTIO_QUEUE_SIZE 0x0C -#define QVIRTIO_QUEUE_SELECT 0x0E -#define QVIRTIO_QUEUE_NOTIFY 0x10 -#define QVIRTIO_DEVICE_STATUS 0x12 -#define QVIRTIO_ISR_STATUS 0x13 -#define QVIRTIO_MSIX_CONF_VECTOR 0x14 -#define QVIRTIO_MSIX_QUEUE_VECTOR 0x16 -#define QVIRTIO_DEVICE_SPECIFIC_MSIX 0x18 -#define QVIRTIO_DEVICE_SPECIFIC_NO_MSIX 0x14 +#define QVIRTIO_PCI_DEVICE_FEATURES 0x00 +#define QVIRTIO_PCI_GUEST_FEATURES 0x04 +#define QVIRTIO_PCI_QUEUE_ADDRESS 0x08 +#define QVIRTIO_PCI_QUEUE_SIZE 0x0C +#define QVIRTIO_PCI_QUEUE_SELECT 0x0E +#define QVIRTIO_PCI_QUEUE_NOTIFY 0x10 +#define QVIRTIO_PCI_DEVICE_STATUS 0x12 +#define QVIRTIO_PCI_ISR_STATUS 0x13 +#define QVIRTIO_PCI_MSIX_CONF_VECTOR 0x14 +#define QVIRTIO_PCI_MSIX_QUEUE_VECTOR 0x16 +#define QVIRTIO_PCI_DEVICE_SPECIFIC_MSIX 0x18 +#define QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX 0x14#define QVIRTIO_PCI_ALIGN 4096
tests/virtio-blk-test.c +6 -5
@@ -157,6 +157,7 @@ static void test_basic(const QVirtioBus *bus, QVirtioDevice *dev,char *data; capacity =qvirtio_config_readq (bus, dev, device_specific); + g_assert_cmpint(capacity, ==, TEST_IMAGE_SIZE / 512); features =qvirtio_get_features (bus, dev);
@@ -283,7 +284,7 @@ static void pci_basic(void) alloc, 0);/* MSI-X is not enabled */ - addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_NO_MSIX ; + addr = dev->addr +QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX ;test_basic (&qvirtio_pci, &dev->vdev, alloc, &vqpci->vq, (uint64_t )(uintptr_t )addr);
@@ -318,7 +319,7 @@ static void pci_indirect(void) dev =virtio_blk_pci_init (bus,PCI_SLOT );/* MSI-X is not enabled */ - addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_NO_MSIX ; + addr = dev->addr +QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX ; capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, (uint64_t )(uintptr_t )addr);
@@ -412,7 +413,7 @@ static void pci_config(void) dev =virtio_blk_pci_init (bus,PCI_SLOT );/* MSI-X is not enabled */ - addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_NO_MSIX ; + addr = dev->addr +QVIRTIO_PCI_DEVICE_SPECIFIC_NO_MSIX ; capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, (uint64_t )(uintptr_t )addr);
@@ -459,7 +460,7 @@ static void pci_msix(void)qvirtio_pci_set_msix_configuration_vector (dev, alloc,0 );/* MSI-X is enabled */ - addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_MSIX ; + addr = dev->addr +QVIRTIO_PCI_DEVICE_SPECIFIC_MSIX ; capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, (uint64_t )(uintptr_t )addr);
@@ -572,7 +573,7 @@ static void pci_idx(void)qvirtio_pci_set_msix_configuration_vector (dev, alloc,0 );/* MSI-X is enabled */ - addr = dev->addr +QVIRTIO_DEVICE_SPECIFIC_MSIX ; + addr = dev->addr +QVIRTIO_PCI_DEVICE_SPECIFIC_MSIX ; capacity =qvirtio_config_readq (&qvirtio_pci, &dev->vdev, (uint64_t )(uintptr_t )addr);
Signature · 1 line
1.7.10.4
PATCH v3 4/5 libqos: Add malloc generic
In reply to Marc MaríThis malloc is a basic interface implementation that works for any platform. It should be replaced in the future for a real malloc implementation for each of the platforms.
--- tests/libqos/malloc-generic.c | 50 +++++++++++++++++++++++++++++++++++++++++ tests/libqos/malloc-generic.h | 21 +++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 tests/libqos/malloc-generic.c create mode 100644 tests/libqos/malloc-generic.h
tests/libqos/malloc-generic.c new file +50 -0
@@ -0,0 +1,50 @@ +/* +* Basic libqos generic malloc support +* +* Copyright (c) 2014 Marc Marí +* +* 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 <glib.h> +#include "libqos/malloc-generic.h" +#include "libqos/malloc.h" + +/* +* Mostly for valgrind happiness, but it does offer +* a chokepoint for debugging guest memory leaks, too. +*/ +void generic_alloc_uninit (QGuestAllocator *allocator) +{ +alloc_uninit (allocator); +} + +QGuestAllocator *generic_alloc_init_flags (uint64_t base_addr,uint64_t size, +uint32_t page_size,QAllocOpts flags) +{ +QGuestAllocator *s =g_malloc0 (sizeof (*s)); +MemBlock *node; + + s->opts = flags; + s->page_size = page_size; + +/* Start at 1MB */ + s->start = base_addr + (1 <<20 ); + + s->end = s->start + size; + +QTAILQ_INIT (&s->used); +QTAILQ_INIT (&s->free); + + node =mlist_new (s->start, s->end - s->start); +QTAILQ_INSERT_HEAD (&s->free, node,MLIST_ENTNAME ); + +return s; +} + +inline QGuestAllocator *generic_alloc_init (uint64_t base_addr,uint64_t size, +uint32_t page_size) +{ +return generic_alloc_init_flags (base_addr, size, page_size,ALLOC_NO_FLAGS ); +}
tests/libqos/malloc-generic.h new file +21 -0
@@ -0,0 +1,21 @@ +/* +* Basic libqos generic malloc support +* +* Copyright (c) 2014 Marc Marí +* +* 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_MALLOC_GENERIC_H +#define LIBQOS_MALLOC_GENERIC_H + +#include "libqos/malloc.h" + +QGuestAllocator *generic_alloc_init (uint64_t base_addr,uint64_t size, +uint32_t page_size); +QGuestAllocator *generic_alloc_init_flags (uint64_t base_addr,uint64_t size, +uint32_t page_size,QAllocOpts flags); +void generic_alloc_uninit (QGuestAllocator *allocator); + +#endif
Signature · 1 line
1.7.10.4
PATCH v3 5/5 libqos: Add virtio MMIO support
In reply to Marc MaríAdd virtio MMIO support.
Add virtio-blk-test MMIO test case.
--- tests/Makefile | 4 +- tests/libqos/virtio-mmio.c | 190 ++++++++++++++++++++++++++++++++++++++++++++ tests/libqos/virtio-mmio.h | 46 +++++++++++ tests/virtio-blk-test.c | 81 +++++++++++++++++-- 4 files changed, 313 insertions(+), 8 deletions(-) create mode 100644 tests/libqos/virtio-mmio.c create mode 100644 tests/libqos/virtio-mmio.h
tests/Makefile +3 -1
@@ -183,6 +183,8 @@ gcov-files-sparc-y += hw/timer/m48t59.c gcov-files-sparc64-y += hw/timer/m48t59.c check-qtest-arm-y = tests/tmp105-test$(EXESUF) gcov-files-arm-y += hw/misc/tmp105.c +check-qtest-arm-y += tests/virtio-blk-test$(EXESUF) +gcov-files-arm-y += arm-softmmu/hw/block/virtio-blk.c check-qtest-ppc-y += tests/boot-order-test$(EXESUF) check-qtest-ppc64-y += tests/boot-order-test$(EXESUF) check-qtest-ppc64-y += tests/spapr-phb-test$(EXESUF)
@@ -300,8 +302,8 @@ libqos-obj-y += tests/libqos/i2c.o libqos-pc-obj-y = $(libqos-obj-y) tests/libqos/pci-pc.o libqos-pc-obj-y += tests/libqos/malloc-pc.o libqos-omap-obj-y = $(libqos-obj-y) tests/libqos/i2c-omap.o -libqos-virtio-obj-y = $(libqos-obj-y) $(libqos-pc-obj-y) tests/libqos/virtio.o tests/libqos/virtio-pci.o libqos-usb-obj-y = $(libqos-pc-obj-y) tests/libqos/usb.o +libqos-virtio-obj-y = $(libqos-pc-obj-y) tests/libqos/virtio.o tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o tests/libqos/malloc-generic.o tests/rtc-test$(EXESUF): tests/rtc-test.o tests/m48t59-test$(EXESUF): tests/m48t59-test.o
tests/libqos/virtio-mmio.c new file +190 -0
190 lines not on this page · raw message
tests/libqos/virtio-mmio.h new file +46 -0
46 lines not on this page · raw message
tests/virtio-blk-test.c +74 -7
117 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Quoted 26 lines · El Wed, 3 Dec 2014 10:31:32 +0100 Marc Marí <[email protected]>…
Add virtio-mmio support to libqos and test case for virtio-blk.
This series depends on patch "libqos: Convert malloc-pc allocator to a generic allocator"
Changes from version 2:
- Fix leaks and minor bugs
- Extract basic test case to a functionMarc Marí (5):
libqos: Change use of pointers touint64_tin virtio
tests: Prepare virtio-blk-test for multi-arch implementation
libqos: Remove PCI assumptions in constants of virtio driver
libqos: Add malloc generic
libqos: Add virtio MMIO supporttests/Makefile | 4 +- tests/libqos/malloc-generic.c | 50 +++++++++ tests/libqos/malloc-generic.h | 21 ++++ tests/libqos/virtio-mmio.c | 190 +++++++++++++++++++++++++++++++ tests/libqos/virtio-mmio.h | 46 ++++++++ tests/libqos/virtio-pci.c | 50 +++++---- tests/libqos/virtio-pci.h | 24 ++-- tests/libqos/virtio.c | 8 +- tests/libqos/virtio.h | 16 +-- tests/virtio-blk-test.c | 249
Quoted 7 lines
++++++++++++++++++++++++++++------------- 10 files changed, 534 insertions(+), 124 deletions(-) create mode 100644
tests/libqos/malloc-generic.ccreate mode 100644tests/libqos/malloc-generic.hcreate mode 100644tests/libqos/virtio-mmio.ccreate mode 100644tests/libqos/virtio-mmio.h
Ping!
Thanks,
Marc
Stefan Hajnoczi
AppliedQuoted 16 lines · Marc Marí
Add virtio-mmio support to libqos and test case for virtio-blk.
This series depends on patch "libqos: Convert malloc-pc allocator to a generic allocator"
Changes from version 2:
- Fix leaks and minor bugs
- Extract basic test case to a functionMarc Marí (5):
libqos: Change use of pointers touint64_tin virtio
tests: Prepare virtio-blk-test for multi-arch implementation
libqos: Remove PCI assumptions in constants of virtio driver
libqos: Add malloc generic
libqos: Add virtio MMIO support
Quoted 20 lines
tests/Makefile | 4 +- tests/libqos/malloc-generic.c | 50 +++++++++ tests/libqos/malloc-generic.h | 21 ++++ tests/libqos/virtio-mmio.c | 190 +++++++++++++++++++++++++++++++ tests/libqos/virtio-mmio.h | 46 ++++++++ tests/libqos/virtio-pci.c | 50 +++++---- tests/libqos/virtio-pci.h | 24 ++-- tests/libqos/virtio.c | 8 +- tests/libqos/virtio.h | 16 +-- tests/virtio-blk-test.c | 249 ++++++++++++++++++++++++++++------------- 10 files changed, 534 insertions(+), 124 deletions(-) create mode 100644 tests/libqos/malloc-generic.c create mode 100644 tests/libqos/malloc-generic.h create mode 100644 tests/libqos/virtio-mmio.c create mode 100644 tests/libqos/virtio-mmio.hSignature · 1 line
1.7.10.4
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan
Quoted 16 lines · Marc Marí
Add virtio-mmio support to libqos and test case for virtio-blk.
This series depends on patch "libqos: Convert malloc-pc allocator to a generic allocator"
Changes from version 2:
- Fix leaks and minor bugs
- Extract basic test case to a functionMarc Marí (5):
libqos: Change use of pointers touint64_tin virtio
tests: Prepare virtio-blk-test for multi-arch implementation
libqos: Remove PCI assumptions in constants of virtio driver
libqos: Add malloc generic
libqos: Add virtio MMIO support
Quoted 15 lines
tests/Makefile | 4 +- tests/libqos/malloc-generic.c | 50 +++++++++ tests/libqos/malloc-generic.h | 21 ++++ tests/libqos/virtio-mmio.c | 190 +++++++++++++++++++++++++++++++ tests/libqos/virtio-mmio.h | 46 ++++++++ tests/libqos/virtio-pci.c | 50 +++++---- tests/libqos/virtio-pci.h | 24 ++-- tests/libqos/virtio.c | 8 +- tests/libqos/virtio.h | 16 +-- tests/virtio-blk-test.c | 249 ++++++++++++++++++++++++++++------------- 10 files changed, 534 insertions(+), 124 deletions(-) create mode 100644 tests/libqos/malloc-generic.c create mode 100644 tests/libqos/malloc-generic.h create mode 100644 tests/libqos/virtio-mmio.c create mode 100644 tests/libqos/virtio-mmio.h
Hi Marc,
Peter Maydell hit two issues with this series when running "make check" under arm-softmmu.
I had to drop this series.
1. The raw format probing warnings, which were recently introduced to warn users when opening a raw file without -drive format=raw.
Quoting Peter:
(1) Ugly warning (seems to happen everywhere):
TEST: tests/virtio-blk-test... (pid=28666)
/arm/virtio/blk/mmio/basic:
WARNING: Image format was not specified for '/tmp/qtest.q0ywpl' and probing guessed raw.
Automatically detecting the format is dangerous for raw
images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
OK
Solution:
In the arm_basic virtio-mmio test, make sure to use -drive ...,format=raw.
2. The qvirtio_wait_queue_isr() timeout is hit (30 seconds?!) sometimes. Not sure why this happens, this needs investigation.
Quoting Peter:
TEST: tests/virtio-blk-test... (pid=16564)
/arm/virtio/blk/mmio/basic:
WARNING: Image format was not specified for '/tmp/qtest.4s4Naf' and
probing guessed raw.
Automatically detecting the format is dangerous for raw
images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
** ERROR:/home/petmay01/linaro/qemu-for-merges/tests/libqos/virtio.c:91:qvirtio_wait_queue_isr:
assertion failed: (g_get_monotonic_time() - start_time <= timeout_us)
FAIL
GTester: last random seed: R02S2b2c6e34351d711919b868b92fde3543
(pid=16570)
FAIL: tests/virtio-blk-test
This might be an intermittent failure; I think my x86-64 gcc build passed the first time and failed on a rerun. The clang build also failed this.
Stefan