From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F411DC35254 for ; Mon, 10 Feb 2020 04:25:19 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B839B206ED for ; Mon, 10 Feb 2020 04:25:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="gloDvs3X" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B839B206ED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 474636B00A7; Sun, 9 Feb 2020 23:25:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 426226B00A9; Sun, 9 Feb 2020 23:25:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 314026B00AA; Sun, 9 Feb 2020 23:25:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0247.hostedemail.com [216.40.44.247]) by kanga.kvack.org (Postfix) with ESMTP id 1AAEE6B00A7 for ; Sun, 9 Feb 2020 23:25:19 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id BFE9E2AAE for ; Mon, 10 Feb 2020 04:25:18 +0000 (UTC) X-FDA: 76472927916.07.shape14_686b021089559 X-HE-Tag: shape14_686b021089559 X-Filterd-Recvd-Size: 6200 Received: from esa2.hgst.iphmx.com (esa2.hgst.iphmx.com [68.232.143.124]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Mon, 10 Feb 2020 04:25:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1581308720; x=1612844720; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=xCqR/3TqqcEaElnFbr8xy71PvTuhQoezMiXwBlsjsdk=; b=gloDvs3XLEhDwaGQ/ZKnwYDPkxRox+i+wH92V7DatRiC6KVVG/T0gzA6 ynbzzUxdrkawkV4YKgqomUHNBOuC0ONKI4A1zTwtBZFSXyAQ/abLOJyaK ZX6qndV3zxM+zqI4C1pAmWVQW0KrRrbithLZcvJkz9Kno/yufN5iqNAUW l4m0Vxjn6Ss9+4qisONU2t4sSjSMpxjWIkntba4IiGdvxb6sA0UuurYWR CVCNdeRK6+Ex97mbd8TthMI0LIBGFdJMEpf3gPNNyW7P/I5IOiatBz6Nt FLkXRiaRUcgXq7fVe4N3Og6lPPxr6h8PEhin2vaCPt1tHANLwmwvnFXLE g==; IronPort-SDR: PLDfVFkQqvici9+pP5iFBy5XinUHDEa3BZWIIVfuMT7UBDQ0dZoTSIp9ZuELU7rPurn6TsxIJ4 tU+my90zUX4EzyxanVCiMlleAXgI6AKiaUgQ6mYJUuMi/z2zaOx0FvHv3cE6nv4+Sdc0dXal03 TCefnL4lT9REcCwn2MWjZPVkvWaCoPWbEmCOJtw9wY0I6ABtBagiM7bfv8qkjSpgJEIpk/GVVt vSj2o5gpw7P+3D+zP60XkCBU1mEnDuoVBMRzG8OO1a99/xjnuY2zEEMPGG92A+K+mWIYt0KBnV XO4= X-IronPort-AV: E=Sophos;i="5.70,423,1574092800"; d="scan'208";a="231263232" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Feb 2020 12:25:17 +0800 IronPort-SDR: 34h578AlKaWJMgoe8sklS96AySIScke7qJZftrqI4seJ9p1K6Tbk8RQ9/YHqWY/hQNVYfCfhFd j3o01LQICeL448VuOVOdHhOQ7547hKbN/Xa8pRK4085NszwIGmCsYZNjc+ELmihCFtKkCOMJ8G pXAjtgP/SW9Yqhd7xy+QWMb8zk1OsnChBfeiZ0Uvakzkq8OkrvMGsNu7/gdESuo2jAVjV0aa+f 8vkdsEWhd+ISVrbW/0Id+fjtdyfcf43MCwI1yGQhQhnfQjcOIeD5xrbAN/p7bh8MJXCvvkT084 dTtN7B5LnLmACl3hGW4aIPCx Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2020 20:18:08 -0800 IronPort-SDR: l3Fa99Y5i8cW2YP21x0i6xbpTm6ZSnTYUZUMQC6VnbMeDU8f8rQtf0ZF5Udzvv0DxrmlIRxL/z mHn8dCywQlDLPmsAqxr48adS3BePeaMRgvltxOdEh7glhYhc/Ch2Hfv3hFRCpD6fbMGChH5bB8 hqKv22x4ykcTf9LHwaAYCD5NNgyU5DGcbjbDm02ig0se3fiHEjlyGUqRlLCd2zJEXBjm+yf0sQ npx3d8AKzSzgpa1T3meErCNiHjSAgPNlAt1EFefSzKgiq9KZXvWKPmhnDAM091yWuH6c142uDB lrs= WDCIronportException: Internal Received: from naota.dhcp.fujisawa.hgst.com ([10.149.52.155]) by uls-op-cesaip02.wdc.com with SMTP; 09 Feb 2020 20:25:14 -0800 Received: (nullmailer pid 2754475 invoked by uid 1000); Mon, 10 Feb 2020 04:25:14 -0000 Date: Mon, 10 Feb 2020 13:25:14 +0900 From: Naohiro Aota To: Andrew Morton Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, Christoph Hellwig , "Darrick J . Wong" Subject: Re: [PATCH v2] mm, swap: move inode_lock out of claim_swapfile Message-ID: <20200210042514.h3hhuqs2v3qketjy@naota.dhcp.fujisawa.hgst.com> References: <20200206090132.154869-1-naohiro.aota@wdc.com> <20200209201612.e5f234b357823df574104cb9@linux-foundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200209201612.e5f234b357823df574104cb9@linux-foundation.org> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sun, Feb 09, 2020 at 08:16:12PM -0800, Andrew Morton wrote: >On Thu, 6 Feb 2020 18:01:32 +0900 Naohiro Aota wrote: > >> claim_swapfile() currently keeps the inode locked when it is successful, or >> the file is already swapfile (with -EBUSY). And, on the other error cases, >> it does not lock the inode. >> >> This inconsistency of the lock state and return value is quite confusing >> and actually causing a bad unlock balance as below in the "bad_swap" >> section of __do_sys_swapon(). >> >> This commit fixes this issue by moving the inode_lock() and IS_SWAPFILE >> check out of claim_swapfile(). The inode is unlocked in >> "bad_swap_unlock_inode" section, so that the inode is ensured to be >> unlocked at "bad_swap". Thus, error handling codes after the locking now >> jumps to "bad_swap_unlock_inode" instead of "bad_swap". >> >> ===================================== >> WARNING: bad unlock balance detected! >> 5.5.0-rc7+ #176 Not tainted >> ------------------------------------- >> swapon/4294 is trying to release lock (&sb->s_type->i_mutex_key) at: >> [] __do_sys_swapon+0x94b/0x3550 >> but there are no more locks to release! >> >> other info that might help us debug this: >> no locks held by swapon/4294. >> >> stack backtrace: >> CPU: 5 PID: 4294 Comm: swapon Not tainted 5.5.0-rc7-BTRFS-ZNS+ #176 >> Hardware name: ASUS All Series/H87-PRO, BIOS 2102 07/29/2014 >> Call Trace: >> dump_stack+0xa1/0xea >> ? __do_sys_swapon+0x94b/0x3550 >> print_unlock_imbalance_bug.cold+0x114/0x123 >> ? __do_sys_swapon+0x94b/0x3550 >> lock_release+0x562/0xed0 >> ? kvfree+0x31/0x40 >> ? lock_downgrade+0x770/0x770 >> ? kvfree+0x31/0x40 >> ? rcu_read_lock_sched_held+0xa1/0xd0 >> ? rcu_read_lock_bh_held+0xb0/0xb0 >> up_write+0x2d/0x490 >> ? kfree+0x293/0x2f0 >> __do_sys_swapon+0x94b/0x3550 >> ? putname+0xb0/0xf0 >> ? kmem_cache_free+0x2e7/0x370 >> ? do_sys_open+0x184/0x3e0 >> ? generic_max_swapfile_size+0x40/0x40 >> ? do_syscall_64+0x27/0x4b0 >> ? entry_SYSCALL_64_after_hwframe+0x49/0xbe >> ? lockdep_hardirqs_on+0x38c/0x590 >> __x64_sys_swapon+0x54/0x80 >> do_syscall_64+0xa4/0x4b0 >> entry_SYSCALL_64_after_hwframe+0x49/0xbe >> RIP: 0033:0x7f15da0a0dc7 >> >> mm/swapfile.c | 41 ++++++++++++++++++++--------------------- >> 1 file changed, 20 insertions(+), 21 deletions(-) >> >> diff --git a/mm/swapfile.c b/mm/swapfile.c >> index bb3261d45b6a..2c4c349e1101 100644 >> --- a/mm/swapfile.c >> +++ b/mm/swapfile.c > >Look correct to me. > >But I don't think this code at the end of sys_swapon(): > > if (inode) > inode_unlock(inode); > >will ever execute? `inode' is always NULL here? On the successful case, inode is not NULL and unlocked here. >