public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Michal Koutný" <mkoutny@suse.com>
To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Cc: "Steven Rostedt" <rostedt@goodmis.org>,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
	"Christian Brauner" <brauner@kernel.org>,
	"Oleg Nesterov" <oleg@redhat.com>,
	"Kent Overstreet" <kent.overstreet@linux.dev>,
	"Kees Cook" <keescook@chromium.org>,
	"Michal Koutný" <mkoutny@suse.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Tycho Andersen" <tandersen@netflix.com>,
	"Jens Axboe" <axboe@kernel.dk>,
	"Aleksa Sarai" <cyphar@cyphar.com>
Subject: [PATCH 3/3] tracing: Compare pid_max against pid_list capacity
Date: Mon,  8 Apr 2024 16:58:19 +0200	[thread overview]
Message-ID: <20240408145819.8787-4-mkoutny@suse.com> (raw)
In-Reply-To: <20240408145819.8787-1-mkoutny@suse.com>

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


      parent reply	other threads:[~2024-04-08 14:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-08 14:58 [PATCH 0/3] kernel/pid: Remove default pid_max value Michal Koutný
2024-04-08 14:58 ` [PATCH 1/3] tracing: Remove dependency of saved_cmdlines_buffer on PID_MAX_DEFAULT Michal Koutný
2024-04-09 15:01   ` Steven Rostedt
2024-05-13 17:30     ` Michal Koutný
2024-04-08 14:58 ` [PATCH 2/3] kernel/pid: Remove default pid_max value Michal Koutný
2024-04-08 20:29   ` Andrew Morton
2024-04-11 15:40     ` Michal Koutný
2024-04-11 22:03       ` Andrew Morton
2024-04-12 14:32         ` Michal Koutný
2024-04-09  0:45   ` kernel test robot
2024-04-09  1:38   ` kernel test robot
2024-05-13 17:26   ` Michal Koutný
2024-04-08 14:58 ` Michal Koutný [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240408145819.8787-4-mkoutny@suse.com \
    --to=mkoutny@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=cyphar@cyphar.com \
    --cc=keescook@chromium.org \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=oleg@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=tandersen@netflix.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox