Re: [PATCH v16 33/51] KVM: nVMX: Add consistency checks for CET states

From: Sean Christopherson

Date: Mon Sep 22 2025 - 12:35:41 EST


On Mon, Sep 22, 2025, Binbin Wu wrote:
> On 9/20/2025 6:32 AM, Sean Christopherson wrote:
> Is the following simpler?

Yeah. I was going to say that separating checks in cases like this is sometimes
"better" when each statement deals with different state. But in this case, SSP
is bundled with S_CET, but not SSP_TBL, and so the whole thing is rather odd.

> index a8a421a8e766..17ba37c2bbfc 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -3102,13 +3102,8 @@ static bool is_l1_noncanonical_address_on_vmexit(u64 la, struct vmcs12 *vmcs12)
>
>  static bool is_valid_cet_state(struct kvm_vcpu *vcpu, u64 s_cet, u64 ssp, u64 ssp_tbl)
>  {
> -       if (!kvm_is_valid_u_s_cet(vcpu, s_cet) || !IS_ALIGNED(ssp, 4))
> -               return false;
> -
> -       if (is_noncanonical_msr_address(ssp_tbl, vcpu))
> -               return false;
> -
> -       return true;
> +       return (kvm_is_valid_u_s_cet(vcpu, s_cet) && IS_ALIGNED(ssp, 4) &&
> +               !is_noncanonical_msr_address(ssp_tbl, vcpu));

Parantheses are unnecessary.

But looking at this again, is_valid_cet_state() is a misleading name. In isolation,
it would be very easy to assume the helper checks _all_ CET state, but that's not
the case. And the other flaw is that the CC() tracepoint won't identify exactly
which check failed.

Completely untested, but assuming I didn't fat-finger something, I'll fixup to
this:

static int nested_vmx_check_cet_state_common(struct kvm_vcpu *vcpu, u64 s_cet,
u64 ssp, u64 ssp_tbl)
{
if (CC(!kvm_is_valid_u_s_cet(vcpu, s_cet)) || CC(!IS_ALIGNED(ssp, 4)) ||
CC(is_noncanonical_msr_address(ssp_tbl, vcpu)))
return -EINVAL;

return 0;
}