Re: [PATCH v3 13/15] perf: Use scoped_guard() for mmap_mutex in perf_mmap()
From: Lorenzo Stoakes
Date: Wed Aug 13 2025 - 02:43:15 EST
On Tue, Aug 12, 2025 at 12:39:11PM +0200, Peter Zijlstra wrote:
> Mostly just re-indent noise.
>
> Suggested-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
LGTM, so:
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx>
> ---
> kernel/events/core.c | 32 ++++++++++++++------------------
> 1 file changed, 14 insertions(+), 18 deletions(-)
>
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -7143,27 +7143,23 @@ static int perf_mmap(struct file *file,
> if (vma_size != PAGE_SIZE * nr_pages)
> return -EINVAL;
>
> - mutex_lock(&event->mmap_mutex);
Yeah getting rid of this lock goto stuff is great... mm is at risk of some
more Lorenzo churn to use this stuff over there... :)
> - ret = -EINVAL;
You see, I'm getting in a pattern here with comment on prior patch and you
reading my mind and fixing it on next ;)
> + 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 :)
> + }
>
> - /*
> - * 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;
> - goto unlock;
> + if (vma->vm_pgoff == 0)
> + ret = perf_mmap_rb(vma, event, nr_pages);
> + else
> + ret = perf_mmap_aux(vma, event, nr_pages);
> }
>
> - if (vma->vm_pgoff == 0)
> - ret = perf_mmap_rb(vma, event, nr_pages);
> - else
> - ret = perf_mmap_aux(vma, event, nr_pages);
> -
> -unlock:
> - mutex_unlock(&event->mmap_mutex);
> -
> if (ret)
> return ret;
>
>
>