netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Neil Horman <nhorman@tuxdriver.com>
To: Bart Van Assche <bvanassche@acm.org>
Cc: David Miller <davem@davemloft.net>,
	netdev@vger.kernel.org, Ingo Molnar <mingo@redhat.com>
Subject: Re: [PATCH RFC] spinlock: split out debugging check from spin_lock_mutex
Date: Mon, 15 Apr 2013 10:16:10 -0400	[thread overview]
Message-ID: <20130415141610.GA3505@hmsreliant.think-freely.org> (raw)
In-Reply-To: <51690AAB.1030102@acm.org>

On Sat, Apr 13, 2013 at 09:35:07AM +0200, Bart Van Assche wrote:
> On 04/12/13 20:45, Neil Horman wrote:
> >On Fri, Apr 12, 2013 at 04:01:04PM +0200, Bart Van Assche wrote:
> >>On 04/12/13 13:32, Neil Horman wrote:
> >>I think there is another issue with invoking mutex_trylock() and mutex_unlock()
> >>from IRQ context: as far as I can see if CONFIG_DEBUG_MUTEXES is disabled
> >>__mutex_unlock_common_slowpath() uses spin_lock() to lock mutex.wait_lock and
> >>hence invoking mutex_unlock() from both non-IRQ and IRQ context is not safe.
> >>Any thoughts about that ?
> >>
> >Yeah, its ugly, but in this specific case, its ok.  the netpoll code (in
> >netpoll_send_skb disables irq on the local cpu before entering the netpoll code
> >path any further, so whenver we frob this mutex from the local cpu, we're
> >guaranteed not to get pre-empted by an irq.
> 
> As far as I know it is neither allowed nor safe to call
> netpoll_rx_disable() with IRQs disabled. But that function can lock
> the dev_lock mutex. What do you think will happen with
> CONFIG_DEBUG_MUTEXES=n if an interrupt occurs during the
> mutex_lock(&ni->dev_lock) call, that mutex_lock() call has already
> locked the mutex-internal spin lock via spin_lock() and
> mutex_trylock() is invoked from inside the interrupt ? Can that
> result in anything else than deadlock and "CPU stuck" messages ?
> 
> Thanks,
> 
> Bart.
> 


So I've been doing some reading over the weekend, and as a result I've been
developing some concerns about how mutex_trylock works.  I'm still convinced its
safe to use with the changes we're discussing here, but all the documentation
regarding mutex_trylock seems to say it simply shouldn't be used in interrupt
context (though it never goes into detail as to why).  As near as I can tell,
its because the spin locks that mutexes use are locked without disabling
interrupts (the implication being that, as we see in the patch we're looking at
here), you're safe if you disable irqs independently).  Ironically, Ingo patched
the mutex debug variants back in 2006 in commit
1fb00c6cbd8356f43b46322742f3c01c2a1f02da to disable irqs to work around a bug,
the result being that the debug variant gives you a WARNING about using
mutex_trylock in interrupts, when its actually safe, while the non-debug variant
provides no warning, but is actually prone to deadlock.

There are a few other use cases in the kernel in which mutex_trylock may be used
in an interrupt context (crash_kexec being the most notable, as its used for the
same purposes that we're using it in netpoll, and where I got the inspiration
for my previous netpoll changes.

The more I look at this, the more I'm starting to think that, in addition to the
debug changes I've got proposed here, we should additionally convert the
non-debug spin_lock_mutex variants to disable irqs while manipulating the
mutexes.  That would make mutex_trylock safe, and give us a nice mechanism to
create exclusion between sleepable paths that should not run atomically and
interrupt context paths.

Ingo, can you comment on these thoughts above please.  I'd like to get your
opinion on this prior to spinning up a new patch if I could please.

Thanks!
Neil

  parent reply	other threads:[~2013-04-15 14:16 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-11 13:42 Netpoll triggers soft lockup Bart Van Assche
2013-04-11 14:08 ` Neil Horman
2013-04-11 15:18 ` [PATCH RFC] spinlock: split out debugging check from spin_lock_mutex Neil Horman
2013-04-11 15:54   ` Christoph Paasch
2013-04-11 17:04     ` Neil Horman
2013-04-11 17:51       ` Christoph Paasch
2013-04-11 15:57   ` Eric Dumazet
2013-04-11 16:56     ` Neil Horman
2013-04-11 17:31   ` Bart Van Assche
2013-04-11 17:52     ` Neil Horman
2013-04-11 19:14     ` Neil Horman
2013-04-12  6:27       ` Bart Van Assche
2013-04-12 11:32         ` Neil Horman
2013-04-12 14:01           ` Bart Van Assche
2013-04-12 18:45             ` Neil Horman
2013-04-13  7:35               ` Bart Van Assche
2013-04-13 12:03                 ` Neil Horman
2013-04-15 14:16                 ` Neil Horman [this message]
     [not found]                   ` <CAO+b5-oBfH3M0dnrQSs-p1BF_5hKy2tsU-dD=EP9+S=iqPs5ew@mail.gmail.com>
2013-04-16 17:24                     ` Neil Horman
2013-04-18 19:29                       ` Neil Horman
2013-04-22 20:12                         ` Neil Horman
     [not found]                           ` <CAO+b5-r5jVJNZWuREUH5MQ3baeSPR8fVV1p9pMnukmiZd9nRhg@mail.gmail.com>
2013-04-23 13:23                             ` Neil Horman
     [not found]                               ` <CAO+b5-rQPyO9QE9v+oQTeo+G-ftcsehSB5=63AZ13QW4EJ1X0Q@mail.gmail.com>
2013-04-23 13:44                                 ` Neil Horman
2013-04-23 17:33                                   ` David Miller
2013-04-23 17:50                                     ` Neil Horman
2013-04-27 18:53                                       ` bvba Bart Van Assche
2013-04-29 18:13                                         ` Neil Horman
2013-04-29 19:12                                           ` Bart Van Assche
2013-04-30 15:35                                           ` [PATCH RFC] netpoll: convert mutex into a semaphore Neil Horman
2013-05-01 19:00                                             ` David Miller
2013-05-01 19:34                                               ` Neil Horman
2013-04-19  8:38             ` [PATCH RFC] spinlock: split out debugging check from spin_lock_mutex Ingo Molnar
2013-04-19 12:52               ` Neil Horman
2013-04-28  2:34 Neil Horman

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=20130415141610.GA3505@hmsreliant.think-freely.org \
    --to=nhorman@tuxdriver.com \
    --cc=bvanassche@acm.org \
    --cc=davem@davemloft.net \
    --cc=mingo@redhat.com \
    --cc=netdev@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;
as well as URLs for NNTP newsgroup(s).