Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1401567lqe; Mon, 8 Apr 2024 07:58:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWkWY+Bm9mAIA9oNL2bj1Cze7y+tfVAOR/B+a7b0CMpf6my2soY1KOVaGyD6lbRi8MSVvhGeVjqLAGH8Dw9rDwmzHWq4E9DzliqyEX3cA== X-Google-Smtp-Source: AGHT+IGUBayf4/WVGdolrXRPf2nJDaThPVer2gZc2Zrcac4RByfunm+8OFmkdz9F93IEvmA5C0He X-Received: by 2002:a05:6a20:d490:b0:1a7:51f6:87e6 with SMTP id im16-20020a056a20d49000b001a751f687e6mr6155841pzb.54.1712588320465; Mon, 08 Apr 2024 07:58:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712588320; cv=pass; d=google.com; s=arc-20160816; b=JenE0m6KkDqCA6LdC5aO+8XEaiQZlvB/5p0etxwTa1DRRkcLpxiajIhBkKpJhuk3LV EpyjbsOkEr9WTS4b9102lpu5K5d2u6mI0YeRng5rDQD7bi+3ohj15K4atsWdpFrx9DiM dimkKAEfSYpdiACjvDHyOUEe46PObduIuPHAjeeDcTEaMVqV+nk23rMgNhVq5PpvHtdJ v/mrE5Dg5OGdW4TrpeY/hIBfGBJqejYzBC5e6VDQmXzCWSLwVWr/911mhpw0je9shhJU qxjvfKNewQBM1pzb++GHg177XbgxPAcfKCplscrWyTmYrBTo7LkpI3aCof4st0t0qjbB T8VA== 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=QJrVwWdxkkiTZc1yahR+7aeNYeIbFQr7fotMaQYTpR0=; fh=98ocDBpp+IZAwyfCuREEAbU9bGmLXIFgfCGoR5yoENI=; b=EkOwR/OqPkjDSajsnWsWefXMg9modnF63P1raaI+Off7lE+yChE2A12BP2XEfKBP9d CCIpdQxXEnsHh2bTOizr8bsij72C6w+eIkZrg+4gsOCSopmlYVvyF2a8fRdkPNUyp0rO xtB2DVaIWyrTAcpXzzxMl15ix86EVVuKpP4kWRyyZk52kRGUOWzKqF/bQHw/WK3/YKzQ kPyR3u/lmpFMbEkSl2vf/2/+onBMDAHP47wQ2lJBh7DEDjwRONSVtW0BThP3wzbfa8vY 1AdgOvFBQzKl5xP2d6Bhe+9MQyCmHuciBsRs7aitzT1+Mf6Bp6Tr4CBwmJjP1qGq8ICS 0tyA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=Owog8HkE; dkim=pass header.i=@suse.com header.s=susede1 header.b=eJiJB7Pp; 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-135568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135568-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id co10-20020a17090afe8a00b002a1fd0acce1si6522733pjb.163.2024.04.08.07.58.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 07:58:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=Owog8HkE; dkim=pass header.i=@suse.com header.s=susede1 header.b=eJiJB7Pp; 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-135568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135568-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id F419C284783 for ; Mon, 8 Apr 2024 14:58:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D22C613F44A; 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="Owog8HkE"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="eJiJB7Pp" 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 C65A7127B54; 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=bO7iZ5juU1J7BfUTDI6RXfALU2EveDNwyiqpnbjPC3gUCbMKoseWrdlXF5gWS9H/8OBUZ4UmP+zIusC9M8re7XH0f7HSV13L4blI4TfiZTNlN6xg3S66B6Fui+dvmpDvmfzgL4gECnayOuyxi4+c1jFvRxcZ8jTaGqr/6PmzarE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712588305; c=relaxed/simple; bh=Vq9UE4oFVEBC3u6xpAf7VoHaSvXGu0QbBtJsYwS5Rb8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MHD8J/ZzyAokqrp6fHuwKpZrwJnV+Zq/4TYfWDuIoRGO8KP5TWRWlD/zPtyRZsln0UHEUt90TsZkWzfsaashOgFbxNqTZTHHZDtY/HnqYd0Lni6TPTQ0PNnFY1buvaFFwMoNwTavJclCNp0/6cgfippryVr74EASxCcapgJhiLs= 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=Owog8HkE; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=eJiJB7Pp; 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 [IPv6:2a07:de40:b281:104: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 DF5B0229F9; Mon, 8 Apr 2024 14:58:21 +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=QJrVwWdxkkiTZc1yahR+7aeNYeIbFQr7fotMaQYTpR0=; b=Owog8HkEfsuIxJ8C0wwnkm7E5aijikkK4WV0OVwnHYZ5rlKf11wfho1iqM0D/eFVu/VNKk TFG2HboKjiaqBHuQ0BZXfrC7iiYTE4keFXFM5LaRG+HOwyNqTyGmkAbijZLy5mUUqB8Bui yf0Jh/eRF6uCdLdsmeWq0emWnZm4cis= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=eJiJB7Pp DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1712588301; 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=QJrVwWdxkkiTZc1yahR+7aeNYeIbFQr7fotMaQYTpR0=; b=eJiJB7Pp+/l2J66TVKbOj4zRj7KvHYLXEAF8LVydYpwEEMGmpamUQTbtX3BtpjRCykw54n gNwML15JTtIDd0HaT1WfnjP9XB/k50JwN99n9WyM9LzlXOnztaxyR88SZd+AGnNfwJI6AQ QMSVIuch1l2tXzgBEGSl/5FEs9WrsO8= 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 BE57D13AA2; Mon, 8 Apr 2024 14:58:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id YAlKLg0GFGa8dgAAn2gu4w (envelope-from ); Mon, 08 Apr 2024 14:58:21 +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 1/3] tracing: Remove dependency of saved_cmdlines_buffer on PID_MAX_DEFAULT Date: Mon, 8 Apr 2024 16:58:17 +0200 Message-ID: <20240408145819.8787-2-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-Level: X-Spamd-Result: default: False [-0.52 / 50.00]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; BAYES_HAM(-0.01)[50.28%]; MX_GOOD(-0.01)[]; RCPT_COUNT_TWELVE(0.00)[14]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; FUZZY_BLOCKED(0.00)[rspamd.com]; MIME_TRACE(0.00)[0:+]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:98:from]; FROM_HAS_DN(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:98:from]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_SOME(0.00)[]; DWL_DNSWL_BLOCKED(0.00)[suse.com:dkim]; R_RATELIMIT(0.00)[to_ip_from(RLbzsy9nfkyasyfk9a5p8bmpf9)]; RCVD_VIA_SMTP_AUTH(0.00)[]; DKIM_TRACE(0.00)[suse.com:+]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap2.dmz-prg2.suse.org:helo,imap2.dmz-prg2.suse.org:rdns,suse.com:dkim,suse.com:email] X-Spam-Flag: NO X-Spam-Score: -0.52 X-Spamd-Bar: / X-Rspamd-Queue-Id: DF5B0229F9 X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action Calculations into map_pid_to_cmdline use PID_MAX_DEFAULT but they actually depend on the size of map_pid_to_cmdline. The size of the map may be arbitrary. First, refer to the map size where necessary, second, pick a good value for the size of the map. Since the buffer is allocated at boot (i.e. user cannot affect its size later), accounting for full PID_MAX_LIMIT would inflate map's size unnecessarily (4*4M) for all users. Stick to the original value of 4*32k, the commit 785e3c0a3a87 ("tracing: Map all PIDs to command lines") explains why it still works for higher pids. The point of this exercise is to remove dependency on PID_MAX_DEFAULT. Signed-off-by: Michal Koutný --- kernel/trace/trace_sched_switch.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/kernel/trace/trace_sched_switch.c b/kernel/trace/trace_sched_switch.c index 8a407adb0e1c..aca2dafdd97a 100644 --- a/kernel/trace/trace_sched_switch.c +++ b/kernel/trace/trace_sched_switch.c @@ -161,6 +161,7 @@ static size_t tgid_map_max; #define SAVED_CMDLINES_DEFAULT 128 #define NO_CMDLINE_MAP UINT_MAX +#define PID_MAP_SIZE (CONFIG_BASE_SMALL ? 0x1000 : 0x8000) /* * Preemption must be disabled before acquiring trace_cmdline_lock. * The various trace_arrays' max_lock must be acquired in a context @@ -168,7 +169,7 @@ static size_t tgid_map_max; */ static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED; struct saved_cmdlines_buffer { - unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1]; + unsigned map_pid_to_cmdline[PID_MAP_SIZE]; unsigned *map_cmdline_to_pid; unsigned cmdline_num; int cmdline_idx; @@ -248,7 +249,7 @@ int trace_save_cmdline(struct task_struct *tsk) if (!tsk->pid) return 1; - tpid = tsk->pid & (PID_MAX_DEFAULT - 1); + tpid = tsk->pid % PID_MAP_SIZE; /* * It's not the end of the world if we don't get @@ -294,7 +295,7 @@ static void __trace_find_cmdline(int pid, char comm[]) return; } - tpid = pid & (PID_MAX_DEFAULT - 1); + tpid = pid % PID_MAP_SIZE; map = savedcmd->map_pid_to_cmdline[tpid]; if (map != NO_CMDLINE_MAP) { tpid = savedcmd->map_cmdline_to_pid[map]; @@ -645,8 +646,8 @@ tracing_saved_cmdlines_size_write(struct file *filp, const char __user *ubuf, if (ret) return ret; - /* must have at least 1 entry or less than PID_MAX_DEFAULT */ - if (!val || val > PID_MAX_DEFAULT) + /* must have at least 1 entry or fit into map_pid_to_cmdline */ + if (!val || val >= PID_MAP_SIZE) return -EINVAL; ret = tracing_resize_saved_cmdlines((unsigned int)val); -- 2.44.0