[PATCH RFC 2/6] x86/msr: Create a new minimal set of local MSR access functions

From: Juergen Gross

Date: Mon Apr 20 2026 - 05:22:04 EST


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@xxxxxxxx>
---
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