]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
x86/dom0: only disable SMAP for the PV dom0 build
authorRoger Pau Monne <roger.pau@citrix.com>
Tue, 18 Jun 2024 14:51:51 +0000 (16:51 +0200)
committerRoger Pau Monne <roger.pau@citrix.com>
Tue, 25 Jun 2024 09:16:34 +0000 (11:16 +0200)
The PVH dom0 builder doesn't switch page tables and has no need to run with
SMAP disabled.

Put the SMAP disabling close to the code region where it's necessary, as it
then becomes obvious why switch_cr3_cr4() is required instead of
write_ptbase().

Note removing SMAP from cr4_pv32_mask is not required, as we never jump into
guest context, and hence updating the value of cr4_pv32_mask is not relevant.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
xen/arch/x86/pv/dom0_build.c

index d8043fa58a274f890fd57797a5c9aa3c589c55c4..05e49435d9c8e744cee427469740268068d4d83b 100644 (file)
@@ -814,6 +814,13 @@ int __init dom0_construct_pv(struct domain *d,
     /* Set up CR3 value for switch_cr3_cr4(). */
     update_cr3(v);
 
+    /*
+     * Temporarily clear SMAP in CR4 to allow user-accesses when running with
+     * the dom0 page-tables.
+     */
+    if ( cpu_has_smap )
+        write_cr4(read_cr4() & ~X86_CR4_SMAP);
+
     /* We run on dom0's page tables for the final part of the build process. */
     switch_cr3_cr4(cr3_pa(v->arch.cr3), read_cr4());
     mapcache_override_current(v);
@@ -837,6 +844,8 @@ int __init dom0_construct_pv(struct domain *d,
         {
             mapcache_override_current(NULL);
             switch_cr3_cr4(current->arch.cr3, read_cr4());
+            if ( cpu_has_smap )
+                write_cr4(read_cr4() | X86_CR4_SMAP);
             printk("Invalid HYPERCALL_PAGE field in ELF notes.\n");
             return -EINVAL;
         }
@@ -980,6 +989,9 @@ int __init dom0_construct_pv(struct domain *d,
     mapcache_override_current(NULL);
     switch_cr3_cr4(current->arch.cr3, read_cr4());
 
+    if ( cpu_has_smap )
+        write_cr4(read_cr4() | X86_CR4_SMAP);
+
     update_domain_wallclock_time(d);
 
     /*