Re: [patch V2 04/14] x86/pkru: Make the fpinit state update work
From: Borislav Petkov
Date: Mon Jun 07 2021 - 11:18:50 EST
On Sun, Jun 06, 2021 at 01:47:46AM +0200, Thomas Gleixner wrote:
> @@ -120,6 +121,8 @@ void __init check_bugs(void)
>
> arch_smt_update();
>
> + pkru_propagate_default();
I guess this fits better at the end of identify_boot_cpu(), which is
pretty close to here, in the boot order.
Regardless, that function check_bugs() needs cleaning up as it has
collected a lot more stuff than just checking the bugs nasty.
> +void pkru_propagate_default(void)
> {
> - u32 init_pkru_value_snapshot = READ_ONCE(init_pkru_value);
> + struct pkru_state *pk;
> +
> + if (!boot_cpu_has(X86_FEATURE_OSPKE))
cpu_feature_enabled()
> + return;
> /*
> - * Override the PKRU state that came from 'init_fpstate'
> - * with the baseline from the process.
> + * Force XFEATURE_PKRU to be set in the header otherwise
> + * get_xsave_addr() does not work and it needs to be set
> + * to make XRSTOR(S) load it.
> */
> - write_pkru(init_pkru_value_snapshot);
> + init_fpstate.xsave.header.xfeatures |= XFEATURE_MASK_PKRU;
> + pk = get_xsave_addr(&init_fpstate.xsave, XFEATURE_PKRU);
> + pk->pkru = READ_ONCE(init_pkru_value);
> }
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette