]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
XTF: Drop test_wants_user_mappings
authorAndrew Cooper <andrew.cooper3@citrix.com>
Sat, 2 Mar 2024 22:54:27 +0000 (22:54 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Sun, 3 Mar 2024 00:13:29 +0000 (00:13 +0000)
This was a giant bodge around several bugs in Xen, all of which have been
fixed since Xen 4.8, and around XTF deficiences, now fixed with __text_user.

Xen 4.8 is a perfectly old enough minimum baseline now.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/hvm/head.S
arch/x86/hvm/traps.c
arch/x86/pv/traps.c
arch/x86/setup.c
docs/mainpage.dox
include/xtf/test.h

index cfe165e2832f7db9fec2594cc27c19d4843ee5d2..f94dd0bc284407dec17f169e0ae91a1861062104 100644 (file)
@@ -13,21 +13,6 @@ GLOBAL(_elf_start)              /* HVM common setup. */
 
 #if CONFIG_PAGING_LEVELS > 0    /* Paging setup for CR3 and CR4 */
 
-        /* Set _PAGE_USER on leaf mappings if a test wants them. */
-        cmpb $0, test_wants_user_mappings
-        je .Lskip_user
-
-        mov $l1_identmap, %edx
-        mov $l2_identmap_end, %ecx
-        sub %edx, %ecx
-        shr $PTE_ORDER, %ecx
-        add $PTE_SIZE, %edx /* Avoid setting _PAGE_USER in the NULL entry. */
-.Lnext_pte:
-        orb $_PAGE_USER, (%edx)
-        add $PTE_SIZE, %edx
-        loop .Lnext_pte
-.Lskip_user:
-
 #if CONFIG_PAGING_LEVELS == 2
         mov $X86_CR4_PSE, %eax
 #elif CONFIG_PAGING_LEVELS == 3 || CONFIG_PAGING_LEVELS == 4
index 6eee8124023126f6d0a5bd0013b5a8c2b5099dab..ad7b8cbc3ddaec6bd0c42083ac5bcc5bbce14a1e 100644 (file)
@@ -122,26 +122,21 @@ void arch_init_traps(void)
     ltr(GDTE_TSS * 8);
 
     /*
-     * If we haven't applied blanket PAGE_USER mappings, remap the structures
-     * which specifically want to be user.
+     * Remap the structures which specifically want to be user.  No need for a
+     * TLB flush as this is a strict relaxing of permissions.
      */
-    if ( !test_wants_user_mappings )
-    {
-        extern const char __start_user_text[], __end_user_text[];
-        extern const char __start_user_data[], __end_user_data[];
-        extern const char __start_user_bss[],  __end_user_bss[];
-
-        remap_user(virt_to_gfn(__start_user_text),
-                   virt_to_gfn(__end_user_text));
+    extern const char __start_user_text[], __end_user_text[];
+    extern const char __start_user_data[], __end_user_data[];
+    extern const char __start_user_bss[],  __end_user_bss[];
 
-        remap_user(virt_to_gfn(__start_user_data),
-                   virt_to_gfn(__end_user_data));
+    remap_user(virt_to_gfn(__start_user_text),
+               virt_to_gfn(__end_user_text));
 
-        remap_user(virt_to_gfn(__start_user_bss),
-                   virt_to_gfn(__end_user_bss));
+    remap_user(virt_to_gfn(__start_user_data),
+               virt_to_gfn(__end_user_data));
 
-        write_cr3(_u(cr3_target));
-    }
+    remap_user(virt_to_gfn(__start_user_bss),
+               virt_to_gfn(__end_user_bss));
 }
 
 void __noreturn arch_crash_hard(void)
index e78f97e6f933861a7c4f5d0cda77dc88ec26fbec..66ef40e366f674c09fa5254499d601283d977ecf 100644 (file)
@@ -77,20 +77,6 @@ int xtf_set_idte(unsigned int vector, const struct xtf_idte *idte)
     return hypercall_set_trap_table(ti);
 }
 
-static bool __maybe_unused ex_pf_user(struct cpu_regs *regs,
-                                      const struct extable_entry *ex)
-{
-    if ( regs->entry_vector == X86_EXC_PF && read_cr2() == 0xfff )
-    {
-        regs->ax = true;
-        regs->ip = ex->fixup;
-
-        return true;
-    }
-
-    return false;
-}
-
 static int remap_linear(const void *linear, uint64_t flags)
 {
     intpte_t nl1e = pte_from_virt(linear, flags);
@@ -199,116 +185,19 @@ void arch_init_traps(void)
         panic("Failed to set user %%cr3: %d\n", rc);
 
 #elif defined(__i386__)
-    if ( test_wants_user_mappings )
-    {
-        /*
-         * XTF uses a shared user/kernel address space, and _PAGE_USER must be
-         * set to permit cpl3 access to the virtual addresses without taking a
-         * pagefault.
-         *
-         * PV guests and Xen share a virtual address space, and before Xen
-         * 4.7, Xen's setting of CR4.{SMEP,SMAP} leaked with 32bit PV guests.
-         * On hardware which supports SMEP/SMAP, older versions of Xen must be
-         * booted with 'smep=0 smap=0' for pv32pae tests to run.
-         */
-
-        /*
-         * First, probe whether Xen is leaking its SMEP/SMAP settings.
-         */
-        intpte_t nl1e = pte_from_gfn(pfn_to_mfn(0), PF_SYM(AD, U, RW, P));
-        bool leaked = false;
-
-        /* Remap the page at 0 with _PAGE_USER. */
-        rc = hypercall_update_va_mapping(0, nl1e, UVMF_INVLPG);
-        if ( rc )
-            panic("Failed to remap page at NULL with _PAGE_USER: %d\n", rc);
-
-        /*
-         * Write a `ret` instruction into the page at 0 (will be caught by
-         * leaked SMAP), then attempt to call at the `ret` instruction (will
-         * be caught by leaked SMEP).
-         */
-        asm volatile ("1: movb $0xc3, (%[ptr]);"
-                      "call *%[ptr];"
-                      "jmp 3f;"
-                      "2: ret;"
-                      "3:"
-                      _ASM_EXTABLE_HANDLER(1b,    3b, %P[rec])
-                      _ASM_EXTABLE_HANDLER(0xfff, 2b, %P[rec])
-                      : "+a" (leaked)
-                      : [ptr] "r" (0xfff),
-                        [rec] "p" (ex_pf_user));
-
-        if ( leaked )
-            panic("Xen's SMEP/SMAP settings leaked into guest context.\n"
-                  "Must boot this Xen with 'smep=0 smap=0' to run this test.\n");
-
-        /*
-         * If we have got this far, SMEP/SMAP are not leaking into guest
-         * context.  Proceed with remapping all mappings as _PAGE_USER.
-         */
-        uint64_t *l3 = _p(pv_start_info->pt_base);
-        unsigned long linear = 0;
-
-        while ( linear < __HYPERVISOR_VIRT_START_PAE )
-        {
-            unsigned int i3 = l3_table_offset(linear);
-
-            if ( !(l3[i3] & _PAGE_PRESENT) )
-            {
-                linear += 1UL << L3_PT_SHIFT;
-                continue;
-            }
-
-            uint64_t *l2 = maddr_to_virt(pte_to_paddr(l3[i3]));
-            unsigned int i2 = l2_table_offset(linear);
-
-            if ( !(l2[i2] & _PAGE_PRESENT) )
-            {
-                linear += 1UL << L2_PT_SHIFT;
-                continue;
-            }
-
-            uint64_t *l1 = maddr_to_virt(pte_to_paddr(l2[i2]));
-            unsigned int i1 = l1_table_offset(linear);
-
-            if ( !(l1[i1] & _PAGE_PRESENT) )
-            {
-                linear += 1UL << L1_PT_SHIFT;
-                continue;
-            }
-
-            if ( !(l1[i1] & _PAGE_USER) )
-            {
-                rc = hypercall_update_va_mapping(
-                    linear, l1[i1] | _PAGE_USER, UVMF_INVLPG);
-                if ( rc )
-                    panic("update_va_mapping(%p, 0x%016"PRIx64") failed: %d\n",
-                          _p(linear), l1[i1] | _PAGE_USER, rc);
-            }
-
-            linear += 1UL << L1_PT_SHIFT;
-        }
-    }
-    else
-    {
-        /*
-         * If we haven't applied blanket PAGE_USER mappings, remap the
-         * structures which specifically want to be user.
-         */
-        extern const char __start_user_text[], __end_user_text[];
-        extern const char __start_user_data[], __end_user_data[];
-        extern const char __start_user_bss[],  __end_user_bss[];
-
-        remap_linear_range(__start_user_text, __end_user_text,
-                           PF_SYM(AD, U, RW, P));
-
-        remap_linear_range(__start_user_data, __end_user_data,
-                           PF_SYM(AD, U, RW, P));
-
-        remap_linear_range(__start_user_bss, __end_user_bss,
-                           PF_SYM(AD, U, RW, P));
-    }
+    /* Remap the structures which specifically want to be user. */
+    extern const char __start_user_text[], __end_user_text[];
+    extern const char __start_user_data[], __end_user_data[];
+    extern const char __start_user_bss[],  __end_user_bss[];
+
+    remap_linear_range(__start_user_text, __end_user_text,
+                       PF_SYM(AD, U, RW, P));
+
+    remap_linear_range(__start_user_data, __end_user_data,
+                       PF_SYM(AD, U, RW, P));
+
+    remap_linear_range(__start_user_bss, __end_user_bss,
+                       PF_SYM(AD, U, RW, P));
 #endif
 
     /* Unmap page at 0 to catch errors with NULL pointers. */
index 3c84e963f90bb83e79ddec2892e5bb7b0a06774a..d47fb620109112c277dfbb03ab1fc0d30911c5dd 100644 (file)
@@ -284,7 +284,6 @@ bool xtf_has_fep = false;
  * test_needs_* indicates options required by the test, without which the test
  * isn't worth running.
  */
-bool __weak test_wants_user_mappings = false;
 bool __weak test_needs_fep = false;
 
 void test_setup(void)
index 782f115171de7257df0b9c28cf0034ea6bc8c7ac..feb4744d54afdf2e0f1a0e44b44229139df58679 100644 (file)
@@ -33,6 +33,7 @@ Environment | Guest | Width | Paging
 @section getting-started Getting Started
 
 Requirements:
+- Xen 4.8 or later
 - GNU Make >= 3.81
 - Python 2.7 or later
 
@@ -70,15 +71,6 @@ To run tests on a Xen host: (see @ref errata first)
 
 @section errata Errata
 
-- Xen 4.6 and earlier running on hardware with SMEP (Intel IvyBridge/AMD
-  Excavator and later) or SMAP (Intel Broadwell/AMD Zen or later) leaked its
-  SMEP/SMAP settings into 32bit PV guests, which interferes with some tests.
-  Xen 4.7 and later is fixed not to leak its SMAP/SMEP settings.
-
-  To run certain pv32pae tests against Xen 4.6 or earlier on such hardware,
-  Xen must be booted with `"smep=0 smap=0"`.  Affected pv32pae tests will
-  probe for leaked settings and panic with a suitable error.
-
 - For the paths of binaries, `xl` accepts either an absolute path, or certain
   relative paths (`/etc/xen/` or `$CWD` for `kernel=`, `$libdir/xen/boot` for
   `firmware_override=`).  The default `xtfdir=` is configured correctly for
index 1584e5054693fcc1f1b0fc6a72d2134cea39cd8e..9e3dd2940b89923b8c2506bb57bf5407ea004698 100644 (file)
@@ -24,20 +24,6 @@ extern const char test_title[];
  */
 extern bool xtf_has_fep;
 
-/**
- * Boolean indicating whether the test wants user mappings or not.
- *
- * Some tests want an easy transition between supervisor and user modes.  For
- * such tests, this requires running on _PAGE_USER mappings, and they must
- * opt-in.
- *
- * @see @ref errata
- *
- * The framework variable is a weak reference, and may be overridden by a test
- * wishing to change the default.
- */
-extern bool test_wants_user_mappings;
-
 /**
  * Boolean indicating whether the test is entirely predicated on the available
  * of the Force Emulation Prefix.