@@ -6698,9 +6698,18 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
6698
6698
return ret ;
6699
6699
6700
6700
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 ;
6701
6710
6702
6711
if (vma -> vm_pgoff == 0 ) {
6703
- nr_pages = ( vma_size / PAGE_SIZE ) - 1 ;
6712
+ nr_pages -= 1 ;
6704
6713
6705
6714
/*
6706
6715
* 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)
6709
6718
if (nr_pages != 0 && !is_power_of_2 (nr_pages ))
6710
6719
return - EINVAL ;
6711
6720
6712
- if (vma_size != PAGE_SIZE * (1 + nr_pages ))
6713
- return - EINVAL ;
6714
-
6715
6721
WARN_ON_ONCE (event -> ctx -> parent_ctx );
6716
6722
again :
6717
6723
mutex_lock (& event -> mmap_mutex );
@@ -6735,8 +6741,6 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
6735
6741
rb = event -> rb ;
6736
6742
goto unlock ;
6737
6743
}
6738
-
6739
- user_extra = nr_pages + 1 ;
6740
6744
} else {
6741
6745
/*
6742
6746
* 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)
6748
6752
if (!event -> rb )
6749
6753
return - EINVAL ;
6750
6754
6751
- nr_pages = vma_size / PAGE_SIZE ;
6752
- if (nr_pages > INT_MAX )
6753
- return - ENOMEM ;
6754
-
6755
6755
mutex_lock (& event -> mmap_mutex );
6756
6756
ret = - EINVAL ;
6757
6757
@@ -6795,7 +6795,6 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
6795
6795
}
6796
6796
6797
6797
atomic_set (& rb -> aux_mmap_count , 1 );
6798
- user_extra = nr_pages ;
6799
6798
}
6800
6799
6801
6800
user_lock_limit = sysctl_perf_event_mlock >> (PAGE_SHIFT - 10 );
0 commit comments