Skip to content

Commit 0983593

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
perf/core: Lift event->mmap_mutex in perf_mmap()
This puts 'all' of perf_mmap() under single event->mmap_mutex. 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 8eaec7b commit 0983593

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

kernel/events/core.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6680,7 +6680,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
66806680
unsigned long vma_size;
66816681
unsigned long nr_pages;
66826682
long user_extra = 0, extra = 0;
6683-
int ret = 0, flags = 0;
6683+
int ret, flags = 0;
66846684

66856685
/*
66866686
* Don't allow mmap() of inherited per-task counters. This would
@@ -6708,6 +6708,9 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
67086708

67096709
user_extra = nr_pages;
67106710

6711+
mutex_lock(&event->mmap_mutex);
6712+
ret = -EINVAL;
6713+
67116714
if (vma->vm_pgoff == 0) {
67126715
nr_pages -= 1;
67136716

@@ -6716,16 +6719,13 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
67166719
* can do bitmasks instead of modulo.
67176720
*/
67186721
if (nr_pages != 0 && !is_power_of_2(nr_pages))
6719-
return -EINVAL;
6722+
goto unlock;
67206723

67216724
WARN_ON_ONCE(event->ctx->parent_ctx);
6722-
mutex_lock(&event->mmap_mutex);
67236725

67246726
if (event->rb) {
6725-
if (data_page_nr(event->rb) != nr_pages) {
6726-
ret = -EINVAL;
6727+
if (data_page_nr(event->rb) != nr_pages)
67276728
goto unlock;
6728-
}
67296729

67306730
if (atomic_inc_not_zero(&event->rb->mmap_count)) {
67316731
/*
@@ -6754,12 +6754,6 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
67546754
*/
67556755
u64 aux_offset, aux_size;
67566756

6757-
if (!event->rb)
6758-
return -EINVAL;
6759-
6760-
mutex_lock(&event->mmap_mutex);
6761-
ret = -EINVAL;
6762-
67636757
rb = event->rb;
67646758
if (!rb)
67656759
goto aux_unlock;
@@ -6869,6 +6863,8 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
68696863
rb->aux_mmap_locked = extra;
68706864
}
68716865

6866+
ret = 0;
6867+
68726868
unlock:
68736869
if (!ret) {
68746870
atomic_long_add(user_extra, &user->locked_vm);

0 commit comments

Comments
 (0)