From: "Mi, Dapeng" <dapeng1.mi@linux.intel.com>
To: Jiwoo Kim <arpe1618@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Kan Liang <kan.liang@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
Thomas Gleixner <tglx@kernel.org>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf/x86/intel: Don't allow extended register sampling for BTS events
Date: Wed, 18 Nov 2026 11:14:10 +0800 [thread overview]
Message-ID: <9fbc301a-68ab-4839-b5c7-177ad9fcde76@linux.intel.com> (raw)
In-Reply-To: <20261114062249.1301-1-arpe1618@gmail.com>
Thanks for reporting and fixing this issue.
Reviewed-by: Dapeng Mi <dapeng1.mi@linux.intel.com>
On 11/14/2026 2:22 PM, Jiwoo Kim wrote:
> x86_pmu_hw_config() accepts extended (XMM) register sampling in
> REGS_USER for events without precise_ip, and the same goes for the SIMD
> register fields. The BTS event is such an event, and
> intel_pmu_bts_config() does not reject it.
>
> For a sample taken in the PMI handler, x86_pmu_update_perf_regs() copies
> the user registers into the per-CPU x86_user_regs, which is a struct
> x86_perf_regs. That is what perf_reg_value() and perf_simd_reg_value()
> expect: they use container_of() on the sampled struct pt_regs to reach
> the fields that follow it.
>
> intel_pmu_drain_bts_buffer() does not call x86_pmu_update_perf_regs().
> It passes zeroed on-stack registers to perf_prepare_sample(), so the
> generic perf_sample_regs_user() takes the user registers from
> perf_get_regs_user(). That returns task_pt_regs(current), or on x86_64,
> when the buffer is drained from the PMI handler, a copy in the per-CPU
> nmi_user_regs, and neither is embedded in a struct x86_perf_regs. For a
> BTS event that requests these registers in REGS_USER, perf_reg_value()
> and perf_simd_reg_value() therefore read past the end of the struct
> pt_regs they are given, and use the words found there as pointers.
> REGS_INTR is not affected: BTS events must set exclude_kernel, and
> perf_sample_regs_intr() then reports no registers, as the zeroed ones
> are not user mode.
>
> BTS samples are built from the BTS buffer when it is drained, not from
> the registers of an interrupted context, so there is nothing meaningful
> to report in these registers for them. Reject extended and SIMD
> register sampling for BTS events in intel_pmu_bts_config(), as was the
> case before these registers could be sampled for events without
> precise_ip.
>
> This was found with an AI coding assistant, which also drafted this
> patch and its changelog. It has not been reproduced, and the change
> has only been compile-tested.
>
> Fixes: edd9aec51213 ("perf/x86: Enable XMM register sampling for REGS_USER case")
> Signed-off-by: Jiwoo Kim <arpe1618@gmail.com>
> ---
> No Cc: stable, as the Fixes target first appeared in v7.4-rc1.
>
> The container_of() on a struct pt_regs that is not embedded in a struct
> x86_perf_regs came up in the review of v10 of the SIMD sampling series,
> for software events and bpf_perf_event_output():
> https://lore.kernel.org/r/20260824091225.514D71F000E9@smtp.kernel.org
> The reply there pointed out that the PMU capability checks reject those
> events. The BTS event is created on the core PMU, which has
> PERF_PMU_CAP_EXTENDED_REGS (and PERF_PMU_CAP_SIMD_REGS where supported),
> so those checks do not stop it.
>
> arch/x86/events/intel/core.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
> index 0a34d674df59..88a60d3e4eeb 100644
> --- a/arch/x86/events/intel/core.c
> +++ b/arch/x86/events/intel/core.c
> @@ -4778,6 +4778,16 @@ static int intel_pmu_bts_config(struct perf_event *event)
> if (attr->precise_ip)
> return -EOPNOTSUPP;
>
> + /*
> + * BTS samples are built from the BTS buffer when it is drained,
> + * not from the registers of an interrupted context, and
> + * intel_pmu_drain_bts_buffer() does not provide the registers in
> + * the struct x86_perf_regs layout that extended register sampling
> + * relies on.
> + */
> + if (event_has_extended_regs(event) || event_has_simd_regs(event))
> + return -EOPNOTSUPP;
> +
> /* disallow bts if conflicting events are present */
> if (x86_add_exclusive(x86_lbr_exclusive_lbr))
> return -EBUSY;
>
> base-commit: 59f1398140869432c7171b9a2a279ca315467c4e
prev parent reply other threads:[~2026-11-18 3:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 6:22 [PATCH] perf/x86/intel: Don't allow extended register sampling for BTS events Jiwoo Kim
2026-11-14 6:44 ` sashiko-bot
2026-11-18 3:14 ` Mi, Dapeng [this message]
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=9fbc301a-68ab-4839-b5c7-177ad9fcde76@linux.intel.com \
--to=dapeng1.mi@linux.intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=arpe1618@gmail.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--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