* [patch 0/3] [RESEND] kvm test: test rmap chains
@ 2010-07-05 18:16 Marcelo Tosatti
2010-07-05 18:16 ` [patch 1/3] kvm test: protect fwfcg accesses with spinlock Marcelo Tosatti
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Marcelo Tosatti @ 2010-07-05 18:16 UTC (permalink / raw)
To: avi; +Cc: kvm
^ permalink raw reply [flat|nested] 6+ messages in thread
* [patch 1/3] kvm test: protect fwfcg accesses with spinlock
2010-07-05 18:16 [patch 0/3] [RESEND] kvm test: test rmap chains Marcelo Tosatti
@ 2010-07-05 18:16 ` Marcelo Tosatti
2010-07-05 18:16 ` [patch 2/3] kvm test: export vm helpers Marcelo Tosatti
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Marcelo Tosatti @ 2010-07-05 18:16 UTC (permalink / raw)
To: avi; +Cc: kvm, Marcelo Tosatti
[-- Attachment #1: 3-8-test-protect-fwcfg-accesses-with-lock.patch --]
[-- Type: text/plain, Size: 795 bytes --]
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: qemu-kvm/kvm/user/test/lib/x86/fwcfg.c
===================================================================
--- qemu-kvm.orig/kvm/test/lib/x86/fwcfg.c
+++ qemu-kvm/kvm/test/lib/x86/fwcfg.c
@@ -1,4 +1,7 @@
#include "fwcfg.h"
+#include "smp.h"
+
+static struct spinlock lock;
uint64_t fwcfg_get_u(uint16_t index, int bytes)
{
@@ -6,11 +9,13 @@ uint64_t fwcfg_get_u(uint16_t index, int
uint8_t b;
int i;
+ spin_lock(&lock);
asm volatile ("out %0, %1" : : "a"(index), "d"((uint16_t)BIOS_CFG_IOPORT));
for (i = 0; i < bytes; ++i) {
asm volatile ("in %1, %0" : "=a"(b) : "d"((uint16_t)(BIOS_CFG_IOPORT + 1)));
r |= (uint64_t)b << (i * 8);
}
+ spin_unlock(&lock);
return r;
}
^ permalink raw reply [flat|nested] 6+ messages in thread
* [patch 2/3] kvm test: export vm helpers
2010-07-05 18:16 [patch 0/3] [RESEND] kvm test: test rmap chains Marcelo Tosatti
2010-07-05 18:16 ` [patch 1/3] kvm test: protect fwfcg accesses with spinlock Marcelo Tosatti
@ 2010-07-05 18:16 ` Marcelo Tosatti
2010-07-05 18:16 ` [patch 3/3] kvm test: long rmap chains Marcelo Tosatti
2010-07-06 7:27 ` [patch 0/3] [RESEND] kvm test: test " Avi Kivity
3 siblings, 0 replies; 6+ messages in thread
From: Marcelo Tosatti @ 2010-07-05 18:16 UTC (permalink / raw)
To: avi; +Cc: kvm, Marcelo Tosatti
[-- Attachment #1: 4-8-test-export-vm-helpers.patch --]
[-- Type: text/plain, Size: 5901 bytes --]
To be used by rmap chain patch. Also make install_pte take an argument
indicating physical location of pagetable.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: qemu-kvm/kvm/test/x86/vm.c
===================================================================
--- qemu-kvm.orig/kvm/test/x86/vm.c
+++ qemu-kvm/kvm/test/x86/vm.c
@@ -14,16 +14,6 @@
static void *free = 0;
static void *vfree_top = 0;
-static unsigned long virt_to_phys(const void *virt)
-{
- return (unsigned long)virt;
-}
-
-static void *phys_to_virt(unsigned long phys)
-{
- return (void *)phys;
-}
-
void *memset(void *data, int c, unsigned long len)
{
char *s = data;
@@ -66,11 +56,6 @@ void free_page(void *page)
extern char edata;
static unsigned long end_of_memory;
-#define PTE_PRESENT (1ull << 0)
-#define PTE_PSE (1ull << 7)
-#define PTE_WRITE (1ull << 1)
-#define PTE_ADDR (0xffffffffff000ull)
-
#ifdef __x86_64__
#define PAGE_LEVEL 4
#define PGDIR_WIDTH 9
@@ -81,10 +66,11 @@ static unsigned long end_of_memory;
#define PGDIR_MASK 1023
#endif
-static void install_pte(unsigned long *cr3,
- int pte_level,
- void *virt,
- unsigned long pte)
+void install_pte(unsigned long *cr3,
+ int pte_level,
+ void *virt,
+ unsigned long pte,
+ unsigned long *pt_page)
{
int level;
unsigned long *pt = cr3;
@@ -93,7 +79,11 @@ static void install_pte(unsigned long *c
for (level = PAGE_LEVEL; level > pte_level; --level) {
offset = ((unsigned long)virt >> ((level-1) * PGDIR_WIDTH + 12)) & PGDIR_MASK;
if (!(pt[offset] & PTE_PRESENT)) {
- unsigned long *new_pt = alloc_page();
+ unsigned long *new_pt = pt_page;
+ if (!new_pt)
+ new_pt = alloc_page();
+ else
+ pt_page = 0;
memset(new_pt, 0, PAGE_SIZE);
pt[offset] = virt_to_phys(new_pt) | PTE_PRESENT | PTE_WRITE;
}
@@ -123,58 +113,20 @@ static unsigned long get_pte(unsigned lo
return pte;
}
-static void install_large_page(unsigned long *cr3,
- unsigned long phys,
- void *virt)
-{
- install_pte(cr3, 2, virt, phys | PTE_PRESENT | PTE_WRITE | PTE_PSE);
-}
-
-static void install_page(unsigned long *cr3,
- unsigned long phys,
- void *virt)
-{
- install_pte(cr3, 1, virt, phys | PTE_PRESENT | PTE_WRITE);
-}
-
-static inline void load_cr3(unsigned long cr3)
-{
- asm ( "mov %0, %%cr3" : : "r"(cr3) );
-}
-
-static inline unsigned long read_cr3()
+void install_large_page(unsigned long *cr3,
+ unsigned long phys,
+ void *virt)
{
- unsigned long cr3;
-
- asm volatile ( "mov %%cr3, %0" : "=r"(cr3) );
- return cr3;
+ install_pte(cr3, 2, virt, phys | PTE_PRESENT | PTE_WRITE | PTE_PSE, 0);
}
-static inline void load_cr0(unsigned long cr0)
+void install_page(unsigned long *cr3,
+ unsigned long phys,
+ void *virt)
{
- asm volatile ( "mov %0, %%cr0" : : "r"(cr0) );
-}
-
-static inline unsigned long read_cr0()
-{
- unsigned long cr0;
-
- asm volatile ( "mov %%cr0, %0" : "=r"(cr0) );
- return cr0;
+ install_pte(cr3, 1, virt, phys | PTE_PRESENT | PTE_WRITE, 0);
}
-static inline void load_cr4(unsigned long cr4)
-{
- asm volatile ( "mov %0, %%cr4" : : "r"(cr4) );
-}
-
-static inline unsigned long read_cr4()
-{
- unsigned long cr4;
-
- asm volatile ( "mov %%cr4, %0" : "=r"(cr4) );
- return cr4;
-}
struct gdt_table_descr
{
Index: qemu-kvm/kvm/test/x86/vm.h
===================================================================
--- qemu-kvm.orig/kvm/test/x86/vm.h
+++ qemu-kvm/kvm/test/x86/vm.h
@@ -1,10 +1,85 @@
#ifndef VM_H
#define VM_H
+#define PAGE_SIZE 4096ul
+#ifdef __x86_64__
+#define LARGE_PAGE_SIZE (512 * PAGE_SIZE)
+#else
+#define LARGE_PAGE_SIZE (1024 * PAGE_SIZE)
+#endif
+
+#define PTE_PRESENT (1ull << 0)
+#define PTE_PSE (1ull << 7)
+#define PTE_WRITE (1ull << 1)
+#define PTE_ADDR (0xffffffffff000ull)
+
void setup_vm();
void *vmalloc(unsigned long size);
void vfree(void *mem);
void *vmap(unsigned long long phys, unsigned long size);
+void install_pte(unsigned long *cr3,
+ int pte_level,
+ void *virt,
+ unsigned long pte,
+ unsigned long *pt_page);
+
+void *alloc_page();
+
+void install_large_page(unsigned long *cr3,unsigned long phys,
+ void *virt);
+void install_page(unsigned long *cr3, unsigned long phys, void *virt);
+
+static inline unsigned long virt_to_phys(const void *virt)
+{
+ return (unsigned long)virt;
+}
+
+static inline void *phys_to_virt(unsigned long phys)
+{
+ return (void *)phys;
+}
+
+
+static inline void load_cr3(unsigned long cr3)
+{
+ asm ( "mov %0, %%cr3" : : "r"(cr3) );
+}
+
+static inline unsigned long read_cr3()
+{
+ unsigned long cr3;
+
+ asm volatile ( "mov %%cr3, %0" : "=r"(cr3) );
+ return cr3;
+}
+
+static inline void load_cr0(unsigned long cr0)
+{
+ asm volatile ( "mov %0, %%cr0" : : "r"(cr0) );
+}
+
+static inline unsigned long read_cr0()
+{
+ unsigned long cr0;
+
+ asm volatile ( "mov %%cr0, %0" : "=r"(cr0) );
+ return cr0;
+}
+
+
+static inline void load_cr4(unsigned long cr4)
+{
+ asm volatile ( "mov %0, %%cr4" : : "r"(cr4) );
+}
+
+static inline unsigned long read_cr4()
+{
+ unsigned long cr4;
+
+ asm volatile ( "mov %%cr4, %0" : "=r"(cr4) );
+ return cr4;
+}
+
#endif
Index: qemu-kvm/kvm/test/x86/emulator.c
===================================================================
--- qemu-kvm.orig/kvm/test/x86/emulator.c
+++ qemu-kvm/kvm/test/x86/emulator.c
@@ -220,14 +220,6 @@ jmpf:
report("ljmp", res);
}
-unsigned long read_cr0(void)
-{
- unsigned long cr0;
-
- asm volatile ("mov %%cr0, %0" : "=r"(cr0));
- return cr0;
-}
-
void test_smsw(void)
{
char mem[16];
^ permalink raw reply [flat|nested] 6+ messages in thread
* [patch 3/3] kvm test: long rmap chains
2010-07-05 18:16 [patch 0/3] [RESEND] kvm test: test rmap chains Marcelo Tosatti
2010-07-05 18:16 ` [patch 1/3] kvm test: protect fwfcg accesses with spinlock Marcelo Tosatti
2010-07-05 18:16 ` [patch 2/3] kvm test: export vm helpers Marcelo Tosatti
@ 2010-07-05 18:16 ` Marcelo Tosatti
2010-07-06 7:32 ` Avi Kivity
2010-07-06 7:27 ` [patch 0/3] [RESEND] kvm test: test " Avi Kivity
3 siblings, 1 reply; 6+ messages in thread
From: Marcelo Tosatti @ 2010-07-05 18:16 UTC (permalink / raw)
To: avi; +Cc: kvm, Marcelo Tosatti
[-- Attachment #1: 8-8-test-long-rmap-chains.patch --]
[-- Type: text/plain, Size: 2515 bytes --]
test long rmap chains
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: qemu-kvm/kvm/test/config-x86-common.mak
===================================================================
--- qemu-kvm.orig/kvm/test/config-x86-common.mak
+++ qemu-kvm/kvm/test/config-x86-common.mak
@@ -65,6 +65,9 @@ $(TEST_DIR)/idt_test.flat: $(cstart.o) $
$(TEST_DIR)/xsave.flat: $(cstart.o) $(TEST_DIR)/idt.o $(TEST_DIR)/xsave.o
+$(TEST_DIR)/rmap_chain.flat: $(cstart.o) $(TEST_DIR)/rmap_chain.o \
+ $(TEST_DIR)/print.o $(TEST_DIR)/vm.o
+
arch_clean:
$(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat \
$(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.o
Index: qemu-kvm/kvm/test/config-x86_64.mak
===================================================================
--- qemu-kvm.orig/kvm/test/config-x86_64.mak
+++ qemu-kvm/kvm/test/config-x86_64.mak
@@ -6,6 +6,6 @@ CFLAGS += -D__x86_64__
tests = $(TEST_DIR)/access.flat $(TEST_DIR)/apic.flat \
$(TEST_DIR)/emulator.flat $(TEST_DIR)/idt_test.flat \
- $(TEST_DIR)/xsave.flat
+ $(TEST_DIR)/xsave.flat $(TEST_DIR)/rmap_chain.flat
include config-x86-common.mak
Index: qemu-kvm/kvm/test/x86/rmap_chain.c
===================================================================
--- /dev/null
+++ qemu-kvm/kvm/test/x86/rmap_chain.c
@@ -0,0 +1,53 @@
+/* test long rmap chains */
+
+#include "libcflat.h"
+#include "vm.h"
+#include "smp.h"
+
+void print(const char *s);
+
+static unsigned int inl(unsigned short port)
+{
+ unsigned int val;
+ asm volatile ("inl %w1, %0":"=a" (val):"Nd" (port));
+ return val;
+}
+
+int main (void)
+{
+ int i;
+ int nr_pages;
+ void *target_page, *virt_addr;
+
+ setup_vm();
+
+ nr_pages = inl(0xd1) / PAGE_SIZE;
+ nr_pages -= 1000;
+ target_page = alloc_page();
+
+ virt_addr = (void *) 0xfffffa000;
+ for (i = 0; i < nr_pages; i++) {
+ install_page(phys_to_virt(read_cr3()), virt_to_phys(target_page),
+ virt_addr);
+ virt_addr += PAGE_SIZE;
+ }
+ printf("created %d mappings\n", nr_pages);
+
+ virt_addr = (void *) 0xfffffa000;
+ for (i = 0; i < nr_pages; i++) {
+ unsigned long *touch = virt_addr;
+
+ *touch = 0;
+ virt_addr += PAGE_SIZE;
+ }
+ printf("instantiated mappings\n");
+
+ virt_addr += PAGE_SIZE;
+ install_pte(phys_to_virt(read_cr3()), 1, virt_addr,
+ 0 | PTE_PRESENT | PTE_WRITE, target_page);
+
+ *(unsigned long *)virt_addr = 0;
+ printf("PASS\n");
+
+ return 0;
+}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch 0/3] [RESEND] kvm test: test rmap chains
2010-07-05 18:16 [patch 0/3] [RESEND] kvm test: test rmap chains Marcelo Tosatti
` (2 preceding siblings ...)
2010-07-05 18:16 ` [patch 3/3] kvm test: long rmap chains Marcelo Tosatti
@ 2010-07-06 7:27 ` Avi Kivity
3 siblings, 0 replies; 6+ messages in thread
From: Avi Kivity @ 2010-07-06 7:27 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: kvm
On 07/05/2010 09:16 PM, Marcelo Tosatti wrote:
Applied, thanks.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch 3/3] kvm test: long rmap chains
2010-07-05 18:16 ` [patch 3/3] kvm test: long rmap chains Marcelo Tosatti
@ 2010-07-06 7:32 ` Avi Kivity
0 siblings, 0 replies; 6+ messages in thread
From: Avi Kivity @ 2010-07-06 7:32 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: kvm
On 07/05/2010 09:16 PM, Marcelo Tosatti wrote:
> test long rmap chains
>
> +
> +int main (void)
> +{
> + int i;
> + int nr_pages;
> + void *target_page, *virt_addr;
> +
> + setup_vm();
> +
> + nr_pages = inl(0xd1) / PAGE_SIZE;
> + nr_pages -= 1000;
>
No need to depend on the number of physical pages, since just one page
is used (+ 1/512 page for the pte).
> + target_page = alloc_page();
> +
> + virt_addr = (void *) 0xfffffa000;
> + for (i = 0; i< nr_pages; i++) {
> + install_page(phys_to_virt(read_cr3()), virt_to_phys(target_page),
> + virt_addr);
> + virt_addr += PAGE_SIZE;
> + }
> + printf("created %d mappings\n", nr_pages);
> +
> + virt_addr = (void *) 0xfffffa000;
> + for (i = 0; i< nr_pages; i++) {
> + unsigned long *touch = virt_addr;
> +
> + *touch = 0;
> + virt_addr += PAGE_SIZE;
> + }
> + printf("instantiated mappings\n");
> +
> + virt_addr += PAGE_SIZE;
> + install_pte(phys_to_virt(read_cr3()), 1, virt_addr,
> + 0 | PTE_PRESENT | PTE_WRITE, target_page);
> +
> + *(unsigned long *)virt_addr = 0;
> + printf("PASS\n");
> +
>
Would be nice to add measure the time for this, and fail above some
threshold. Of course it's problematic in automated scenarios where the
host can be overloaded, but still.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-07-06 7:32 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-05 18:16 [patch 0/3] [RESEND] kvm test: test rmap chains Marcelo Tosatti
2010-07-05 18:16 ` [patch 1/3] kvm test: protect fwfcg accesses with spinlock Marcelo Tosatti
2010-07-05 18:16 ` [patch 2/3] kvm test: export vm helpers Marcelo Tosatti
2010-07-05 18:16 ` [patch 3/3] kvm test: long rmap chains Marcelo Tosatti
2010-07-06 7:32 ` Avi Kivity
2010-07-06 7:27 ` [patch 0/3] [RESEND] kvm test: test " Avi Kivity
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).