@@ -6701,6 +6701,42 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
6701
6701
6702
6702
if (vma -> vm_pgoff == 0 ) {
6703
6703
nr_pages = (vma_size / PAGE_SIZE ) - 1 ;
6704
+
6705
+ /*
6706
+ * If we have rb pages ensure they're a power-of-two number, so we
6707
+ * can do bitmasks instead of modulo.
6708
+ */
6709
+ if (nr_pages != 0 && !is_power_of_2 (nr_pages ))
6710
+ return - EINVAL ;
6711
+
6712
+ if (vma_size != PAGE_SIZE * (1 + nr_pages ))
6713
+ return - EINVAL ;
6714
+
6715
+ WARN_ON_ONCE (event -> ctx -> parent_ctx );
6716
+ again :
6717
+ mutex_lock (& event -> mmap_mutex );
6718
+ if (event -> rb ) {
6719
+ if (data_page_nr (event -> rb ) != nr_pages ) {
6720
+ ret = - EINVAL ;
6721
+ goto unlock ;
6722
+ }
6723
+
6724
+ if (!atomic_inc_not_zero (& event -> rb -> mmap_count )) {
6725
+ /*
6726
+ * Raced against perf_mmap_close(); remove the
6727
+ * event and try again.
6728
+ */
6729
+ ring_buffer_attach (event , NULL );
6730
+ mutex_unlock (& event -> mmap_mutex );
6731
+ goto again ;
6732
+ }
6733
+
6734
+ /* We need the rb to map pages. */
6735
+ rb = event -> rb ;
6736
+ goto unlock ;
6737
+ }
6738
+
6739
+ user_extra = nr_pages + 1 ;
6704
6740
} else {
6705
6741
/*
6706
6742
* AUX area mapping: if rb->aux_nr_pages != 0, it's already
@@ -6760,47 +6796,8 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
6760
6796
6761
6797
atomic_set (& rb -> aux_mmap_count , 1 );
6762
6798
user_extra = nr_pages ;
6763
-
6764
- goto accounting ;
6765
- }
6766
-
6767
- /*
6768
- * If we have rb pages ensure they're a power-of-two number, so we
6769
- * can do bitmasks instead of modulo.
6770
- */
6771
- if (nr_pages != 0 && !is_power_of_2 (nr_pages ))
6772
- return - EINVAL ;
6773
-
6774
- if (vma_size != PAGE_SIZE * (1 + nr_pages ))
6775
- return - EINVAL ;
6776
-
6777
- WARN_ON_ONCE (event -> ctx -> parent_ctx );
6778
- again :
6779
- mutex_lock (& event -> mmap_mutex );
6780
- if (event -> rb ) {
6781
- if (data_page_nr (event -> rb ) != nr_pages ) {
6782
- ret = - EINVAL ;
6783
- goto unlock ;
6784
- }
6785
-
6786
- if (!atomic_inc_not_zero (& event -> rb -> mmap_count )) {
6787
- /*
6788
- * Raced against perf_mmap_close(); remove the
6789
- * event and try again.
6790
- */
6791
- ring_buffer_attach (event , NULL );
6792
- mutex_unlock (& event -> mmap_mutex );
6793
- goto again ;
6794
- }
6795
-
6796
- /* We need the rb to map pages. */
6797
- rb = event -> rb ;
6798
- goto unlock ;
6799
6799
}
6800
6800
6801
- user_extra = nr_pages + 1 ;
6802
-
6803
- accounting :
6804
6801
user_lock_limit = sysctl_perf_event_mlock >> (PAGE_SHIFT - 10 );
6805
6802
6806
6803
/*
0 commit comments