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: 3997551 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 3B0F09F2BA for ; Wed, 16 Apr 2014 04:23:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 743ED20200 for ; Wed, 16 Apr 2014 04:23:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A0E6E2013D for ; Wed, 16 Apr 2014 04:23:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753801AbaDPETM (ORCPT ); Wed, 16 Apr 2014 00:19:12 -0400 Received: from cantor2.suse.de ([195.135.220.15]:38838 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753794AbaDPETI (ORCPT ); Wed, 16 Apr 2014 00:19:08 -0400 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 272B5AB0E; Wed, 16 Apr 2014 04:19:08 +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 11/19] FS: set PF_FSTRANS while holding mmap_sem in exec.c Cc: xfs@oss.sgi.com Message-ID: <20140416040336.10604.31309.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 Because mmap_sem is sometimes(*) taken while holding a sock lock, and the sock lock might be needed for reclaim (at least when loop-back NFS is active), we must not block on FS reclaim while mmap_sem is held. exec.c allocates memory while holding mmap_sem, and so needs PF_FSTRANS protection. * lockdep reports: [ 57.653355] [] lock_acquire+0xa8/0x1f0 [ 57.653355] [] might_fault+0x84/0xb0 [ 57.653355] [] do_ip_setsockopt.isra.18+0x93d/0xed0 [ 57.653355] [] ip_setsockopt+0x27/0x90 [ 57.653355] [] udp_setsockopt+0x16/0x30 [ 57.653355] [] sock_common_setsockopt+0xf/0x20 [ 57.653355] [] SyS_setsockopt+0x5e/0xc0 [ 57.653355] [] system_call_fastpath+0x16/0x1b to explain why mmap_sem might be taken while sock lock is held. Signed-off-by: NeilBrown --- fs/exec.c | 6 ++++++ 1 file changed, 6 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/fs/exec.c b/fs/exec.c index 3d78fccdd723..2c70a03ddb2b 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -652,6 +652,7 @@ int setup_arg_pages(struct linux_binprm *bprm, unsigned long stack_size; unsigned long stack_expand; unsigned long rlim_stack; + unsigned int pflags; #ifdef CONFIG_STACK_GROWSUP /* Limit stack size to 1GB */ @@ -688,6 +689,7 @@ int setup_arg_pages(struct linux_binprm *bprm, down_write(&mm->mmap_sem); vm_flags = VM_STACK_FLAGS; + current_set_flags_nested(&pflags, PF_FSTRANS); /* * Adjust stack execute permissions; explicitly enable for @@ -741,6 +743,7 @@ int setup_arg_pages(struct linux_binprm *bprm, ret = -EFAULT; out_unlock: + current_restore_flags_nested(&pflags, PF_FSTRANS); up_write(&mm->mmap_sem); return ret; } @@ -1369,6 +1372,7 @@ int search_binary_handler(struct linux_binprm *bprm) bool need_retry = IS_ENABLED(CONFIG_MODULES); struct linux_binfmt *fmt; int retval; + unsigned int pflags; /* This allows 4 levels of binfmt rewrites before failing hard. */ if (bprm->recursion_depth > 5) @@ -1381,6 +1385,7 @@ int search_binary_handler(struct linux_binprm *bprm) retval = -ENOENT; retry: read_lock(&binfmt_lock); + current_set_flags_nested(&pflags, PF_FSTRANS); list_for_each_entry(fmt, &formats, lh) { if (!try_module_get(fmt->module)) continue; @@ -1396,6 +1401,7 @@ int search_binary_handler(struct linux_binprm *bprm) read_lock(&binfmt_lock); put_binfmt(fmt); } + current_restore_flags_nested(&pflags, PF_FSTRANS); read_unlock(&binfmt_lock); if (need_retry && retval == -ENOEXEC) {