[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220207170259.2566-1-xiezhipeng1@huawei.com>
Date: Mon, 7 Feb 2022 12:02:59 -0500
From: Zhipeng Xie <xiezhipeng1@...wei.com>
To: <peterz@...radead.org>, <mingo@...hat.com>, <acme@...nel.org>,
<mark.rutland@....com>, <alexander.shishkin@...ux.intel.com>,
<jolsa@...hat.com>, <namhyung@...nel.org>
CC: <linux-perf-users@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<xiezhipeng1@...wei.com>
Subject: [PATCH] Fix perf_mmap fail when CONFIG_PERF_USE_VMALLOC enabled
when CONFIG_PERF_USE_VMALLOC is enabled, rb->nr_pages is always
equal to 1 in rb_alloc, causing perf_mmap return -EINVAL when mmap.
Fix this problem using data_page_nr.
Signed-off-by: Zhipeng Xie <xiezhipeng1@...wei.com>
---
kernel/events/core.c | 2 +-
kernel/events/internal.h | 5 +++++
kernel/events/ring_buffer.c | 5 -----
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 57c7197838db..370292effd32 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6352,7 +6352,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)
again:
mutex_lock(&event->mmap_mutex);
if (event->rb) {
- if (event->rb->nr_pages != nr_pages) {
+ if (data_page_nr(event->rb) != nr_pages) {
ret = -EINVAL;
goto unlock;
}
diff --git a/kernel/events/internal.h b/kernel/events/internal.h
index 082832738c8f..5816c0719dbf 100644
--- a/kernel/events/internal.h
+++ b/kernel/events/internal.h
@@ -116,6 +116,11 @@ static inline int page_order(struct perf_buffer *rb)
}
#endif
+static int data_page_nr(struct perf_buffer *rb)
+{
+ return rb->nr_pages << page_order(rb);
+}
+
static inline unsigned long perf_data_size(struct perf_buffer *rb)
{
return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index 52868716ec35..fb35b926024c 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -859,11 +859,6 @@ void rb_free(struct perf_buffer *rb)
}
#else
-static int data_page_nr(struct perf_buffer *rb)
-{
- return rb->nr_pages << page_order(rb);
-}
-
static struct page *
__perf_mmap_to_page(struct perf_buffer *rb, unsigned long pgoff)
{
--
2.18.1
Powered by blists - more mailing lists