From patchwork Wed Apr 16 04:03:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 3997561 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9AFA69F2BA for ; Wed, 16 Apr 2014 04:23:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D547120200 for ; Wed, 16 Apr 2014 04:23:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF4472013D for ; Wed, 16 Apr 2014 04:23:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753609AbaDPETF (ORCPT ); Wed, 16 Apr 2014 00:19:05 -0400 Received: from cantor2.suse.de ([195.135.220.15]:38828 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751554AbaDPETC (ORCPT ); Wed, 16 Apr 2014 00:19:02 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 23AEDAB0E; Wed, 16 Apr 2014 04:19:01 +0000 (UTC) From: NeilBrown To: linux-mm@kvack.org, linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 16 Apr 2014 14:03:36 +1000 Subject: [PATCH 10/19] NET: set PF_FSTRANS while holding sk_lock Cc: xfs@oss.sgi.com Cc: netdev@vger.kernel.org Message-ID: <20140416040336.10604.96000.stgit@notabene.brown> In-Reply-To: <20140416033623.10604.69237.stgit@notabene.brown> References: <20140416033623.10604.69237.stgit@notabene.brown> User-Agent: StGit/0.16 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP sk_lock can be taken while reclaiming memory (in nfsd for loop-back NFS mounts, and presumably in nfs), and memory can be allocated while holding sk_lock, at least via: inet_listen -> inet_csk_listen_start ->reqsk_queue_alloc So to avoid deadlocks, always set PF_FSTRANS while holding sk_lock. This deadlock was found by lockdep. Signed-off-by: NeilBrown --- include/net/sock.h | 1 + net/core/sock.c | 2 ++ 2 files changed, 3 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/net/sock.h b/include/net/sock.h index b9586a137cad..27c355637e44 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -324,6 +324,7 @@ struct sock { #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr socket_lock_t sk_lock; + unsigned int sk_pflags; /* process flags before taking lock */ struct sk_buff_head sk_receive_queue; /* * The backlog queue is special, it is always used with diff --git a/net/core/sock.c b/net/core/sock.c index cf9bd24e4099..8bc677ef072e 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2341,6 +2341,7 @@ void lock_sock_nested(struct sock *sk, int subclass) /* * The sk_lock has mutex_lock() semantics here: */ + current_set_flags_nested(&sk->sk_pflags, PF_FSTRANS); mutex_acquire(&sk->sk_lock.dep_map, subclass, 0, _RET_IP_); local_bh_enable(); } @@ -2352,6 +2353,7 @@ void release_sock(struct sock *sk) * The sk_lock has mutex_unlock() semantics: */ mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_); + current_restore_flags_nested(&sk->sk_pflags, PF_FSTRANS); spin_lock_bh(&sk->sk_lock.slock); if (sk->sk_backlog.tail)