[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250813084448.GB4068168@noisy.programming.kicks-ass.net>
Date: Wed, 13 Aug 2025 10:44:48 +0200
From: Peter Zijlstra <peterz@...radead.org>
To: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
Cc: tglx@...utronix.de, linux-kernel@...r.kernel.org,
torvalds@...uxfoundation.org, mingo@...nel.org, namhyung@...nel.org,
acme@...hat.com, kees@...nel.org
Subject: Re: [PATCH v3 13/15] perf: Use scoped_guard() for mmap_mutex in
perf_mmap()
On Wed, Aug 13, 2025 at 10:32:44AM +0200, Peter Zijlstra wrote:
> On Wed, Aug 13, 2025 at 07:42:41AM +0100, Lorenzo Stoakes wrote:
>
> > > + scoped_guard (mutex, &event->mmap_mutex) {
> > > + /*
> > > + * This relies on __pmu_detach_event() taking mmap_mutex after marking
> > > + * the event REVOKED. Either we observe the state, or __pmu_detach_event()
> > > + * will detach the rb created here.
> > > + */
> > > + if (event->state <= PERF_EVENT_STATE_REVOKED) {
> > > + ret = -ENODEV;
> > > + break;
> >
> > I don't absolutely love this break-for-what-is-not-obviously-a-for-loop
> > formulation (I know scoped_guard in practice _is_ a for loop, but obviously
> > that's hidden by macro), but I guess hey it's C, and we have to do what we
> > have to do :)
>
> Right, don't love it either, but the alternative was a goto and that's
> arguably worse, so meh.
>
> > > + }
> > >
> > > + if (vma->vm_pgoff == 0)
> > > + ret = perf_mmap_rb(vma, event, nr_pages);
> > > + else
> > > + ret = perf_mmap_aux(vma, event, nr_pages);
> > > }
> > >
> > > if (ret)
> > > return ret;
> > >
Nah, I'm an idiot.. How's this?
---
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 20189a3354f2..4b82f8ed6b4e 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7151,20 +7151,17 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
* the event REVOKED. Either we observe the state, or __pmu_detach_event()
* will detach the rb created here.
*/
- if (event->state <= PERF_EVENT_STATE_REVOKED) {
- ret = -ENODEV;
- break;
- }
+ if (event->state <= PERF_EVENT_STATE_REVOKED)
+ return -ENODEV;
if (vma->vm_pgoff == 0)
ret = perf_mmap_rb(vma, event, nr_pages);
else
ret = perf_mmap_aux(vma, event, nr_pages);
+ if (ret)
+ return ret;
}
- if (ret)
- return ret;
-
/*
* Since pinned accounting is per vm we cannot allow fork() to copy our
* vma.
Powered by blists - more mailing lists