Re: [PATCH v16 19/51] KVM: x86: Don't emulate task switches when IBT or SHSTK is enabled

Xiaoyao Li
2025-09-23T14:17:04Z

On 9/23/2025 1:23 AM, Sean Christopherson wrote:
> On Mon, Sep 22, 2025, Binbin Wu wrote:
>>
>>
>> On 9/20/2025 6:32 AM, Sean Christopherson wrote:
>>> Exit to userspace with KVM_INTERNAL_ERROR_EMULATION if the guest triggers
>>> task switch emulation with Indirect Branch Tracking or Shadow Stacks
>>> enabled,
>>
>> The code just does it when shadow stack is enabled.
>
> Doh. Fixed that and the EMULATION_FAILED typo Chao pointed out:
>
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 8b31dfcb1de9..06a88a2b08d7 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -12194,9 +12194,9 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int idt_index,
> */
> if (__kvm_emulate_msr_read(vcpu, MSR_IA32_U_CET, &u_cet) ||
> __kvm_emulate_msr_read(vcpu, MSR_IA32_S_CET, &s_cet))
> - return EMULATION_FAILED;
> + goto unhandled_task_switch;
>
> - if ((u_cet | s_cet) & CET_SHSTK_EN)
> + if ((u_cet | s_cet) & (CET_ENDBR_EN | CET_SHSTK_EN))
> goto unhandled_task_switch;
> }

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>