From nobody Sat Nov 1 08:50:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=zytor.com ARC-Seal: i=1; a=rsa-sha256; t=1743409474; cv=none; d=zohomail.com; s=zohoarc; b=gHgkoJ/+g711t/ZN7pVXwSHV9gjUo9BRuwEfBfatTyzsCFyvqlEwF3fVNPOq3mIrC8jBPLNXCaEPWY/AKH8oqh257IA8yjKXYFmuCmtlyyG48kqJfzkcqMa6WcJzEGgU5K6AQ9lFLB7AF+GLGQ7wVYPkVo1UcD2OV9YI7gyoKqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1743409474; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=m4M8UGMKKd7tRa3nJstnKZwTxnwNx/YpFEKHVX35S1M=; b=TW1n3WNgo/+RtYWuk3s/V75yV+BQ0xH6gtAd9E5dfNwqjBxcSkrBtNKzpS+Pkr+OfhODk2XBxqWRLn2LaDZrFUtsqQhc2mxTxW337O86JV7z2b8OisZATYRY43e7n4y7IV8tihrdNrL53M1L6iJ81Q3Ii4ojU1NwPqom5+ICuv8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1743409474436762.2027831887534; Mon, 31 Mar 2025 01:24:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.931992.1334175 (Exim 4.92) (envelope-from ) id 1tzARA-0001uL-Pg; Mon, 31 Mar 2025 08:24:04 +0000 Received: by outflank-mailman (output) from mailman id 931992.1334175; Mon, 31 Mar 2025 08:24:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzARA-0001uE-Lr; Mon, 31 Mar 2025 08:24:04 +0000 Received: by outflank-mailman (input) for mailman id 931992; Mon, 31 Mar 2025 08:24:03 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tzAR9-0001u1-Am for xen-devel@lists.xenproject.org; Mon, 31 Mar 2025 08:24:03 +0000 Received: from mail.zytor.com (unknown [2607:7c80:54:3::138]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 7eb2eed8-0e09-11f0-9ea7-5ba50f476ded; Mon, 31 Mar 2025 10:24:01 +0200 (CEST) Received: from terminus.zytor.com (terminus.zytor.com [IPv6:2607:7c80:54:3:0:0:0:136]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 52V8Mp023171319 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 31 Mar 2025 01:23:02 -0700 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 7eb2eed8-0e09-11f0-9ea7-5ba50f476ded DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 52V8Mp023171319 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025032001; t=1743409384; bh=m4M8UGMKKd7tRa3nJstnKZwTxnwNx/YpFEKHVX35S1M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GMjpnnYXMYpU67NGz93c7h9ws4Z3p3rE979fcI5Xs1NdNl+Td/mpmwbnPiYulmfj8 b8fSVsdt2ad5j0QSex3qUA/BNF0M8ziPcP4Mkz38x3S+XUwD4rvbU8+eDWfUPxnO7E Y70mhL72N7fvX3WqwqaTorgtiRS94zS/fVo8nOEjFVs9kCAUlFTEOFTIKmdPh072el C2aXZqY89xdoTLHuywMC03Z51D76GbRxilkwQRwDPUqIeAdLHWceDRXcmPCxXB7B88 vzqb8gdBtHAv76CahwdMT05nUSEwKm9KaXVsW8BCSDJ3odt76mR0w6Fy90TxcG4WqJ QtAekxEcU2fGw== From: "Xin Li (Intel)" To: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, linux-edac@vger.kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-ide@vger.kernel.org, linux-pm@vger.kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, jgross@suse.com, andrew.cooper3@citrix.com, peterz@infradead.org, acme@kernel.org, namhyung@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, wei.liu@kernel.org, ajay.kaher@broadcom.com, alexey.amakhalov@broadcom.com, bcm-kernel-feedback-list@broadcom.com, tony.luck@intel.com, pbonzini@redhat.com, vkuznets@redhat.com, seanjc@google.com, luto@kernel.org, boris.ostrovsky@oracle.com, kys@microsoft.com, haiyangz@microsoft.com, decui@microsoft.com Subject: [RFC PATCH v1 02/15] x86/msr: Replace __rdmsr() with native_rdmsrl() Date: Mon, 31 Mar 2025 01:22:38 -0700 Message-ID: <20250331082251.3171276-3-xin@zytor.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250331082251.3171276-1-xin@zytor.com> References: <20250331082251.3171276-1-xin@zytor.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @zytor.com) X-ZM-MESSAGEID: 1743409475876019100 Content-Type: text/plain; charset="utf-8" __rdmsr() is the lowest level primitive MSR read API, and its direct use is NOT preferred. Use its wrapper function native_rdmsrl() instead. No functional change intended. Signed-off-by: Xin Li (Intel) --- arch/x86/coco/sev/core.c | 2 +- arch/x86/events/amd/brs.c | 2 +- arch/x86/hyperv/hv_vtl.c | 4 ++-- arch/x86/hyperv/ivm.c | 2 +- arch/x86/include/asm/mshyperv.h | 2 +- arch/x86/include/asm/msr.h | 5 +++++ arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/cpu/mce/core.c | 4 ++-- arch/x86/kernel/cpu/resctrl/pseudo_lock.c | 2 +- arch/x86/kvm/vmx/vmx.c | 4 ++-- arch/x86/mm/mem_encrypt_identity.c | 4 ++-- 11 files changed, 19 insertions(+), 14 deletions(-) diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c index b0c1a7a57497..d38e6f0ff9c4 100644 --- a/arch/x86/coco/sev/core.c +++ b/arch/x86/coco/sev/core.c @@ -276,7 +276,7 @@ static noinstr struct ghcb *__sev_get_ghcb(struct ghcb_= state *state) =20 static inline u64 sev_es_rd_ghcb_msr(void) { - return __rdmsr(MSR_AMD64_SEV_ES_GHCB); + return native_rdmsrl(MSR_AMD64_SEV_ES_GHCB); } =20 static __always_inline void sev_es_wr_ghcb_msr(u64 val) diff --git a/arch/x86/events/amd/brs.c b/arch/x86/events/amd/brs.c index 4a47f3c108de..3ad7d87b5403 100644 --- a/arch/x86/events/amd/brs.c +++ b/arch/x86/events/amd/brs.c @@ -49,7 +49,7 @@ static __always_inline void set_debug_extn_cfg(u64 val) =20 static __always_inline u64 get_debug_extn_cfg(void) { - return __rdmsr(MSR_AMD_DBG_EXTN_CFG); + return native_rdmsrl(MSR_AMD_DBG_EXTN_CFG); } =20 static bool __init amd_brs_detect(void) diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c index 13242ed8ff16..4a27e475d35f 100644 --- a/arch/x86/hyperv/hv_vtl.c +++ b/arch/x86/hyperv/hv_vtl.c @@ -149,11 +149,11 @@ static int hv_vtl_bringup_vcpu(u32 target_vp_index, i= nt cpu, u64 eip_ignored) input->vp_context.rip =3D rip; input->vp_context.rsp =3D rsp; input->vp_context.rflags =3D 0x0000000000000002; - input->vp_context.efer =3D __rdmsr(MSR_EFER); + input->vp_context.efer =3D native_rdmsrl(MSR_EFER); input->vp_context.cr0 =3D native_read_cr0(); input->vp_context.cr3 =3D __native_read_cr3(); input->vp_context.cr4 =3D native_read_cr4(); - input->vp_context.msr_cr_pat =3D __rdmsr(MSR_IA32_CR_PAT); + input->vp_context.msr_cr_pat =3D native_rdmsrl(MSR_IA32_CR_PAT); input->vp_context.idtr.limit =3D idt_ptr.size; input->vp_context.idtr.base =3D idt_ptr.address; input->vp_context.gdtr.limit =3D gdt_ptr.size; diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 77bf05f06b9e..95cf2113a72a 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -110,7 +110,7 @@ u64 hv_ghcb_hypercall(u64 control, void *input, void *o= utput, u32 input_size) =20 static inline u64 rd_ghcb_msr(void) { - return __rdmsr(MSR_AMD64_SEV_ES_GHCB); + return native_rdmsrl(MSR_AMD64_SEV_ES_GHCB); } =20 static inline void wr_ghcb_msr(u64 val) diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyper= v.h index bab5ccfc60a7..2ca6ef89530d 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -304,7 +304,7 @@ void hv_set_non_nested_msr(unsigned int reg, u64 value); =20 static __always_inline u64 hv_raw_get_msr(unsigned int reg) { - return __rdmsr(reg); + return native_rdmsrl(reg); } =20 #else /* CONFIG_HYPERV */ diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index 27ea8793705d..fb3d7c4cb774 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -106,6 +106,11 @@ do { \ (void)((val2) =3D (u32)(__val >> 32)); \ } while (0) =20 +static __always_inline u64 native_rdmsrl(const u32 msr) +{ + return __rdmsr(msr); +} + #define native_wrmsr(msr, low, high) \ __wrmsr(msr, low, high) =20 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 12126adbc3a9..a268db71d944 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -164,7 +164,7 @@ static void ppin_init(struct cpuinfo_x86 *c) =20 /* Is the enable bit set? */ if (val & 2UL) { - c->ppin =3D __rdmsr(info->msr_ppin); + c->ppin =3D native_rdmsrl(info->msr_ppin); set_cpu_cap(c, info->feature); return; } diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c index 0eaeaba12df2..0e050af723f5 100644 --- a/arch/x86/kernel/cpu/mce/core.c +++ b/arch/x86/kernel/cpu/mce/core.c @@ -121,7 +121,7 @@ void mce_prep_record_common(struct mce *m) { m->cpuid =3D cpuid_eax(1); m->cpuvendor =3D boot_cpu_data.x86_vendor; - m->mcgcap =3D __rdmsr(MSR_IA32_MCG_CAP); + m->mcgcap =3D native_rdmsrl(MSR_IA32_MCG_CAP); /* need the internal __ version to avoid deadlocks */ m->time =3D __ktime_get_real_seconds(); } @@ -1298,7 +1298,7 @@ static noinstr bool mce_check_crashing_cpu(void) (crashing_cpu !=3D -1 && crashing_cpu !=3D cpu)) { u64 mcgstatus; =20 - mcgstatus =3D __rdmsr(MSR_IA32_MCG_STATUS); + mcgstatus =3D native_rdmsrl(MSR_IA32_MCG_STATUS); =20 if (boot_cpu_data.x86_vendor =3D=3D X86_VENDOR_ZHAOXIN) { if (mcgstatus & MCG_STATUS_LMCES) diff --git a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c b/arch/x86/kernel/cp= u/resctrl/pseudo_lock.c index 55536120c8d1..675fd9f93e33 100644 --- a/arch/x86/kernel/cpu/resctrl/pseudo_lock.c +++ b/arch/x86/kernel/cpu/resctrl/pseudo_lock.c @@ -480,7 +480,7 @@ int resctrl_arch_pseudo_lock_fn(void *_plr) * the buffer and evict pseudo-locked memory read earlier from the * cache. */ - saved_msr =3D __rdmsr(MSR_MISC_FEATURE_CONTROL); + saved_msr =3D native_rdmsrl(MSR_MISC_FEATURE_CONTROL); native_wrmsrl(MSR_MISC_FEATURE_CONTROL, prefetch_disable_bits); closid_p =3D this_cpu_read(pqr_state.cur_closid); rmid_p =3D this_cpu_read(pqr_state.cur_rmid); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 5c5766467a61..2a24060397cd 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; =20 - msr =3D __rdmsr(MSR_IA32_MCU_OPT_CTRL); + msr =3D native_rdmsrl(MSR_IA32_MCU_OPT_CTRL); msr |=3D FB_CLEAR_DIS; native_wrmsrl(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_v= mx *vmx, return; =20 if (flags & VMX_RUN_SAVE_SPEC_CTRL) - vmx->spec_ctrl =3D __rdmsr(MSR_IA32_SPEC_CTRL); + vmx->spec_ctrl =3D native_rdmsrl(MSR_IA32_SPEC_CTRL); =20 /* * If the guest/host SPEC_CTRL values differ, restore the host value. diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_i= dentity.c index 5eecdd92da10..3005b07a0016 100644 --- a/arch/x86/mm/mem_encrypt_identity.c +++ b/arch/x86/mm/mem_encrypt_identity.c @@ -526,7 +526,7 @@ void __head sme_enable(struct boot_params *bp) me_mask =3D 1UL << (ebx & 0x3f); =20 /* Check the SEV MSR whether SEV or SME is enabled */ - RIP_REL_REF(sev_status) =3D msr =3D __rdmsr(MSR_AMD64_SEV); + RIP_REL_REF(sev_status) =3D msr =3D native_rdmsrl(MSR_AMD64_SEV); feature_mask =3D (msr & MSR_AMD64_SEV_ENABLED) ? AMD_SEV_BIT : AMD_SME_BI= T; =20 /* @@ -557,7 +557,7 @@ void __head sme_enable(struct boot_params *bp) return; =20 /* For SME, check the SYSCFG MSR */ - msr =3D __rdmsr(MSR_AMD64_SYSCFG); + msr =3D native_rdmsrl(MSR_AMD64_SYSCFG); if (!(msr & MSR_AMD64_SYSCFG_MEM_ENCRYPT)) return; } --=20 2.49.0