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

[xen staging] x86/pv: Make cr4_pv32_mask be PV32-only



commit 7ab0f83e604d44c92daa218423bf7644502fcefe
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Wed Aug 28 20:20:34 2024 +0100
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Fri Aug 30 18:08:48 2024 +0100

    x86/pv: Make cr4_pv32_mask be PV32-only
    
    The user of cr4_pv32_mask (the cr4_pv32_restore() function) only exists in a
    CONFIG_PV32 build, but right now the variable is unconditionally set up.
    
    To start with, move the setup into set_in_cr4() and remove it from it's
    somewhat ad-hoc position in __start_xen().  This means the variable will be
    set up in two steps for a CONFIG_PV32=y build, but it's cleaner and more
    robust logic overall.
    
    With that, there's no good reason for the variable to stay in setup.c.  Move
    it to x86/pv/domain.c (beside opt_pv32, for want of any better place to 
live),
    and move the declaration to beside set_in_cr4() and mmu_cr4_features which 
is
    a better position than setup.h.
    
    Guard the reference with CONFIG_PV32, and fix up a recent typo in an 
adjacent
    comment while at it.
    
    No functional change.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
 xen/arch/x86/include/asm/processor.h |  4 ++++
 xen/arch/x86/include/asm/setup.h     |  2 --
 xen/arch/x86/pv/dom0_build.c         | 10 +++++++---
 xen/arch/x86/pv/domain.c             |  1 +
 xen/arch/x86/setup.c                 |  4 ----
 5 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/xen/arch/x86/include/asm/processor.h 
b/xen/arch/x86/include/asm/processor.h
index 66463f6a6d..e71dbb8d3f 100644
--- a/xen/arch/x86/include/asm/processor.h
+++ b/xen/arch/x86/include/asm/processor.h
@@ -312,11 +312,15 @@ static inline void stts(void)
  * after us can get the correct flags.
  */
 extern unsigned long mmu_cr4_features;
+extern unsigned long cr4_pv32_mask;
 
 static always_inline void set_in_cr4 (unsigned long mask)
 {
     mmu_cr4_features |= mask;
     write_cr4(read_cr4() | mask);
+
+    if ( IS_ENABLED(CONFIG_PV32) && (mask & XEN_CR4_PV32_BITS) )
+        cr4_pv32_mask |= (mask & XEN_CR4_PV32_BITS);
 }
 
 static always_inline void __monitor(const void *eax, unsigned long ecx,
diff --git a/xen/arch/x86/include/asm/setup.h b/xen/arch/x86/include/asm/setup.h
index 8f7dfefb4d..d75589178b 100644
--- a/xen/arch/x86/include/asm/setup.h
+++ b/xen/arch/x86/include/asm/setup.h
@@ -64,8 +64,6 @@ extern bool opt_dom0_verbose;
 extern bool opt_dom0_cpuid_faulting;
 extern bool opt_dom0_msr_relaxed;
 
-extern unsigned long cr4_pv32_mask;
-
 #define max_init_domid (0)
 
 #endif
diff --git a/xen/arch/x86/pv/dom0_build.c b/xen/arch/x86/pv/dom0_build.c
index 57b1834b5e..262edb6bf2 100644
--- a/xen/arch/x86/pv/dom0_build.c
+++ b/xen/arch/x86/pv/dom0_build.c
@@ -1061,12 +1061,14 @@ int __init dom0_construct_pv(struct domain *d,
 
     /*
      * Clear SMAP in CR4 to allow user-accesses in construct_dom0().  This
-     * prevents us needing to write rewrite construct_dom0() in terms of
+     * prevents us needing to write construct_dom0() in terms of
      * copy_{to,from}_user().
      */
     if ( boot_cpu_has(X86_FEATURE_XEN_SMAP) )
     {
-        cr4_pv32_mask &= ~X86_CR4_SMAP;
+        if ( IS_ENABLED(CONFIG_PV32) )
+            cr4_pv32_mask &= ~X86_CR4_SMAP;
+
         write_cr4(read_cr4() & ~X86_CR4_SMAP);
     }
 
@@ -1075,7 +1077,9 @@ int __init dom0_construct_pv(struct domain *d,
     if ( boot_cpu_has(X86_FEATURE_XEN_SMAP) )
     {
         write_cr4(read_cr4() | X86_CR4_SMAP);
-        cr4_pv32_mask |= X86_CR4_SMAP;
+
+        if ( IS_ENABLED(CONFIG_PV32) )
+            cr4_pv32_mask |= X86_CR4_SMAP;
     }
 
     return rc;
diff --git a/xen/arch/x86/pv/domain.c b/xen/arch/x86/pv/domain.c
index 86b74fb372..d5a8564c1c 100644
--- a/xen/arch/x86/pv/domain.c
+++ b/xen/arch/x86/pv/domain.c
@@ -19,6 +19,7 @@
 
 #ifdef CONFIG_PV32
 int8_t __read_mostly opt_pv32 = -1;
+unsigned long __ro_after_init cr4_pv32_mask;
 #endif
 
 static int __init cf_check parse_pv(const char *s)
diff --git a/xen/arch/x86/setup.c b/xen/arch/x86/setup.c
index f1076c7203..c2e0082a30 100644
--- a/xen/arch/x86/setup.c
+++ b/xen/arch/x86/setup.c
@@ -79,8 +79,6 @@ bool __read_mostly use_invpcid;
 int8_t __initdata opt_probe_port_aliases = -1;
 boolean_param("probe-port-aliases", opt_probe_port_aliases);
 
-unsigned long __ro_after_init cr4_pv32_mask;
-
 /* **** Linux config option: propagated to domain0. */
 /* "acpi=off":    Sisables both ACPI table parsing and interpreter. */
 /* "acpi=force":  Override the disable blacklist.                   */
@@ -1898,8 +1896,6 @@ void asmlinkage __init noreturn __start_xen(unsigned long 
mbi_p)
     if ( boot_cpu_has(X86_FEATURE_XEN_SMAP) )
         set_in_cr4(X86_CR4_SMAP);
 
-    cr4_pv32_mask = mmu_cr4_features & XEN_CR4_PV32_BITS;
-
     if ( boot_cpu_has(X86_FEATURE_FSGSBASE) )
         set_in_cr4(X86_CR4_FSGSBASE);
 
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.