[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240408145819.8787-4-mkoutny@suse.com>
Date: Mon, 8 Apr 2024 16:58:19 +0200
From: Michal Koutný <mkoutny@...e.com>
To: linux-kernel@...r.kernel.org,
linux-trace-kernel@...r.kernel.org
Cc: Steven Rostedt <rostedt@...dmis.org>,
Masami Hiramatsu <mhiramat@...nel.org>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
Christian Brauner <brauner@...nel.org>,
Oleg Nesterov <oleg@...hat.com>,
Kent Overstreet <kent.overstreet@...ux.dev>,
Kees Cook <keescook@...omium.org>,
Michal Koutný <mkoutny@...e.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Tycho Andersen <tandersen@...flix.com>,
Jens Axboe <axboe@...nel.dk>,
Aleksa Sarai <cyphar@...har.com>
Subject: [PATCH 3/3] tracing: Compare pid_max against pid_list capacity
trace_pid_list_alloc() checks pid_max against a magic number referencing
an (obsolete) source file when it actually should check against the
capacity of pid_list tree. Turn definition of MAX_PID around -- derive
it from tree parameters and replace references to magic value and
header files with so defined MAX_PID.
Should PID_MAX_LIMIT change in future or pid_max escapes PID_MAX_LIMIT,
appropriate checks remain in place. No functional change intended.
Signed-off-by: Michal Koutný <mkoutny@...e.com>
---
kernel/trace/pid_list.c | 6 +++---
kernel/trace/pid_list.h | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/kernel/trace/pid_list.c b/kernel/trace/pid_list.c
index 95106d02b32d..b968f0b65dc1 100644
--- a/kernel/trace/pid_list.c
+++ b/kernel/trace/pid_list.c
@@ -93,7 +93,7 @@ static inline bool upper_empty(union upper_chunk *chunk)
static inline int pid_split(unsigned int pid, unsigned int *upper1,
unsigned int *upper2, unsigned int *lower)
{
- /* MAX_PID should cover all pids */
+ /* MAX_PID must cover all possible pids */
BUILD_BUG_ON(MAX_PID < PID_MAX_LIMIT);
/* In case a bad pid is passed in, then fail */
@@ -413,8 +413,8 @@ struct trace_pid_list *trace_pid_list_alloc(void)
struct trace_pid_list *pid_list;
int i;
- /* According to linux/thread.h, pids can be no bigger that 30 bits */
- WARN_ON_ONCE(pid_max > (1 << 30));
+ /* See pid_split(), equal to pid_max > PID_MAX_LIMIT */
+ WARN_ON_ONCE(pid_max > MAX_PID);
pid_list = kzalloc(sizeof(*pid_list), GFP_KERNEL);
if (!pid_list)
diff --git a/kernel/trace/pid_list.h b/kernel/trace/pid_list.h
index 62e73f1ac85f..28562a9a3d01 100644
--- a/kernel/trace/pid_list.h
+++ b/kernel/trace/pid_list.h
@@ -56,8 +56,8 @@
#define UPPER_MASK (UPPER_MAX - 1)
-/* According to linux/thread.h pids can not be bigger than or equal to 1 << 30 */
-#define MAX_PID (1 << 30)
+/* Structure can hold only pids strictly below this limit */
+#define MAX_PID (1 << (UPPER_BITS + UPPER_BITS + LOWER_BITS))
/* Just keep 6 chunks of both upper and lower in the cache on alloc */
#define CHUNK_ALLOC 6
--
2.44.0
Powered by blists - more mailing lists