* [PATCH] perf/x86/intel/ds: don't WARN when the BTS buffer can't be allocated
@ 2026-11-06 3:06 Yuehong Wu
2026-11-20 19:22 ` Xu Yilun
2026-11-21 5:36 ` Mi, Dapeng
0 siblings, 2 replies; 3+ messages in thread
From: Yuehong Wu @ 2026-11-06 3:06 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, x86
Cc: Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark, Thomas Gleixner, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Dapeng Mi, Kan Liang, David Rientjes,
linux-perf-users, linux-kernel
alloc_bts_buffer() asks for the buffer with __GFP_NOWARN and then WARNs
if the allocation failed anyway. The failure is already handled: the
caller disables BTS for the event and releases what was set up, and
perf_event_open() returns -ENOMEM.
The WARN_ONCE() came with commit 4485154138f6 ("perf/x86/intel: Avoid
spamming kernel log for BTS buffer failure"), which added __GFP_NOWARN to
stop the log spam of the failing per-CPU allocation but kept one warning
as a hint. That hint is fatal under panic_on_warn: on a machine with
BTS, the 64 KiB buffer allocation can fail on a memory-constrained
system and a plain perf_event_open() then panics the kernel. Since the
allocation explicitly asked not to warn and the error path is fine, drop
the WARN_ONCE().
Reproduced on 7.3.0-next-20261027 by making the page allocator fail the
order-4 BTS buffer allocation (fail_page_alloc: min-order=4,
ignore-gfp-wait=0). Without this change the first perf_event_open() of
a hardware event hits the warning and, with panic_on_warn=1, panics.
With this change the same allocation failure is silent: BTS is disabled
and a following branches/period=1 event returns -EOPNOTSUPP, while the
kernel keeps running. The buffer is allocated per possible CPU,
independently of any specific BTS event, so the failure path is
exercised without BTS tracing.
Fixes: 4485154138f6 ("perf/x86/intel: Avoid spamming kernel log for BTS buffer failure")
Signed-off-by: Yuehong Wu <wuyuehong@cmss.chinamobile.com>
---
arch/x86/events/intel/ds.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c
index 8444670..27e4115 100644
--- a/arch/x86/events/intel/ds.c
+++ b/arch/x86/events/intel/ds.c
@@ -939,10 +939,8 @@ static int alloc_bts_buffer(int cpu)
return 0;
buffer = dsalloc_pages(BTS_BUFFER_SIZE, GFP_KERNEL | __GFP_NOWARN, cpu);
- if (unlikely(!buffer)) {
- WARN_ONCE(1, "%s: BTS buffer allocation failure\n", __func__);
+ if (unlikely(!buffer))
return -ENOMEM;
- }
hwev->ds_bts_vaddr = buffer;
/* Update the fixmap */
cea = &get_cpu_entry_area(cpu)->cpu_debug_buffers.bts_buffer;
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] perf/x86/intel/ds: don't WARN when the BTS buffer can't be allocated
2026-11-06 3:06 [PATCH] perf/x86/intel/ds: don't WARN when the BTS buffer can't be allocated Yuehong Wu
@ 2026-11-20 19:22 ` Xu Yilun
2026-11-21 5:36 ` Mi, Dapeng
1 sibling, 0 replies; 3+ messages in thread
From: Xu Yilun @ 2026-11-20 19:22 UTC (permalink / raw)
To: Yuehong Wu
Cc: Peter Zijlstra, Ingo Molnar, x86, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter, James Clark, Thomas Gleixner,
Borislav Petkov, Dave Hansen, H. Peter Anvin, Dapeng Mi,
Kan Liang, David Rientjes, linux-perf-users, linux-kernel
On Fri, Nov 06, 2026 at 11:06:41AM +0800, Yuehong Wu wrote:
> alloc_bts_buffer() asks for the buffer with __GFP_NOWARN and then WARNs
> if the allocation failed anyway. The failure is already handled: the
> caller disables BTS for the event and releases what was set up, and
> perf_event_open() returns -ENOMEM.
perf_event_open() won't return -ENOMEM. You said your test went on until
a following BTS event returns -EOPNOTSUPP.
>
> The WARN_ONCE() came with commit 4485154138f6 ("perf/x86/intel: Avoid
> spamming kernel log for BTS buffer failure"), which added __GFP_NOWARN to
> stop the log spam of the failing per-CPU allocation but kept one warning
> as a hint. That hint is fatal under panic_on_warn: on a machine with
> BTS, the 64 KiB buffer allocation can fail on a memory-constrained
> system and a plain perf_event_open() then panics the kernel.
I think that's the only point for reviewers to debate, do we need to
panic on warn when a user could easily trigger it? An alternative is
pr_warn_once(), not keep silent and go on running.
But basically I dislike the code churn, and don't think the entire
change is necessary.
> Since the
> allocation explicitly asked not to warn and the error path is fine, drop
> the WARN_ONCE().
Here the logic is broken. As mentioned in 4485154138f6,__GFP_NOWARN
stops excessive warnings, WARN_ONCE() keeps one warning, they don't
conflict.
BTW, the changelog contains too much unrelated info, it is just a single
log removal.
>
> Reproduced on 7.3.0-next-20261027 by making the page allocator fail the
> order-4 BTS buffer allocation (fail_page_alloc: min-order=4,
> ignore-gfp-wait=0). Without this change the first perf_event_open() of
> a hardware event hits the warning and, with panic_on_warn=1, panics.
> With this change the same allocation failure is silent: BTS is disabled
> and a following branches/period=1 event returns -EOPNOTSUPP, while the
> kernel keeps running. The buffer is allocated per possible CPU,
> independently of any specific BTS event, so the failure path is
> exercised without BTS tracing.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] perf/x86/intel/ds: don't WARN when the BTS buffer can't be allocated
2026-11-06 3:06 [PATCH] perf/x86/intel/ds: don't WARN when the BTS buffer can't be allocated Yuehong Wu
2026-11-20 19:22 ` Xu Yilun
@ 2026-11-21 5:36 ` Mi, Dapeng
1 sibling, 0 replies; 3+ messages in thread
From: Mi, Dapeng @ 2026-11-21 5:36 UTC (permalink / raw)
To: Yuehong Wu, Peter Zijlstra, Ingo Molnar, x86
Cc: Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
James Clark, Thomas Gleixner, Borislav Petkov, Dave Hansen,
H. Peter Anvin, Kan Liang, David Rientjes, linux-perf-users,
linux-kernel
On 11/6/2026 11:06 AM, Yuehong Wu wrote:
> alloc_bts_buffer() asks for the buffer with __GFP_NOWARN and then WARNs
> if the allocation failed anyway. The failure is already handled: the
> caller disables BTS for the event and releases what was set up, and
> perf_event_open() returns -ENOMEM.
>
> The WARN_ONCE() came with commit 4485154138f6 ("perf/x86/intel: Avoid
> spamming kernel log for BTS buffer failure"), which added __GFP_NOWARN to
> stop the log spam of the failing per-CPU allocation but kept one warning
> as a hint. That hint is fatal under panic_on_warn: on a machine with
> BTS, the 64 KiB buffer allocation can fail on a memory-constrained
> system and a plain perf_event_open() then panics the kernel. Since the
> allocation explicitly asked not to warn and the error path is fine, drop
> the WARN_ONCE().
>
> Reproduced on 7.3.0-next-20261027 by making the page allocator fail the
> order-4 BTS buffer allocation (fail_page_alloc: min-order=4,
> ignore-gfp-wait=0). Without this change the first perf_event_open() of
> a hardware event hits the warning and, with panic_on_warn=1, panics.
> With this change the same allocation failure is silent: BTS is disabled
> and a following branches/period=1 event returns -EOPNOTSUPP, while the
> kernel keeps running. The buffer is allocated per possible CPU,
> independently of any specific BTS event, so the failure path is
> exercised without BTS tracing.
>
> Fixes: 4485154138f6 ("perf/x86/intel: Avoid spamming kernel log for BTS buffer failure")
> Signed-off-by: Yuehong Wu <wuyuehong@cmss.chinamobile.com>
> ---
> arch/x86/events/intel/ds.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/arch/x86/events/intel/ds.c b/arch/x86/events/intel/ds.c
> index 8444670..27e4115 100644
> --- a/arch/x86/events/intel/ds.c
> +++ b/arch/x86/events/intel/ds.c
> @@ -939,10 +939,8 @@ static int alloc_bts_buffer(int cpu)
> return 0;
>
> buffer = dsalloc_pages(BTS_BUFFER_SIZE, GFP_KERNEL | __GFP_NOWARN, cpu);
> - if (unlikely(!buffer)) {
> - WARN_ONCE(1, "%s: BTS buffer allocation failure\n", __func__);
It's meaningful to keep the WARN_ONCE() here since __GFP_NOWARN is set and
the memory allocator won't print the warning message when allocation fails.
About the panic_on_warn worries , as the
"Documentation/process/coding-style.rst" said, it's the users'
responsibility to deal with the possible crash if user enables the
"panic_on_warn" option.
"
Do not worry about panic_on_warn users
**************************************
A few more words about panic_on_warn: Remember that ``panic_on_warn`` is an
available kernel option, and that many users set this option. This is why
there is a "Do not WARN lightly" writeup, above. However, the existence of
panic_on_warn users is not a valid reason to avoid the judicious use
WARN*(). That is because, whoever enables panic_on_warn has explicitly
asked the kernel to crash if a WARN*() fires, and such users must be
prepared to deal with the consequences of a system that is somewhat more
likely to crash.
"
> + if (unlikely(!buffer))
> return -ENOMEM;
> - }
> hwev->ds_bts_vaddr = buffer;
> /* Update the fixmap */
> cea = &get_cpu_entry_area(cpu)->cpu_debug_buffers.bts_buffer;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-21 5:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-06 3:06 [PATCH] perf/x86/intel/ds: don't WARN when the BTS buffer can't be allocated Yuehong Wu
2026-11-20 19:22 ` Xu Yilun
2026-11-21 5:36 ` Mi, Dapeng
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox