Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp491268pxb; Wed, 3 Mar 2021 08:09:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxf7h+M6iI36wWNmUnUTsoS3sM1TaUTWMi28lqcVmzuayLwiMF32k4GMZHTltr0DWeuzJf3 X-Received: by 2002:a17:907:76ed:: with SMTP id kg13mr25122330ejc.99.1614787786817; Wed, 03 Mar 2021 08:09:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614787786; cv=none; d=google.com; s=arc-20160816; b=bzp32C5FU3PnixXHAaChY+nvcSDeCkVBFfqEpmdddKYC0+ro/8KfI0x1WLPqfMllrr kAzSrEOLrSQ3LqnH8dV9uihHWjYM83/h70JHxzXt8v09wjV9UWBNqoyeD37Vo0azUvMr 1J8XYwXXkadPwmfs8m/IJRgvVceh65btkBsfiId5bepuZRfzFni0ndtfhx2ViDYNiB0I BNZLuQbbHihb7sYhDPaTZNS+pJZxVBXITkpXeK4JDTEI91kHXxCPE/nuWckqqUunHykg 1tEQlLc2byeVulAQAbPglbuyZw2plp3EcMRw7FWpL4BCHHztuhGEtQJZr3aWGzgtCWSo voKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=68nBntRVoZLzfmOxnGlFOXlPjJh7B6SClstCsPyO07M=; b=hHT2qeHSIFkpKQD/qG2BP8KJ5Eit6j61vuI9nYhVQpeNHNB6CIUtoKeuoGJPtXtMao DCAUVydFQeFOPhXO+THb3SofsZ2G/7lJs8n6/arfeJ6kd0gwVlsPI7OQhcXcgbc1d1Tv aRV0oY/FTjBNY9HHmW+2neOWRIWFJKXyb1YSPdHPkubP7hr+8+5ZjlJeGj4uoxUnum3b Dno+Qt2iM7Dmulyqc85JtJVuMx7QrCaS3CKYolds8sSdNrJWQC80CUT1EgWcLbe7ntEM dHe7y4iCVWo5ZRUuj3TYnU0Ers+gzzAfHb9N3Fkv2l6GibCrusVz52l5tezVQTaOq8wa JAKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="k4e9h15/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c3si8063713edv.329.2021.03.03.08.09.17; Wed, 03 Mar 2021 08:09:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="k4e9h15/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345931AbhCAXea (ORCPT + 99 others); Mon, 1 Mar 2021 18:34:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:57212 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239013AbhCASGi (ORCPT ); Mon, 1 Mar 2021 13:06:38 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1F9346502A; Mon, 1 Mar 2021 17:13:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614618816; bh=chlXqqNxFUMkX9JphlrvzkPfsNDgmKNdMUUROlQ/fMo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k4e9h15/yn0J4B2Sb/Ch5D35TOtCsc69UPFTQvi5OKxuAAtA+NPlW0tAFHDrOBAor +GIjURp3MtiSIR6bpKuLrDp9ThWnhUXMkabGLwoFRFjRhyVJ676f8+mRlsWAHteGO3 GSshbhM0qDPNOvXzFcnT/Sey4gQ/JNDAr59gvi2g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.10 197/663] f2fs: compress: fix potential deadlock Date: Mon, 1 Mar 2021 17:07:25 +0100 Message-Id: <20210301161151.527590889@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chao Yu [ Upstream commit 3afae09ffea5e08f523823be99a784675995d6bb ] generic/269 reports a hangtask issue, the root cause is ABBA deadlock described as below: Thread A Thread B - down_write(&sbi->gc_lock) -- A - f2fs_write_data_pages - lock all pages in cluster -- B - f2fs_write_multi_pages - f2fs_write_raw_pages - f2fs_write_single_data_page - f2fs_balance_fs - down_write(&sbi->gc_lock) -- A - f2fs_gc - do_garbage_collect - ra_data_block - pagecache_get_page -- B To fix this, it needs to avoid calling f2fs_balance_fs() if there is still cluster pages been locked in context of cluster writeback, so instead, let's call f2fs_balance_fs() in the end of f2fs_write_raw_pages() when all cluster pages were unlocked. Fixes: 4c8ff7095bef ("f2fs: support data compression") Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/compress.c | 5 ++++- fs/f2fs/data.c | 10 ++++++---- fs/f2fs/f2fs.h | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c index c5fee4d7ea72f..d3f407ba64c9e 100644 --- a/fs/f2fs/compress.c +++ b/fs/f2fs/compress.c @@ -1393,7 +1393,7 @@ retry_write: ret = f2fs_write_single_data_page(cc->rpages[i], &_submitted, NULL, NULL, wbc, io_type, - compr_blocks); + compr_blocks, false); if (ret) { if (ret == AOP_WRITEPAGE_ACTIVATE) { unlock_page(cc->rpages[i]); @@ -1428,6 +1428,9 @@ retry_write: *submitted += _submitted; } + + f2fs_balance_fs(F2FS_M_SB(mapping), true); + return 0; out_err: for (++i; i < cc->cluster_size; i++) { diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index b29243ee1c3e5..4f326bce525f7 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2757,7 +2757,8 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, sector_t *last_block, struct writeback_control *wbc, enum iostat_type io_type, - int compr_blocks) + int compr_blocks, + bool allow_balance) { struct inode *inode = page->mapping->host; struct f2fs_sb_info *sbi = F2FS_I_SB(inode); @@ -2895,7 +2896,7 @@ out: } unlock_page(page); if (!S_ISDIR(inode->i_mode) && !IS_NOQUOTA(inode) && - !F2FS_I(inode)->cp_task) + !F2FS_I(inode)->cp_task && allow_balance) f2fs_balance_fs(sbi, need_balance_fs); if (unlikely(f2fs_cp_error(sbi))) { @@ -2942,7 +2943,7 @@ out: #endif return f2fs_write_single_data_page(page, NULL, NULL, NULL, - wbc, FS_DATA_IO, 0); + wbc, FS_DATA_IO, 0, true); } /* @@ -3110,7 +3111,8 @@ continue_unlock: } #endif ret = f2fs_write_single_data_page(page, &submitted, - &bio, &last_block, wbc, io_type, 0); + &bio, &last_block, wbc, io_type, + 0, true); if (ret == AOP_WRITEPAGE_ACTIVATE) unlock_page(page); #ifdef CONFIG_F2FS_FS_COMPRESSION diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 06e5a6053f3f9..699815e94bd30 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3507,7 +3507,7 @@ int f2fs_write_single_data_page(struct page *page, int *submitted, struct bio **bio, sector_t *last_block, struct writeback_control *wbc, enum iostat_type io_type, - int compr_blocks); + int compr_blocks, bool allow_balance); void f2fs_invalidate_page(struct page *page, unsigned int offset, unsigned int length); int f2fs_release_page(struct page *page, gfp_t wait); -- 2.27.0