From: sashiko-bot@kernel.org
To: "Matthew Ruffell" <matthew.ruffell@canonical.com>,
"Waiman Long" <longman@redhat.com>,
"Frederic Weisbecker" <frederic@kernel.org>,
"Tejun Heo" <tj@kernel.org>,
"Peter Zijlstra" <peterz@infradead.org>,
"Ingo Molnar" <mingo@redhat.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"David Hildenbrand" <david@kernel.org>
Cc: "Caron Wills" <caron.wills@pulsar.com>,
"Ridong Chen" <ridong.chen@linux.dev>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Michal Koutný" <mkoutny@suse.com>,
"Juri Lelli" <juri.lelli@redhat.com>,
"Vincent Guittot" <vincent.guittot@linaro.org>,
"Dietmar Eggemann" <dietmar.eggemann@arm.com>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Ben Segall" <bsegall@google.com>, "Mel Gorman" <mgorman@suse.de>,
"Valentin Schneider" <vschneid@redhat.com>,
"K Prateek Nayak" <kprateek.nayak@amd.com>,
"Lorenzo Stoakes" <ljs@kernel.org>,
"Liam R . Howlett" <liam@infradead.org>,
"Vlastimil Babka" <vbabka@kernel.org>,
"Mike Rapoport" <rppt@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Michal Hocko" <mhocko@suse.com>, "Jann Horn" <jannh@google.com>,
"Pedro Falcato" <pfalcato@suse.de>,
linux-mm@kvack.org, "Jay Vosburgh" <jay.vosburgh@canonical.com>
Subject: Re: [PATCH 2/6] kthread: Keep unbound kthreads off nohz_full CPUs
Date: Wed, 04 Nov 2026 08:01:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-196846@kernel.org> (raw)
In-Reply-To: <20261103075940.110308-3-matthew.ruffell@canonical.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] kthread: offline preferred CPUs bypass hk_kthread in kthread_fetch_affinity()
--
commit e454a827bc8a9ce4259c7edb902592efbf81ab53
Author: Caron Wills <caron.wills@pulsar.com>
kthread: Keep unbound kthreads off nohz_full CPUs
This commit intersects unbound kthread affinity with both HK_TYPE_DOMAIN and
HK_TYPE_KERNEL_NOISE in kthread_fetch_affinity() so that unbound kthreads are
kept off nohz_full CPUs even when those CPUs remain in scheduler domains.
Link: https://bugs.launchpad.net/bugs/2165410
> diff --git a/kernel/kthread.c b/kernel/kthread.c
> index fdb8fb07f40bd..b9d8dfe1b6cad 100644
> --- a/kernel/kthread.c
> +++ b/kernel/kthread.c
> @@ -327,24 +327,46 @@ void __noreturn kthread_complete_and_exit(struct completion *comp, long code)
> }
> EXPORT_SYMBOL(kthread_complete_and_exit);
>
> +/*
> + * Unbound kthreads must run neither on domain isolated CPUs (isolcpus=domain,
> + * cpuset isolated partitions) nor on CPUs isolated from kernel noise
> + * (nohz_full=, isolcpus=nohz). The two sets usually coincide, but the kernel
> + * accepts nohz_full CPUs that remain in the scheduler domains, so both
> + * housekeeping types have to be honoured.
> + */
> static void kthread_fetch_affinity(struct kthread *kthread, struct cpumask *cpumask)
> {
> - const struct cpumask *pref;
> + const struct cpumask *pref, *hk_domain, *hk_kthread;
>
> guard(rcu)();
>
> + hk_domain = housekeeping_cpumask(HK_TYPE_DOMAIN);
> + /*
> + * Deliberately not HK_TYPE_KTHREAD: since v7.1 that is an alias of
> + * HK_TYPE_DOMAIN (commit 8f78b749f3da), which is the very assumption
> + * being corrected here.
> + */
> + hk_kthread = housekeeping_cpumask(HK_TYPE_KERNEL_NOISE);
> +
> if (kthread->preferred_affinity) {
> pref = kthread->preferred_affinity;
> } else {
> if (kthread->node == NUMA_NO_NODE)
> - pref = housekeeping_cpumask(HK_TYPE_DOMAIN);
> + pref = hk_domain;
> else
> pref = cpumask_of_node(kthread->node);
> }
>
> - cpumask_and(cpumask, pref, housekeeping_cpumask(HK_TYPE_DOMAIN));
> + cpumask_and(cpumask, pref, hk_domain);
> + cpumask_and(cpumask, cpumask, hk_kthread);
> + if (cpumask_empty(cpumask))
> + cpumask_and(cpumask, hk_domain, hk_kthread);
> + /*
> + * Both the boot parameters and cpuset guarantee that at least one
> + * CPU stays housekeeping for every type, but don't rely on it.
> + */
> if (!cpumask_intersects(cpumask, cpu_online_mask))
> - cpumask_copy(cpumask, housekeeping_cpumask(HK_TYPE_DOMAIN));
> + cpumask_copy(cpumask, hk_domain);
[Severity: High]
What happens in kthread_fetch_affinity() when the intersection of pref,
hk_domain, and hk_kthread is non-empty, but contains only offline CPUs?
Commit 78ff77ded78f ("kthread: Fall back when no preferred housekeeping CPU
is online") replaced cpumask_empty(cpumask) with
!cpumask_intersects(cpumask, cpu_online_mask) because preferred_affinity can
contain possible CPUs that are offline. For example, rcu_thread_affine_rnp()
populates preferred_affinity with all possible CPUs of the leaf rcu_node:
kernel/rcu/tree.c:rcu_thread_affine_rnp() {
...
for_each_leaf_node_possible_cpu(rnp, cpu)
cpumask_set_cpu(cpu, affinity);
kthread_affine_preferred(t, affinity);
...
}
If a leaf rcu_node has online CPUs that are all in nohz_full, plus offline
possible CPUs that were not listed in nohz_full=, or if the preferred
housekeeping CPUs are later hot-unplugged, then pref & hk_domain & hk_kthread
will contain only those offline CPUs.
In that case:
1. cpumask_empty(cpumask) is false, so the fallback to
cpumask_and(cpumask, hk_domain, hk_kthread) is skipped.
2. !cpumask_intersects(cpumask, cpu_online_mask) is true, so cpumask is
overwritten with hk_domain.
On systems where nohz_full CPUs remain in HK_TYPE_DOMAIN, wouldn't this
bypass hk_kthread and allow the kthread to be affined to nohz_full CPUs even
when online CPUs in hk_domain & hk_kthread exist elsewhere on the system?
Should the first fallback check !cpumask_intersects(cpumask, cpu_online_mask)
instead of cpumask_empty(cpumask)?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261103075940.110308-1-matthew.ruffell@canonical.com?part=2
next prev parent reply other threads:[~2026-11-04 8:01 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 7:59 [PATCH 0/6] mm, sched, cgroup: LRU Cache never drains when isolcpus are used with spinning SCHED_FIFO tasks causing page migration stalls Matthew Ruffell
2026-11-03 7:59 ` [PATCH 1/6] sched/isolation: Consider nohz_full CPUs isolated in cpu_is_isolated() again Matthew Ruffell
2026-11-03 7:59 ` [PATCH 2/6] kthread: Keep unbound kthreads off nohz_full CPUs Matthew Ruffell
2026-11-03 14:01 ` Frederic Weisbecker
2026-11-03 15:13 ` Waiman Long
2026-11-04 12:31 ` Frederic Weisbecker
2026-11-04 8:01 ` sashiko-bot [this message]
2026-11-03 7:59 ` [PATCH 3/6] mm/folio, mm/mlock: Don't batch folios in per-CPU LRU caches on isolated CPUs Matthew Ruffell
2026-11-03 12:53 ` kernel test robot
2026-11-03 13:30 ` kernel test robot
2026-11-03 7:59 ` [PATCH 4/6] sched/isolation: Drain per-CPU LRU batches when CPUs become isolated Matthew Ruffell
2026-11-03 14:10 ` Frederic Weisbecker
2026-11-03 7:59 ` [PATCH 5/6] cgroup/cpuset: Don't wait for memory migration when cpuset.mems is written with O_NONBLOCK Matthew Ruffell
2026-11-03 14:59 ` Tejun Heo
2026-11-03 15:22 ` Waiman Long
2026-11-03 7:59 ` [PATCH 6/6] cgroup/cpuset: Don't make a forking task wait for memory migration Matthew Ruffell
2026-11-03 14:58 ` Tejun Heo
2026-11-03 9:32 ` [PATCH 0/6] mm, sched, cgroup: LRU Cache never drains when isolcpus are used with spinning SCHED_FIFO tasks causing page migration stalls Michal Hocko
2026-11-03 15:01 ` Tejun Heo
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-196846@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bsegall@google.com \
--cc=caron.wills@pulsar.com \
--cc=david@kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=frederic@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=jannh@google.com \
--cc=jay.vosburgh@canonical.com \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=liam@infradead.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=longman@redhat.com \
--cc=matthew.ruffell@canonical.com \
--cc=mgorman@suse.de \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=peterz@infradead.org \
--cc=pfalcato@suse.de \
--cc=ridong.chen@linux.dev \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=surenb@google.com \
--cc=tj@kernel.org \
--cc=vbabka@kernel.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.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