Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp1880363lql; Wed, 13 Mar 2024 10:37:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVbDwPmxK7Ln2KbtX/4uHUbx7x0TLDgg7Pra89OYBJW3uBhajcyvGJJ2zDslZjRWYKK1vjlunkwws3jBFwCr0+T0yfuP0pu6laklO5LSA== X-Google-Smtp-Source: AGHT+IFM3N7Gk6mwYXFGk1MFsYmLDmbcbAfCYq4iPW9ewdVYlU0rZHXO49yJrsB3/cdsjEFkRP03 X-Received: by 2002:a17:902:e98a:b0:1dc:b531:833 with SMTP id f10-20020a170902e98a00b001dcb5310833mr11481040plb.63.1710351426063; Wed, 13 Mar 2024 10:37:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710351426; cv=pass; d=google.com; s=arc-20160816; b=Y3gdfLyHEK+UB5rQXu9DWhQ+yJSzcYw0lXE4ffX719hfNJ6kUGIN6iwF1lyYmhW4UF HjsleQ5MPqzvQFcvdvMZcusnHVxnowLGKAft3ZxZ9u7vg0/P++FwkCQxY6vL1FX15zEp FuzCB7eYPnxm0v11hJ8A70MjfzN3U0Jx/P91q4yEEJtqhJrWYy3PhhX9uaPi/qIx+0AP wMTt52dMLykVKJYRmqAPqllgGOfIMdpUPFkYdhbJjQaRQXQIVlhGDjl8W2E7evLSsE6t cc/3ClXa/vvpT8ww32LNqQo08AYorC44zNInDHeHzYMMDKefRRTS2GsaQIt2LO1l22A1 9G6Q== 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=wDxLy4jUcFscd+7M2T3l+ydPVBR7Lnjr5yr94LFRRTY=; fh=QHYoePTVyKNoydmDXmfPR/lPlJYVhXqsBmqXV4JCFVY=; b=sgyL/oaEf2kmKTiEDzY7IGyPBuq9F+ySeXuBeNFPELCmckXWrbl2AqTeQ+LBzbn7UV 3L86sv1BOL0rrxFp0hk7zGJWYSltVQ2fWET30itSSjIn6Jw+GGuc5ewmyNKNu3Ox+kLN hcJP5ad9rRl9d85n7tSpbW/R/jz94UY49Z7N4Ugcun4rTEJfjVEZgR80u4RX82Gr1xMC RcDz0MnzhCJUFh4IYvig6pJ3uL+sL4nz+ItiTqJ6BpGYfhu6AUgbl8gQcb3CFNTQuGKr e14xvqSHTT3xl6Rb9lmO//5/Pmspw1SsNFJnsXWb2SfgbxL+CTN4insyh5So4Z68gn2p BkWA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=B+dH4tin; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-102006-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102006-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 e13-20020a170903240d00b001dd97ce4a74si7129369plo.114.2024.03.13.10.37.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Mar 2024 10:37:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-102006-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=B+dH4tin; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-102006-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102006-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 B71DE282F70 for ; Wed, 13 Mar 2024 17:37:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 341F414CAA0; Wed, 13 Mar 2024 16:43:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="B+dH4tin" 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 3692414C5A2; Wed, 13 Mar 2024 16:43:39 +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=1710348219; cv=none; b=YBlNJfdsSRwG9hv8onLbivk3t6y+CrtzM0MhUs4RrKDYSWdcLwf7zWilWCXSN0NG76oI6+d6K8EvK9Neq8mxDCyIfgLUkGvyTdPHMxxbgzz2j6LtyO4e7MCFREvucpf5ZthJbKLv9aS0y4Wq7/kDIqSBM1stz5RnfcvHzTUPWEg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710348219; c=relaxed/simple; bh=PgNbsfSnge8biy8YM3pVL9sIVanFruRxDzQvse34EW0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UAiItjvibRo78oVSXQ9XYsw615j2on+4I3poMC0zPSQBMeuiDRWsa3BDQh/be6FzTTj1cxEJHYUHV3lR9nM8cbyoyKUWHizjmaU9H8ZiXH3y409xZLruEwzGd5mBJxdwqMaHBWT+b8H5Qt+s5/uWz2Ytzn9sh3iI1WmXBlSSqNY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B+dH4tin; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27F99C433F1; Wed, 13 Mar 2024 16:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710348219; bh=PgNbsfSnge8biy8YM3pVL9sIVanFruRxDzQvse34EW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B+dH4tin/pdpzY+vUX2/goLoeKAoqY/vRLrW00xkwTLpGg+QSd1yt7QPbLbU41m28 rycGsxtwfhLt2VJVp27ytE6KBulMR/eKzktJkVuYJSq3XAEgfi7WfMP8I/L6/j0T3c ghPA1ctDRLQQPUrX2YHjMlMmH2gncyzQWMS3cayBh78J6ukXNZ58UV0GH0tFTe5kul wEolxGGvg/qjWZEZQV9HKkvm4HbdFkb71yBkO+sOgiIkeAEFHyST3HH20ZQEhIyEzm L88WO0ykAuoDmekXGEfvMK5iO90F41efku7UAbPADYLhHdqFa7ZT5BmTllt/p/YMe5 CSAo+/V0ikxFg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Oleg Nesterov , Dylan Hatch , "Eric W . Biederman" , Andrew Morton , Sasha Levin Subject: [PATCH 5.15 65/76] fs/proc: do_task_stat: move thread_group_cputime_adjusted() outside of lock_task_sighand() Date: Wed, 13 Mar 2024 12:42:12 -0400 Message-ID: <20240313164223.615640-66-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: Oleg Nesterov [ Upstream commit 60f92acb60a989b14e4b744501a0df0f82ef30a3 ] Patch series "fs/proc: do_task_stat: use sig->stats_". do_task_stat() has the same problem as getrusage() had before "getrusage: use sig->stats_lock rather than lock_task_sighand()": a hard lockup. If NR_CPUS threads call lock_task_sighand() at the same time and the process has NR_THREADS, spin_lock_irq will spin with irqs disabled O(NR_CPUS * NR_THREADS) time. This patch (of 3): thread_group_cputime() does its own locking, we can safely shift thread_group_cputime_adjusted() which does another for_each_thread loop outside of ->siglock protected section. Not only this removes for_each_thread() from the critical section with irqs disabled, this removes another case when stats_lock is taken with siglock held. We want to remove this dependency, then we can change the users of stats_lock to not disable irqs. Link: https://lkml.kernel.org/r/20240123153313.GA21832@redhat.com Link: https://lkml.kernel.org/r/20240123153355.GA21854@redhat.com Signed-off-by: Oleg Nesterov Signed-off-by: Dylan Hatch Cc: Eric W. Biederman Cc: Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- fs/proc/array.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/proc/array.c b/fs/proc/array.c index 77cf4187adecc..c925287a4dc4b 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -495,7 +495,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, sigemptyset(&sigign); sigemptyset(&sigcatch); - cutime = cstime = utime = stime = 0; + cutime = cstime = 0; cgtime = gtime = 0; if (lock_task_sighand(task, &flags)) { @@ -529,7 +529,6 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, min_flt += sig->min_flt; maj_flt += sig->maj_flt; - thread_group_cputime_adjusted(task, &utime, &stime); gtime += sig->gtime; } @@ -542,10 +541,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, if (permitted && (!whole || num_threads < 2)) wchan = !task_is_running(task); - if (!whole) { + + if (whole) { + thread_group_cputime_adjusted(task, &utime, &stime); + } else { + task_cputime_adjusted(task, &utime, &stime); min_flt = task->min_flt; maj_flt = task->maj_flt; - task_cputime_adjusted(task, &utime, &stime); gtime = task_gtime(task); } -- 2.43.0