Re: [PATCH] perf/x86/intel/ds: don't WARN when the BTS buffer can't be allocated
From: Xu Yilun
Date: Fri Nov 20 2026 - 14:31:45 EST
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.