[PATCH v2 6/8] x86/msr: Consolidate rdpmc() implementations

From: Dave Hansen

Date: Wed Apr 29 2026 - 14:47:31 EST



From: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>

Doing this is debatable. It does not actually remove any code. But,
this makes rdpmc() follow the same pattern as all of the MSR functions
where paravirt.h defines a paravirt_foo() function and then msr.h
uses that function in common code.

Signed-off-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
---

b/arch/x86/include/asm/msr.h | 11 ++++++-----
b/arch/x86/include/asm/paravirt.h | 2 +-
2 files changed, 7 insertions(+), 6 deletions(-)

diff -puN arch/x86/include/asm/msr.h~rdmsr-dups-9 arch/x86/include/asm/msr.h
--- a/arch/x86/include/asm/msr.h~rdmsr-dups-9 2026-04-01 14:32:58.366520634 -0700
+++ b/arch/x86/include/asm/msr.h 2026-04-01 14:32:58.373520897 -0700
@@ -179,6 +179,7 @@ static inline u64 native_read_pmc(int co
#define paravirt_read_msr_safe native_read_msr_safe
#define paravirt_write_msr native_write_msr
#define paravirt_write_msr_safe native_write_msr_safe
+#define paravirt_read_pmc native_read_pmc

/*
* Access to machine-specific registers (available on 586 and better only)
@@ -186,11 +187,6 @@ static inline u64 native_read_pmc(int co
* pointer indirection), this allows gcc to optimize better
*/

-static __always_inline u64 rdpmc(int counter)
-{
- return native_read_pmc(counter);
-}
-
#endif /* !CONFIG_PARAVIRT_XXL */

/*
@@ -237,6 +233,11 @@ static inline void wrmsrq(u32 msr, u64 v
paravirt_write_msr(msr, val);
}

+static __always_inline u64 rdpmc(int counter)
+{
+ return paravirt_read_pmc(counter);
+}
+
/* Instruction opcode for WRMSRNS supported in binutils >= 2.40 */
#define ASM_WRMSRNS _ASM_BYTES(0x0f,0x01,0xc6)

diff -puN arch/x86/include/asm/paravirt.h~rdmsr-dups-9 arch/x86/include/asm/paravirt.h
--- a/arch/x86/include/asm/paravirt.h~rdmsr-dups-9 2026-04-01 14:32:58.370520784 -0700
+++ b/arch/x86/include/asm/paravirt.h 2026-04-01 14:32:58.373520897 -0700
@@ -161,7 +161,7 @@ static inline int paravirt_write_msr_saf
return PVOP_CALL2(int, pv_ops, cpu.write_msr_safe, msr, val);
}

-static __always_inline u64 rdpmc(int counter)
+static __always_inline u64 paravirt_read_pmc(int counter)
{
return PVOP_CALL1(u64, pv_ops, cpu.read_pmc, counter);
}
_