Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 B163F3750DC; Thu, 20 Aug 2026 17:49:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787248153; cv=none; b=NdTOWrIyFyWYf8SkiLs7eOCxqwJMHxlpr5+m9FYGT3b2IvTAYqCjyC23Sc5COJhKUkyWc2b0IA0dYRWA4g+gi4A48wD5b2yzy7t8htVnX/Kfxy8IyqAWIWC5OiAhwWNSpqRRdR168GO79AIn2hkDvH+4a4gfyqf5wKKd6Fc41+8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787248153; c=relaxed/simple; bh=MyiCCNXukE3TK60NnANoWAMA1bpmYe4Tohe1NKZp184=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kGs3CzJOxRqBe9/GIfvMEmklBav6AckbOVPazbhUCmPffnjxCVW98tND+SwRJdL97HONSZ9JpDC5UT8TlKnjwO/wI86GJeC8wvkcQTxZiZrg46s9UZPMD/VF9IJi9pM2/4isK+nAi5XpGaEpC1h9gTUqLmLmsZf2MHMyNR9EjHc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=kEX76Krs; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="kEX76Krs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB1C61F000E9; Thu, 20 Aug 2026 17:49:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1787248152; bh=WiYjratxdYlj/eWyBfpue8pRIF+vpnvSUsToDxJpb2g=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kEX76KrsArnXZvFxA4VBENV6qNpqwAWlLA/VviluxeWe8DYpi3V6Pjc0XZOOzFLGV Wd1SmoX7BSn+dLWvjKFLunuECtaY9/a2jlxuW+q78oRjMm3RVGVifbN31Vga3rPhnT /HeTFgfeFXZ19VfbM5U8S0H/Bs1WR0msifZlIceQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Oleg Nesterov , "Eric W. Biederman" , Andrew Morton , Sasha Levin Subject: [PATCH 6.1 128/303] taskstats: fill_stats_for_tgid: use for_each_thread() Date: Thu, 20 Aug 2026 16:54:24 +0200 Message-ID: <20260820145257.121447423@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260820145253.200766705@linuxfoundation.org> References: <20260820145253.200766705@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Oleg Nesterov [ Upstream commit ed5378a387fd7c382497f2abcf4605e030b64044 ] do/while_each_thread should be avoided when possible. Plus I _think_ this change allows to avoid lock_task_sighand() but I am not sure, I forgot everything about taskstats. In any case, this code does not look right in that the same thread can be accounted twice: taskstats_exit() can account the exiting thread in signal->stats and drop ->siglock but this thread is still on the thread-group list, so lock_task_sighand() can't help. Link: https://lkml.kernel.org/r/20230909214951.GA24274@redhat.com Signed-off-by: Oleg Nesterov Cc: Eric W. Biederman Signed-off-by: Andrew Morton Stable-dep-of: b3e4fbb04220 ("taskstats: retain dead thread stats in TGID queries") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/taskstats.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) --- a/kernel/taskstats.c +++ b/kernel/taskstats.c @@ -233,9 +233,8 @@ static int fill_stats_for_tgid(pid_t tgi else memset(stats, 0, sizeof(*stats)); - tsk = first; start_time = ktime_get_ns(); - do { + for_each_thread(first, tsk) { if (tsk->exit_state) continue; /* @@ -258,7 +257,7 @@ static int fill_stats_for_tgid(pid_t tgi stats->nvcsw += tsk->nvcsw; stats->nivcsw += tsk->nivcsw; - } while_each_thread(first, tsk); + } unlock_task_sighand(first, &flags); rc = 0;