Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1422036lqe; Mon, 8 Apr 2024 08:27:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVrD7Av/CE6GKhKPcu7asdLdjeK4ufI9Nesu4ySQ7Kw6t/C0151dLI9NuCsQn2Qkkjlrof9GJOS0N4jsr6Xx263V8/bJxCfHGFdIvyhSg== X-Google-Smtp-Source: AGHT+IHFnGpkqM5yLof+7movKkmaKlPOuPNhseSxmuUiewzwPVG9w+9LTDiujszhQDRGkWbhai5a X-Received: by 2002:a17:90a:ab97:b0:2a5:3637:1968 with SMTP id n23-20020a17090aab9700b002a536371968mr1974486pjq.9.1712590075481; Mon, 08 Apr 2024 08:27:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712590075; cv=pass; d=google.com; s=arc-20160816; b=xirtBS9CG5FT8t/JuM1P2lOo/k4I8X9TaY41fQ4jdRLbvGkXkmjn8flwwMtnTasQkV dO8rA+p1eN3qMebsEPETSr9IeTxK0nK0lREoQkmqhlOZ73lUsU9CE4qgErhvYV/utQNB zcngzXWeiDg7dHABnltNJrIYkop3bJsPy4FpCCrsfqDOEbBbpi+CrQVu8lKUZDzIW2UK HFgIo7NJnMVR6KDLmmVCLPdMJmDZjhqSTwpHt29V08dH5FGqxPfeeHd4qsIJ8TOuDqEb wjv0jBTOMXYWjXdXErzpnJRtnpImBVohXadg/IqtB16jclFB2d13z4VMDQH4gwW+Zq+c 5lnQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature:dkim-signature; bh=1rbXAunVKbUV1XwN367Y+XydNp2/9W1e0lOfKLCJipg=; fh=98ocDBpp+IZAwyfCuREEAbU9bGmLXIFgfCGoR5yoENI=; b=Vmf7qEwNXK8Y/8hNveFykSt3YNymYaghn6ZCcVADxWXqn+ZmLjzIR41LEMXF9Nezl2 Cy/x+xuqDc3vrXdlvzUZ2XTDPoej83mIy3LJMMi8nqHqQaphXldkw/Zva208rBZ0adLQ G1n28xYZokzRZt422wwtC9lQlIt/hGRgTRCOzpronfOo0nyEpplCdLsB7V+LNobu3RZy RPuYSrC7Ot4SbeF7L0/HXyI7c509l1Xc4R6i20HYFXfS1GT/7yVJ6QTXx4i3R2jvZbH6 AGgn8zmY/NlnDx3iZPPWjdARGM2yO65xTgMK/ARNrCXMCQeKD/2EJqXiw3rf3VZxm4CM zfhw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=kyKRGI0F; dkim=pass header.i=@suse.com header.s=susede1 header.b=kyKRGI0F; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-135567-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135567-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y13-20020a17090aa40d00b002a4abf41261si4472038pjp.89.2024.04.08.08.27.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 08:27:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135567-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=kyKRGI0F; dkim=pass header.i=@suse.com header.s=susede1 header.b=kyKRGI0F; arc=pass (i=1 spf=pass spfdomain=suse.com dkim=pass dkdomain=suse.com dkim=pass dkdomain=suse.com dmarc=pass fromdomain=suse.com); spf=pass (google.com: domain of linux-kernel+bounces-135567-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135567-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 0DA1BB2A1FC for ; Mon, 8 Apr 2024 14:58:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B2B5313F447; Mon, 8 Apr 2024 14:58:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="kyKRGI0F"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="kyKRGI0F" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0080013EFE3; Mon, 8 Apr 2024 14:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712588305; cv=none; b=H8SKeGatTZxB7BodTcc7mjp2UXIqtbVifqHK5QfMQn5d7f2xiysXObd/rF54JwkqTygv3wGv+L6jO4qaeQvk6x+67tfKHyycDSuOKZNWDyYNg0b3vxXx+m5Jl9WXaPsxTBEppYBiO8mkkoam7dYiV6IYh3+wRP/OLCNJd2KqeAM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712588305; c=relaxed/simple; bh=LwifpkONrUkWLyBk8gbNdvhiMcqi281CAICCZSh3f7U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=UKgg9fLy1coGSTSogPwbDWJlv8ltrZZrYXaeMLcyOx3XoX9Oec2xc57rPipo0j+/mQuZZMM7dFJCvt3nXL0ENm72v0EJgeykpMYLyDjxPbsXYBngndJ9Nz/gYBGpzJ00DO8AcL6/hmi7qDXga/Le6xsm2CkOSkKI9ZagfM9v/D0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=kyKRGI0F; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=kyKRGI0F; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 1F791229FB; Mon, 8 Apr 2024 14:58:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1712588302; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1rbXAunVKbUV1XwN367Y+XydNp2/9W1e0lOfKLCJipg=; b=kyKRGI0FcxpevV6x3NfZMC5Decj/TV0PerpAe/1hTi6et5v4cQEV4Srt+H9/UQMQ/VhQ5W 7plLn2bhAQzqcS19/Y9PjEtD+VYz7dgpn8DslW/vKsSwast3bQd3+qAo6oVkaSs0C6b96R iXytpSk2/gXNIRvfUTEbsVkZ7oNDNLw= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1712588302; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1rbXAunVKbUV1XwN367Y+XydNp2/9W1e0lOfKLCJipg=; b=kyKRGI0FcxpevV6x3NfZMC5Decj/TV0PerpAe/1hTi6et5v4cQEV4Srt+H9/UQMQ/VhQ5W 7plLn2bhAQzqcS19/Y9PjEtD+VYz7dgpn8DslW/vKsSwast3bQd3+qAo6oVkaSs0C6b96R iXytpSk2/gXNIRvfUTEbsVkZ7oNDNLw= Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 04B1F13AB3; Mon, 8 Apr 2024 14:58:22 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id 8Df/AA4GFGa8dgAAn2gu4w (envelope-from ); Mon, 08 Apr 2024 14:58:22 +0000 From: =?UTF-8?q?Michal=20Koutn=C3=BD?= To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Christian Brauner , Oleg Nesterov , Kent Overstreet , Kees Cook , =?UTF-8?q?Michal=20Koutn=C3=BD?= , Andrew Morton , Tycho Andersen , Jens Axboe , Aleksa Sarai Subject: [PATCH 3/3] tracing: Compare pid_max against pid_list capacity Date: Mon, 8 Apr 2024 16:58:19 +0200 Message-ID: <20240408145819.8787-4-mkoutny@suse.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240408145819.8787-1-mkoutny@suse.com> References: <20240408145819.8787-1-mkoutny@suse.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Flag: NO X-Spam-Score: -0.30 X-Spam-Level: X-Spamd-Result: default: False [-0.30 / 50.00]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; BAYES_HAM(-0.00)[43.99%]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_TWELVE(0.00)[14]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap2.dmz-prg2.suse.org:helo,imap2.dmz-prg2.suse.org:rdns,suse.com:email] 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ý --- 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