* [patch 1/2] net: don't use in_atomic() in gfp_any()
@ 2009-02-11 21:27 akpm
2009-02-11 21:38 ` Tetsuo Handa
2009-02-13 0:43 ` David Miller
0 siblings, 2 replies; 6+ messages in thread
From: akpm @ 2009-02-11 21:27 UTC (permalink / raw)
To: davem; +Cc: netdev, akpm, andi
From: Andrew Morton <akpm@linux-foundation.org>
The problem is that in_atomic() will return false inside spinlocks if
CONFIG_PREEMPT=n. This will lead to deadlockable GFP_KERNEL allocations
from spinlocked regions.
Secondly, if CONFIG_PREEMPT=y, this bug solves itself because networking
will instead use GFP_ATOMIC from this callsite. Hence we won't get the
might_sleep() debugging warnings which would have informed us of the buggy
callsites.
Solve both these problems by switching to in_interrupt(). Now, if someone
runs a gfp_any() allocation from inside spinlock we will get the warning
if CONFIG_PREEMPT=y.
I reviewed all callsites and most of them were too complex for my little
brain and none of them documented their interface requirements. I have no
idea what this patch will do.
Cc: Andi Kleen <andi@firstfloor.org>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
include/net/sock.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff -puN include/net/sock.h~net-dont-use-in_atomic-in-gfp_any include/net/sock.h
--- a/include/net/sock.h~net-dont-use-in_atomic-in-gfp_any
+++ a/include/net/sock.h
@@ -1313,7 +1313,7 @@ static inline int sock_writeable(const s
static inline gfp_t gfp_any(void)
{
- return in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
+ return in_softirq() ? GFP_ATOMIC : GFP_KERNEL;
}
static inline long sock_rcvtimeo(const struct sock *sk, int noblock)
_
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch 1/2] net: don't use in_atomic() in gfp_any()
2009-02-11 21:27 [patch 1/2] net: don't use in_atomic() in gfp_any() akpm
@ 2009-02-11 21:38 ` Tetsuo Handa
2009-02-11 21:48 ` Andrew Morton
2009-02-11 21:49 ` Andrew Morton
2009-02-13 0:43 ` David Miller
1 sibling, 2 replies; 6+ messages in thread
From: Tetsuo Handa @ 2009-02-11 21:38 UTC (permalink / raw)
To: akpm; +Cc: netdev
Andrew Morton wrote:
> Solve both these problems by switching to in_interrupt(). Now, if someone
> runs a gfp_any() allocation from inside spinlock we will get the warning
> if CONFIG_PREEMPT=y.
> static inline gfp_t gfp_any(void)
> {
> - return in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
> + return in_softirq() ? GFP_ATOMIC : GFP_KERNEL;
> }
sed -i -e 's/in_softirq/in_interrupt/' ?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch 1/2] net: don't use in_atomic() in gfp_any()
2009-02-11 21:38 ` Tetsuo Handa
@ 2009-02-11 21:48 ` Andrew Morton
2009-02-11 22:02 ` David Miller
2009-02-11 21:49 ` Andrew Morton
1 sibling, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2009-02-11 21:48 UTC (permalink / raw)
To: Tetsuo Handa; +Cc: netdev
On Thu, 12 Feb 2009 06:38:55 +0900
Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:
> Andrew Morton wrote:
> > Solve both these problems by switching to in_interrupt(). Now, if someone
> > runs a gfp_any() allocation from inside spinlock we will get the warning
> > if CONFIG_PREEMPT=y.
>
> > static inline gfp_t gfp_any(void)
> > {
> > - return in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
> > + return in_softirq() ? GFP_ATOMIC : GFP_KERNEL;
> > }
> sed -i -e 's/in_softirq/in_interrupt/' ?
heh, good question.
I did all my testing with in_softirq() - the changelog didn't catch up.
Is gfp_any() supposed to be usable from hardirq context?
If so, we should use in_interrupt().
If not, we should use in_softirq(), and we'll then get might_sleep()
warnings if anyone uses gfp_any() from hard irq context.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch 1/2] net: don't use in_atomic() in gfp_any()
2009-02-11 21:38 ` Tetsuo Handa
2009-02-11 21:48 ` Andrew Morton
@ 2009-02-11 21:49 ` Andrew Morton
1 sibling, 0 replies; 6+ messages in thread
From: Andrew Morton @ 2009-02-11 21:49 UTC (permalink / raw)
To: Tetsuo Handa; +Cc: netdev, David S. Miller, Andi Kleen
Resend with cc's restored. Please DO NOT edit the Cc: line :(
On Thu, 12 Feb 2009 06:38:55 +0900
Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:
> Andrew Morton wrote:
> > Solve both these problems by switching to in_interrupt(). Now, if someone
> > runs a gfp_any() allocation from inside spinlock we will get the warning
> > if CONFIG_PREEMPT=y.
>
> > static inline gfp_t gfp_any(void)
> > {
> > - return in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
> > + return in_softirq() ? GFP_ATOMIC : GFP_KERNEL;
> > }
> sed -i -e 's/in_softirq/in_interrupt/' ?
heh, good question.
I did all my testing with in_softirq() - the changelog didn't catch up.
Is gfp_any() supposed to be usable from hardirq context?
If so, we should use in_interrupt().
If not, we should use in_softirq(), and we'll then get might_sleep()
warnings if anyone uses gfp_any() from hard irq context.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch 1/2] net: don't use in_atomic() in gfp_any()
2009-02-11 21:48 ` Andrew Morton
@ 2009-02-11 22:02 ` David Miller
0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2009-02-11 22:02 UTC (permalink / raw)
To: akpm; +Cc: penguin-kernel, netdev
From: Andrew Morton <akpm@linux-foundation.org>
Date: Wed, 11 Feb 2009 13:48:42 -0800
> Is gfp_any() supposed to be usable from hardirq context?
>
> If so, we should use in_interrupt().
>
> If not, we should use in_softirq(), and we'll then get might_sleep()
> warnings if anyone uses gfp_any() from hard irq context.
It never will be used in hardware IRQ context, at least
in the networking.
And all uses in the tree are.. networking :-)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch 1/2] net: don't use in_atomic() in gfp_any()
2009-02-11 21:27 [patch 1/2] net: don't use in_atomic() in gfp_any() akpm
2009-02-11 21:38 ` Tetsuo Handa
@ 2009-02-13 0:43 ` David Miller
1 sibling, 0 replies; 6+ messages in thread
From: David Miller @ 2009-02-13 0:43 UTC (permalink / raw)
To: akpm; +Cc: netdev, andi
From: akpm@linux-foundation.org
Date: Wed, 11 Feb 2009 13:27:19 -0800
> The problem is that in_atomic() will return false inside spinlocks if
> CONFIG_PREEMPT=n. This will lead to deadlockable GFP_KERNEL allocations
> from spinlocked regions.
>
> Secondly, if CONFIG_PREEMPT=y, this bug solves itself because networking
> will instead use GFP_ATOMIC from this callsite. Hence we won't get the
> might_sleep() debugging warnings which would have informed us of the buggy
> callsites.
>
> Solve both these problems by switching to in_interrupt(). Now, if someone
> runs a gfp_any() allocation from inside spinlock we will get the warning
> if CONFIG_PREEMPT=y.
>
> I reviewed all callsites and most of them were too complex for my little
> brain and none of them documented their interface requirements. I have no
> idea what this patch will do.
>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Applied.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-02-13 0:43 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-11 21:27 [patch 1/2] net: don't use in_atomic() in gfp_any() akpm
2009-02-11 21:38 ` Tetsuo Handa
2009-02-11 21:48 ` Andrew Morton
2009-02-11 22:02 ` David Miller
2009-02-11 21:49 ` Andrew Morton
2009-02-13 0:43 ` David Miller
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).