]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
Provide a common user_stack[] for tests
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 2 Mar 2017 16:04:49 +0000 (16:04 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 6 Mar 2017 10:55:41 +0000 (10:55 +0000)
Automatically remap this frame as _PAGE_USER.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/hvm/traps.c
arch/x86/include/arch/traps.h
arch/x86/link.lds.S
arch/x86/pv/traps.c
arch/x86/setup.c
include/xtf/traps.h
tests/xsa-183/main.c

index eb05f271569b93e1c9462c326d67a7e1aba0ae4e..cfaa69b31c2c25f4973cf8a068e7116732cf63a6 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <arch/idt.h>
 #include <arch/lib.h>
+#include <arch/mm.h>
 #include <arch/processor.h>
 #include <arch/desc.h>
 
@@ -153,6 +154,22 @@ void arch_init_traps(void)
 
     gdt[GDTE_TSS] = (typeof(*gdt))INIT_GDTE((unsigned long)&tss, 0x67, 0x89);
     ltr(GDTE_TSS * 8);
+
+    /*
+     * If we haven't applied blanket PAGE_USER mappings, remap the structures
+     * which specifically want to be user.
+     */
+    if ( !test_wants_user_mappings )
+    {
+        unsigned long gfn = virt_to_gfn(user_stack);
+
+        if ( gfn >= ARRAY_SIZE(l1_identmap) )
+            panic("user_stack[] outside of l1_identmap[]\n");
+
+        l1_identmap[gfn] |= _PAGE_USER;
+
+        write_cr3((unsigned long)&cr3_target);
+    }
 }
 
 void __noreturn arch_crash_hard(void)
index ae68293c9e4d630af017ec7df2986a658dbf5d33..a428630b6faad0819fd89dd233edd4c8e37581c3 100644 (file)
@@ -24,6 +24,7 @@ unsigned long cpu_regs_sp(const struct cpu_regs *regs);
 unsigned int  cpu_regs_ss(const struct cpu_regs *regs);
 
 extern uint8_t boot_stack[3 * PAGE_SIZE];
+extern uint8_t user_stack[PAGE_SIZE];
 
 #if defined(CONFIG_PV)
 #include <xen/xen.h>
index 4f7eaf54bc807ffa3a587bea390d6ce51a86861c..1f4f604a4c094e414dae0877567e76f79700db64 100644 (file)
@@ -72,6 +72,7 @@ zeroptr = 0;
 
 ASSERT(IS_ALIGNED(hypercall_page, PAGE_SIZE), "hypercall_page misaligned");
 ASSERT(IS_ALIGNED(boot_stack, PAGE_SIZE), "boot_stack misaligned");
+ASSERT(IS_ALIGNED(user_stack, PAGE_SIZE), "user_stack misaligned");
 
 #ifdef CONFIG_HVM
 
index 9561cbaab7b320bc21204dce015a4defefdeed8b..f4a1b17281520dc92912e46aeb3ddc9031f256b0 100644 (file)
@@ -212,6 +212,17 @@ void arch_init_traps(void)
             va += 1UL << L1_PT_SHIFT;
         }
     }
+    else
+    {
+        /*
+         * If we haven't applied blanket PAGE_USER mappings, remap the
+         * structures which specifically want to be user.
+         */
+        intpte_t nl1e = pte_from_virt(user_stack, PF_SYM(AD, U, RW, P));
+
+        if ( hypercall_update_va_mapping(user_stack, nl1e, UVMF_INVLPG) )
+            panic("Unable to remap user_stack with _PAGE_USER\n");
+    }
 #endif
 
     /* Unmap page at 0 to catch errors with NULL pointers. */
index 497c368d8f39df1befe2ece14d403fd2e68ca309..45fef99dc9276f94d5858d0734b37865d62a0d8c 100644 (file)
@@ -17,6 +17,7 @@
  * boot_stack[page 1] Top of work stack
  */
 uint8_t boot_stack[3 * PAGE_SIZE] __aligned(PAGE_SIZE);
+uint8_t user_stack[PAGE_SIZE] __aligned(PAGE_SIZE);
 uint32_t x86_features[FSCAPINTS];
 enum x86_vendor x86_vendor;
 unsigned int x86_family, x86_model, x86_stepping;
index 872b86f7ad75505d497616792e2d32d8958762ac..6deb496efcfec16bd8ccd2a9e18b9c8551a9e0ce 100644 (file)
@@ -2,6 +2,7 @@
 #define XTF_TRAPS_H
 
 #include <xtf/extable.h>
+#include <xtf/test.h>
 
 #include <arch/traps.h>
 
index b388283c5491ed1a014790d3a111ca1e57bcc9fc..12cc7b7865a9479689193d9bb362a376a4e08842 100644 (file)
 
 const char test_title[] = "XSA-183 PoC";
 
-uint8_t user_stack[PAGE_SIZE] __aligned(PAGE_SIZE);
-
 void test_main(void)
 {
     unsigned long curr_stk, discard;
-    intpte_t nl1e = pte_from_virt(user_stack, PF_SYM(AD, U, RW, P));
-
-    /* Remap user_stack with _PAGE_USER. */
-    if ( hypercall_update_va_mapping(user_stack, nl1e, UVMF_INVLPG) )
-        panic("Unable to remap user_stack with _PAGE_USER\n");
 
     /* Load NULL selector to guarantee a fault. */
     write_fs(0);