mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 2/2] kthread: Drop warning on cpumask allocation failure in kthread_affine_node()
@ 2026-09-14 12:09 Quchaosheng
  2026-09-14 16:52 ` Bradley Morgan
  2026-09-14 17:04 ` Waiman Long
  0 siblings, 2 replies; 9+ messages in thread
From: Quchaosheng @ 2026-09-14 12:09 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng
  Cc: Waiman Long, linux-kernel, Quchaosheng

kthread_affine_node() warns when zalloc_cpumask_var() fails:

  if (!zalloc_cpumask_var(&affinity, GFP_KERNEL)) {
          WARN_ON_ONCE(1);
          return;
  }

The allocation uses GFP_KERNEL, so it can fail under memory pressure or
fault injection.  A failed allocation is a recoverable condition and not a
kernel bug, so the warning is noise.  syzbot reports it for a WireGuard
NAPI thread:

  WARNING: kernel/kthread.c:359 at kthread_affine_node+0x200/0x2e8
  CPU: 0 PID: 5207 Comm: napi/wg2-0
  Call Trace:
   alloc_cpumask_var_node+0xfc/0x138
   zalloc_cpumask_var
   kthread_affine_node+0x148/0x2e8
   kthread+0x29c/0x3d4
   ret_from_fork+0x10/0x20

The other two callers of zalloc_cpumask_var() in this file, in the kthread
preferred affinity and kthreads_online_cpu() paths, return -ENOMEM without
a warning.  kthread_affine_node() returns void, so it cannot report the
error either, and it only skips the affinity setup for this thread.  Return
early without warning, matching those callers.

Reported-by: syzbot+37ca7ae3e98cb65c3209@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=37ca7ae3e98cb65c3209
Signed-off-by: Quchaosheng <quchaosheng000406@163.com>
---
 kernel/kthread.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/kthread.c b/kernel/kthread.c
index a3f95c904..f735a74b6 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -355,10 +355,8 @@ static void kthread_affine_node(void)
 	if (WARN_ON_ONCE(kthread_is_per_cpu(current)))
 		return;
 
-	if (!zalloc_cpumask_var(&affinity, GFP_KERNEL)) {
-		WARN_ON_ONCE(1);
+	if (!zalloc_cpumask_var(&affinity, GFP_KERNEL))
 		return;
-	}
 
 	mutex_lock(&kthread_affinity_lock);
 	WARN_ON_ONCE(!list_empty(&kthread->affinity_node));


^ permalink raw reply	[flat|nested] 9+ messages in thread
* [PATCH 2/2] kthread: Drop warning on cpumask allocation failure in kthread_affine_node()
@ 2026-09-14 12:09 Quchaosheng
  0 siblings, 0 replies; 9+ messages in thread
From: Quchaosheng @ 2026-09-14 12:09 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Will Deacon, Boqun Feng
  Cc: Waiman Long, linux-kernel, Quchaosheng

kthread_affine_node() warns when zalloc_cpumask_var() fails:

  if (!zalloc_cpumask_var(&affinity, GFP_KERNEL)) {
          WARN_ON_ONCE(1);
          return;
  }

The allocation uses GFP_KERNEL, so it can fail under memory pressure or
fault injection.  A failed allocation is a recoverable condition and not a
kernel bug, so the warning is noise.  syzbot reports it for a WireGuard
NAPI thread:

  WARNING: kernel/kthread.c:359 at kthread_affine_node+0x200/0x2e8
  CPU: 0 PID: 5207 Comm: napi/wg2-0
  Call Trace:
   alloc_cpumask_var_node+0xfc/0x138
   zalloc_cpumask_var
   kthread_affine_node+0x148/0x2e8
   kthread+0x29c/0x3d4
   ret_from_fork+0x10/0x20

The other two callers of zalloc_cpumask_var() in this file, in the kthread
preferred affinity and kthreads_online_cpu() paths, return -ENOMEM without
a warning.  kthread_affine_node() returns void, so it cannot report the
error either, and it only skips the affinity setup for this thread.  Return
early without warning, matching those callers.

Reported-by: syzbot+37ca7ae3e98cb65c3209@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=37ca7ae3e98cb65c3209
Signed-off-by: Quchaosheng <quchaosheng000406@163.com>
---
 kernel/kthread.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/kernel/kthread.c b/kernel/kthread.c
index a3f95c904..f735a74b6 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -355,10 +355,8 @@ static void kthread_affine_node(void)
 	if (WARN_ON_ONCE(kthread_is_per_cpu(current)))
 		return;
 
-	if (!zalloc_cpumask_var(&affinity, GFP_KERNEL)) {
-		WARN_ON_ONCE(1);
+	if (!zalloc_cpumask_var(&affinity, GFP_KERNEL))
 		return;
-	}
 
 	mutex_lock(&kthread_affinity_lock);
 	WARN_ON_ONCE(!list_empty(&kthread->affinity_node));


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-09-17  5:16 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-14 12:09 [PATCH 2/2] kthread: Drop warning on cpumask allocation failure in kthread_affine_node() Quchaosheng
2026-09-14 16:52 ` Bradley Morgan
2026-09-14 17:04 ` Waiman Long
2026-09-15 10:45   ` Frederic Weisbecker
2026-09-16  1:59     ` [PATCH] kthread: Report cpumask allocation failure without warning Quchaosheng
2026-09-16 16:40       ` Bradley Morgan
2026-09-17  5:15         ` Quchaosheng
2026-09-16  8:10     ` [PATCH 2/2] kthread: Drop warning on cpumask allocation failure in kthread_affine_node() Quchaosheng
  -- strict thread matches above, loose matches on Subject: below --
2026-09-14 12:09 Quchaosheng

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®