mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bradley Morgan <brads@mainlining.org>
To: thnkslprpt@gmail.com
Cc: frederic@kernel.org, linux-kernel@vger.kernel.org, longman@redhat.com
Subject: Re: [PATCH] kthread: fall back when no preferred housekeeping CPU is online
Date: Tue, 20 Oct 2026 16:08:26 +0100	[thread overview]
Message-ID: <66925C75-D453-4733-BF77-B0EF71FCBE11@mainlining.org> (raw)
In-Reply-To: <20261020125518.1114230-1-thnkslprpt@gmail.com>

On 20 October 2026 13:55:18 BST, Avi Weiss <thnkslprpt@gmail.com> wrote:
>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))

Nice catch! 

Reviewed-by: Bradley Morgan <brads@mainlining.org>


> 		cpumask_copy(cpumask, housekeeping_cpumask(HK_TYPE_DOMAIN));
> }
> 
>
>base-commit: f47d223627f80cb7a1eb14c585fe6cb35de5e984
>

--- Thanks!
"I'm not a very positive person" - Linus torvalds

      reply	other threads:[~2026-10-20 15:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 12:55 Avi Weiss
2026-10-20 15:08 ` Bradley Morgan [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=66925C75-D453-4733-BF77-B0EF71FCBE11@mainlining.org \
    --to=brads@mainlining.org \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=thnkslprpt@gmail.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®