From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACF20606A31F for ; Sat, 5 Dec 2026 19:16:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Z6JNOxei Received: by kanga.kvack.org (Postfix) id CAE9D6B00EF; Sat, 5 Dec 2026 14:16:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C86706B05B1; Sat, 5 Dec 2026 14:16:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC2A36B05B2; Sat, 5 Dec 2026 14:16:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 96DB86B00EF for ; Sat, 5 Dec 2026 14:16:15 -0500 (EST) Received: from smtpin28.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3FE28C0615 for ; Sat, 5 Dec 2026 19:16:14 +0000 (UTC) X-FDA: 85510885068.28.F1A5DF9 Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by imf01.hostedemail.com (Postfix) with ESMTP id 26EE740007 for ; Sat, 5 Dec 2026 19:16:10 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=Z6JNOxei; spf=pass (imf01.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796498171; b=pjBuNJcqRQgFhPvpPGybtOCzBvMADrfTlJs1Z/C/ds0VlEE+m+NlFv/3smxUoSTOrLepMV htozY2WyamSkS2dfF4xie1sKEmcobkCjopks8Oy8lTfS8Q80QS6o8T47LLSHM3jEPGoqPF rjeJUfUiKb16NIAUi9JWzM79j0WTK48= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796498171; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9/FuTRduaOYI3uqvwq0OqWqrHQES7ltWfGjNV3/YTvA=; b=WhPno2HJp4end7bEbYb8RJKjmeeatjaVHurdtQKBMI5rmqMLlFA5v7sffmOg2uORKsli2E XKLnxeuRsoCoV+JOVN3QpbfQ2dEDB7f0P0g+Sqlr2ShISDhqIY+9X/ZMCkB2BmNuu4HkQX vuMfg7vVGC2HPilfF0PqBGjhlXgqTFs= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=Z6JNOxei; spf=pass (imf01.hostedemail.com: domain of sashiko-bot@kernel.org designates 172.105.4.254 as permitted sender) smtp.mailfrom=sashiko-bot@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id B16F5600B9; Sat, 5 Dec 2026 19:16:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 087211F0092B; Sat, 5 Dec 2026 19:16:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796498169; bh=9/FuTRduaOYI3uqvwq0OqWqrHQES7ltWfGjNV3/YTvA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Z6JNOxeibiJEvWORbNa57ZzR7IKo2tLVgJNSgSeJvzDGumCMlhPmZ7vQkgNPrhs1u 2nsrmV5m1IXF7J+AeHj5AeOtMaVrCIL7gdrKL5LRaSI5HMeqJn4ZH9rGJkfYbCIqiM YlalO4m+MsO+WKpu51Q48wQhtKV/jAxjRhImt9fSH6JcIp3vYIIKFJgJeTZ+c90uvh UtiorztGRRaFjzVIBzNIq/E5pB7GS+0rKJ1iXt2Fq6pQsSMyccYli+oDyiLChrIB0J jE+ixG/SottrQXyw5Ppo34zXrjyMTkT/CEg0YhXYAaWkptU+Y6GJeUfB4xT3WIcGfL 2dqHyUd7PFBpA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 4/4] NOT_FOR_INCLUSION: selftests/resctrl: Tasks keep using removed RMID after fork() reproducer Reply-To: sashiko-reviews@lists.linux.dev To: "Reinette Chatre" , kees@kernel.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, kprateek.nayak@amd.com, david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, tony.luck@intel.com, ben.horgan@arm.com, bp@alien8.de, tglx@linutronix.de, dave.hansen@linux.intel.com, Dave.Martin@arm.com, james.morse@arm.com, babu.moger@amd.com, fustini@kernel.org, jedrzej.wasiukiewicz@intel.com Cc: fenghuay@nvidia.com, peternewman@google.com, yu.c.chen@intel.com, x86@kernel.org, linux-mm@kvack.org In-Reply-To: <78cea45bb6a09a092bf1ca48b582843fdac627e7.1796411500.git.reinette.chatre@intel.com> References: <78cea45bb6a09a092bf1ca48b582843fdac627e7.1796411500.git.reinette.chatre@intel.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 19:16:07 +0000 X-Rspam-User: X-Rspamd-Queue-Id: 26EE740007 X-Rspamd-Server: rspam03 X-Stat-Signature: dihb3zn6oh5hhjhh38fqjcf4z75um7dc X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796498170-78877 X-HE-Meta: U2FsdGVkX19q84rBwvvhZ7pYnmv+oojWYiL6dMaWgBZ71QOBG1HxGqGfmzxC1hrMiq1NQXaVzSKkq5/Q7c2Ysvmy/MizajBYuo6yrWYvtwdFz3e++moa4DRwXGezPSW2uV26gDagG1/vO18tPOJyz5m62OJ1BAO+IH0E1LxLSPUa6X8txDehw+bf0KM0wqu+cSnieW87ziWDYd3Gne6BXhsZARk8w0xCRrrbFbdGfh9YrLE19H/1QEpkhHpCU5DDAakvxdXD0/j1xiV3A4odho/5bvZEsJUWE/mfhjCV7q+DQjfqdkWHMAIcDZVjXOSOr/uGRiwfayCJsJaJWCgJdPEYVM8A9MyBA5G5ZtvQBMbsRwYAbz4YTSQg+W8CuuglkaeKBRzlricVzJDvGEEdj4N6LAeH7Gpwm3q54679waD29/nT2mByMuvZpLAp96Wnx4x2XMLnfvbue6JK6pKG08YPRvyY6xMtaPrBzN6DoPvIirrbNSAjObVeSCjUt/lfPCq3d7iMTZZqAtLAj5A7NwuYhzO/T7StMLCTmfzxiY7g9g21E9o44MxjDCvLcj5agYBBNDkARkFo/9dgJeV5C7z41r++JGBttf51O+dBIg7hNb4jIGqcmvv4nbM6hQqfu4owCr7z2Jodxi4nz5U0a/fhIaSSjRv4nb+30w65urOZyGzigGjLBCY01C4HNDkVGeqVrFohLEPqe+gGAMD0CTq8bQDV22QITu3t4K+OUFeINsv4V1pUpP7xyw/GANs73x8EzjNuQaTHqHVIdqta8IaW8XfMp2Vlgu16Dos6Nae2Jj1tC/p1cTsK17Oajtwqy65C3VVeklDlrJM7fHu5OoxEcNimRXGlUT9Q9PfCH6eZTyxLgR1BwEMHiEnX0QoExWvNQbsuThlQ/18Utz5+3er0AscY/kY8VY6MbefrT/Nrnc3WFTsu1RcjmGLH5L+S9ovGzY7fWq6ch/R/XJ+ CAk4E0uH DMsDEq3EBfFlRWi3RXLwmIkmOGjtWjleAuMT0edguJoq4WUOZ8+Vcr9wR7D6R2xWorpd0YVuDfuPj6eYjxGoJVdmBVNihkmn8ccqzl++p4OohjC/OW7s52bqY0S5nI0/JJ2aDAinDF3ZmWthB0BJi8Po1Z5Jv7fSDfmcyIFiA/No1Y8bWtCC9+IduSAo1FVb7SNZ5UqLlX2+3xwKobAoVi1N0OQH1pdQ0/VmRf1v60nogc0W1GDTJlQXJdllHfqlV7/aWEx948lBQiATOOAQtfyVT4o1t7QKnY38BD6h1K9dOc8GkDBbw0PXnQP8HLHieVkXWydOmnrkd4s4FJU/V3L4nbbVzl7fBM7ZVGOCfN/e6KFmJ7KH2G8zzqXOtZ7e63YzhBfRvD5ez0sP0LAWTSjBsonrIJ9s6eNQEYryTLCYv/QBAD9fbO5xb2rjp+ozjkicxUGlTZwyXL/z6jhaEMjsPqUfxLmIP904RiryV/f4Fosnbo3SDfgoVoU5MdbKBH6wm/E9rEAjHin7lZG72U0kip9pCHRgW4a6eatM9Pgi0nhdLW3aHOJ1QxZcsP0uR+Z84qMTrjzqNa2A3IxHdDdz9IA/Y9ArddH2/UEiiw6G3HR10XU1vhc2sO6+gijAl5WbaEsTd3DE0nrez0DpQjWWhs1bbJQr/M3/O3nuTGsiyr+H9zQ7mhpO17hoiieyySznhRvFErUAB6uVbAPe17cmsvPs1ARGcefCvxQLclICe3PghZdj056YaoNRvS57/WwuA7jc4brYa8r+CcdspC12EySz9vo8NkkFh0NViHA2guo0NmdvOfwHZAoC2fDdcqdZMEcxSXenUw8ZjBfkjJ4zsrrxwyUeqiNHkfiOYT5T3+/o= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Low] selftests/resctrl: cleanup() signals stale reaped PIDs as root - [Low] selftests/resctrl: cleanup() resets INT and TERM traps to default - [Low] selftests/resctrl: signal race leaks untracked forker before FORKERS append - [Low] selftests/resctrl: arming cleanup() before mkdir causes TOCTOU rmdir -- commit 2ab03f3eb3449ef47dd2b5c82faf9532afafebbe Author: Jedrzej Wasiukiewicz NOT_FOR_INCLUSION: selftests/resctrl: Tasks keep using removed RMID after f= ork() reproducer This commit adds a standalone reproducer script under tools/testing/selftests/resctrl/ that races removing a resctrl monitor group against concurrent forks and checks whether any task retains the removed RMID when new monitor groups exhaust the RMID pool. > diff --git a/tools/testing/selftests/resctrl/stray_tasks_repro.sh b/tools= /testing/selftests/resctrl/stray_tasks_repro.sh > new file mode 100755 > index 0000000000000..42f65d7d7bb4d > --- /dev/null > +++ b/tools/testing/selftests/resctrl/stray_tasks_repro.sh > @@ -0,0 +1,122 @@ [ ... ] > +[ ! -e $C ] || { echo "$C already exists, remove it first"; exit 1; } > + > +FORKERS=3D() # PIDs of the forker processes > +KIDS=3D"" # PIDs of their children > + > +# Runs on every exit, including Ctrl-C: stop all test processes and remo= ve the > +# test groups. > +cleanup() { > + trap - EXIT INT TERM > + [ -n "$KIDS" ] || [ ${#FORKERS[@]} -eq 0 ] || > + KIDS=3D$(pgrep -P "$(IFS=3D,; echo "${FORKERS[*]}")") > + [ ${#FORKERS[@]} -eq 0 ] || kill "${FORKERS[@]}" 2>/dev/null > + [ -z "$KIDS" ] || kill $KIDS 2>/dev/null > + sleep 1 > + rmdir $C/mon_groups/* 2>/dev/null > + rmdir $C 2>/dev/null > +} [Severity: Low] Should cleanup() clear EXIT and ignore INT and TERM (trap - EXIT; trap '' I= NT TERM) instead of resetting them to default with trap - EXIT INT TERM? A second Ctrl-C or SIGTERM arriving during the 1-second sleep aborts cleanu= p() before rmdir removes $C and its monitor groups, leaving the RMID pool exhausted until manually cleaned up. If interrupted before killing FORKERS, the 8 background fork loops also stay running. > +trap cleanup EXIT > +trap 'exit 130' INT TERM > + > +mkdir $C $M || { echo "cannot create $C and $M"; exit 1; } [Severity: Low] Can arming the EXIT trap before mkdir $C succeeds delete an unrelated contr= ol group? If /sys/fs/resctrl/c is created concurrently between the [ ! -e $C ] check = and mkdir $C $M, mkdir fails and runs exit 1, invoking cleanup(). Because resctrl's rdtgroup_rmdir_ctrl() removes non-empty control groups and moves their tasks to the default group, cleanup() would tear down that group. Creating $C before installing the EXIT trap, or gating rmdir in cleanup() on mkdir $C succeeding, would avoid this. > +# 8 forkers. Each joins c, then m, and then forks in a loop: a sleeping = child > +# that lives 20 s, plus a very short one that keeps the fork rate high. > +for i in 1 2 3 4 5 6 7 8; do > + ( echo $BASHPID > $C/tasks; echo $BASHPID > $M/tasks > + while :; do sleep 20 & sleep 0.0003; done ) & > + FORKERS+=3D($!) > +done [Severity: Low] Can a signal arriving between starting a background subshell and appending = $! to FORKERS leak an infinite fork loop? In bash, pending trapped signals run between commands: ( ... ) & (subshell spawned, $! set) exit 130 -> cleanup() kill "${FORKERS[@]}" <-- new subshell not yet in FORKERS Because non-interactive bash ignores SIGINT in asynchronous subshells and SIGTERM to the script is not forwarded to children, the untracked subshell keeps spawning sleeping processes indefinitely. Terminating children of $$ in cleanup() or deferring signals around the spa= wn loop would close this window. [ ... ] > +# Remember the children for cleanup, then stop the forkers. The children= stay. > +KIDS=3D$(pgrep -P "$(IFS=3D,; echo "${FORKERS[*]}")") > +kill "${FORKERS[@]}" 2>/dev/null > +sleep 2 # let forks that are still in flight finish [Severity: Low] Can cleanup() send SIGTERM as root to unrelated processes via stale PIDs in FORKERS and KIDS? Here KIDS captures short-lived sleep 0.0003 children that exit and get reap= ed almost immediately, and FORKERS is killed without waiting or clearing FORKERS=3D(). During sleep 2 and the mkdir loop, bash reaps the FORKERS jo= bs and returns their PIDs to the kernel. On exit, cleanup() runs as root and calls kill "${FORKERS[@]}" again (and pgrep -P on those PIDs if KIDS was empty) along with kill $KIDS. If the PID allocator wraps around during that window, especially when running the scri= pt in a loop, cleanup() can terminate unrelated processes. Waiting on FORKERS and clearing FORKERS=3D() after killing them, or running= the workload in a dedicated process group, would avoid signaling reaped PIDs. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/cover.1796411500.gi= t.reinette.chatre@intel.com?part=3D4