Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

net: don't use in_atomic() in gfp_any()

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

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

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 <>
Signed-off-by: David S. Miller <>
  • Loading branch information...
commit 99709372736a216f99eb32b76fba835a2bfc93a8 1 parent fb08867
Andrew Morton authored davem330 committed

Showing 1 changed file with 1 addition and 1 deletion. Show diff stats Hide diff stats

  1. +1 1  include/net/sock.h
2  include/net/sock.h
@@ -1308,7 +1308,7 @@ static inline int sock_writeable(const struct sock *sk)
1308 1308
1309 1309 static inline gfp_t gfp_any(void)
1310 1310 {
1311   - return in_atomic() ? GFP_ATOMIC : GFP_KERNEL;
  1311 + return in_softirq() ? GFP_ATOMIC : GFP_KERNEL;
1312 1312 }
1313 1313
1314 1314 static inline long sock_rcvtimeo(const struct sock *sk, int noblock)

0 comments on commit 9970937

Please sign in to comment.
Something went wrong with that request. Please try again.