Re: [PATCH] exit: dump thread info on global init exit

From: Oleg Nesterov
Date: Thu Nov 09 2023 - 06:03:27 EST


I've just noticed we discuss this offlist. Add lkml...

On 11/09, lijiazi wrote:
>
> On Wed, Nov 08, 2023 at 10:57:32AM +0100, Oleg Nesterov wrote:
>
> > > + if (mmap_read_lock_killable(mm)) {
> >
> > why do you need _killable ?
> >
> I'm not sure which type lock (killable or unkillable) should be used here

killable should be used to allow to kill the task which waits for this lock.
Who can kill the global init? Yes it is possible (but very unlikely) that
fatal_signal_pending() is true, but I don't think this was your concern.

> if there is a lock contention, perhaps using down_read_trylock is better.

Perhaps. If we have another bug mmap_read_lock() can hang forever.

> > > +static void dump_thread_info(struct task_struct *tsk)
> > > +{
> > > + struct pt_regs *regs = task_pt_regs(tsk);
> > > +
> > > + if (user_mode(regs))
> > > + dump_thread_maps_info(tsk);
> > > + show_regs(regs);
> >
> > This looks confusing to me...
> >
> > How can user_mode() return false in this case? And even if this is
> > possible, then show_regs() should depend on user_mode() as well?
> > I must have missed something.
> >
> Sure, the last global init thread cannot be exited in non-user mode.

Forgot to mention... panic() should dump the regs, so I think show_regs()
is not needed?

Oleg.