[kvm-unit-tests PATCH v1 1/2] x86: smap: fix the test to work with new allocator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The test used to simply take a chunk of memory and use it, hoping the
memory allocator would never touch it. The memory area used was exactly
at the beginning of the 16M boundary.

The new allocator stores metadata information there, and causes the
test to fail.

This patch uses the new features of the allocator to properly reserve
a memory block. To make things easier and cleaner, the memory area used
is now smaller and starts at 8M.

Signed-off-by: Claudio Imbrenda <imbrenda@xxxxxxxxxxxxx>
Reported-by: David Matlack <dmatlack@xxxxxxxxxx>
---
 x86/smap.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/x86/smap.c b/x86/smap.c
index 5782c4a..ac2c8d5 100644
--- a/x86/smap.c
+++ b/x86/smap.c
@@ -1,4 +1,5 @@
 #include "libcflat.h"
+#include <alloc_page.h>
 #include "x86/desc.h"
 #include "x86/processor.h"
 #include "x86/vm.h"
@@ -44,7 +45,7 @@ asm ("pf_tss:\n"
         "jmp pf_tss\n\t");
 
 
-#define USER_BASE	(1 << 24)
+#define USER_BASE	(1 << 23)
 #define USER_VAR(v)	(*((__typeof__(&(v))) (((unsigned long)&v) + USER_BASE)))
 #define USER_ADDR(v)   ((void *)((unsigned long)(&v) + USER_BASE))
 
@@ -101,13 +102,15 @@ int main(int ac, char **av)
 	setup_alt_stack();
 	set_intr_alt_stack(14, pf_tss);
 
-	// Map first 16MB as supervisor pages
+	if (reserve_pages(USER_BASE, USER_BASE >> 12))
+		report_abort("Could not reserve memory");
+	// Map first 8MB as supervisor pages
 	for (i = 0; i < USER_BASE; i += PAGE_SIZE) {
 		*get_pte(phys_to_virt(read_cr3()), phys_to_virt(i)) &= ~PT_USER_MASK;
 		invlpg((void *)i);
 	}
 
-	// Present the same 16MB as user pages in the 16MB-32MB range
+	// Present the same 8MB as user pages in the 8MB-16MB range
 	for (i = USER_BASE; i < 2 * USER_BASE; i += PAGE_SIZE) {
 		*get_pte(phys_to_virt(read_cr3()), phys_to_virt(i)) &= ~USER_BASE;
 		invlpg((void *)i);
-- 
2.26.2




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux