mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: James Hogan <james.hogan@imgtec.com>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 4/5] metag: kick: prevent nested kick handlers
Date: Tue, 2 Jul 2013 00:56:05 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.02.1307020022570.4013@ionos.tec.linutronix.de> (raw)
In-Reply-To: <CAAG0J9_fTNrKe7idPi3=O2kGRWBJmYSwMQuzGPiT2G+rXy4QuA@mail.gmail.com>

On Mon, 1 Jul 2013, James Hogan wrote:
> On 1 July 2013 22:51, Thomas Gleixner <tglx@linutronix.de> wrote:
> > On Mon, 1 Jul 2013, James Hogan wrote:
> >
> >> The main kick trigger handler iterates a list of kick handlers and calls
> >> each one. This is done with the kick_handlers_lock spin lock held, but
> >> this causes a problem on SMP where IPIs are implemented with kicks. A
> >> reschedule IPI calls scheduler_ipi() which uses irq_enter() and
> >> irq_exit(). This results in the scheduler being invoked with
> >> kick_handlers_lock held which can result in a nested kick trigger
> >> attempting to acquire the lock, resulting in deadlock.
> >>
> >> irq_enter() and irq_exit() can nest, so call them from the main kick
> >> interrupt handler so that softirqs are only handled after
> >> kick_handlers_lock is released.
> >
> > This changelog is confusing. What I decode from the patch is, that you
> > are adding a missing irq_enter/exit pair to the kick_handler, right ?
> 
> Yes. Previously the outermost pair of irq_enter/exit was inside the
> spin lock critical section (inside scheduler_ipi). so soft-irqs
> (apparently including the scheduler) would run from irq_exit with the
> spinlock still held. Now it waits until the new outermost irq_exit(),
> after the spin lock is released.
> 
> I should probably have increased the number of lines of diff context.
> http://lxr.linux.no/#linux+v3.10/arch/metag/kernel/kick.c#L66

No, you should have written the changelog less confusing. I can see
the context by just looking at the current and the patched code.

The explanation you provided right now that the outermost pair of
irq_enter/exit was inside the spin locked section matches the patch
and makes sense.

So the real issue is, that all of your various interrupts come from
the same place, i.e. kick_handler. The kick_handler locks a global
lock and calls the handlers which have registered. These handlers
(partially calling generic code) might invoke irq_enter/exit pairs,
which leads to the underlying problem.

If irq_exit() results in a nest count of hard interrupts = 0, then it
invokes eventually pending soft interrupts. The softirq callbacks can
issue an IPI of some sorts and because this IPI will end up in the
kick handler, the systems livelocks on the already held global lock
which protects the kick_handler list. This can happen from any invoked
handler, because the kick_handler is missing an irq_enter/pair
preventing a kick_handler invocation recursion.

The obvious fix for now is to add an irq_enter/exit() pair around the
spin locked section in the kick handler, so irq_exit() invocations of
subhandlers wont lead to softirq execution.

The more elegant fix would be to replace that global lock which is not
really scalable with an RCU protected list of subscribed handlers.

The most elegant fix would be to have separate entry points for
various exceptions, but that seems to be an architectural issue.

Thanks,

	tglx



  reply	other threads:[~2013-07-01 22:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-01 16:04 [PATCH 0/5] metag: smp/hotplug fixes James Hogan
2013-07-01 16:04 ` [PATCH 1/5] metag: use clear_tasks_mm_cpumask() James Hogan
2013-07-01 16:04 ` [PATCH 2/5] metag: smp: enable irqs after set_cpu_online James Hogan
2013-07-01 21:42   ` Thomas Gleixner
2013-07-02  5:57   ` Srivatsa S. Bhat
2013-07-01 16:04 ` [PATCH 3/5] metag: smp: don't spin waiting for CPU to start James Hogan
2013-07-01 21:46   ` Thomas Gleixner
2013-07-01 22:02     ` James Hogan
2013-07-02  6:12   ` Srivatsa S. Bhat
2013-07-01 16:04 ` [PATCH 4/5] metag: kick: prevent nested kick handlers James Hogan
2013-07-01 21:51   ` Thomas Gleixner
2013-07-01 22:17     ` James Hogan
2013-07-01 22:56       ` Thomas Gleixner [this message]
2013-07-02  0:00         ` James Hogan
2013-07-01 16:04 ` [PATCH 5/5] metag: cpu hotplug: route_irq: preserve irq mask James Hogan
2013-07-01 21:51   ` Thomas Gleixner
2013-07-02  6:16   ` Srivatsa S. Bhat
2013-07-02  9:59     ` James Hogan

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=alpine.DEB.2.02.1307020022570.4013@ionos.tec.linutronix.de \
    --to=tglx@linutronix.de \
    --cc=james.hogan@imgtec.com \
    --cc=linux-kernel@vger.kernel.org \
    /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®