[PATCH v3 11/15] perf: Make RB allocation branch self sufficient

Peter Zijlstra posted 15 patches 1 month, 3 weeks ago
[PATCH v3 11/15] perf: Make RB allocation branch self sufficient
Posted by Peter Zijlstra 1 month, 3 weeks ago
Ensure @rb usage doesn't extend out of the branch block.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 kernel/events/core.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7116,8 +7116,6 @@ static int perf_mmap(struct file *file,
 				 * multiple times.
 				 */
 				ret = 0;
-				/* We need the rb to map pages. */
-				rb = event->rb;
 				perf_mmap_account(vma, user_extra, extra);
 				atomic_inc(&event->mmap_count);
 				goto unlock;
@@ -7136,8 +7134,6 @@ static int perf_mmap(struct file *file,
 			goto unlock;
 		}
 
-		WARN_ON(!rb && event->rb);
-
 		if (vma->vm_flags & VM_WRITE)
 			flags |= RING_BUFFER_WRITABLE;
 
@@ -7190,7 +7186,7 @@ static int perf_mmap(struct file *file,
 	 * full cleanup in this case and therefore does not invoke
 	 * vmops::close().
 	 */
-	ret = map_range(rb, vma);
+	ret = map_range(event->rb, vma);
 	if (ret)
 		perf_mmap_close(vma);
Re: [PATCH v3 11/15] perf: Make RB allocation branch self sufficient
Posted by Lorenzo Stoakes 1 month, 3 weeks ago
On Tue, Aug 12, 2025 at 12:39:09PM +0200, Peter Zijlstra wrote:
> Ensure @rb usage doesn't extend out of the branch block.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>

Nice to separate this out and make this bit clear.

I'm guessing you're holding off on putting the rb decl into the branch as
you intend in a future patch to separate out the rb branch too into a
helper like tglx's original did?

Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

> ---
>  kernel/events/core.c |    6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
>
> --- a/kernel/events/core.c
> +++ b/kernel/events/core.c
> @@ -7116,8 +7116,6 @@ static int perf_mmap(struct file *file,
>  				 * multiple times.
>  				 */
>  				ret = 0;
> -				/* We need the rb to map pages. */
> -				rb = event->rb;
>  				perf_mmap_account(vma, user_extra, extra);
>  				atomic_inc(&event->mmap_count);
>  				goto unlock;
> @@ -7136,8 +7134,6 @@ static int perf_mmap(struct file *file,
>  			goto unlock;
>  		}
>
> -		WARN_ON(!rb && event->rb);
> -
>  		if (vma->vm_flags & VM_WRITE)
>  			flags |= RING_BUFFER_WRITABLE;
>
> @@ -7190,7 +7186,7 @@ static int perf_mmap(struct file *file,
>  	 * full cleanup in this case and therefore does not invoke
>  	 * vmops::close().
>  	 */
> -	ret = map_range(rb, vma);
> +	ret = map_range(event->rb, vma);
>  	if (ret)
>  		perf_mmap_close(vma);
>
>
>
[tip: perf/core] perf: Make RB allocation branch self sufficient
Posted by tip-bot2 for Peter Zijlstra 1 month, 2 weeks ago
The following commit has been merged into the perf/core branch of tip:

Commit-ID:     191759e5ea9f6995171ed2ffcc41a2377f946a3a
Gitweb:        https://git.kernel.org/tip/191759e5ea9f6995171ed2ffcc41a2377f946a3a
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Tue, 12 Aug 2025 12:39:09 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 15 Aug 2025 13:13:01 +02:00

perf: Make RB allocation branch self sufficient

Ensure @rb usage doesn't extend out of the branch block.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Link: https://lore.kernel.org/r/20250812104019.605285302@infradead.org
---
 kernel/events/core.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index e76afd9..875c27b 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7116,8 +7116,6 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
 				 * multiple times.
 				 */
 				ret = 0;
-				/* We need the rb to map pages. */
-				rb = event->rb;
 				perf_mmap_account(vma, user_extra, extra);
 				atomic_inc(&event->mmap_count);
 				goto unlock;
@@ -7136,8 +7134,6 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
 			goto unlock;
 		}
 
-		WARN_ON(!rb && event->rb);
-
 		if (vma->vm_flags & VM_WRITE)
 			flags |= RING_BUFFER_WRITABLE;
 
@@ -7190,7 +7186,7 @@ unlock:
 	 * full cleanup in this case and therefore does not invoke
 	 * vmops::close().
 	 */
-	ret = map_range(rb, vma);
+	ret = map_range(event->rb, vma);
 	if (ret)
 		perf_mmap_close(vma);