x86/boot: Sanitise PKRU on boot

While the reset value of the register is 0, it might not be after kexec/etc.
If PKEY0.{WD,AD} have leaked in from an earlier context, construction of a PV
dom0 will explode.

Sequencing wise, this must come after setting CR4.PKE, and before we touch any
user mappings.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
This commit is contained in:
Andrew Cooper committed 2023-01-20 19:39:32 +00:00
1 parent 5f08bc9404
commit c4f9a3bad3
3 files changed
+5 -1

No files matched your search

+3
View File
@@ -936,6 +936,9 @@ void cpu_init(void)
write_debugreg(6, X86_DR6_DEFAULT);
write_debugreg(7, X86_DR7_DEFAULT);
if (cpu_has_pku)
wrpkru(0);
/*
* If the platform is performing a Secure Launch via SKINIT, GIF is
* clear to prevent external interrupts interfering with Secure
+1
View File
@@ -109,6 +109,7 @@
/* CPUID level 0x00000007:0.ecx */
#define cpu_has_avx512_vbmi boot_cpu_has(X86_FEATURE_AVX512_VBMI)
#define cpu_has_pku boot_cpu_has(X86_FEATURE_PKU)
#define cpu_has_avx512_vbmi2 boot_cpu_has(X86_FEATURE_AVX512_VBMI2)
#define cpu_has_gfni boot_cpu_has(X86_FEATURE_GFNI)
#define cpu_has_vaes boot_cpu_has(X86_FEATURE_VAES)
+1 -1
View File
@@ -1798,7 +1798,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
if ( boot_cpu_has(X86_FEATURE_FSGSBASE) )
set_in_cr4(X86_CR4_FSGSBASE);
if ( boot_cpu_has(X86_FEATURE_PKU) )
if ( cpu_has_pku )
set_in_cr4(X86_CR4_PKE);
if ( opt_invpcid && cpu_has_invpcid )
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.