Re: [PATCH v3 RESEND] perf: Fix refcount warning on event->mmap_count increment
From: Peter Zijlstra
Date: Tue Jan 20 2026 - 07:24:09 EST
On Mon, Jan 19, 2026 at 11:49:56AM -0700, Will Rosenberg wrote:
>
> Notes:
> v2 -> v3: Update patch to error out instead of incrementing.
>
> Thank you, this is a much better solution. I was not thinking
> that the mmap itself was unintended.
>
> I believe you are missing a "!" in your patch. After adding
> that, I tested the patch, and it fixed the bug.
D'0h indeed. Sometimes typing is so very hard ;-)
> I also wanted to check my understanding of the race with
> perf_mmap_close() to double check this patch will not cause
> an issue. perf_mmap_rb() should always hold the
> event->mmap_mutex, so there should be no race on
> event->mmap_count with perf_mmap_close()'s
> refcount_dec_and_mutex_lock(). If there was a race, we would
> risk returning -EBUSY when we should "continue as if !event->rb."
Since we're failing perf_mmap_rb(), it won't call ->close(), right?
Also, we already have an error path on data_page_nr() mismatch.
The caller of perf_mmap_rb() has if (ret) return ret; nothing is
modified before calling perf_mmap_rb() and perf_mmap_rb() itself hasn't
modified anytyhing yet at the point of failure.
So afaict we're good.
Anyway, thanks for the patch, I'll get it applied!