From: David Woodhouse <dwmw2@infradead.org>
To: Fernand Sieber <sieberf@amazon.com>, peterz@infradead.org
Cc: abusse@amazon.de, bp@alien8.de, dave.hansen@linux.intel.com,
hborghor@amazon.de, hpa@zytor.com, jschoenh@amazon.de,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
mingo@redhat.com, nh-open-source@amazon.com, nsaenz@amazon.com,
pbonzini@redhat.com, seanjc@google.com, stable@vger.kernel.org,
tglx@linutronix.de, x86@kernel.org
Subject: Re: [PATCH v2] perf/x86/intel: Do not enable BTS for guests
Date: Wed, 14 Jan 2026 17:25:37 +0000 [thread overview]
Message-ID: <ff49b3013a4ff7626c6f6ac574f85348c35ccc42.camel@infradead.org> (raw)
In-Reply-To: <20251211183604.868641-1-sieberf@amazon.com>
[-- Attachment #1: Type: text/plain, Size: 1957 bytes --]
On Thu, 2025-12-11 at 20:36 +0200, Fernand Sieber wrote:
> By default when users program perf to sample branch instructions
> (PERF_COUNT_HW_BRANCH_INSTRUCTIONS) with a sample period of 1, perf
> interprets this as a special case and enables BTS (Branch Trace Store)
> as an optimization to avoid taking an interrupt on every branch.
>
> Since BTS doesn't virtualize, this optimization doesn't make sense when
> the request originates from a guest. Add an additional check that
> prevents this optimization for virtualized events (exclude_host).
>
> Reported-by: Jan H. Schönherr <jschoenh@amazon.de>
> Suggested-by: Peter Zijlstra <peterz@infradead.org>
> Signed-off-by: Fernand Sieber <sieberf@amazon.com>
Did this get applied?
I think you want Cc: stable@vger.kernel.org here in the body of the
commit itself, not just on the actual email.
> ---
> arch/x86/events/perf_event.h | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
> index 3161ec0a3416..f2e2d9b03367 100644
> --- a/arch/x86/events/perf_event.h
> +++ b/arch/x86/events/perf_event.h
> @@ -1574,13 +1574,22 @@ static inline bool intel_pmu_has_bts_period(struct perf_event *event, u64 period
> struct hw_perf_event *hwc = &event->hw;
> unsigned int hw_event, bts_event;
>
> - if (event->attr.freq)
> + /*
> + * Only use BTS for fixed rate period==1 events.
> + */
> + if (event->attr.freq || period != 1)
> + return false;
> +
> + /*
> + * BTS doesn't virtualize.
> + */
> + if (event->attr.exclude_host)
> return false;
>
> hw_event = hwc->config & INTEL_ARCH_EVENT_MASK;
> bts_event = x86_pmu.event_map(PERF_COUNT_HW_BRANCH_INSTRUCTIONS);
>
> - return hw_event == bts_event && period == 1;
> + return hw_event == bts_event;
> }
>
> static inline bool intel_pmu_has_bts(struct perf_event *event)
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5069 bytes --]
next prev parent reply other threads:[~2026-01-14 17:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-01 14:23 [PATCH] KVM: x86/pmu: Do not accidentally create BTS events Fernand Sieber
2025-12-01 14:45 ` Woodhouse, David
2025-12-02 9:35 ` Peter Zijlstra
2025-12-02 9:59 ` Fernand Sieber
2025-12-02 2:19 ` Like Xu
2025-12-02 10:03 ` Peter Zijlstra
2025-12-02 12:44 ` Peter Zijlstra
2025-12-02 16:03 ` Sean Christopherson
2025-12-10 10:11 ` Fernand Sieber
2025-12-10 11:16 ` Peter Zijlstra
2025-12-11 18:36 ` [PATCH v2] perf/x86/intel: Do not enable BTS for guests Fernand Sieber
2026-01-14 17:25 ` David Woodhouse [this message]
2026-01-21 13:57 ` Fernand Sieber
2026-01-21 15:31 ` Peter Zijlstra
2026-01-21 15:50 ` [tip: perf/urgent] " tip-bot2 for Fernand Sieber
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=ff49b3013a4ff7626c6f6ac574f85348c35ccc42.camel@infradead.org \
--to=dwmw2@infradead.org \
--cc=abusse@amazon.de \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hborghor@amazon.de \
--cc=hpa@zytor.com \
--cc=jschoenh@amazon.de \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=nh-open-source@amazon.com \
--cc=nsaenz@amazon.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=sieberf@amazon.com \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--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
all inboxes | Powered by JetHome®