[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241104135519.354909594@infradead.org>
Date: Mon, 04 Nov 2024 14:39:25 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: mingo@...nel.org,
lucas.demarchi@...el.com
Cc: linux-kernel@...r.kernel.org,
peterz@...radead.org,
willy@...radead.org,
acme@...nel.org,
namhyung@...nel.org,
mark.rutland@....com,
alexander.shishkin@...ux.intel.com,
jolsa@...nel.org,
irogers@...gle.com,
adrian.hunter@...el.com,
kan.liang@...ux.intel.com
Subject: [PATCH 16/19] perf: Further simplify perf_mmap()
Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
---
kernel/events/core.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6644,9 +6644,18 @@ static int perf_mmap(struct file *file,
return ret;
vma_size = vma->vm_end - vma->vm_start;
+ nr_pages = vma_size / PAGE_SIZE;
+
+ if (nr_pages > INT_MAX)
+ return -ENOMEM;
+
+ if (vma_size != PAGE_SIZE * nr_pages)
+ return -EINVAL;
+
+ user_extra = nr_pages;
if (vma->vm_pgoff == 0) {
- nr_pages = (vma_size / PAGE_SIZE) - 1;
+ nr_pages -= 1;
/*
* If we have rb pages ensure they're a power-of-two number, so we
@@ -6655,9 +6664,6 @@ static int perf_mmap(struct file *file,
if (nr_pages != 0 && !is_power_of_2(nr_pages))
return -EINVAL;
- if (vma_size != PAGE_SIZE * (1 + nr_pages))
- return -EINVAL;
-
WARN_ON_ONCE(event->ctx->parent_ctx);
again:
mutex_lock(&event->mmap_mutex);
@@ -6679,8 +6685,6 @@ static int perf_mmap(struct file *file,
goto unlock;
}
-
- user_extra = nr_pages + 1;
} else {
/*
* AUX area mapping: if rb->aux_nr_pages != 0, it's already
@@ -6692,10 +6696,6 @@ static int perf_mmap(struct file *file,
if (!event->rb)
return -EINVAL;
- nr_pages = vma_size / PAGE_SIZE;
- if (nr_pages > INT_MAX)
- return -ENOMEM;
-
mutex_lock(&event->mmap_mutex);
ret = -EINVAL;
@@ -6739,7 +6739,6 @@ static int perf_mmap(struct file *file,
}
atomic_set(&rb->aux_mmap_count, 1);
- user_extra = nr_pages;
}
user_lock_limit = sysctl_perf_event_mlock >> (PAGE_SHIFT - 10);
Powered by blists - more mailing lists