[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aFrD-Pn9cmHcVxWs@google.com>
Date: Tue, 24 Jun 2025 08:27:52 -0700
From: Sean Christopherson <seanjc@...gle.com>
To: "Xin Li (Intel)" <xin@...or.com>
Cc: pbonzini@...hat.com, kvm@...r.kernel.org, linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org, corbet@....net, tglx@...utronix.de,
mingo@...hat.com, bp@...en8.de, dave.hansen@...ux.intel.com, x86@...nel.org,
hpa@...or.com, andrew.cooper3@...rix.com, luto@...nel.org,
peterz@...radead.org, chao.gao@...el.com, xin3.li@...el.com
Subject: Re: [PATCH v4 06/19] KVM: VMX: Set FRED MSR interception
On Fri, Mar 28, 2025, Xin Li (Intel) wrote:
> @@ -7935,6 +7945,34 @@ static void update_intel_pt_cfg(struct kvm_vcpu *vcpu)
> vmx->pt_desc.ctl_bitmask &= ~(0xfULL << (32 + i * 4));
> }
>
> +static void vmx_set_intercept_for_fred_msr(struct kvm_vcpu *vcpu)
> +{
This function should short-circult on
if (!kvm_cpu_cap_has(X86_FEATURE_FRED))
return;
Functionally, it shouldn't matter. It's mostly for documentation purposes, and
to avoid doing unnecessary work.
> + bool flag = !guest_cpu_cap_has(vcpu, X86_FEATURE_FRED);
"flag" is unnecessarily ambiguous (eww, I see that the exiting PT code does that).
I like "set", as it has (hopefully) obvious polarity, and aligns with the function
being called.
> +
> + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_RSP1, MSR_TYPE_RW, flag);
> + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_RSP2, MSR_TYPE_RW, flag);
> + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_RSP3, MSR_TYPE_RW, flag);
> + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_STKLVLS, MSR_TYPE_RW, flag);
> + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_SSP1, MSR_TYPE_RW, flag);
> + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_SSP2, MSR_TYPE_RW, flag);
> + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_SSP3, MSR_TYPE_RW, flag);
> + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_CONFIG, MSR_TYPE_RW, flag);
> +
> + /*
> + * IA32_FRED_RSP0 and IA32_PL0_SSP (a.k.a. IA32_FRED_SSP0) are only used
> + * for delivering events when running userspace, while KVM always runs in
> + * kernel mode (the CPL is always 0 after any VM exit), thus KVM can run
> + * safely with guest IA32_FRED_RSP0 and IA32_PL0_SSP.
> + *
> + * As a result, no need to intercept IA32_FRED_RSP0 and IA32_PL0_SSP.
> + *
> + * Note, save and restore of IA32_PL0_SSP belong to CET supervisor context
> + * management no matter whether FRED is enabled or not. So leave its
> + * state management to CET code.
> + */
> + vmx_set_intercept_for_msr(vcpu, MSR_IA32_FRED_RSP0, MSR_TYPE_RW, flag);
> +}
Powered by blists - more mailing lists