Re: [PATCH] x86/entry/64: Disallow RDPID in paranoid entry if KVM is enabled

From: peterz
Date: Fri Aug 21 2020 - 03:24:47 EST


On Thu, Aug 20, 2020 at 07:50:50PM -0700, Sean Christopherson wrote:
> diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
> index 70dea93378162..fd915c46297c5 100644
> --- a/arch/x86/entry/entry_64.S
> +++ b/arch/x86/entry/entry_64.S
> @@ -842,8 +842,13 @@ SYM_CODE_START_LOCAL(paranoid_entry)
> *
> * The MSR write ensures that no subsequent load is based on a
> * mispredicted GSBASE. No extra FENCE required.
> + *
> + * Disallow RDPID if KVM is enabled as it may consume a guest's TSC_AUX
> + * if an NMI arrives in KVM's run loop. KVM loads guest's TSC_AUX on
> + * VM-Enter and may not restore the host's value until the CPU returns
> + * to userspace, i.e. KVM depends on the kernel not using TSC_AUX.
> */
> - SAVE_AND_SET_GSBASE scratch_reg=%rax save_reg=%rbx
> + SAVE_AND_SET_GSBASE scratch_reg=%rax save_reg=%rbx no_rdpid=IS_ENABLED(CONFIG_KVM)
> ret

With distro configs that's going to be a guaranteed no_rdpid. Also with
a grand total of 0 performance numbers that RDPID is even worth it, I'd
suggest to just unconditionally remove that thing. Simpler code
all-around.