pci-testdev add support for kvm ioeventfd pf
cover pci-testdev add support for kvm ioeventfd pf
This adds a test for triggering ioeventfd on pagefaults. This was used to verify that mmio ioeventfd on pagefault is as fast as portio.
Michael S. Tsirkin (3):
pci-testdev: separate page for each mmio test
pci-testdev: add subregion
pci-testdev: add RO pages for ioeventfd
hw/misc/pci-testdev.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
Signature · 1 line
MST
RFC PATCH 1/3 pci-testdev: separate page for each mmio test
note: this makes BAR > 4K, which requires kvm unit test patch to support such BAR. Do we need to worry about old kvm unit test binaries? I'm guessing not ...
--- hw/misc/pci-testdev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/misc/pci-testdev.c +3 -2
@@ -48,7 +48,7 @@ typedef struct IOTest {#define IOTEST_NODATA 0xAB#define IOTEST_IOSIZE 128 -#define IOTEST_MEMSIZE 2048 +#define IOTEST_MEMSIZE 0x10000static const char *iotest_test[] = {"no-eventfd" ,
@@ -262,7 +262,7 @@ static void pci_testdev_realize(PCIDevice *pci_dev, Error **errp) test->hdr =g_malloc0 (test->bufsize);memcpy (test->hdr->name, name,strlen (name) +1 );g_free (name); - test->hdr->offset =cpu_to_le32 (IOTEST_SIZE (i) + i *IOTEST_ACCESS_WIDTH ); + test->hdr->offset =cpu_to_le32 (IOTEST_SIZE (i) + i * (IOTEST_IS_MEM (i) ?0x1000 :IOTEST_ACCESS_WIDTH )); test->size =strcmp (IOTEST_TEST (i),"nodata-eventfd" ) ?IOTEST_ACCESS_WIDTH :0 ; test->match_data = strcmp(IOTEST_TEST(i), "wildcard-eventfd") &&
@@ -273,6 +273,7 @@ static void pci_testdev_realize(PCIDevice *pci_dev, Error **errp) test->mr =IOTEST_REGION (d, i);if (!test->size && !IOTEST_IS_MEM (i)) { + test->hdr->width =0 ; test->hasnotifier = false;continue ; }
Signature · 1 line
MST
RFC PATCH 2/3 pci-testdev: add subregion
In reply to Michael S. TsirkinMake mmio a subregion of the BAR.
This will allow mapping rom within the same BAR down the road.
--- hw/misc/pci-testdev.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
hw/misc/pci-testdev.c +6 -1
@@ -83,6 +83,7 @@ typedef struct PCITestDevState {/*< public >*/ MemoryRegion mmio; +MemoryRegion mbar;MemoryRegion portio;IOTest *tests;int current;
@@ -248,9 +249,13 @@ static void pci_testdev_realize(PCIDevice *pci_dev, Error **errp)memory_region_init_io (&d->mmio,OBJECT (d), &pci_testdev_mmio_ops, d,"pci-testdev-mmio" ,IOTEST_MEMSIZE *2 ); +memory_region_init (&d->mbar,OBJECT (d), +"pci-testdev-mmio" ,IOTEST_MEMSIZE *2 );memory_region_init_io (&d->portio,OBJECT (d), &pci_testdev_pio_ops, d,"pci-testdev-portio" ,IOTEST_IOSIZE *2 ); -pci_register_bar (pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY , &d->mmio); + +memory_region_add_subregion_overlap (&d->mbar,0 , &d->mmio,1 /* prio */ ); +pci_register_bar (pci_dev,0 ,PCI_BASE_ADDRESS_SPACE_MEMORY , &d->mbar);pci_register_bar (pci_dev,1 ,PCI_BASE_ADDRESS_SPACE_IO , &d->portio); d->current =-1 ;
Signature · 1 line
MST
RFC PATCH 3/3 pci-testdev: add RO pages for ioeventfd
In reply to Michael S. TsirkinThis seems hackish - would it be better to create this region automatically within kvm? Suggestions are welcome.
--- hw/misc/pci-testdev.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
hw/misc/pci-testdev.c +13 -0
@@ -21,6 +21,7 @@#include "hw/pci/pci.h" #include "qemu/event_notifier.h" #include "qemu/osdep.h" +#include <sys/mman.h> typedef struct PCITestDevHdr { uint8_t test;
@@ -82,11 +83,13 @@ typedef struct PCITestDevState {PCIDevice parent_obj;/*< public >*/ +MemoryRegion zeromr;MemoryRegion mmio;MemoryRegion mbar;MemoryRegion portio;IOTest *tests;int current; +void *zero; } PCITestDevState;#define TYPE_PCI_TEST_DEV "pci-testdev"
@@ -242,6 +245,11 @@ static void pci_testdev_realize(PCIDevice *pci_dev, Error **errp)uint8_t *pci_conf;char *name;int r, i; + d->zero =mmap (NULL ,IOTEST_MEMSIZE *2 ,PROT_READ , +MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); + +memory_region_init_ram_ptr (&d->zeromr,OBJECT (d),"pci-testdev-zero" ,0x1000 , d->zero); +memory_region_set_readonly (&d->zeromr, true); pci_conf = pci_dev->config;
@@ -286,6 +294,11 @@ static void pci_testdev_realize(PCIDevice *pci_dev, Error **errp) test->hasnotifier = false;continue ; } + +if (test->hasnotifier && !test->size) { +memory_region_add_subregion_overlap (&d->mbar,le32_to_cpu (test->hdr->offset), + &d->zeromr,2 /* prio */ ); + } r =event_notifier_init (&test->notifier,0 );assert (r >=0 ); test->hasnotifier = true;
Signature · 1 line
MST
Re: [PATCH RFC 3/3] pci-testdev: add RO pages for ioeventfd
Quoted 35 lines · Michael S. Tsirkin
This seems hackish - would it be better to create this region automatically within kvm? Suggestions are welcome.
Signed-off-by Michael S. Tsirkin <[email protected]>--- hw/misc/pci-testdev.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)hw/misc/pci-testdev.c +3
-0@@ -21,6 +21,7 @@#include "hw/pci/pci.h" #include "qemu/event_notifier.h" #include "qemu/osdep.h" +#include <sys/mman.h> typedef struct PCITestDevHdr { uint8_t test;@@ -82,11 +83,13 @@ typedef struct PCITestDevState {PCIDevice parent_obj;/*< public >*/ +MemoryRegion zeromr;MemoryRegion mmio;MemoryRegion mbar;MemoryRegion portio;IOTest *tests;int current; +void *zero; } PCITestDevState;#define TYPE_PCI_TEST_DEV "pci-testdev"
hw/misc/pci-testdev.c static void pci_testdev_realize(PCIDevice *pci_dev, Error **errp) · line 250
Quoted 6 lines
hw/misc/pci-testdev.c +3
-0@@ -242,6 +245,11 @@ static void pci_testdev_realize(PCIDevice *pci_dev, Error **errp)uint8_t *pci_conf;char *name;int r, i; + d->zero =mmap (NULL ,IOTEST_MEMSIZE *2 ,PROT_READ , +MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); +
Do we need think about hotplugging pci-testdev ? If yes, then we should release some resources when hot-unplug a pci-testdev device:munmap(d->zero, ...)memory_region_del_subregion(&d->mbar, &d->mmio)
...
Regards,
-Gonglei
Quoted 18 lines
hw/misc/pci-testdev.c +7
-0+memory_region_init_ram_ptr (&d->zeromr,OBJECT (d),"pci-testdev-zero" ,0x1000 , d->zero); +memory_region_set_readonly (&d->zeromr, true); pci_conf = pci_dev->config;@@ -286,6 +294,11 @@ static void pci_testdev_realize(PCIDevice *pci_dev, Error **errp) test->hasnotifier = false;continue ; } + +if (test->hasnotifier && !test->size) { +memory_region_add_subregion_overlap (&d->mbar,le32_to_cpu (test->hdr->offset), + &d->zeromr,2 /* prio */ ); + } r =event_notifier_init (&test->notifier,0 );assert (r >=0 ); test->hasnotifier = true;