From patchwork Mon Aug 12 14:12:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13760663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0D435C3DA7F for ; Mon, 12 Aug 2024 14:13:10 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1sdVnJ-0000Nk-RM; Mon, 12 Aug 2024 14:13:09 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1sdVnH-0000Nc-I1 for linux-f2fs-devel@lists.sourceforge.net; Mon, 12 Aug 2024 14:13:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=A7rTqX4bjiS57zDBaOkeT7jcor1NZ5CdF7IXaHdJUhk=; b=SjfVNnevFWQXr35y46r07InA+X Ma5hYLr496u2pAdf9SlTax1hGhC2s8YB+RATdCAjbpONUF4uYXnr2grWrgEtV7BoxRzmBg+wuyJRV 7br1gNYTz6df2qnBDjwBrR4rQOJ+hywJGJIa1dKTe/E5cETMVSGxLI5h0Qa9IxsDSksc=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=A7rTqX4bjiS57zDBaOkeT7jcor1NZ5CdF7IXaHdJUhk=; b=X upP0u7Hd5m62KJoutNTpBamQHbDKT9q1qUbDnQApY5/oSmVUOQdX2EwcFpXTB2Ot2kcm/J42Np5F+ Soc0rYbNF1BVawOlrHuYyiNic824/dKGnS2v4GFI1m6CygN3DkgYWwdyx3q1kuYMXIgjNiuBhAEPP gxgFG9LI1XYqkgsg=; Received: from sin.source.kernel.org ([145.40.73.55]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1sdVnG-0002Im-OR for linux-f2fs-devel@lists.sourceforge.net; Mon, 12 Aug 2024 14:13:07 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id EB733CE0EAD for ; Mon, 12 Aug 2024 14:12:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E1EBC32782; Mon, 12 Aug 2024 14:12:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1723471973; bh=7gSDC/cYVMwFkYxC7WG5mpNOT6P1rABfpHlISArbjQQ=; h=From:To:Cc:Subject:Date:From; b=h2Nhj3jY4l1WBltCi6rXWlfN2AIuo1Nr+RsYBAU/6mTIoTTDAUZwWcpy7HF0Cw0tR PGcw/vZHLFAzLjHoaxfVCzGDfUiG+min1ofn4ehWim4NZ1UmvC+zKdGJVZ+1jAHien rZwdXE1IENLkJp3fw365NkcU9WxhNnsfKrImxH83n3G1o4JFZTY4JeRokq/yOWZRJN 8355OUaAkmCkvfDBnzU5nq7zMCcZLEhZQg1iAaJ/Y/hRksYx+ox+V0A0qe3ckv/ju2 JmFqtOYEKqnuZx0riNenL0VjxCjNaz702q1p7pKvrTrxOM7OYmrRlgTXnTYCDns05R IuxqzAx56LAaw== From: Chao Yu To: jaegeuk@kernel.org Date: Mon, 12 Aug 2024 22:12:42 +0800 Message-Id: <20240812141242.4159033-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Headers-End: 1sdVnG-0002Im-OR Subject: [f2fs-dev] [PATCH] f2fs: fix to wait page writeback before setting gcing flag X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Soft IRQ Thread - f2fs_write_end_io - f2fs_defragment_range - set_page_private_gcing - type = WB_DATA_TYPE(page, false); : assign type w/ F2FS_WB_CP_DATA due to page_private_gcing() is true - dec_page_count() w/ wrong type - end_page_writeback() Value of F2FS_WB_CP_DATA reference count may become negative under above race condition, the root cause is we missed to wait page writeback before setting gcing page private flag, let's fix it. Fixes: 2d1fe8a86bf5 ("f2fs: fix to tag gcing flag on page during file defragment") Fixes: 4961acdd65c9 ("f2fs: fix to tag gcing flag on page during block migration") Signed-off-by: Chao Yu --- fs/f2fs/file.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index eaa39c50f782..56e27e305600 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2817,6 +2817,8 @@ static int f2fs_defragment_range(struct f2fs_sb_info *sbi, goto clear_out; } + f2fs_wait_on_page_writeback(page, DATA, true, true); + set_page_dirty(page); set_page_private_gcing(page); f2fs_put_page(page, 1); @@ -4217,6 +4219,8 @@ static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len) /* It will never fail, when page has pinned above */ f2fs_bug_on(F2FS_I_SB(inode), !page); + f2fs_wait_on_page_writeback(page, DATA, true, true); + set_page_dirty(page); set_page_private_gcing(page); f2fs_put_page(page, 1);