[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aAexLqjhKncFyw2V@google.com>
Date: Tue, 22 Apr 2025 08:09:34 -0700
From: Sean Christopherson <seanjc@...gle.com>
To: "Xin Li (Intel)" <xin@...or.com>
Cc: linux-kernel@...r.kernel.org, kvm@...r.kernel.org,
linux-perf-users@...r.kernel.org, linux-hyperv@...r.kernel.org,
virtualization@...ts.linux.dev, linux-pm@...r.kernel.org,
linux-edac@...r.kernel.org, xen-devel@...ts.xenproject.org,
linux-acpi@...r.kernel.org, linux-hwmon@...r.kernel.org,
netdev@...r.kernel.org, platform-driver-x86@...r.kernel.org,
tglx@...utronix.de, mingo@...hat.com, bp@...en8.de,
dave.hansen@...ux.intel.com, x86@...nel.org, hpa@...or.com, acme@...nel.org,
jgross@...e.com, andrew.cooper3@...rix.com, peterz@...radead.org,
namhyung@...nel.org, mark.rutland@....com, alexander.shishkin@...ux.intel.com,
jolsa@...nel.org, irogers@...gle.com, adrian.hunter@...el.com,
kan.liang@...ux.intel.com, wei.liu@...nel.org, ajay.kaher@...adcom.com,
bcm-kernel-feedback-list@...adcom.com, tony.luck@...el.com,
pbonzini@...hat.com, vkuznets@...hat.com, luto@...nel.org,
boris.ostrovsky@...cle.com, kys@...rosoft.com, haiyangz@...rosoft.com,
decui@...rosoft.com
Subject: Re: [RFC PATCH v2 10/34] x86/msr: Convert __rdmsr() uses to
native_rdmsrq() uses
On Tue, Apr 22, 2025, Xin Li (Intel) wrote:
> __rdmsr() is the lowest level primitive MSR read API, and its direct
> use is NOT preferred.
Doesn't mean it's wrong.
> Use its wrapper function native_rdmsrq() instead.
...
> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index 1547bfacd40f..e73c1d5ba6c4 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c
> @@ -380,7 +380,7 @@ static __always_inline void vmx_disable_fb_clear(struct vcpu_vmx *vmx)
> if (!vmx->disable_fb_clear)
> return;
>
> - msr = __rdmsr(MSR_IA32_MCU_OPT_CTRL);
> + msr = native_rdmsrq(MSR_IA32_MCU_OPT_CTRL);
> msr |= FB_CLEAR_DIS;
> native_wrmsrq(MSR_IA32_MCU_OPT_CTRL, msr);
> /* Cache the MSR value to avoid reading it later */
> @@ -7307,7 +7307,7 @@ void noinstr vmx_spec_ctrl_restore_host(struct vcpu_vmx *vmx,
> return;
>
> if (flags & VMX_RUN_SAVE_SPEC_CTRL)
> - vmx->spec_ctrl = __rdmsr(MSR_IA32_SPEC_CTRL);
> + vmx->spec_ctrl = native_rdmsrq(MSR_IA32_SPEC_CTRL);
And what guarantees that native_rdmsrq() won't have tracing? Ugh, a later patch
renames native_rdmsrq() => native_rdmsrq_no_trace().
I really don't like this. It makes simple and obvious code:
vmx->spec_ctrl = __rdmsr(MSR_IA32_SPEC_CTRL);
so much harder to read:
vmx->spec_ctrl = native_rdmsrq_no_trace(MSR_IA32_SPEC_CTRL);
and does so in a way that is difficult to review, e.g. I have to peek ahead to
understand that this is even ok.
I strongly prefer that we find a way to not require such verbose APIs, especially
if KVM ends up using native variants throughout. Xen PV is supposed to be the
odd one out, yet native code is what suffers. Blech.
Powered by blists - more mailing lists