The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Joerg Vehlow <lkml@jv-coder.de>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Huang Ying <ying.huang@intel.com>,
	linux-kernel@vger.kernel.org,
	Joerg Vehlow <joerg.vehlow@aox-tech.de>
Subject: Re: [BUG RT] dump-capture kernel not executed for panic in interrupt context
Date: Fri, 21 Aug 2020 11:08:48 -0400	[thread overview]
Message-ID: <20200821110848.6c3183d1@oasis.local.home> (raw)
In-Reply-To: <c6b095af-fc92-420f-303f-d2efd9f28873@jv-coder.de>

On Fri, 21 Aug 2020 12:25:33 +0200
Joerg Vehlow <lkml@jv-coder.de> wrote:

> Hi Andrew and Others (please read at least the part with @RT developers),
> 
> > Yup, mutex_trylock() from interrupt is improper.  Well dang, that's a
> > bit silly.  Presumably the 2006 spin_lock_mutex() wasn't taken with
> > irqs-off.
> >
> > Ho hum, did you look at switching the kexec code back to the xchg
> > approach?
> >  
> I looked into reverting to the xchg approach, but that seems to be
> not a good solution anymore, because the mutex is used in many places,
> a lot with waiting locks and I guess that would require spinning now,
> if we do this with bare xchg.
> 
> Instead I thought about using a spinlock, because they are supposed
> to be used in interrupt context as well, if I understand the documentation
> correctly ([1]).
> @RT developers
> Unfortunately the rt patches seem to interpret it a bit different and
> spin_trylock uses __rt_mutex_trylock again, with the same consequences as
> with the current code.
> 
> I tried raw_spinlocks, but it looks like they result in a deadlock at
> least in the rt kernel. Thiy may be because of memory allocations in the
> critical sections, that are not allowed if I understand it correctly.
> 
> I have no clue how to fix it at this point.
> 
> Jörg
> 
> [1] https://kernel.readthedocs.io/en/sphinx-samples/kernel-locking.html

There's only two places that wait on the mutex, and all other places
try to get it, and if it fails, it simply exits.

What I would do is introduce a kexec_busy counter, and have something
like this:

For the two locations that actually wait on the mutex:

loop:
	mutex_lock(&kexec_mutex);
	ret = atomic_inc_return(&kexec_busy);
	if (ret > 1) {
		/* Atomic context is busy on this counter, spin */
		atomic_dec(&kexec_busy);
		mutex_unlock(&kexec_mutex);
		goto loop;
	}
	[..]
	atomic_dec(&kexec_busy);
	mutex_unlock(&kexec_mutex);

And then all the other places that do the trylock:

	cant_sleep();
	ret = atomic_inc_return(&kexec_busy);
	if (ret > 1) {
		atomic_dec(&kexec_busy);
		return;
	}
	[..]
	atomic_dec(&kexec_busy);


-- Steve

  reply	other threads:[~2020-08-21 15:08 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-28 11:41 [BUG RT] dump-capture kernel not executed for panic in interrupt context Joerg Vehlow
2020-05-28 12:46 ` Steven Rostedt
2020-07-22  4:30   ` Joerg Vehlow
2020-07-22 20:51     ` Steven Rostedt
2020-07-27 23:36     ` Andrew Morton
2020-08-21 10:25       ` Joerg Vehlow
2020-08-21 15:08         ` Steven Rostedt [this message]
2020-08-21 20:47           ` Andrew Morton
2020-08-21 21:03             ` Steven Rostedt
2020-08-22 12:32               ` peterz
2020-08-22 23:49                 ` Steven Rostedt
2020-09-07 11:41                   ` peterz
2020-09-07 12:49                     ` Valentin Schneider
2020-09-14 19:00                     ` Steven Rostedt
2020-09-07 10:51               ` Joerg Vehlow
2020-09-07 11:46                 ` peterz
2020-09-07 12:03                   ` Joerg Vehlow
2020-09-07 16:23                     ` peterz
2020-09-08  5:48                       ` Joerg Vehlow
2020-09-09  5:46                         ` Joerg Vehlow
2020-09-11 22:48                           ` Eric W. Biederman
2020-09-14  6:03                             ` Joerg Vehlow
2020-09-14 16:46                               ` Eric W. Biederman

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=20200821110848.6c3183d1@oasis.local.home \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=bigeasy@linutronix.de \
    --cc=joerg.vehlow@aox-tech.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkml@jv-coder.de \
    --cc=tglx@linutronix.de \
    --cc=ying.huang@intel.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