pci: add pci test device
The following changes since commit e2ec3f976803b360c70d9ae2ba13852fa5d11665:
qjson: to_json() case QTYPE_QSTRING is buggy, rewrite (2013-04-13 19:40:25 +0000)
are available in the git repository at:
git://git.kernel.org/pub/scm/virt/kvm/mst/qemu.git tags/for_anthony
for you to fetch changes up to 22773d6066a7f01a95f78c270edf9dbd2e755ac3:
pci: add pci test device (2013-04-16 01:41:53 +0300)
----------------------------------------------------------------
pci: add pci test device
This adds a new device that we can use for testing PCI PIO and MMIO, with and without ioeventfd in different configurations. FAST_MMIO will be added if/when kvm supports it. Also included are minor cleanups in kvm APIs that it needs.
----------------------------------------------------------------
Michael S. Tsirkin (4):
kvm: remove unused APIs
kvm: support any size for pio eventfd
kvm: support non datamatch ioeventfd
pci: add pci test device
default-configs/pci.mak | 1 + docs/specs/pci-testdev.txt | 26 ++++ hw/misc/Makefile.objs | 1 + hw/misc/pci-testdev.c | 325 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 1 + include/sysemu/kvm.h | 4 - kvm-all.c | 133 ++++++++++--------- kvm-stub.c | 10 -- 8 files changed, 422 insertions(+), 79 deletions(-) create mode 100644 docs/specs/pci-testdev.txt create mode 100644 hw/misc/pci-testdev.c
Michael S. Tsirkin (4):
kvm: remove unused APIs
kvm: support any size for pio eventfd
kvm: support non datamatch ioeventfd
pci: add pci test device
default-configs/pci.mak | 1 + docs/specs/pci-testdev.txt | 26 ++++ hw/misc/Makefile.objs | 1 + hw/misc/pci-testdev.c | 325 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 1 + include/sysemu/kvm.h | 4 - kvm-all.c | 133 ++++++++++--------- kvm-stub.c | 10 -- 8 files changed, 422 insertions(+), 79 deletions(-) create mode 100644 docs/specs/pci-testdev.txt create mode 100644 hw/misc/pci-testdev.c
Signature · 1 line
MST
PATCH 1/4 kvm: remove unused APIs
There are only used internally now, move them
out of header and out of stub.
--- include/sysemu/kvm.h | 4 -- kvm-all.c | 107 ++++++++++++++++++++++++++------------------------- kvm-stub.c | 10 ----- 3 files changed, 54 insertions(+), 67 deletions(-)
include/sysemu/kvm.h +0 -4
@@ -283,10 +283,6 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr,#endif #endif -int kvm_set_ioeventfd_mmio (int fd,uint32_t adr,uint32_t val,bool assign, -uint32_t size); - -int kvm_set_ioeventfd_pio_word (int fd,uint16_t adr,uint16_t val,bool assign);int kvm_irqchip_add_msi_route (KVMState *s,MSIMessage msg);int kvm_irqchip_update_msi_route (KVMState *s,int virq,MSIMessage msg);
kvm-all.c +54 -53
119 lines not on this page · raw message
kvm-stub.c +0 -10
@@ -102,16 +102,6 @@ int kvm_set_signal_mask(CPUArchState *env, const sigset_t *sigset) }#endif -int kvm_set_ioeventfd_pio_word (int fd,uint16_t addr,uint16_t val,bool assign) -{ -return -ENOSYS ; -} - -int kvm_set_ioeventfd_mmio (int fd,uint32_t adr,uint32_t val,bool assign,uint32_t len) -{ -return -ENOSYS ; -} -int kvm_on_sigbus_vcpu (CPUState *cpu,int code,void *addr) {return 1 ;
Signature · 1 line
MST
PATCH 2/4 kvm: support any size for pio eventfd
In reply to Michael S. Tsirkin--- kvm-all.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
kvm-all.c +12 -12
@@ -500,8 +500,8 @@ int kvm_check_extension(KVMState *s, unsigned int extension)return ret; } -static int kvm_set_ioeventfd_mmio (int fd,uint32_t addr,uint32_t val,bool assign, -uint32_t size) +static int kvm_set_ioeventfd_mmio (int fd,uint32_t addr,uint32_t val, +bool assign,uint32_t size) {int ret;struct kvm_ioeventfd iofd;
@@ -529,13 +529,13 @@ static int kvm_set_ioeventfd_mmio(int fd, uint32_t addr, uint32_t val, bool assireturn 0 ; } -static int kvm_set_ioeventfd_pio_word (int fd,uint16_t addr,uint16_t val, -bool assign) +static int kvm_set_ioeventfd_pio (int fd,uint16_t addr,uint16_t val, +bool assign,uint32_t size) {struct kvm_ioeventfd kick = { .datamatch = val, .addr = addr, - .len =2 , + .len = size, .flags =KVM_IOEVENTFD_FLAG_DATAMATCH |KVM_IOEVENTFD_FLAG_PIO , .fd = fd, };
@@ -571,7 +571,7 @@ static int kvm_check_many_ioeventfds(void)if (ioeventfds[i] <0 ) {break ; } - ret =kvm_set_ioeventfd_pio_word (ioeventfds[i],0 , i, true); + ret =kvm_set_ioeventfd_pio (ioeventfds[i],0 , i, true,2 );if (ret <0 ) {close (ioeventfds[i]);break ;
@@ -582,7 +582,7 @@ static int kvm_check_many_ioeventfds(void) ret = i ==ARRAY_SIZE (ioeventfds);while (i-- >0 ) { -kvm_set_ioeventfd_pio_word (ioeventfds[i],0 , i, false); +kvm_set_ioeventfd_pio (ioeventfds[i],0 , i, false,2 );close (ioeventfds[i]); }return ret;
@@ -834,10 +834,10 @@ static void kvm_io_ioeventfd_add(MemoryListener *listener,int fd =event_notifier_get_fd (e);int r; -assert (match_data && section->size ==2 ); +assert (match_data && section->size <=8 ); - r =kvm_set_ioeventfd_pio_word (fd, section->offset_within_address_space, - data, true); + r =kvm_set_ioeventfd_pio (fd, section->offset_within_address_space, + data, true, section->size);if (r <0 ) {abort (); }
@@ -852,8 +852,8 @@ static void kvm_io_ioeventfd_del(MemoryListener *listener,int fd =event_notifier_get_fd (e);int r; - r =kvm_set_ioeventfd_pio_word (fd, section->offset_within_address_space, - data, false); + r =kvm_set_ioeventfd_pio (fd, section->offset_within_address_space, + data, false, section->size);if (r <0 ) {abort (); }
Signature · 1 line
MST
PATCH 3/4 kvm: support non datamatch ioeventfd
In reply to Michael S. TsirkinAdding restrictions just adds code.
--- kvm-all.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
kvm-all.c +18 -16
@@ -501,21 +501,24 @@ int kvm_check_extension(KVMState *s, unsigned int extension) }static int kvm_set_ioeventfd_mmio (int fd,uint32_t addr,uint32_t val, -bool assign,uint32_t size) +bool assign,uint32_t size,bool datamatch) {int ret;struct kvm_ioeventfd iofd; - iofd.datamatch = val; + iofd.datamatch = datamatch ? val :0 ; iofd.addr = addr; iofd.len = size; - iofd.flags =KVM_IOEVENTFD_FLAG_DATAMATCH ; + iofd.flags =0 ; iofd.fd = fd;if (!kvm_enabled ()) {return -ENOSYS ; } +if (datamatch) { + iofd.flags |=KVM_IOEVENTFD_FLAG_DATAMATCH ; + }if (!assign) { iofd.flags |=KVM_IOEVENTFD_FLAG_DEASSIGN ; }
@@ -530,19 +533,22 @@ static int kvm_set_ioeventfd_mmio(int fd, uint32_t addr, uint32_t val, }static int kvm_set_ioeventfd_pio (int fd,uint16_t addr,uint16_t val, -bool assign,uint32_t size) +bool assign,uint32_t size,bool datamatch) {struct kvm_ioeventfd kick = { - .datamatch = val, + .datamatch = datamatch ? val :0 , .addr = addr, + .flags =KVM_IOEVENTFD_FLAG_PIO , .len = size, - .flags =KVM_IOEVENTFD_FLAG_DATAMATCH |KVM_IOEVENTFD_FLAG_PIO , .fd = fd, };int r;if (!kvm_enabled ()) {return -ENOSYS ; } +if (datamatch) { + kick.flags |=KVM_IOEVENTFD_FLAG_DATAMATCH ; + }if (!assign) { kick.flags |=KVM_IOEVENTFD_FLAG_DEASSIGN ; }
@@ -571,7 +577,7 @@ static int kvm_check_many_ioeventfds(void)if (ioeventfds[i] <0 ) {break ; } - ret =kvm_set_ioeventfd_pio (ioeventfds[i],0 , i, true,2 ); + ret =kvm_set_ioeventfd_pio (ioeventfds[i],0 , i, true,2 , true);if (ret <0 ) {close (ioeventfds[i]);break ;
@@ -582,7 +588,7 @@ static int kvm_check_many_ioeventfds(void) ret = i ==ARRAY_SIZE (ioeventfds);while (i-- >0 ) { -kvm_set_ioeventfd_pio (ioeventfds[i],0 , i, false,2 ); +kvm_set_ioeventfd_pio (ioeventfds[i],0 , i, false,2 , true);close (ioeventfds[i]); }return ret;
@@ -802,10 +808,8 @@ static void kvm_mem_ioeventfd_add(MemoryListener *listener,int fd =event_notifier_get_fd (e);int r; -assert (match_data && section->size <=8 ); - r =kvm_set_ioeventfd_mmio (fd, section->offset_within_address_space, - data, true, section->size); + data, true, section->size, match_data);if (r <0 ) {abort (); }
@@ -820,7 +824,7 @@ static void kvm_mem_ioeventfd_del(MemoryListener *listener,int r; r =kvm_set_ioeventfd_mmio (fd, section->offset_within_address_space, - data, false, section->size); + data, false, section->size, match_data);if (r <0 ) {abort (); }
@@ -834,10 +838,8 @@ static void kvm_io_ioeventfd_add(MemoryListener *listener,int fd =event_notifier_get_fd (e);int r; -assert (match_data && section->size <=8 ); - r =kvm_set_ioeventfd_pio (fd, section->offset_within_address_space, - data, true, section->size); + data, true, section->size, match_data);if (r <0 ) {abort (); }
@@ -853,7 +855,7 @@ static void kvm_io_ioeventfd_del(MemoryListener *listener,int r; r =kvm_set_ioeventfd_pio (fd, section->offset_within_address_space, - data, false, section->size); + data, false, section->size, match_data);if (r <0 ) {abort (); }
Signature · 1 line
MST
PATCH 4/4 pci: add pci test device
In reply to Michael S. TsirkinThis device is used for kvm unit tests, currently it supports testing performance of ioeventfd. Using updated kvm unittest, here's an example output:
mmio-no-eventfd:pci-mem 8796
mmio-wildcard-eventfd:pci-mem 3609
mmio-datamatch-eventfd:pci-mem 3685
portio-no-eventfd:pci-io 5287
portio-wildcard-eventfd:pci-io 1762
portio-datamatch-eventfd:pci-io 1777--- default-configs/pci.mak | 1 + docs/specs/pci-testdev.txt | 26 ++++ hw/misc/Makefile.objs | 1 + hw/misc/pci-testdev.c | 325 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/pci/pci.h | 1 + 5 files changed, 354 insertions(+) create mode 100644 docs/specs/pci-testdev.txt create mode 100644 hw/misc/pci-testdev.c
default-configs/pci.mak +1 -0
@@ -24,3 +24,4 @@ CONFIG_SERIAL=y CONFIG_SERIAL_PCI=y CONFIG_IPACK=y CONFIG_WDT_IB6300ESB=y +CONFIG_PCI_TESTDEV=y
docs/specs/pci-testdev.txt new file +26 -0
@@ -0,0 +1,26 @@ +pci-test is a device used for testing low level IO + +device implements up to two BARs: BAR0 and BAR1. +Each BAR can be memory or IO. Guests must detect +BAR type and act accordingly. + +Each BAR size is up to 4K bytes. +Each BAR starts with the following header: + +typedef struct PCITestDevHdr { + uint8_t test; <- write-only, starts a given test number + uint8_t width_type; <- read-only, type and width of access for a given test. + 1,2,4 for byte,word or long write. + any other value if test not supported on this BAR + uint8_t pad0[2]; + uint32_t offset; <- read-only, offset in this BAR for a given test + uint32_t data; <- read-only, data to use for a given test + uint32_t count; <- for debugging. number of writes detected. + uint8_t name[]; <- for debugging. 0-terminated ASCII string. +} PCITestDevHdr; + +All registers are little endian. + +device is expected to always implement tests 0 to N on each BAR, and to add new +tests with higher numbers. In this way a guest can scan test numbers until it +detects an access type that it does not support on this BAR, then stop.
hw/misc/Makefile.objs +1 -0
@@ -4,6 +4,7 @@ common-obj-$(CONFIG_TMP105) += tmp105.o common-obj-$(CONFIG_ISA_DEBUG) += debugexit.o common-obj-$(CONFIG_SGA) += sga.o common-obj-$(CONFIG_ISA_TESTDEV) += pc-testdev.o +common-obj-$(CONFIG_PCI_TESTDEV) += pci-testdev.o obj-$(CONFIG_VMPORT) += vmport.o
hw/misc/pci-testdev.c new file +325 -0
325 lines not on this page · raw message
include/hw/pci/pci.h +1 -0
@@ -85,6 +85,7 @@#define PCI_DEVICE_ID_REDHAT_SERIAL 0x0002#define PCI_DEVICE_ID_REDHAT_SERIAL2 0x0003#define PCI_DEVICE_ID_REDHAT_SERIAL4 0x0004 +#define PCI_DEVICE_ID_REDHAT_TEST 0x0005#define PCI_DEVICE_ID_REDHAT_QXL 0x0100#define FMT_PCIBUS PRIx64
Signature · 1 line
MST