From: Shreshth Srivastava <shreshth.srivastava@intel.com>
To: Juergen Gross <jgross@suse.com>,
linux-kernel@vger.kernel.org, x86@kernel.org,
virtualization@lists.linux.dev
Cc: tglx@kernel.org, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, hpa@zytor.com,
ajay.kaher@broadcom.com, alexey.makhalov@broadcom.com,
bcm-kernel-feedback-list@broadcom.com
Subject: Re: [PATCH v5 04/17] x86/msr: Move MSR trace calls one function level up
Date: Wed, 23 Sep 2026 16:26:35 -0400 [thread overview]
Message-ID: <20260923202654.1412087-1-shreshth.srivastava@intel.com> (raw)
In-Reply-To: <20260911084211.3149957-5-jgross@suse.com>
On 11.09.26 10:41, Juergen Gross wrote:
> In order to prepare paravirt inlining of the MSR access instructions
> move the calls of MSR trace functions one function level up.
> Introduce {read|write}_msr[_safe]() helpers allowing to have common
> definitions in msr.h doing the trace calls.
Hi Juergen,
read_msr() and write_msr() get a single wrapper below the
CONFIG_PARAVIRT_XXL ifdef holding the tracepoint, so it fires for either
implementation. rdpmc() moved into the same ifdef but kept the old
arrangement: still defined twice, once per arm, with do_trace_rdpmc()
still called from native_read_pmc() above the ifdef.
With CONFIG_PARAVIRT_XXL=y that leaves rdpmc() on a path with no trace
call:
rdpmc() => paravirt-msr.h, PVOP_CALL1(pv_ops_msr,
read_pmc)
xen_read_pmc() => Xen PV sets pv_ops_msr.read_pmc to this
reads the value out of the Xen shared PMU page
=> returns without ever calling
native_read_pmc(), which is where
do_trace_rdpmc() sits
So msr:rdpmc doesn't fire under Xen PV, while msr:read_msr and
msr:write_msr now do.
Was that deliberate? If it wasn't, here is a diff that treats rdpmc the
same way as the other six: rename both definitions to read_pmc(), matching
the pv_ops_msr member they dispatch to, and add one rdpmc() below the
endif holding the tracepoint. native_read_pmc() is then an untraced
primitive next to native_rdmsrq() and native_wrmsrq(). Would something
like this help?
diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h
index eba325ecfe4c..6f50b703fba9 100644
--- a/arch/x86/include/asm/msr.h
+++ b/arch/x86/include/asm/msr.h
@@ -305,8 +305,7 @@ static __always_inline u64 native_read_pmc(int counter)
EAX_EDX_DECLARE_ARGS(val, low, high);
asm volatile("rdpmc" : EAX_EDX_RET(val, low, high) : "c" (counter));
- if (tracepoint_enabled(rdpmc))
- do_trace_rdpmc(counter, EAX_EDX_VAL(val, low, high), 0);
+
return EAX_EDX_VAL(val, low, high);
}
@@ -343,7 +342,7 @@ static __always_inline int write_msrns_safe(u32 msr, u64 val)
return native_wrmsrns_safe(msr, val);
}
-static __always_inline u64 rdpmc(int counter)
+static __always_inline u64 read_pmc(int counter)
{
return native_read_pmc(counter);
}
@@ -413,6 +412,16 @@ static __always_inline int wrmsrns_safe(u32 msr, u64 val)
return err;
}
+static __always_inline u64 rdpmc(int counter)
+{
+ u64 val = read_pmc(counter);
+
+ if (tracepoint_enabled(rdpmc))
+ do_trace_rdpmc(counter, val, 0);
+
+ return val;
+}
+
static __always_inline void sync_cpu_after_wrmsrns(void)
{
if (cpu_feature_enabled(X86_FEATURE_WRMSRNS))
diff --git a/arch/x86/include/asm/paravirt-msr.h b/arch/x86/include/asm/paravirt-msr.h
index ba3ee64446db..47220bf16cf3 100644
--- a/arch/x86/include/asm/paravirt-msr.h
+++ b/arch/x86/include/asm/paravirt-msr.h
@@ -172,7 +172,7 @@ static __always_inline int write_msrns_safe(u32 msr, u64 val)
return err ? -EIO : 0;
}
-static __always_inline u64 rdpmc(int counter)
+static __always_inline u64 read_pmc(int counter)
{
return PVOP_CALL1(u64, pv_ops_msr, read_pmc, counter);
}
I have no Xen PV guest, so that path is untested. What I did check is that
the __tracepoint_rdpmc relocation shows up in arch/x86/events/core.o with
CONFIG_PARAVIRT_XXL=y, where it previously did not, and that x86_64
defconfig still builds clean with gcc and clang.
Thanks,
Shreshth
next prev parent reply other threads:[~2026-09-23 20:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 8:41 [PATCH v5 00/17] x86/msr: Inline rdmsr/wrmsr instructions Juergen Gross
2026-09-11 8:41 ` [PATCH v5 04/17] x86/msr: Move MSR trace calls one function level up Juergen Gross
2026-09-23 20:26 ` Shreshth Srivastava [this message]
2026-09-25 13:15 ` Jürgen Groß
2026-09-11 8:42 ` [PATCH v5 08/17] x86/msr: Make wrmsrns() a first class citizen Juergen Gross
2026-09-11 8:42 ` [PATCH v5 12/17] x86/paravirt: Split off MSR related hooks into new header Juergen Gross
2026-09-11 8:42 ` [PATCH v5 13/17] x86/paravirt: Prepare support of MSR instruction interfaces Juergen Gross
2026-09-11 8:42 ` [PATCH v5 14/17] x86/paravirt: Switch MSR access pv_ops functions to " Juergen Gross
2026-09-11 8:42 ` [PATCH v5 16/17] x86/paravirt: Use alternatives for MSR access with paravirt Juergen Gross
2026-09-23 19:36 ` [PATCH v5 00/17] x86/msr: Inline rdmsr/wrmsr instructions Shreshth Srivastava
2026-09-23 20:15 ` Nick Desaulniers
2026-09-25 10:25 ` 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=20260923202654.1412087-1-shreshth.srivastava@intel.com \
--to=shreshth.srivastava@intel.com \
--cc=ajay.kaher@broadcom.com \
--cc=alexey.makhalov@broadcom.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--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