mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: "Richard B. Johnson" <linux-os@analogic.com>
Cc: Timur Tabi <timur.tabi@ammasso.com>,
	Denis Vlasenko <vda@ilport.com.ua>,
	Arjan van de Ven <arjan@infradead.org>,
	Jens Axboe <axboe@suse.de>,
	linux-kernel@vger.kernel.org
Subject: Re: kmalloc without GFP_xxx?
Date: Wed, 29 Jun 2005 14:07:56 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.58.0506291349510.22775@localhost.localdomain> (raw)
In-Reply-To: <Pine.LNX.4.61.0506291337230.5067@chaos.analogic.com>


On Wed, 29 Jun 2005, Richard B. Johnson wrote:

> >
> > task 1:
> >  spin_lock(&non_irq_lock);
> >
> > task 2:
> >
> >  spin_lock_irqsave(&some_irq_used_lock);
> >  spin_lock(&non_irq_lock);
> >
> > Here we see that task 2 can spin with interrupts off, while the first task
> > is servicing an interrupt, and God forbid if the IRQ handler sends some
> > kind of SMP signal to the CPU running task 2 since that would be a
> > deadlock.  Granted, this is a hypothetical situation, but makes using
> > spin_lock with interrupts enabled a little scary.
> >
>
> But it wouldn't deadlock! It would just spin until the guy on
> another CPU that had the lock unlocked.
>

Since Timur specified that spin_lock is used when you know that the lock
is not used in an interrupt, I'll continue as if that was the case.

This is a deadlock, because sending most SMP signals expect a reply when
it is received, and will wait until it gets it. Here's a more detailed
version.

CPU 1: running task 1

   spin_lock(&non_irq_lock);

on CPU 2: running task 2

   spin_lock_irqsave(&some_irq_used_lock); /* interrupts now off */
   spin_lock(&non_irq_lock);  /* blocked and spinning waiting for task 1*/

back on CPU 1:

   interrupt goes off a preempts task 1 before it releases the
   non_irq_lock.

   Calls some stupid ISR that needs to send a signal to the other CPU.
   Sends signal and waits for a reply. (for example the flush_tlb_others)

Now we have a deadlock.  The interrupt on CPU 1 is waiting for a response
after sending an IPI to CPU 2, but CPU 2 is stuck spinning with interrupts
disabled and wont ever respond because the lock it is waiting for is held
by task 1 on CPU 1 that was preempted by the interrupt that will never
return.

This is probably the reason it is not allowed to call most IPIs from
interrupt or bottom half context.

 > FYI, spin_lock() is supposed to be used in an interrupt where it
> is already known that the interrupts are OFF so you don't need
> to save/restore flags because you know the condition. IFF the
> ISR were to enable interrupts, with a spin-lock held (bad practice),
> it still wouldn't deadlock, it's just that the entire system could
> potentially degenerate into a poll-mode, spin in the ISR, mode
> with awful performance.

I stated earlier that the only times I use spin_lock is when I already
know that interrupts are off, and that includes ISRs.

-- Steve

  reply	other threads:[~2005-06-29 18:08 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-29 11:02 Denis Vlasenko
2005-06-29 11:15 ` Arjan van de Ven
2005-06-29 11:20   ` Denis Vlasenko
2005-06-29 11:37     ` Arjan van de Ven
2005-06-29 13:44       ` Steven Rostedt
2005-06-29 14:14         ` Denis Vlasenko
2005-06-29 14:23           ` Jörn Engel
2005-06-29 14:53             ` Steven Rostedt
2005-06-29 15:10               ` Jörn Engel
2005-06-29 15:48                 ` Steven Rostedt
2005-06-29 15:54                   ` Jörn Engel
2005-06-29 16:04                     ` Steven Rostedt
2005-06-29 15:12           ` Oliver Neukum
2005-06-29 16:48           ` Timur Tabi
2005-06-29 17:22             ` Steven Rostedt
2005-06-29 17:43               ` Richard B. Johnson
2005-06-29 18:07                 ` Steven Rostedt [this message]
2005-06-30  7:52             ` Denis Vlasenko
2005-06-30  8:05               ` Steven Rostedt
2005-06-30  1:02         ` Benjamin Herrenschmidt
2005-06-30  6:02           ` Steven Rostedt
2005-06-29 11:15 ` Jens Axboe
2005-06-29 11:18   ` Denis Vlasenko
2005-06-29 11:25     ` Jens Axboe
2005-06-29 20:28 Manfred Spraul
2005-06-29 20:44 Manfred Spraul
2005-06-30  5:57 ` Steven Rostedt

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=Pine.LNX.4.58.0506291349510.22775@localhost.localdomain \
    --to=rostedt@goodmis.org \
    --cc=arjan@infradead.org \
    --cc=axboe@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-os@analogic.com \
    --cc=timur.tabi@ammasso.com \
    --cc=vda@ilport.com.ua \
    /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®