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

Chao Gao
2025-09-22T11:28:08Z

>@@ -12178,6 +12178,25 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int idt_index,
> struct x86_emulate_ctxt *ctxt = vcpu->arch.emulate_ctxt;
> int ret;
>
>+ if (kvm_is_cr4_bit_set(vcpu, X86_CR4_CET)) {
>+ u64 u_cet, s_cet;
>+
>+ /*
>+ * Check both User and Supervisor on task switches as inter-
>+ * privilege level task switches are impacted by CET at both
>+ * the current privilege level and the new privilege level, and
>+ * that information is not known at this time. The expectation
>+ * is that the guest won't require emulation of task switches
>+ * while using IBT or Shadow Stacks.
>+ */
>+ 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;

is it ok to return EMULATION_FAILED (-1) here?

It looks like this error code will be propagated to userspace and be
interpreted as -EPERM.