Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Reinette Chatre" <reinette.chatre@intel.com>,
	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, bp@alien8.de,
	tglx@linutronix.de, dave.hansen@linux.intel.com,
	tony.luck@intel.com, ben.horgan@arm.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
Subject: Re: [RFC PATCH 3/3] NOT_FOR_INCLUSION: selftests/resctrl: Tasks keep using removed RMID after fork() reproducer
Date: Sat, 21 Nov 2026 18:40:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-227266@kernel.org> (raw)
In-Reply-To: <2f95c069a2646af7d5745b14d2c53d0d9d450bc7.1795197419.git.reinette.chatre@intel.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Medium] selftests/resctrl: wrong exit status on fail and skip in
  stray_tasks_repro
- [Low] selftests/resctrl: stray_tasks_repro.sh not integrated into
  resctrl_tests
- [Low] selftests/resctrl: leaked child sleep processes in
  stray_tasks_repro.sh
- [Low] selftests/resctrl: locale-dependent ENOSPC match in
  stray_tasks_repro.sh
--

commit 607e215a0575d792a89253ec24f065f27a1b6a67
Author: Jedrzej Wasiukiewicz <jedrzej.wasiukiewicz@intel.com>

NOT_FOR_INCLUSION: selftests/resctrl: Tasks keep using removed RMID after fork() reproducer

This commit adds a script to reproduce a race where tasks forked while a
resctrl monitor group is being removed continue using the removed group's
RMID.

> 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

[ ... ]

> +R=/sys/fs/resctrl
> +C=$R/c                      # control group used for the test
> +M=$C/mon_groups/m           # monitor group that gets removed
> +MF=$R/info/L3_MON/mon_features

[Severity: Low]
Could this test be integrated into the resctrl_tests harness or wired into
tools/testing/selftests/resctrl/Makefile?  Right now it is not listed in
TEST_PROGS, so standard kselftest runs will not execute it, and it requires
/sys/fs/resctrl to be pre-mounted instead of reusing the mount_resctrlfs()
and feature-check helpers in resctrlfs.c.

> +
> +[ "$(id -u)" = 0 ] || { echo "run as root"; exit 1; }
> +[ -f $MF ] || { echo "resctrl with monitoring is not mounted at $R"; exit 1; }
> +if grep -q llc_occupancy $MF; then
> +	echo "llc_occupancy is enabled: freed RMIDs can sit in limbo."
> +	echo "Boot with the kernel parameter rdt=!cmt."
> +	exit 1
> +fi
> +[ ! -e $C ] || { echo "$C already exists, remove it first"; exit 1; }
> +
> +FORKERS=()                  # PIDs of the forker processes
> +KIDS=""                     # PIDs of their children
> +
> +# Runs on every exit, including Ctrl-C: stop all test processes and remove the
> +# test groups.
> +cleanup() {
> +	trap - EXIT INT TERM
> +	[ -n "$KIDS" ] || [ ${#FORKERS[@]} -eq 0 ] ||
> +		KIDS=$(pgrep -P "$(IFS=,; echo "${FORKERS[*]}")")
> +	[ ${#FORKERS[@]} -eq 0 ] || kill "${FORKERS[@]}" 2>/dev/null
> +	[ -z "$KIDS" ] || kill $KIDS 2>/dev/null

[ ... ]

> +# Remember the children for cleanup, then stop the forkers. The children stay.
> +KIDS=$(pgrep -P "$(IFS=,; echo "${FORKERS[*]}")")
> +kill "${FORKERS[@]}" 2>/dev/null
> +sleep 2                     # let forks that are still in flight finish

[Severity: Low]
Does capturing KIDS with pgrep before killing FORKERS leak sleep 20 child
processes?

Because the 8 forker subshells are still forking in a tight loop while
pgrep scans /proc (and both here and in cleanup() pgrep runs before sending
SIGTERM to FORKERS), any child spawned after pgrep checks its parent or
whose fork() is still in flight is missed in KIDS, reparented when FORKERS
exit, and left running after the script terminates.

> +
> +# Take every free RMID. Stop on the first error, normally ENOSPC (pool full).
> +n=0
> +while err=$(mkdir $C/mon_groups/n$n 2>&1); do n=$((n+1)); done
> +echo "monitor groups created: $n, stopped on: ${err##*: }"
> +
> +# Nothing was ever put into n*, so any task listed here is a stray.
> +strays=$(cat $C/mon_groups/n*/tasks 2>/dev/null | wc -l)
> +echo "tasks in new monitor groups (expect none): $strays"
> +if [ "$strays" -gt 0 ]; then
> +	grep -l . $C/mon_groups/n*/tasks        # which group holds them
> +	echo "RESULT: $strays stray task(s) kept the removed group's RMID"
> +	exit 0
> +fi
> +
> +case $err in
> +*"No space left"*)
> +	echo "RESULT: no stray this run, run again"
> +	exit 0 ;;
> +esac

[Severity: Low]
Does matching $err against "No space left" fail under non-English locales?
Without LC_ALL=C, mkdir prints a localized strerror(ENOSPC) message and the
script falls through to the inconclusive result even when the RMID pool was
exhausted.

> +
> +# Not ENOSPC: the pool was never full, so the freed RMID was not reused and a
> +# stray cannot be seen in this run.
> +echo "RESULT: INCONCLUSIVE, the freed RMID was never reused (${err##*: })"

[Severity: Medium]
Should the exit codes follow kselftest conventions?

When stray tasks are found ($strays -gt 0) or the run is inconclusive at
the end of the script, exiting with 0 makes automated runners treat a
reproduced bug or an inconclusive run as a pass.  Conversely, the
prerequisite checks at the top (root, resctrl mounted, and llc_occupancy
disabled) exit with 1 instead of the kselftest skip code 4 (ksft_skip=4).

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795197419.git.reinette.chatre@intel.com?part=3


      reply	other threads:[~2026-11-21 18:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 18:39 [RFC PATCH 0/3] fork,arm,x86,fs/resctrl: Fix stale resource group assignment on fork Reinette Chatre
2026-11-20 18:39 ` [RFC PATCH 1/3] fork,arm,x86,fs/resctrl: Fix stale resource group assignment vs copy_process() Reinette Chatre
2026-11-20 18:39 ` [RFC PATCH 2/3] arm,x86/resctrl: Assert tasklist_lock is held when setting CLOSID and RMID Reinette Chatre
2026-11-20 18:39 ` [RFC PATCH 3/3] NOT_FOR_INCLUSION: selftests/resctrl: Tasks keep using removed RMID after fork() reproducer Reinette Chatre
2026-11-21 18:40   ` sashiko-bot [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-227266@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Dave.Martin@arm.com \
    --cc=babu.moger@amd.com \
    --cc=ben.horgan@arm.com \
    --cc=bp@alien8.de \
    --cc=bsegall@google.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=david@kernel.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=fenghuay@nvidia.com \
    --cc=fustini@kernel.org \
    --cc=james.morse@arm.com \
    --cc=jedrzej.wasiukiewicz@intel.com \
    --cc=juri.lelli@redhat.com \
    --cc=kees@kernel.org \
    --cc=kprateek.nayak@amd.com \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mgorman@suse.de \
    --cc=mhocko@suse.com \
    --cc=mingo@redhat.com \
    --cc=peternewman@google.com \
    --cc=peterz@infradead.org \
    --cc=reinette.chatre@intel.com \
    --cc=rostedt@goodmis.org \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=surenb@google.com \
    --cc=tglx@linutronix.de \
    --cc=tony.luck@intel.com \
    --cc=vbabka@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=x86@kernel.org \
    --cc=yu.c.chen@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox