From nobody Fri Jul 24 21:52:59 2026 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F235D432E76 for ; Thu, 23 Jul 2026 10:00:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784800819; cv=none; b=WqUgilpF1iQ2jyQJheZ7x6X7GgoVmA+3iCag7HEe7mrMrt8cPOgLytI/h72lrrMm3obaG6V3eBZIW+wSZR5sYLFKaA5iZAyQ5pZmWSqeIVV3zDWNf4TXeadyoGkHSAhKk7BPtKTbGclYbFNs3G065q/y/sFW8zy2ielsh7Jj3q4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784800819; c=relaxed/simple; bh=JJ4ADESycWpAJrtKtP4EarjSeTRD2hvpYuqdUvN7ww0=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=KuaKx8OpaodqtmsBsxJh/wKgYxzOca+5l4j+GRh6JM3ZOcF1AKLOTfdBr/+IDqyf+1oD4bJb5oi2Hy3YDe+awIEqVvNZRBH7kwYGQHvEcOJXQFXwYyuYaEqk4S+9MTUCQIqa8bG0OPccb6dmK3nPSjBByisolgvrU2+4liNjOBM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jpiecuch.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DAu3wBrg; arc=none smtp.client-ip=209.85.128.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jpiecuch.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DAu3wBrg" Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-49554715277so5427385e9.1 for ; Thu, 23 Jul 2026 03:00:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784800816; x=1785405616; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=XKxBAqWAIB0Dm6g/9qu+W8Gnm70FoQBMtCNd2PvBBII=; b=DAu3wBrgTM6qJq6etI5F/3R2SkFpt7MZaXque8pC+CzX11kBoZnNwSyFX2ZhA3dASi ilFaKGIlg+6LW29NMqKmN/gl2Qn4n5axNAuHgfLU2K81xqnSZwpTET0cys5nTY5MRPfi jR/A8FhA11NqQbTww5uGguGIsoTsJNJRQzE5BULKRBGW7zzASYy+FkJ5e/A7GIrgIg+o ytZsuo366SENqYxR43ER1KNNqPUcrsDZ2/N1+yyd89DRfcv6u1ZKN9YOubU8lCPV74In QhRtJIhChFygXro9sfI9yOIb6tNwXQfgGFOZp3Ztmm6xWqp47IYP72rSkM/UsXMBDcIx DwTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784800816; x=1785405616; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=XKxBAqWAIB0Dm6g/9qu+W8Gnm70FoQBMtCNd2PvBBII=; b=U5EOUTXYweuAs0exrwdna96tKPUukPDsasBhTy+4bZwfmGf95AXMojvBlJ6m6NsBR0 okLtBbWxcDFzzC55waO+FAdh0KE59H289GnwFIF8mD00jycDah9waq7aZZBphvD9e76i wx3UgsJImcyfBhP9RwYk9M8E+7dFUQGtNKt39jxF5Hdf2fnnw5VcvsNQnYjHd0lAUZXT BmE3LNZzsGsdUQMsyMHzOuoW1/6pLD7LLpVaHtE7PNbxuxBMByd3/PjZoLGfAO8M1JrP E7pB7J7XHaHoeyPA7f1NpxYELL6Bhh/C8zbvML9LO+j7GJikTtPdoDl+6keYmQO4ZlSf wt8A== X-Gm-Message-State: AOJu0YwdXdUJqbYUCdt2UK4/KwnGwUvOzj7i5ZS2BG8aWH/Y0vHXc37A ZLItUrMiy52Nut84Qpw9bYeSl6cyFk+fIU70jKhMc840059E+Uoi81ddPdKdo/YCByfNc8imgmF wpucRtIlSW5TCZA== X-Received: from wmpr21.prod.google.com ([2002:a05:600c:3215:b0:493:d3c4:6a28]) (user=jpiecuch job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:c091:b0:495:636b:e519 with SMTP id 5b1f17b1804b1-49573cfd67cmr25196765e9.21.1784800815871; Thu, 23 Jul 2026 03:00:15 -0700 (PDT) Date: Thu, 23 Jul 2026 09:59:55 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog Message-ID: <20260723095955.1415621-1-jpiecuch@google.com> Subject: [PATCH sched_ext/for-7.2-fixes] selftests/sched_ext: Handle sleeping task affinity changes in numa test From: Kuba Piecuch To: Tejun Heo , Andrea Righi , Changwoo Min , David Vernet Cc: linux-kernel@vger.kernel.org, sched-ext@lists.linux.dev, Kuba Piecuch Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When a sleeping task's affinity is changed, task_cpu(p) can be outside of p->cpus_ptr until after select_task_rq() selects a new runqueue for the task during wakeup. Thus, the task's NUMA node determined by numa_select_cpu() can be completely outside of the task's cpumask, leading to scx_pick_{idle,any}_cpu_node() failing to find an eligible CPU and returning -EBUSY. This leads to the numa.bpf.c scheduler abnormally exiting with the following message in dmesg: sched_ext: numa: invalid CPU -16 scx_bpf_cpu_node+0x120/0x190 bpf_prog_0a34b8e0f515771f_numa_select_cpu+0x108/0x14e bpf__sched_ext_ops_select_cpu+0x4f/0xb4 select_task_rq_scx+0xb0/0x210 select_task_rq+0xa0/0xd0 __try_to_wake_up+0x196/0x650 complete_all+0x76/0x100 migration_cpu_stop+0x22b/0x300 cpu_stopper_thread+0xc1/0x180 smpboot_thread_fn+0x16b/0x230 kthread+0x2d7/0x350 ret_from_fork+0x1c2/0x350 ret_from_fork_asm+0x1a/0x30 Make numa_select_cpu() robust against this case by returning @prev_cpu if no CPU could be found in the selected NUMA node _and_ we have reason to believe that the task's affinity was changed while it was sleeping. Fixes: 5ae5161820e5 ("selftests/sched_ext: Add NUMA-aware scheduler test") Signed-off-by: Kuba Piecuch --- tools/testing/selftests/sched_ext/numa.bpf.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/sched_ext/numa.bpf.c b/tools/testing/s= elftests/sched_ext/numa.bpf.c index 78cc49a7f9a6..6b4515c28aa0 100644 --- a/tools/testing/selftests/sched_ext/numa.bpf.c +++ b/tools/testing/selftests/sched_ext/numa.bpf.c @@ -34,7 +34,8 @@ static bool is_cpu_idle(s32 cpu, int node) s32 BPF_STRUCT_OPS(numa_select_cpu, struct task_struct *p, s32 prev_cpu, u64 wake_flags) { - int node =3D __COMPAT_scx_bpf_cpu_node(scx_bpf_task_cpu(p)); + s32 task_cpu =3D scx_bpf_task_cpu(p); + int node =3D __COMPAT_scx_bpf_cpu_node(task_cpu); s32 cpu; =20 /* @@ -48,6 +49,16 @@ s32 BPF_STRUCT_OPS(numa_select_cpu, cpu =3D __COMPAT_scx_bpf_pick_any_cpu_node(p->cpus_ptr, node, __COMPAT_SCX_PICK_IDLE_IN_NODE); =20 + /* + * @task_cpu may be outside of p->cpus_ptr if @p's affinity + * changed while it was sleeping. This means it's possible for + * p->cpus_ptr to not include any CPUs from @node. + * If we failed to find a cpu in @node, check if @task_cpu + * is outside of p->cpus_ptr and just return @prev_cpu if it is. + */ + if (cpu < 0 && !bpf_cpumask_test_cpu(task_cpu, p->cpus_ptr)) + return prev_cpu; + if (is_cpu_idle(cpu, node)) scx_bpf_error("CPU %d should be marked as busy", cpu); =20 --=20 2.55.0.229.g6434b31f56-goog