* [Qemu-devel] [PATCH RFC 0/3] pci-testdev add support for kvm ioeventfd pf
@ 2015-08-30 9:20 ` Michael S. Tsirkin
0 siblings, 0 replies; 10+ messages in thread
From: Michael S. Tsirkin @ 2015-08-30 9:20 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, kvm
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(-)
--
MST
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH RFC 1/3] pci-testdev: separate page for each mmio test
2015-08-30 9:20 ` [Qemu-devel] " Michael S. Tsirkin
@ 2015-08-30 9:20 ` Michael S. Tsirkin
-1 siblings, 0 replies; 10+ messages in thread
From: Michael S. Tsirkin @ 2015-08-30 9:20 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, kvm, Markus Armbruster, Gonglei
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 ...
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/misc/pci-testdev.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/hw/misc/pci-testdev.c b/hw/misc/pci-testdev.c
index b6e11d6..6edc1cd 100644
--- a/hw/misc/pci-testdev.c
+++ b/hw/misc/pci-testdev.c
@@ -48,7 +48,7 @@ typedef struct IOTest {
#define IOTEST_NODATA 0xAB
#define IOTEST_IOSIZE 128
-#define IOTEST_MEMSIZE 2048
+#define IOTEST_MEMSIZE 0x10000
static 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;
}
--
MST
^ permalink raw reply related [flat|nested] 10+ messages in thread* [Qemu-devel] [PATCH RFC 1/3] pci-testdev: separate page for each mmio test
@ 2015-08-30 9:20 ` Michael S. Tsirkin
0 siblings, 0 replies; 10+ messages in thread
From: Michael S. Tsirkin @ 2015-08-30 9:20 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, Gonglei, Markus Armbruster, kvm
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 ...
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/misc/pci-testdev.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/hw/misc/pci-testdev.c b/hw/misc/pci-testdev.c
index b6e11d6..6edc1cd 100644
--- a/hw/misc/pci-testdev.c
+++ b/hw/misc/pci-testdev.c
@@ -48,7 +48,7 @@ typedef struct IOTest {
#define IOTEST_NODATA 0xAB
#define IOTEST_IOSIZE 128
-#define IOTEST_MEMSIZE 2048
+#define IOTEST_MEMSIZE 0x10000
static 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;
}
--
MST
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH RFC 2/3] pci-testdev: add subregion
2015-08-30 9:20 ` [Qemu-devel] " Michael S. Tsirkin
@ 2015-08-30 9:20 ` Michael S. Tsirkin
-1 siblings, 0 replies; 10+ messages in thread
From: Michael S. Tsirkin @ 2015-08-30 9:20 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, kvm, Gonglei, Markus Armbruster
Make mmio a subregion of the BAR.
This will allow mapping rom within the same BAR down the road.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/misc/pci-testdev.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/hw/misc/pci-testdev.c b/hw/misc/pci-testdev.c
index 6edc1cd..94141a3 100644
--- a/hw/misc/pci-testdev.c
+++ b/hw/misc/pci-testdev.c
@@ -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;
--
MST
^ permalink raw reply related [flat|nested] 10+ messages in thread* [Qemu-devel] [PATCH RFC 2/3] pci-testdev: add subregion
@ 2015-08-30 9:20 ` Michael S. Tsirkin
0 siblings, 0 replies; 10+ messages in thread
From: Michael S. Tsirkin @ 2015-08-30 9:20 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, Gonglei, Markus Armbruster, kvm
Make mmio a subregion of the BAR.
This will allow mapping rom within the same BAR down the road.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/misc/pci-testdev.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/hw/misc/pci-testdev.c b/hw/misc/pci-testdev.c
index 6edc1cd..94141a3 100644
--- a/hw/misc/pci-testdev.c
+++ b/hw/misc/pci-testdev.c
@@ -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;
--
MST
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH RFC 3/3] pci-testdev: add RO pages for ioeventfd
2015-08-30 9:20 ` [Qemu-devel] " Michael S. Tsirkin
@ 2015-08-30 9:20 ` Michael S. Tsirkin
-1 siblings, 0 replies; 10+ messages in thread
From: Michael S. Tsirkin @ 2015-08-30 9:20 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, kvm, Markus Armbruster, Gonglei
This seems hackish - would it be better to create this region
automatically within kvm? Suggestions are welcome.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/misc/pci-testdev.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/hw/misc/pci-testdev.c b/hw/misc/pci-testdev.c
index 94141a3..55efc32 100644
--- a/hw/misc/pci-testdev.c
+++ b/hw/misc/pci-testdev.c
@@ -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;
--
MST
^ permalink raw reply related [flat|nested] 10+ messages in thread* [Qemu-devel] [PATCH RFC 3/3] pci-testdev: add RO pages for ioeventfd
@ 2015-08-30 9:20 ` Michael S. Tsirkin
0 siblings, 0 replies; 10+ messages in thread
From: Michael S. Tsirkin @ 2015-08-30 9:20 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, Gonglei, Markus Armbruster, kvm
This seems hackish - would it be better to create this region
automatically within kvm? Suggestions are welcome.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/misc/pci-testdev.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/hw/misc/pci-testdev.c b/hw/misc/pci-testdev.c
index 94141a3..55efc32 100644
--- a/hw/misc/pci-testdev.c
+++ b/hw/misc/pci-testdev.c
@@ -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;
--
MST
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH RFC 3/3] pci-testdev: add RO pages for ioeventfd
2015-08-30 9:20 ` [Qemu-devel] " Michael S. Tsirkin
@ 2015-08-30 9:44 ` Gonglei
-1 siblings, 0 replies; 10+ messages in thread
From: Gonglei @ 2015-08-30 9:44 UTC (permalink / raw)
To: Michael S. Tsirkin, qemu-devel; +Cc: pbonzini, Markus Armbruster, kvm
On 2015/8/30 17:20, Michael S. Tsirkin wrote:
> This seems hackish - would it be better to create this region
> automatically within kvm? Suggestions are welcome.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> hw/misc/pci-testdev.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/hw/misc/pci-testdev.c b/hw/misc/pci-testdev.c
> index 94141a3..55efc32 100644
> --- a/hw/misc/pci-testdev.c
> +++ b/hw/misc/pci-testdev.c
> @@ -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);
> +
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
> + 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;
>
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [Qemu-devel] [PATCH RFC 3/3] pci-testdev: add RO pages for ioeventfd
@ 2015-08-30 9:44 ` Gonglei
0 siblings, 0 replies; 10+ messages in thread
From: Gonglei @ 2015-08-30 9:44 UTC (permalink / raw)
To: Michael S. Tsirkin, qemu-devel; +Cc: pbonzini, Markus Armbruster, kvm
On 2015/8/30 17:20, Michael S. Tsirkin wrote:
> This seems hackish - would it be better to create this region
> automatically within kvm? Suggestions are welcome.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> hw/misc/pci-testdev.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/hw/misc/pci-testdev.c b/hw/misc/pci-testdev.c
> index 94141a3..55efc32 100644
> --- a/hw/misc/pci-testdev.c
> +++ b/hw/misc/pci-testdev.c
> @@ -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);
> +
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
> + 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;
>
^ permalink raw reply [flat|nested] 10+ messages in thread