From patchwork Mon Nov 9 11:47:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 11891343 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2DC7B1130 for ; Mon, 9 Nov 2020 11:47:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9BEE620789 for ; Mon, 9 Nov 2020 11:47:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BEE620789 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B28ED6B0036; Mon, 9 Nov 2020 06:47:35 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id ABF0A6B005D; Mon, 9 Nov 2020 06:47:35 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9EE626B0068; Mon, 9 Nov 2020 06:47:35 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0163.hostedemail.com [216.40.44.163]) by kanga.kvack.org (Postfix) with ESMTP id 72F346B0036 for ; Mon, 9 Nov 2020 06:47:35 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 1B9BD3622 for ; Mon, 9 Nov 2020 11:47:35 +0000 (UTC) X-FDA: 77464704870.16.spy85_4706bca272ec Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id EC5F5100E690B for ; Mon, 9 Nov 2020 11:47:34 +0000 (UTC) X-Spam-Summary: 1,0,0,e8c0d7373d05ca58,d41d8cd98f00b204,alex.shi@linux.alibaba.com,,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1261:1345:1431:1437:1534:1541:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2559:2562:2731:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3870:3872:4250:4321:4384:4385:4395:5007:6261:6671:7208:7903:8603:9113:10004:11026:11658:11914:12043:12297:12438:12555:12679:12895:12986:13007:13069:13153:13228:13311:13357:13846:14181:14384:14721:21060:21080:21433:21451:21627:30054:30064,0,RBL:115.124.30.130:@linux.alibaba.com:.lbl8.mailshell.net-62.20.2.100 64.201.201.201;04yfqkxcx44tbchfjtqps5781hhkjop1epqby73pzffg6j8xnmusuyo36gugr1t.ruhkamdnxrice6kf1spkqaj3tu6r3g3sqzgzjm9jptip6ir71yp77zbdm9cnzhh.g-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:70,LUA_SUMMARY:none X-HE-Tag: spy85_4706bca272ec X-Filterd-Recvd-Size: 2747 Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Mon, 9 Nov 2020 11:47:32 +0000 (UTC) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R931e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04400;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=6;SR=0;TI=SMTPD_---0UEjNPeQ_1604922442; Received: from aliy8.localdomain(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0UEjNPeQ_1604922442) by smtp.aliyun-inc.com(127.0.0.1); Mon, 09 Nov 2020 19:47:22 +0800 From: Alex Shi To: linmiaohe@huawei.com, akpm@linux-foundation.org Cc: "Darrick J. Wong" , Hugh Dickins , linux-mm@kvack.org , linux-kernel@vger.kernel.org Subject: [REF PATCH] mm/swap: fix swapon failure Date: Mon, 9 Nov 2020 19:47:16 +0800 Message-Id: <1604922436-16597-1-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 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: One of my VM guest has a swapon issue: root #swapon -v -f /swap1 swapon /swap1 swapon: /swap1: found swap signature: version 1, page-size 4, same byte order swapon: /swap1: pagesize=4096, swapsize=1607467008, devsize=1607467008 swapon: /swap1: swapon failed: Invalid argument and bisection report commit 822bca52ee7e "mm/swapfile.c: fix potential memory leak in sys_swapon" cause the trouble. Go through the context I found the exit_swap_address_space(p->type) shouldn't be used in good result path. So just move it to error path. Fixes: 822bca52ee7e ("mm/swapfile.c: fix potential memory leak in sys_swapon") Signed-off-by: Alex Shi Cc: Andrew Morton Cc: "Darrick J. Wong" Cc: Miaohe Lin Cc: Hugh Dickins Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- mm/swapfile.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index c8966b8fc6ac..1ac1f737fee3 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3339,7 +3339,8 @@ static bool swap_discardable(struct swap_info_struct *si) error = inode_drain_writes(inode); if (error) { inode->i_flags &= ~S_SWAPFILE; - goto free_swap_address_space; + exit_swap_address_space(p->type); + goto bad_swap_unlock_inode; } mutex_lock(&swapon_mutex); @@ -3364,8 +3365,6 @@ static bool swap_discardable(struct swap_info_struct *si) error = 0; goto out; -free_swap_address_space: - exit_swap_address_space(p->type); bad_swap_unlock_inode: inode_unlock(inode); bad_swap: