From: Juergen Gross <jgross@suse.com>
To: linux-kernel@vger.kernel.org, x86@kernel.org
Cc: Juergen Gross <jgross@suse.com>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H. Peter Anvin" <hpa@zytor.com>
Subject: [PATCH RFC 2/6] x86/msr: Create a new minimal set of local MSR access functions
Date: Mon, 20 Apr 2026 11:16:30 +0200 [thread overview]
Message-ID: <20260420091634.128787-3-jgross@suse.com> (raw)
In-Reply-To: <20260420091634.128787-1-jgross@suse.com>
Today there are two sets of MSR access functions (apart from the low
level ones): one is using 64 bit values, and the other a pair of
32-bit values for the MSR contents. The read variants are macros,
while the write variants are proper inline functions.
In order to prepare for non-serializing variants of the write
functions, create a complete set of MSR functions using a proper
name space ("msr_*") without the 32-bit pair variants.
Name the write variants explicitly msr_write_[safe_]ser() and
msr_write_[safe_]noser() in order to make it very clear whether
the serializing or the non-serializing variant is meant.
Right now the new set will be based on the old wrmsr*() and rdmsr*()
functions, but when all users have been switched to use the new
functions, the old wrmsr*() and rdmsr*() functions will be dropped.
Signed-off-by: Juergen Gross <jgross@suse.com>
---
arch/x86/include/asm/msr.h | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h
index 9c2ea29e12a9..cc21c8699e23 100644
--- a/arch/x86/include/asm/msr.h
+++ b/arch/x86/include/asm/msr.h
@@ -227,6 +227,44 @@ static __always_inline u64 rdpmc(int counter)
#endif /* !CONFIG_PARAVIRT_XXL */
+/*
+ * New set of MSR access functions. New code should use those instead of the
+ * legacy wrmsr*() and rdmsr*() ones.
+ */
+static __always_inline u64 msr_read(u32 msr)
+{
+ u64 val;
+
+ rdmsrq(msr, val);
+
+ return val;
+}
+
+static __always_inline int msr_read_safe(u32 msr, u64 *val)
+{
+ return rdmsrq_safe(msr, val);
+}
+
+static __always_inline void msr_write_ser(u32 msr, u64 val)
+{
+ wrmsrq(msr, val);
+}
+
+static __always_inline int msr_write_safe_ser(u32 msr, u64 val)
+{
+ return wrmsrq_safe(msr, val);
+}
+
+static __always_inline void msr_write_noser(u32 msr, u64 val)
+{
+ wrmsrq(msr, val);
+}
+
+static __always_inline int msr_write_safe_noser(u32 msr, u64 val)
+{
+ return wrmsrq_safe(msr, val);
+}
+
/* Instruction opcode for WRMSRNS supported in binutils >= 2.40 */
#define ASM_WRMSRNS _ASM_BYTES(0x0f,0x01,0xc6)
--
2.53.0
next prev parent reply other threads:[~2026-04-20 9:16 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-20 9:16 [PATCH RFC 0/6] x86/msr: Rename MSR access functions Juergen Gross
2026-04-20 9:16 ` [PATCH RFC 1/6] x86/msr: Rename msr_read() and msr_write() Juergen Gross
2026-04-20 9:16 ` Juergen Gross [this message]
2026-04-20 9:16 ` [PATCH RFC 3/6] x86/msr: Create a new minimal set of inter-CPU MSR access functions Juergen Gross
2026-04-20 9:16 ` [PATCH RFC 4/6] x86/msr: Rename the *_safe_regs[_on_cpu]() MSR functions Juergen Gross
2026-04-20 9:16 ` [PATCH RFC 5/6] x86/events: Switch core parts to use new MSR access functions Juergen Gross
2026-04-20 9:16 ` [PATCH RFC 6/6] x86/cpu/mce: Switch code " Juergen Gross
2026-04-20 11:35 ` [PATCH RFC 0/6] x86/msr: Rename " Peter Zijlstra
2026-04-20 11:41 ` Peter Zijlstra
2026-04-20 11:51 ` Jürgen Groß
2026-04-20 13:44 ` Sean Christopherson
2026-04-20 14:04 ` Jürgen Groß
2026-04-20 15:34 ` H. Peter Anvin
2026-04-20 11:49 ` Jürgen Groß
2026-04-20 12:33 ` Peter Zijlstra
2026-04-20 13:01 ` Jürgen Groß
2026-04-20 13:10 ` Peter Zijlstra
2026-04-20 13:23 ` Jürgen Groß
2026-04-20 13:36 ` Sean Christopherson
2026-04-20 13:57 ` Jürgen Groß
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260420091634.128787-3-jgross@suse.com \
--to=jgross@suse.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox