Re: [PATCH v3 13/15] perf: Use scoped_guard() for mmap_mutex in perf_mmap()
From: Lorenzo Stoakes
Date: Wed Aug 13 2025 - 04:52:28 EST
On Wed, Aug 13, 2025 at 10:44:48AM +0200, Peter Zijlstra wrote:
> 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?
Right yeah, you could just return instead of break :))