[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aNF62zmnuXTETlKv@google.com>
Date: Mon, 22 Sep 2025 09:35:39 -0700
From: Sean Christopherson <seanjc@...gle.com>
To: Binbin Wu <binbin.wu@...ux.intel.com>
Cc: Paolo Bonzini <pbonzini@...hat.com>, kvm@...r.kernel.org, linux-kernel@...r.kernel.org,
Tom Lendacky <thomas.lendacky@....com>, Mathias Krause <minipli@...ecurity.net>,
John Allen <john.allen@....com>, Rick Edgecombe <rick.p.edgecombe@...el.com>,
Chao Gao <chao.gao@...el.com>, Xiaoyao Li <xiaoyao.li@...el.com>,
Maxim Levitsky <mlevitsk@...hat.com>, Zhang Yi Z <yi.z.zhang@...ux.intel.com>, Xin Li <xin@...or.com>
Subject: Re: [PATCH v16 33/51] KVM: nVMX: Add consistency checks for CET states
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;
}
Powered by blists - more mailing lists