Re: [PATCH 14/29] x86/ibt: Add IBT feature, MSR and #CP handling

From: Andrew Cooper
Date: Fri Feb 18 2022 - 14:32:03 EST


On 18/02/2022 16:49, Peter Zijlstra wrote:
> --- a/arch/x86/kernel/cpu/common.c
> +++ b/arch/x86/kernel/cpu/common.c
> @@ -592,6 +593,27 @@ static __init int setup_disable_pku(char
> __setup("nopku", setup_disable_pku);
> #endif /* CONFIG_X86_64 */
>
> +static __always_inline void setup_cet(struct cpuinfo_x86 *c)
> +{
> + u64 msr;
> +
> + if (!IS_ENABLED(CONFIG_X86_IBT) ||
> + !cpu_feature_enabled(X86_FEATURE_IBT))
> + return;
> +
> + cr4_set_bits(X86_CR4_CET);
> +
> + rdmsrl(MSR_IA32_S_CET, msr);
> + if (cpu_feature_enabled(X86_FEATURE_IBT))
> + msr |= CET_ENDBR_EN;
> + wrmsrl(MSR_IA32_S_CET, msr);

So something I learnt the hard way with shstk is that you really want to
disable S_CET before heading into purgatory.

I've got no idea what's going to result from UEFI finally getting CET
support.  However, clearing out the other IBT settings is probably a
wise move.

In particular, if there was a stale legacy bitmap pointer, then
ibt_selftest() could take #PF ahead of #CP.

~Andrew