Linux virtualization list
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@linux.intel.com>
To: linux-kernel@vger.kernel.org
Cc: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Borislav Petkov <bp@alien8.de>,
	x86@kernel.org, Juergen Gross <jgross@suse.com>,
	virtualization@lists.linux.dev,
	Dave Hansen <dave.hansen@linux.intel.com>
Subject: [PATCH v2 5/8] x86/msr: Consolidate {rd,wr}msr[q]_safe() implementations
Date: Wed, 29 Apr 2026 11:45:25 -0700	[thread overview]
Message-ID: <20260429184525.F1123DA9@davehans-spike.ostc.intel.com> (raw)
In-Reply-To: <20260429184517.7E078510@davehans-spike.ostc.intel.com>


From: Dave Hansen <dave.hansen@linux.intel.com>

These should be very familiar by now. Move the native implementations
of the "safe" MSR functions out to common code and zap the paravirt.h
version. Do four at once now because these are quite straightforward.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
---

 b/arch/x86/include/asm/msr.h      |   42 +++++++++++++++++++-------------------
 b/arch/x86/include/asm/paravirt.h |   20 ------------------
 2 files changed, 21 insertions(+), 41 deletions(-)

diff -puN arch/x86/include/asm/msr.h~rdmsr-dups-6 arch/x86/include/asm/msr.h
--- a/arch/x86/include/asm/msr.h~rdmsr-dups-6	2026-04-01 14:32:57.802499509 -0700
+++ b/arch/x86/include/asm/msr.h	2026-04-01 14:32:57.809499772 -0700
@@ -186,27 +186,6 @@ static inline u64 native_read_pmc(int co
  * pointer indirection), this allows gcc to optimize better
  */
 
-static inline void wrmsr(u32 msr, u32 low, u32 high)
-{
-	paravirt_write_msr(msr, (u64)high << 32 | low);
-}
-
-static inline void wrmsrq(u32 msr, u64 val)
-{
-	paravirt_write_msr(msr, val);
-}
-
-/* wrmsr with exception handling */
-static inline int wrmsrq_safe(u32 msr, u64 val)
-{
-	return paravirt_write_msr_safe(msr, val);
-}
-
-static inline int rdmsrq_safe(u32 msr, u64 *p)
-{
-	return paravirt_read_msr_safe(msr, p);
-}
-
 static __always_inline u64 rdpmc(int counter)
 {
 	return native_read_pmc(counter);
@@ -237,6 +216,27 @@ do {								\
 #define rdmsrq(msr, val)			\
 	((val) = paravirt_read_msr((msr)))
 
+static inline int rdmsrq_safe(u32 msr, u64 *p)
+{
+	return paravirt_read_msr_safe(msr, p);
+}
+
+/* wrmsr with exception handling */
+static inline int wrmsrq_safe(u32 msr, u64 val)
+{
+	return paravirt_write_msr_safe(msr, val);
+}
+
+static inline void wrmsr(u32 msr, u32 low, u32 high)
+{
+	paravirt_write_msr(msr, (u64)high << 32 | low);
+}
+
+static inline void wrmsrq(u32 msr, u64 val)
+{
+	paravirt_write_msr(msr, val);
+}
+
 /* 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-6 arch/x86/include/asm/paravirt.h
--- a/arch/x86/include/asm/paravirt.h~rdmsr-dups-6	2026-04-01 14:32:57.806499659 -0700
+++ b/arch/x86/include/asm/paravirt.h	2026-04-01 14:32:57.809499772 -0700
@@ -161,26 +161,6 @@ static inline int paravirt_write_msr_saf
 	return PVOP_CALL2(int, pv_ops, cpu.write_msr_safe, msr, val);
 }
 
-static __always_inline void wrmsr(u32 msr, u32 low, u32 high)
-{
-	paravirt_write_msr(msr, (u64)high << 32 | low);
-}
-
-static inline void wrmsrq(u32 msr, u64 val)
-{
-	paravirt_write_msr(msr, val);
-}
-
-static inline int wrmsrq_safe(u32 msr, u64 val)
-{
-	return paravirt_write_msr_safe(msr, val);
-}
-
-static __always_inline int rdmsrq_safe(u32 msr, u64 *p)
-{
-	return paravirt_read_msr_safe(msr, p);
-}
-
 static __always_inline u64 rdpmc(int counter)
 {
 	return PVOP_CALL1(u64, pv_ops, cpu.read_pmc, counter);
_

  parent reply	other threads:[~2026-04-29 18:45 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-29 18:45 [PATCH v2 0/8] x86/msr: Consolidate native/paravirt MSR functions Dave Hansen
2026-04-29 18:45 ` [PATCH v2 1/8] x86/msr: Use paravirt "calls" in common code Dave Hansen
2026-04-29 18:45 ` [PATCH v2 2/8] x86/msr: Consolidate rdmsr() definitions Dave Hansen
2026-05-06  2:03   ` Yan Zhao
2026-05-06 10:25     ` Yan Zhao
2026-05-06 11:09       ` Jürgen Groß
2026-05-07  8:21         ` Yan Zhao
2026-04-29 18:45 ` [PATCH v2 3/8] x86/msr: Consolidate rdmsr_safe() implementations Dave Hansen
2026-04-30 19:43   ` Maciej Wieczor-Retman
2026-04-29 18:45 ` [PATCH v2 4/8] x86/msr: Consolidate rdmsrq() implementations Dave Hansen
2026-04-29 18:45 ` Dave Hansen [this message]
2026-04-29 18:45 ` [PATCH v2 6/8] x86/msr: Consolidate rdpmc() implementations Dave Hansen
2026-04-29 18:45 ` [PATCH v2 7/8] x86/msr: Remove old crusty comment Dave Hansen
2026-04-29 18:45 ` [PATCH v2 8/8] x86/msr: Remove duplicate #include Dave Hansen
2026-04-30  7:20   ` Jürgen Groß
2026-04-30 17:42     ` Dave Hansen
2026-04-30 19:22       ` Jürgen Groß
2026-04-30  7:21 ` [PATCH v2 0/8] x86/msr: Consolidate native/paravirt MSR functions 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=20260429184525.F1123DA9@davehans-spike.ostc.intel.com \
    --to=dave.hansen@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@kernel.org \
    --cc=virtualization@lists.linux.dev \
    --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