mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Avi Weiss <thnkslprpt@gmail.com>
To: Frederic Weisbecker <frederic@kernel.org>
Cc: Waiman Long <longman@redhat.com>,
	linux-kernel@vger.kernel.org, Avi Weiss <thnkslprpt@gmail.com>
Subject: [PATCH] kthread: fall back when no preferred housekeeping CPU is online
Date: Tue, 20 Oct 2026 15:55:18 +0300	[thread overview]
Message-ID: <20261020125518.1114230-1-thnkslprpt@gmail.com> (raw)

kthread_fetch_affinity() falls back to the housekeeping mask
only when the intersection with the preferred mask is empty.

If the intersection contains only offline CPUs,
set_cpus_allowed_ptr() returns -EINVAL and the kthread keeps
its previous affinity, which may still include an isolated CPU.

Check whether the intersection contains an online CPU instead.
Fall back to the full housekeeping mask when none are online.

Fixes: e894f6339808 ("kthread: Honour kthreads preferred affinity after cpuset changes")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
---

Tested on x86_64 Linux 7.3.0 with vng/qemu and a kthread with 
preferred CPUs 1-2.

With CPU 2 offline and CPU 1 isolated, the unpatched kernel kept
affinity 1-2 and set_cpus_allowed_ptr() returned -EINVAL. With the
fix, affinity changed to 0,2. Bringing CPU 2 online restored 
affinity to 2, and removing isolation restored 1-2.

 kernel/kthread.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/kthread.c b/kernel/kthread.c
index cc8cb5d3eab7..fdb8fb07f40b 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -343,7 +343,7 @@ static void kthread_fetch_affinity(struct kthread *kthread, struct cpumask *cpum
 	}
 
 	cpumask_and(cpumask, pref, housekeeping_cpumask(HK_TYPE_DOMAIN));
-	if (cpumask_empty(cpumask))
+	if (!cpumask_intersects(cpumask, cpu_online_mask))
 		cpumask_copy(cpumask, housekeeping_cpumask(HK_TYPE_DOMAIN));
 }
 

base-commit: f47d223627f80cb7a1eb14c585fe6cb35de5e984
-- 
2.43.0


             reply	other threads:[~2026-10-20 12:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 12:55 Avi Weiss [this message]
2026-10-20 15:08 ` Bradley Morgan

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=20261020125518.1114230-1-thnkslprpt@gmail.com \
    --to=thnkslprpt@gmail.com \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@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

all inboxes | Powered by JetHome®