mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Chen, Yu C" <yu.c.chen@intel.com>
To: Jirka Hladky <jhladky@redhat.com>
Cc: Libo Chen <libo.chen@oracle.com>,
	Abhigyan ghosh <zscript.team.zs@gmail.com>,
	<linux-kernel@vger.kernel.org>,
	Chen Yu <yu.chen.surf@foxmail.com>,
	Philip Auld <pauld@redhat.com>,
	"jstancek@redhat.com" <jstancek@redhat.com>
Subject: Re: [BUG] Kernel panic in __migrate_swap_task() on 6.16-rc2 (NULL pointer dereference)
Date: Wed, 2 Jul 2025 19:14:20 +0800	[thread overview]
Message-ID: <4c827399-955c-4c7e-9a52-d38bc6a55aee@intel.com> (raw)
In-Reply-To: <CAE4VaGAzuexw79W+ZpAPf7dDKVtUZs_eNYX5e_ZWVirSt2tONQ@mail.gmail.com>

On 7/2/2025 5:05 AM, Jirka Hladky wrote:
> Hi Chenyu,
> 
> I have the first
> 
> if (unlikely(!p->mm)) {
> trace_printk("!! (%d %s) flags=%lx\n", p->pid, p->comm, p->flags);
> 
> log from dual socket AMD Milanx 7573X server:
> 
> [74615.841401] # entries-in-buffer/entries-written: 1/1   #P:128
> [74615.841401] #
> [74615.841401] #                                _-----=> irqs-off/BH-disabled
> [74615.841401] #                               / _----=> need-resched
> [74615.841401] #                              | / _---=> hardirq/softirq
> [74615.841401] #                              || / _--=> preempt-depth
> [74615.841401] #                              ||| / _-=> migrate-disable
> [74615.841401] #                              |||| /     delay
> [74615.841401] #           TASK-PID     CPU#  |||||  TIMESTAMP  FUNCTION
> [74615.841401] #              | |         |   |||||     |         |
> [74615.841401]      migration/6-54      [006] d..5. 58590.368364:
> __migrate_swap_task: !! (2939199 stress-ng-sem) flags=40004c
> 
> debug code caught a task with p->mm == NULL during __migrate_swap_task().
> 
> Trace shows:
>    * It was a stress-ng-sem process (PID 2939199),
>    * That process was in the process of exiting (PF_EXITING | PF_EXITPIDONE),

Thanks Jirka. So this race condition is related to task exit.

>    * And was a workqueue worker (PF_WQ_WORKER),
>    * It explains why p->mm had already been freed
> 
> I'm curious as to why the command is stress-ng-sem, and the flag
> indicates it is a workqueue worker.

The flag 0x40004c is
PF_EXITING PF_POSTCOREDUMP PF_FORKNOEXEC PF_RANDOMIZE
according to latest
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/linux/sched.h?h=v6.16-rc4

thanks,
Chenyu>
> More jobs are still running. I will keep an eye on them and report the
> other cases as they finish.
> 
> Jirka
> 
> On Tue, Jul 1, 2025 at 5:10 PM Jirka Hladky <jhladky@redhat.com> wrote:
>>
>> Hi Chenyu and Libo,
>>
>> I agree, let's wait for the results. Hopefully, we can fix the root
>> cause based on the debug messages.
>>
>> There was a problem with the infrastructure over the weekend, so I had
>> to restart the jobs yesterday. I should have results tomorrow.
>>
>> Stay tuned.
>> Jirka
>>
>>
>> On Tue, Jul 1, 2025 at 4:59 PM Chen, Yu C <yu.c.chen@intel.com> wrote:
>>>
>>> Hi Libo,
>>>
>>> On 7/1/2025 3:32 PM, Libo Chen wrote:
>>>> Hi Chenyu,
>>>>
>>>> On 6/27/25 00:33, Chen, Yu C wrote:
>>>>> On 6/27/2025 3:16 PM, Chen, Yu C wrote:
>>>>>> Hi Jirka,
>>>>>>
>>>>>> On 6/27/2025 5:46 AM, Jirka Hladky wrote:
>>>>>>> Hi Chen and all,
>>>>>>>
>>>>>>> we have now verified that the following commit causes a kernel panic
>>>>>>> discussed in this thread:
>>>>>>>
>>>>>>> ad6b26b6a0a79 sched/numa: add statistics of numa balance task
>>>>>>>
>>>>>>> Reverting this commit fixes the issue.
>>>>>>>
>>>>>>> I'm happy to help debug this further or test a proposed fix.
>>>>>>>
>>>>>>
>>>>>> Thanks very much for your report, it seems that there is a
>>>>>> race condition that when the swap task candidate was chosen,
>>>>>> but its mm_struct get released due to task exit, then later
>>>>>> when doing the task swaping, the p->mm is NULL which caused
>>>>>> the problem:
>>>>>>
>>>>>> CPU0                                   CPU1
>>>>>> :
>>>>>> ...
>>>>>> task_numa_migrate
>>>>>>      task_numa_find_cpu
>>>>>>       task_numa_compare
>>>>>>         # a normal task p is chosen
>>>>>>         env->best_task = p
>>>>>>
>>>>>>                                           # p exit:
>>>>>>                                           exit_signals(p);
>>>>>>                                              p->flags |= PF_EXITING
>>>>>>                                           exit_mm
>>>>>>                                              p->mm = NULL;
>>>>>>
>>>>>>       migrate_swap_stop
>>>>>>         __migrate_swap_task((arg->src_task, arg->dst_cpu)
>>>>>>          count_memcg_event_mm(p->mm, NUMA_TASK_SWAP)# p->mm is NULL
>>>>>>
>>>>>> Could you please help check if the following debug patch works,
>>>>>
>>>>> Attached the patch:
>>>>>
>>>>> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
>>>>> index 8988d38d46a3..82fc966b390c 100644
>>>>> --- a/kernel/sched/core.c
>>>>> +++ b/kernel/sched/core.c
>>>>> @@ -3364,7 +3364,12 @@ static void __migrate_swap_task(struct task_struct *p, int cpu)
>>>>>    {
>>>>>        __schedstat_inc(p->stats.numa_task_swapped);
>>>>>        count_vm_numa_event(NUMA_TASK_SWAP);
>>>>> -    count_memcg_event_mm(p->mm, NUMA_TASK_SWAP);
>>>>> +    if (unlikely(!p->mm)) {
>>>>
>>>> I am starting to wonder if we should keep this check and add a big fat warning
>>>> like  "there is a bug here, please report it!" rather than brick the kernel.
>>>> A kernel panic, for sure, helps catch bugs like this more than a line of dmesg,
>>>> so it's a tradeoff I guess. What do you think?
>>>>
>>>
>>> I agree with you that adding something like WARN_ON_ONCE()
>>> could help, and it seems that the kernel panic is not expected
>>> in this scenario because this feature is a statistic calculation
>>> rather than the critical logic. Maybe waiting for Jirka's feedback
>>> to decide the next step.
>>>
>>> thanks,
>>> Chenyu
>>>
>>>
>>>
>>>>
>>>> Thanks,
>>>> Libo
>>>>
>>>>> +        trace_printk("!! (%d %s) flags=%lx\n", p->pid, p->comm,
>>>>> +                p->flags);
>>>>> +    } else {
>>>>> +        count_memcg_event_mm(p->mm, NUMA_TASK_SWAP);
>>>>> +    }
>>>>>
>>>>>        if (task_on_rq_queued(p)) {
>>>>>            struct rq *src_rq, *dst_rq;
>>>>
>>>
>>
>>
>> --
>> -Jirka
> 
> 
> 

  reply	other threads:[~2025-07-02 11:14 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-17 20:05 Jirka Hladky
2025-06-18  4:43 ` Aithal, Srikanth
2025-06-18  5:19 ` Abhigyan ghosh
2025-06-18 11:34   ` Jirka Hladky
2025-06-26 21:46     ` Jirka Hladky
2025-06-27  7:16       ` Chen, Yu C
2025-06-27  7:33         ` Chen, Yu C
2025-07-01  7:32           ` Libo Chen
2025-07-01 14:59             ` Chen, Yu C
2025-07-01 15:10               ` Jirka Hladky
2025-07-01 21:05                 ` Jirka Hladky
2025-07-02 11:14                   ` Chen, Yu C [this message]
2025-07-02 11:43                     ` Jirka Hladky
2025-07-02  4:32           ` Aithal, Srikanth
2025-07-02  7:36             ` Aithal, Srikanth
2025-07-02 11:17               ` Chen, Yu C
2025-07-02 11:53                 ` Jirka Hladky
2025-07-02 12:19                   ` Aithal, Srikanth
2025-07-02 13:24                     ` Jirka Hladky
2025-07-03 23:50                       ` Jirka Hladky
2025-06-27 10:48         ` Jirka Hladky

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=4c827399-955c-4c7e-9a52-d38bc6a55aee@intel.com \
    --to=yu.c.chen@intel.com \
    --cc=jhladky@redhat.com \
    --cc=jstancek@redhat.com \
    --cc=libo.chen@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pauld@redhat.com \
    --cc=yu.chen.surf@foxmail.com \
    --cc=zscript.team.zs@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®