Linux Perf Users
 help / color / mirror / Atom feed
* Re: [PATCH] Fix perf_mmap fail when CONFIG_PERF_USE_VMALLOC enabled
  2022-02-07 17:02 [PATCH] Fix perf_mmap fail when CONFIG_PERF_USE_VMALLOC enabled Zhipeng Xie
@ 2022-02-07 14:11 ` Peter Zijlstra
  2022-02-08 15:49   ` Zhipeng Xie
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Zijlstra @ 2022-02-07 14:11 UTC (permalink / raw)
  To: Zhipeng Xie
  Cc: mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung,
	linux-perf-users, linux-kernel


Your $Subject needs a subsystem prefix.

On Mon, Feb 07, 2022 at 12:02:59PM -0500, Zhipeng Xie wrote:
> 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.

How can this be? This would mean that any arch that selects that hasn't
worked for forever ?! That seems unlikely.

> Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>

If this is correct; this is also missing a Fixes: tag.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] Fix perf_mmap fail when CONFIG_PERF_USE_VMALLOC enabled
@ 2022-02-07 17:02 Zhipeng Xie
  2022-02-07 14:11 ` Peter Zijlstra
  0 siblings, 1 reply; 3+ messages in thread
From: Zhipeng Xie @ 2022-02-07 17:02 UTC (permalink / raw)
  To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa,
	namhyung
  Cc: linux-perf-users, linux-kernel, xiezhipeng1

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@huawei.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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix perf_mmap fail when CONFIG_PERF_USE_VMALLOC enabled
  2022-02-07 14:11 ` Peter Zijlstra
@ 2022-02-08 15:49   ` Zhipeng Xie
  0 siblings, 0 replies; 3+ messages in thread
From: Zhipeng Xie @ 2022-02-08 15:49 UTC (permalink / raw)
  To: peterz
  Cc: acme, alexander.shishkin, jolsa, linux-kernel, linux-perf-users,
	mark.rutland, mingo, namhyung, xiezhipeng1, xiexiuqi, fanwentao

On Mon, February 7, 2022 10:12 PM, Peter Zijlstra wrote:
> Your $Subject needs a subsystem prefix.

Thanks for your comments, I will adjust the patch Subject and resend the
patch according to your suggestions.

> On Mon, Feb 07, 2022 at 12:02:59PM -0500, Zhipeng Xie wrote:
> > 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.
> 
> How can this be? This would mean that any arch that selects that hasn't
> worked for forever ?! That seems unlikely.

Arch with CONFIG_PERF_USE_VMALLOC enabled by default: 
	arc/arm/csky/mips/sh/sparc/xtensa
Arch with CONFIG_PERF_USE_VMALLOC disabled by default:
	x86_64/aarch64/...
I have this problem when using sysdig -B(using ebpf)[1] on an aarch64 kernel
with CONFIG_PERF_USE_VMALLOC enabled. sysdig -B works fine after rebuilding
the kernel with the CONFIG_PERF_USE_VMALLOC disabled. I tracked it down to the
if condition event->rb->nr_pages != nr_pages in perf_mmap is true where
event->rb->nr_pages = 1 and nr_pages = 2048 resulting perf_mmap to return
-EINVAL.

[1] https://github.com/draios/sysdig

> > Signed-off-by: Zhipeng Xie <xiezhipeng1@huawei.com>
> 
> If this is correct; this is also missing a Fixes: tag.

Sorry, I don't know when this problem was introduced, so
I have no idea which commit my patch fixes.from the git log,
this problem seems to have existed for a long time, even before
the ebpf feature was introduced.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-08  2:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-07 17:02 [PATCH] Fix perf_mmap fail when CONFIG_PERF_USE_VMALLOC enabled Zhipeng Xie
2022-02-07 14:11 ` Peter Zijlstra
2022-02-08 15:49   ` Zhipeng Xie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox