From patchwork Wed Feb 11 21:27:19 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 22941 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by ozlabs.org (Postfix) with ESMTP id B52F1DDDAD for ; Thu, 12 Feb 2009 08:28:21 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758667AbZBKV2T (ORCPT ); Wed, 11 Feb 2009 16:28:19 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758271AbZBKV2R (ORCPT ); Wed, 11 Feb 2009 16:28:17 -0500 Received: from smtp1.linux-foundation.org ([140.211.169.13]:51475 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758667AbZBKV2Q (ORCPT ); Wed, 11 Feb 2009 16:28:16 -0500 Received: from imap1.linux-foundation.org (imap1.linux-foundation.org [140.211.169.55]) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id n1BLRJPs021029 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 11 Feb 2009 13:27:20 -0800 Received: from localhost.localdomain (localhost [127.0.0.1]) by imap1.linux-foundation.org (8.13.5.20060308/8.13.5/Debian-3ubuntu1.1) with ESMTP id n1BLRJeJ031575; Wed, 11 Feb 2009 13:27:19 -0800 Message-Id: <200902112127.n1BLRJeJ031575@imap1.linux-foundation.org> Subject: [patch 1/2] net: don't use in_atomic() in gfp_any() To: davem@davemloft.net Cc: netdev@vger.kernel.org, akpm@linux-foundation.org, andi@firstfloor.org From: akpm@linux-foundation.org Date: Wed, 11 Feb 2009 13:27:19 -0800 X-Spam-Status: No, hits=-3.442 required=5 tests=AWL, BAYES_00, OSDL_HEADER_SUBJECT_BRACKETED X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.13 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Andrew Morton 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 Cc: "David S. Miller" Signed-off-by: Andrew Morton --- 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)