Subject: Re: linux-next: run time warning after merge of the userns tree

From: [email-masked] (Eric W. Biederman)
Date: Tue, 21 Dec 2021 11:44:02 -0600

Stephen Rothwell <[email-masked]> writes:

> Hi all,
>
> [I am just guessing at the userns tree.]

It is.  This is a real brown paper bag bug.  Somehow I got the sense
of the test wrong and did not notice the warning in my own testing.

The fix is just:

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 0404a8c572a1..ee222b89c692 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -9425,7 +9425,7 @@ void __init sched_init(void)
         * if we want to avoid special-casing it in code that deals with per-CPU
         * kthreads.
         */
-       WARN_ON(set_kthread_struct(current));
+       WARN_ON(!set_kthread_struct(current));
 
        /*
         * Make us the idle thread. Technically, schedule() should not be

I will get that fixed in my for-next branch shortly.

>
> My qemu boot test of a powerpc pseries_le_defconfig kernel produced
> this warning:
>
>   SLUB: HWalign=128, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
>   ftrace: allocating 33453 entries in 13 pages
>   ftrace: allocated 13 pages with 3 groups
>   trace event string verifier disabled
>   ------------[ cut here ]------------
>   WARNING: CPU: 0 PID: 0 at kernel/sched/core.c:9469 sched_init+0x45c/0x4f4
>   Modules linked in:
>   CPU: 0 PID: 0 Comm: swapper Not tainted 5.16.0-rc6 #2
>   NIP:  c000000002027c98 LR: c000000002027c94 CTR: 0000000000000000
>   REGS: c00000000278bb80 TRAP: 0700   Not tainted  (5.16.0-rc6)
>   MSR:  8000000002021033 <SF,VEC,ME,IR,DR,RI,LE>  CR: 84000220  XER: 00000000
>   CFAR: c00000000016c1fc IRQMASK: 1 
>   GPR00: c000000002027c94 c00000000278be20 c00000000278d300 0000000000000001 
>   GPR04: c000000000f88788 c000000002865d98 c000000007070680 0000000000000001 
>   GPR08: 000000007dae0000 c000000007070630 0000000000000000 0000000000000001 
>   GPR12: 0000000000000000 c000000002970000 0000000000000000 0000000000000000 
>   GPR16: 0000000002bf00d0 c0000000027c1f38 c00000000017e510 c000000002867f00 
>   GPR20: c0000000025306b8 c00000000017b520 c00000000017b200 c0000000028682b8 
>   GPR24: 0000000000000400 0000000000000000 c0000000027c2470 c0000000027b3a00 
>   GPR28: c0000000021af900 0000000000000800 0000000000000000 c00000007fc8f900 
>   NIP [c000000002027c98] sched_init+0x45c/0x4f4
>   LR [c000000002027c94] sched_init+0x458/0x4f4
>   Call Trace:
>   [c00000000278be20] [c000000002027c94] sched_init+0x458/0x4f4 (unreliable)
>   [c00000000278bed0] [c000000002004200] start_kernel+0x53c/0x8cc
>   [c00000000278bf90] [c00000000000d39c] start_here_common+0x1c/0x600
>   Instruction dump:
>   90ea0188 f92a0180 3d22fffb 39291890 39490050 7d005028 31080001 7d00512d 
>   40c2fff4 e86d0908 4a144499 60000000 <0b030000> a08d0008 e86d0908 4bfff849 
>   ---[ end trace 0000000000000000 ]---
>
> Exposed by commit
>
>   40966e316f86 ("kthread: Ensure struct kthread is present for all kthreads")