All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
	tglx@kernel.org, peterz@infradead.org
Cc: mingo@redhat.com, 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, paulmck@kernel.org,
	boqun@kernel.org, shuah@kernel.org, kees@kernel.org,
	viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz,
	oleg@redhat.com, bestswngs@gmail.com, xmei5@asu.edu,
	xujiakai24@mails.ucas.ac.cn, linux-mm@kvack.org
Subject: Re: [PATCH 16/17] selftests/rseq: Test affinity changes while a task replaces or drops its mm
Date: Wed, 18 Nov 2026 16:17:41 +0000	[thread overview]
Message-ID: <sashiko-outbox-221459@kernel.org> (raw)
In-Reply-To: <ccc2a6c50429b1ad9c8d5cc45ec8e58c12df7fde.1794932121.git.mathieu.desnoyers@efficios.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Low] selftests/rseq: unreset execs count in run_exec_case() weakens
  progress check
- [Low] selftests/rseq: victim deadline before wait_first_exec() in
  run_exec_case()
- [Low] selftests/rseq: unconditional increment of i in setter_main()
  skips mm updates
- [Low] selftests/rseq: missing mm_cid_teardown_test entry in .gitignore
--

commit cb8cf09e0b94fdd16e87974a38605eabab39bcdf
Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>

selftests/rseq: Test affinity changes while a task replaces or drops its mm

This commit adds the mm_cid_teardown_test selftest to exercise concurrent
sched_setaffinity() calls against tasks replacing their mm via execve() or
dropping their mm on exit.

Link: https://lore.kernel.org/all/20261110183809.3308868-2-bestswngs@gmail.com/

> diff --git a/tools/testing/selftests/rseq/Makefile b/tools/testing/selftests/rseq/Makefile
> index d72502fc76527..2735704f516b8 100644
> --- a/tools/testing/selftests/rseq/Makefile
> +++ b/tools/testing/selftests/rseq/Makefile
> @@ -22,7 +22,7 @@ TEST_GEN_PROGS = basic_test basic_percpu_ops_test basic_percpu_ops_mm_cid_test \
>  		 param_test_benchmark param_test_mm_cid_benchmark \
>  		 mm_cid_execve_test mm_cid_transition_test \
>  		 mm_cid_bound_test mm_cid_exec_affinity_test \
> -		 mm_cid_window_test
> +		 mm_cid_window_test mm_cid_teardown_test

[Severity: Low]
Should mm_cid_teardown_test also be added to
tools/testing/selftests/rseq/.gitignore like the other binaries in
TEST_GEN_PROGS so in-tree builds do not leave an untracked binary behind?

> diff --git a/tools/testing/selftests/rseq/mm_cid_teardown_test.c b/tools/testing/selftests/rseq/mm_cid_teardown_test.c
> new file mode 100644
> index 0000000000000..f07a566901f83
> --- /dev/null
> +++ b/tools/testing/selftests/rseq/mm_cid_teardown_test.c
[ ... ]
> +static void setter_main(struct shared *sh, int index, pid_t pid, int cpu,
> +			int a, int b, long long deadline)
> +{
> +	unsigned long long changes = 0;
> +	cpu_set_t one, two;
> +	int i = 0;
> +
[ ... ]
> +	while (now_us() < deadline) {
> +		const cpu_set_t *mask = (i++ & 1) ? &one : &two;
> +		pid_t target = pid ? pid : RSEQ_READ_ONCE(sh->target);
> +
> +		if (!target)
> +			continue;
> +		if (!sched_setaffinity(target, sizeof(*mask), mask)) {
> +			changes++;
> +			continue;
> +		}

[Severity: Low]
Does incrementing i before checking target cause the first
sched_setaffinity() call on a newly forked child in run_exit_case() to be
a no-op half the time?

In run_exit_case(), the parent pins itself to CPU a (mask one), so each
new child inherits mask one.  Because setter_main() spins while sh->target
is 0 and does not reset i when sh->target changes, roughly half of new
targets first receive mask one, which returns early in
__set_cpus_allowed_ptr_locked() without updating the mm while still
incrementing changes.  Spinning while target is 0 also advances signed int
i without bound, which can overflow on longer runtimes passed via argv[1].

[ ... ]
> +static void run_exec_case(char *name, int runtime_s, struct shared *sh)
> +{
> +	unsigned long long execs = 0, changes = 0;
> +	int a = cpus[nr_cpus - 2], b = cpus[nr_cpus - 1];
> +	pid_t victim, setters[MAX_SETTERS];
> +	int fd, i, nset, status = 0;
> +	long long deadline;
> +	pid_t ret;
> +
> +	nset = nr_cpus - 2 < MAX_SETTERS ? nr_cpus - 2 : MAX_SETTERS;
> +	fd = eventfd(0, EFD_NONBLOCK);
> +	if (fd < 0)
> +		ksft_exit_fail_msg("eventfd: %s\n", strerror(errno));
> +	/* The process under test outlives those that change its affinity. */
> +	victim = start_exec_loop(name, a, fd,
> +				 now_us() + (runtime_s + 1) * 1000000LL);
> +	if (victim < 0)
> +		ksft_exit_fail_msg("fork: %s\n", strerror(errno));
> +	if (wait_first_exec(fd, &execs))
> +		ksft_exit_fail_msg("the process under test did not call execve\n");
> +
> +	deadline = now_us() + runtime_s * 1000000LL;
> +	for (i = 0; i < nset; i++) {
> +		setters[i] = fork();
> +		if (!setters[i])
> +			setter_main(sh, i, victim, cpus[i], a, b, deadline);
> +		if (setters[i] < 0)
> +			ksft_exit_fail_msg("fork: %s\n", strerror(errno));
> +	}
> +	for (i = 0; i < nset; i++) {
> +		if (wait_status(setters[i]))
> +			ksft_exit_fail_msg("a process that changes the affinity failed\n");
> +		changes += sh->changes[i];
> +	}
> +	if (drain(fd, &execs))
> +		ksft_exit_fail_msg("read the count of the execve calls: %s\n",
> +				   strerror(errno));
> +
> +	/* The process under test must still be in its loop. */
> +	ret = waitpid(victim, &status, WNOHANG);
> +	if (ret < 0)
> +		ksft_exit_fail_msg("waitpid: %s\n", strerror(errno));
> +	if (ret) {
> +		ksft_print_msg("the process under test left its loop: 0x%x\n",
> +			       status);
> +		ksft_test_result_fail("%s\n", exec_case);

[Severity: Low]
Can victim reach its end timestamp before the parent reaches waitpid() if
wait_first_exec() and forking/reaping the setters take at least one
second?

victim's end timestamp is computed before wait_first_exec() (which allows
up to 5 seconds) as now_us() + (runtime_s + 1) seconds, whereas the
setters' deadline is computed after wait_first_exec() returns.  On a slow
or KASAN-enabled guest, victim can exit normally with CHILD_PASS in
exec_loop_main() before the setters are reaped, causing waitpid(...,
WNOHANG) here to report a failure.

> +		if (close(fd))
> +			ksft_exit_fail_msg("close: %s\n", strerror(errno));
> +		return;
> +	}
> +	if (kill(victim, SIGKILL))
> +		ksft_exit_fail_msg("kill: %s\n", strerror(errno));
> +	if (waitpid(victim, &status, 0) != victim)
> +		ksft_exit_fail_msg("waitpid: %s\n", strerror(errno));
> +	if (close(fd))
> +		ksft_exit_fail_msg("close: %s\n", strerror(errno));
> +
> +	ksft_print_msg("%llu execve calls, %llu affinity changes\n",
> +		       execs, changes);
> +	ksft_test_result(execs && changes, "%s\n", exec_case);
> +}

[Severity: Low]
Does leaving execs unreset after wait_first_exec() make the execs check in
ksft_test_result() always true?

wait_first_exec() drains the initial eventfd write into execs before any
setter processes are forked, so execs is already at least 1 even if no
further execve() calls complete while the affinity changes are running.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1794932121.git.mathieu.desnoyers@efficios.com?part=16


  reply	other threads:[~2026-11-18 16:17 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 16:17 [PATCH 00/17] sched/mmcid: fixes for execve, mode switches and affinity Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 01/17] sched/mmcid: Give a CID to a task that joins its mm while running Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 02/17] sched/mmcid: Give no concurrency ID to user workers Mathieu Desnoyers
2026-11-18 16:17   ` sashiko-bot
2026-11-18 20:39     ` Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 03/17] sched/mmcid: Reset stale state when the first user joins an mm Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 04/17] sched/mmcid: Let a running joiner take its CID after the fixups Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 05/17] sched/mmcid: Take the allowed CPUs of the first user when it joins Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 06/17] sched/mmcid: Synchronize MM teardown with affinity updates Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 07/17] selftests/rseq: Test the concurrency ID after a failed execve Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 08/17] selftests/rseq: Test the concurrency ID after the last user fails execve Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 09/17] selftests/rseq: Test the concurrency IDs across ownership mode switches Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 10/17] selftests/rseq: Test the upper bound of the concurrency IDs Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 11/17] selftests/rseq: Test affinity changes made by another process Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 12/17] selftests/rseq: Test an affinity change by another process during execve Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 13/17] selftests/rseq: Test concurrent thread creation and forced migration Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 14/17] selftests/rseq: Test the concurrency IDs after the affinity is widened Mathieu Desnoyers
2026-11-18 16:17   ` sashiko-bot
2026-11-18 20:39     ` Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 15/17] selftests/rseq: Test two race windows of the concurrency ID mode switches Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 16/17] selftests/rseq: Test affinity changes while a task replaces or drops its mm Mathieu Desnoyers
2026-11-18 16:17   ` sashiko-bot [this message]
2026-11-18 20:40     ` Mathieu Desnoyers
2026-11-17 16:17 ` [PATCH 17/17] selftests/rseq: Test the last user after an affinity change during execve Mathieu Desnoyers

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-221459@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bestswngs@gmail.com \
    --cc=boqun@kernel.org \
    --cc=brauner@kernel.org \
    --cc=bsegall@google.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=jack@suse.cz \
    --cc=juri.lelli@redhat.com \
    --cc=kees@kernel.org \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-mm@kvack.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=oleg@redhat.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shuah@kernel.org \
    --cc=tglx@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=vschneid@redhat.com \
    --cc=xmei5@asu.edu \
    --cc=xujiakai24@mails.ucas.ac.cn \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.