x86/pv: Make cr4_pv32_mask be PV32-only
PATCH 1/1 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/traps.c (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.
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
--- 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/traps.c | 4 ++++ xen/arch/x86/setup.c | 4 ---- 5 files changed, 15 insertions(+), 9 deletions(-)
xen/arch/x86/include/asm/processor.h +4 -0
@@ -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,
xen/arch/x86/include/asm/setup.h +0 -2
@@ -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
xen/arch/x86/pv/dom0_build.c +7 -3
@@ -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;
xen/arch/x86/pv/traps.c +4 -0
@@ -18,6 +18,10 @@#include <asm/traps.h> #include <irq_vectors.h> +#ifdef CONFIG_PV32 +unsigned long __ro_after_init cr4_pv32_mask; +#endif +void pv_inject_event (const struct x86_event *event) {struct vcpu *curr = current;
xen/arch/x86/setup.c +0 -4
@@ -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 );
base-commit: 99f942f3d410059dc223ee0a908827e928ef3592
Signature · 1 line
2.39.2
Quoted 13 lines · Andrew Cooper
The user of
cr4_pv32_mask(thecr4_pv32_restore()function) only exists in aCONFIG_PV32build, 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 aCONFIG_PV32=ybuild, 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 tox86/pv/traps.c(for want of any better place to live), and move the declaration to besideset_in_cr4()andmmu_cr4_featureswhich is a better position thansetup.h.
Quoted 6 lines
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 <[email protected]>
with a suggestion:
xen/arch/x86/pv/traps.c line 23
Quoted 9 lines
xen/arch/x86/pv/traps.c +3
-0@@ -18,6 +18,10 @@#include <asm/traps.h> #include <irq_vectors.h> +#ifdef CONFIG_PV32 +unsigned long __ro_after_init cr4_pv32_mask; +#endif
To save on the number of such #ifdef-s, how about moving this into an existing one. pv/mm.c has one, albeit near the bottom of the file (which I'd be fine with, but I could imagine you or others not liking such placement), and pv/domain.c has one near the top which seems pretty well suited.
Jan
Roger Pau Monné
Reviewed-byQuoted 30 lines · Jan Beulich
Quoted 13 lines · Andrew Cooper
The user of
cr4_pv32_mask(thecr4_pv32_restore()function) only exists in aCONFIG_PV32build, 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 aCONFIG_PV32=ybuild, 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 tox86/pv/traps.c(for want of any better place to live), and move the declaration to besideset_in_cr4()andmmu_cr4_featureswhich is a better position thansetup.h.Quoted 6 lines
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 <[email protected]>Reviewed-by Jan Beulich <[email protected]>with a suggestion:
Quoted 6 lines
xen/arch/x86/pv/traps.c +0
-0@@ -18,6 +18,10 @@#include <asm/traps.h> #include <irq_vectors.h>
Quoted 8 lines
xen/arch/x86/pv/traps.c line 23
Quoted 3 lines
xen/arch/x86/pv/traps.c +3
-0+#ifdef CONFIG_PV32 +unsigned long __ro_after_init cr4_pv32_mask; +#endif To save on the number of such #ifdef-s, how about moving this into an existing one.
pv/mm.chas one, albeit near the bottom of the file (which I'd be fine with, but I could imagine you or others not liking such placement), andpv/domain.chas one near the top which seems pretty well suited.
I'm fine either way:
Thanks, Roger.
Quoted 37 lines · Roger Pau Monné
Quoted 29 lines · Jan Beulich
Quoted 13 lines · Andrew Cooper
The user of
cr4_pv32_mask(thecr4_pv32_restore()function) only exists in aCONFIG_PV32build, 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 aCONFIG_PV32=ybuild, 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 tox86/pv/traps.c(for want of any better place to live), and move the declaration to besideset_in_cr4()andmmu_cr4_featureswhich is a better position thansetup.h.Quoted 6 lines
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 <[email protected]>Reviewed-by Jan Beulich <[email protected]>with a suggestion:
Quoted 6 lines
xen/arch/x86/pv/traps.c +0
-0@@ -18,6 +18,10 @@#include <asm/traps.h> #include <irq_vectors.h> Quoted 7 lines
xen/arch/x86/pv/traps.c line 23
Quoted 3 lines
xen/arch/x86/pv/traps.c +3
-0+#ifdef CONFIG_PV32 +unsigned long __ro_after_init cr4_pv32_mask; +#endif To save on the number of such #ifdef-s, how about moving this into an existing one.
pv/mm.chas one, albeit near the bottom of the file (which I'd be fine with, but I could imagine you or others not liking such placement), andpv/domain.chas one near the top which seems pretty well suited.
Quoted 5 lines
I'm fine either way:
Reviewed-by Roger Pau Monné <[email protected]>Thanks, Roger.
Thanks. I'll put it alongside opt_pv32 in pv/domain.c which is indeed pretty well suited.
~Andrew