diff mbox

[2/2] pci-test: allow bar > 4k

Message ID 1440665434-2893-2-git-send-email-mst@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Michael S. Tsirkin Aug. 27, 2015, 8:52 a.m. UTC
vmexit using test assumes BAR size is exactly 4K.
Remove this restriction, allow any BAR size.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 x86/vmexit.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/x86/vmexit.c b/x86/vmexit.c
index 7e9af15..3ff7fbf 100644
--- a/x86/vmexit.c
+++ b/x86/vmexit.c
@@ -407,7 +407,7 @@  bool test_wanted(struct test *test, char *wanted[], int nwanted)
 int main(int ac, char **av)
 {
 	int i;
-	unsigned long membar = 0, base, offset;
+	unsigned long membar = 0, base, offset, size;
 	void *m;
 	pcidevaddr_t pcidev;
 
@@ -425,12 +425,18 @@  int main(int ac, char **av)
 				continue;
 			}
 			if (pci_bar_is_memory(pcidev, i)) {
+				int p;
+
+				size = pci_bar_size(pcidev, i);
 				membar = pci_bar_addr(pcidev, i);
-				base = membar & ~4095;
+				base = membar & ~(size - 1);
 				offset = membar - base;
-				m = alloc_vpages(1);
-				
-				install_page((void *)read_cr3(), base, m);
+				m = alloc_vpages(size / 4096);
+
+				for (p = 0; p < size; p += 4096) {
+				    install_page((void *)read_cr3(), base + p,
+                                                 m + p);
+				}
 				pci_test.memaddr = m + offset;
 			} else {
 				pci_test.iobar = pci_bar_addr(pcidev, i);