x86/cpu: Write the default PKRU value when enabling PKE
authorThomas Gleixner <tglx@linutronix.de>
Wed, 23 Jun 2021 12:02:10 +0000 (14:02 +0200)
committerBorislav Petkov <bp@suse.de>
Wed, 23 Jun 2021 17:14:54 +0000 (19:14 +0200)
In preparation of making the PKRU management more independent from XSTATES,
write the default PKRU value into the hardware right after enabling PKRU in
CR4. This ensures that switch_to() and copy_thread() have the correct
setting for init task and the per CPU idle threads right away.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20210623121455.622983906@linutronix.de
arch/x86/kernel/cpu/common.c

index dbfb335..ca668ef 100644 (file)
@@ -480,6 +480,8 @@ static __always_inline void setup_pku(struct cpuinfo_x86 *c)
        }
 
        cr4_set_bits(X86_CR4_PKE);
+       /* Load the default PKRU value */
+       pkru_write_default();
 }
 
 #ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS