Skip to content

Commit 0c8a4e4

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
perf/core: Further simplify perf_mmap()
Perform CSE and such. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Ravi Bangoria <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9548783 commit 0c8a4e4

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

kernel/events/core.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6698,9 +6698,18 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
66986698
return ret;
66996699

67006700
vma_size = vma->vm_end - vma->vm_start;
6701+
nr_pages = vma_size / PAGE_SIZE;
6702+
6703+
if (nr_pages > INT_MAX)
6704+
return -ENOMEM;
6705+
6706+
if (vma_size != PAGE_SIZE * nr_pages)
6707+
return -EINVAL;
6708+
6709+
user_extra = nr_pages;
67016710

67026711
if (vma->vm_pgoff == 0) {
6703-
nr_pages = (vma_size / PAGE_SIZE) - 1;
6712+
nr_pages -= 1;
67046713

67056714
/*
67066715
* If we have rb pages ensure they're a power-of-two number, so we
@@ -6709,9 +6718,6 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
67096718
if (nr_pages != 0 && !is_power_of_2(nr_pages))
67106719
return -EINVAL;
67116720

6712-
if (vma_size != PAGE_SIZE * (1 + nr_pages))
6713-
return -EINVAL;
6714-
67156721
WARN_ON_ONCE(event->ctx->parent_ctx);
67166722
again:
67176723
mutex_lock(&event->mmap_mutex);
@@ -6735,8 +6741,6 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
67356741
rb = event->rb;
67366742
goto unlock;
67376743
}
6738-
6739-
user_extra = nr_pages + 1;
67406744
} else {
67416745
/*
67426746
* AUX area mapping: if rb->aux_nr_pages != 0, it's already
@@ -6748,10 +6752,6 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
67486752
if (!event->rb)
67496753
return -EINVAL;
67506754

6751-
nr_pages = vma_size / PAGE_SIZE;
6752-
if (nr_pages > INT_MAX)
6753-
return -ENOMEM;
6754-
67556755
mutex_lock(&event->mmap_mutex);
67566756
ret = -EINVAL;
67576757

@@ -6795,7 +6795,6 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
67956795
}
67966796

67976797
atomic_set(&rb->aux_mmap_count, 1);
6798-
user_extra = nr_pages;
67996798
}
68006799

68016800
user_lock_limit = sysctl_perf_event_mlock >> (PAGE_SHIFT - 10);

0 commit comments

Comments
 (0)