Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1880305lql; Wed, 13 Mar 2024 10:36:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWfhhVVUkZJMDtTX3qEb/ZkVLoTW2ZoTDRoZts1HTkRHAdgiJ758zKufT2X6hPLYmF15MjOypJKwIsHlRm5NcvfKhma5V4+kELtNQIuVw== X-Google-Smtp-Source: AGHT+IHiuoiSc/pFd07XG/G+Gn+y6AAmnJe4ZxrXKhCHFEdhGoPEAG6IRXdQx02CLnVhv5ArHIXG X-Received: by 2002:a05:6870:8a1e:b0:221:3820:abf5 with SMTP id p30-20020a0568708a1e00b002213820abf5mr4112581oaq.28.1710351418678; Wed, 13 Mar 2024 10:36:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710351418; cv=pass; d=google.com; s=arc-20160816; b=P7dmYfytQN/GxT+CRIWg+XJrKrRlKsUkjUtkT7cDZJN8KbbmPRpK2/EfhfrNbbZe4O yDgE7cOFuumKpk6nK1rtph8pLPQc7afU4YUkjK0s5wgoIHwH5iw83TNZaAobgdI/qIti E9+d8R/9ak5ukWTwmBUjxNcSRscAF9R5unZ+XGju/JTc2BFvQMaQTaNmKlZXf3NkAucr M5k4k3MWflbeA9+1GnzAGpPly4BpGnyR7anE1NwIVBMCmz2GDS3c9TT+jwwXutcGt/hM /clIMuGX4bVS93OAIvWzfpN8Bqz/1r1jTJ7afGBlGF+NWYMar1bP6w2UWnachoFf3U82 HhRg== 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; bh=NC9oHt9bkWn87Rf1lgnf4e3tuvDwiJ+n3ptTDdaN/pQ=; fh=aduvQTcoHj9INBlLqJnkFMv8Aa5JYzE+S1QxkUHZw/8=; b=I1FM3ofskSwnLwH7XQ5Ng3n28EUYzuCSnxEBrYp41we7UWuLJKjOMqfOBNWKQyZqq5 s025MR2ChAj4b/HZ548Syel2tYBzzWlGETzlg1FdwWFPHJ6GNWzavoC3s/dpUdXWrdtd Rh3qzKlKUxfKJi/Y0DGecmhykuCGFsDM8hz4axRo7Mst868UElcVD/ssN8ACLytp4FP3 qN+NK24kuOP73wQj1m6EPqNp+4ebpZb1ll7gxXS7XAK/VFQxELKs2lf0S7rggzm5H9XD 6mfvQ3zxy6ycWXwpcFA7B29qnvahLUSfzZLpksTGDVSFre0URONlEj5OP6wU6kiVrojR ToPg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="bZWMt/64"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-102005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102005-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v5-20020a631505000000b005c66a3f3f5bsi9161752pgl.745.2024.03.13.10.36.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:36:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-102005-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=@kernel.org header.s=k20201202 header.b="bZWMt/64"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-102005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102005-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 37853283425 for ; Wed, 13 Mar 2024 17:36:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7305C14C5AB; Wed, 13 Mar 2024 16:43:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bZWMt/64" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6268E64CDC; Wed, 13 Mar 2024 16:43:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348218; cv=none; b=UGaMzLDm09AH38fo56a9s0VqhSaK14RHGd6fQxWwrCojOGPd653Sio1gOXdp8IdTY2vUHf1eqbY1nTvrbcmnlhMEyO4msHQ1Lo3zcA9yCD54vI8RWeBm/jPB8sRALxw4ccdXi+GozYIbOtdgt/B3OsK1ykUokB85lxS65s0gJTU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348218; c=relaxed/simple; bh=0rNqNmlVXTX/11HQ0XAMJYZPgzeF+GgYg85DZhweKCo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cUGSie4Wy/s7jOObi0pT88uGwNgJD20unuYzemz0Do43bIb0NBHuw174SsJCsveeNfeLnEbpxxSykTy1cUVTLHK+yHJ/o6xeZ4UI3TxxBeo7kaOjeDDLASTKUZJH9+Xz3WjVeHaliQnPF1tdf6EgxD/MqfUI9N+ThQOTp5pAk3k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bZWMt/64; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2138EC43399; Wed, 13 Mar 2024 16:43:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710348217; bh=0rNqNmlVXTX/11HQ0XAMJYZPgzeF+GgYg85DZhweKCo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bZWMt/6437nPh+VHuEI38fkI24S/Fv9GizfeL1EbCRGZGFTihVS4wtdE0Gws1qL5Z 6bpaMgYN9QbbsBMnPstAclVqBqljLR2wdMuXXjHjbTYLKom7i8XB7jUhT5qGUotdsm vGaiNnORwjWsrRbTLUHhLUYeoqpG4I+88zDSSvYDVrpJAD5O7GbDmZo1Or73y9aC42 +kKUkax9Hfsc5N7V5N/oLPwVRynZg4Kwzmg32/gU2hd6fdvtlOyv8nCmx1IsDVh6mr /0oszIjM28bRBwdHqr3lDYALui2TOSwqXSa2SNg1yV4i74IkZXlDYkUM0XA3Auai1/ bAxCOMNweyGDg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kees Cook , Peter Zijlstra , Sasha Levin Subject: [PATCH 5.15 64/76] proc: Use task_is_running() for wchan in /proc/$pid/stat Date: Wed, 13 Mar 2024 12:42:11 -0400 Message-ID: <20240313164223.615640-65-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240313164223.615640-1-sashal@kernel.org> References: <20240313164223.615640-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.15.152-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.15.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.15.152-rc1 X-KernelTest-Deadline: 2024-03-15T16:42+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Kees Cook [ Upstream commit 4e046156792c26bef8a4e30be711777fc8578257 ] The implementations of get_wchan() can be expensive. The only information imparted here is whether or not a process is currently blocked in the scheduler (and even this doesn't need to be exact). Avoid doing the heavy lifting of stack walking and just report that information by using task_is_running(). Signed-off-by: Kees Cook Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20211008111626.211281780@infradead.org Stable-dep-of: 60f92acb60a9 ("fs/proc: do_task_stat: move thread_group_cputime_adjusted() outside of lock_task_sighand()") Signed-off-by: Sasha Levin --- fs/proc/array.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/fs/proc/array.c b/fs/proc/array.c index 49be8c8ef555e..77cf4187adecc 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -541,7 +541,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, } if (permitted && (!whole || num_threads < 2)) - wchan = get_wchan(task); + wchan = !task_is_running(task); if (!whole) { min_flt = task->min_flt; maj_flt = task->maj_flt; @@ -606,10 +606,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, * * This works with older implementations of procps as well. */ - if (wchan) - seq_puts(m, " 1"); - else - seq_puts(m, " 0"); + seq_put_decimal_ull(m, " ", wchan); seq_put_decimal_ull(m, " ", 0); seq_put_decimal_ull(m, " ", 0); -- 2.43.0