From patchwork Tue Sep 8 23:40:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 7143801 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0F958BEEC1 for ; Tue, 8 Sep 2015 23:41:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 26A81205F5 for ; Tue, 8 Sep 2015 23:41:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0986F20459 for ; Tue, 8 Sep 2015 23:41:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754135AbbIHXks (ORCPT ); Tue, 8 Sep 2015 19:40:48 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:34465 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753283AbbIHXkr (ORCPT ); Tue, 8 Sep 2015 19:40:47 -0400 Received: by padhy16 with SMTP id hy16so135230055pad.1; Tue, 08 Sep 2015 16:40:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=qgOM0TzJfOUSJQfLJ53HwbbSuwMfN4SOUHpFkTR7Vh4=; b=z9DT3X2yp04TPeDMc637MGvTmVw0avAVwSA1ATMLVqjD1gyStmbtPCOBtIYKSjUj1J ///5NDU9Zhs7ukRhVM0SLIoNH4pMNxMNvxj04JAOLD8nsjnHpVGBb2cjOhQudkTMxEab ykQwpjSsGjLVo5lksDLAEWmrGeA0AJjyw/JIVxqHBDKCdkxG50jUR3NTaujYYAiHAT8w QEltYPNOCDK6cQNp23SZclLhBw3dpoXgRQgXf5ts4WZRieth2jCmqcvhZRK6aSAiobsl U+2KaO5M2cAGFvsrNFCASHY7xzC+EkW8jbZsOH9KLXLLtMC79i/VjwRyLTGSXdo7WqqU SX4g== X-Received: by 10.68.211.42 with SMTP id mz10mr64094961pbc.118.1441755646903; Tue, 08 Sep 2015 16:40:46 -0700 (PDT) Received: from dtor-ws ([2620:0:1000:1301:e82e:2251:baf8:cfa0]) by smtp.gmail.com with ESMTPSA id xd10sm4722439pab.25.2015.09.08.16.40.45 (version=TLS1_2 cipher=AES128-SHA256 bits=128/128); Tue, 08 Sep 2015 16:40:46 -0700 (PDT) Date: Tue, 8 Sep 2015 16:40:43 -0700 From: Dmitry Torokhov To: Alexander Viro Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] mnt: Silence lockdep warning about i_mutex, mount and reclaim Message-ID: <20150908234043.GA40851@dtor-ws> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_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 We are holding i_mutex over GFP_KERNEL allocation and that causes lockdep complain when we are using ashmem, because it's shrinker descends into shmem fallocate code which also tries to take i_mutex (usually different one): <4>[18464.436926] ================================= <4>[18464.441273] [ INFO: inconsistent lock state ] <4>[18464.445624] 3.18.0-06812-ga3d8c04 #1 Tainted: G U W <4>[18464.451359] --------------------------------- <4>[18464.455706] inconsistent {RECLAIM_FS-ON-W} -> {IN-RECLAIM_FS-W} usage. <4>[18464.462224] kswapd0/66 [HC0[0]:SC0[0]:HE1:SE1] takes: <4>[18464.467265] (&sb->s_type->i_mutex_key#9){+.+.?.}, at: [] shmem_fallocate+0x50/0x328 <4>[18464.476610] {RECLAIM_FS-ON-W} state was registered at: <4>[18464.481737] [] mark_lock+0x2dc/0x6a8 <4>[18464.487053] [] mark_held_locks+0x9c/0xc4 <4>[18464.492712] [] lockdep_trace_alloc+0xc4/0xd8 <4>[18464.498718] [] kmem_cache_alloc_trace+0x38/0x168 <4>[18464.505073] [] lock_mount+0x9c/0x184 <4>[18464.510386] [] do_add_mount+0x20/0xe4 <4>[18464.515784] [] do_mount+0xa10/0xa4c <4>[18464.521009] [] SyS_mount+0x84/0xc0 <4>[18464.526146] [] el0_svc_naked+0x20/0x28 <4>[18464.531634] irq event stamp: 8877137 <4>[18464.535202] hardirqs last enabled at (8877137): [] mutex_trylock+0x190/0x1d0 <4>[18464.543900] hardirqs last disabled at (8877136): [] mutex_trylock+0x8c/0x1d0 <4>[18464.552508] softirqs last enabled at (8874674): [] __do_softirq+0x2b4/0x330 <4>[18464.561117] softirqs last disabled at (8874651): [] irq_exit+0x74/0xd0 <4>[18464.569205] <4>[18464.569205] other info that might help us debug this: <4>[18464.575723] Possible unsafe locking scenario: <4>[18464.575723] <4>[18464.581632] CPU0 <4>[18464.584070] ---- <4>[18464.586509] lock(&sb->s_type->i_mutex_key#9); <4>[18464.591056] <4>[18464.593667] lock(&sb->s_type->i_mutex_key#9); <4>[18464.598387] <4>[18464.598387] *** DEADLOCK *** <4>[18464.598387] <4>[18464.604298] 2 locks held by kswapd0/66: <4>[18464.608124] #0: (shrinker_rwsem){++++..}, at: [] shrink_slab+0x40/0x104 <4>[18464.616506] #1: (ashmem_mutex){+.+.+.}, at: [] ashmem_shrink_scan+0x3c/0x128 <4>[18464.625324] <4>[18464.625324] stack backtrace: <4>[18464.629675] CPU: 1 PID: 66 Comm: kswapd0 Tainted: G U W 3.18.0-06812-ga3d8c04 #1 <4>[18464.637926] Hardware name: Google Tegra210 Smaug Rev 1+ (DT) <0>[18464.643575] Call trace: <4>[18464.646016] [] dump_backtrace+0x0/0x10c <4>[18464.651408] [] show_stack+0x10/0x1c <4>[18464.656452] [] dump_stack+0x74/0x94 <4>[18464.661494] [] print_usage_bug.part.35+0x270/0x28c <4>[18464.667838] [] mark_lock+0x44c/0x6a8 <4>[18464.672969] [] __lock_acquire+0x98c/0x191c <4>[18464.678620] [] lock_acquire+0xec/0x128 <4>[18464.683923] [] mutex_lock_nested+0x58/0x354 <4>[18464.689659] [] shmem_fallocate+0x4c/0x328 <4>[18464.695223] [] ashmem_shrink_scan+0x8c/0x128 <4>[18464.701046] [] shrink_slab_node+0x178/0x260 <4>[18464.706783] [] shrink_slab+0x80/0x104 <4>[18464.712000] [] balance_pgdat+0x310/0x4e4 <4>[18464.717477] [] kswapd+0x3a0/0x410 <4>[18464.722347] [] kthread+0xdc/0xe8 To silence it let's switch to using GFP_NOFS allocation when allocating new mount point. Signed-off-by: Dmitry Torokhov --- fs/namespace.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/namespace.c b/fs/namespace.c index 2b8aa15..25f72d0 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -749,7 +749,12 @@ static struct mountpoint *new_mountpoint(struct dentry *dentry) struct mountpoint *mp; int ret; - mp = kmalloc(sizeof(struct mountpoint), GFP_KERNEL); + /* + * We are allocating as GFP_NOFS to appease lockdep: + * since we are holding i_mutex we should not try to + * recurse into filesystem code. + */ + mp = kmalloc(sizeof(struct mountpoint), GFP_NOFS); if (!mp) return ERR_PTR(-ENOMEM);