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=-9.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 46B8BC432C3 for ; Fri, 22 Nov 2019 05:53:28 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 1B28B2071B; Fri, 22 Nov 2019 05:53:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="kxMcRKH1"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="HDmUqs2Q"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="J0q4jZF9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B28B2071B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1iY1sl-00056o-Hb; Fri, 22 Nov 2019 05:53:27 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1iY1sj-00056Z-GG for linux-f2fs-devel@lists.sourceforge.net; Fri, 22 Nov 2019 05:53:25 +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:References: In-Reply-To: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:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=1zU7YNZaHaRsTUOGxgWtDa5KrjCni4s8YzAFaFNUdV4=; b=kxMcRKH15yHvdZDC4AvuqxNdtB 2mh054jlHyJgPPdkN0ACrwsjfB5xrM8nGww/NfrQCPJXlphX1C8Q0FxBhh0AHqT1Dlyy5/CwYqj8Z 3L8E9EN5P0QYfpoiRjU8MMJww3kN2ynRATjqpeOSQ8UpWodxMRJ3MG+ebSVfVwBUQvCM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: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:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=1zU7YNZaHaRsTUOGxgWtDa5KrjCni4s8YzAFaFNUdV4=; b=HDmUqs2QfuFYauOsNZ89TCVRs/ Wfp3Us9umhe0Fv8igH0DTFGNglJ02r2c+vl3yEPKxUunRS3onaGvSX6qDToiO0qex5QAJuKsJHlc4 +s4ljAbbXuzySSqbnqrqifCYT4+KaZE2FNMLxkIFpaxR3+WxXDE+EqBXEMFWG6KzTPV8=; Received: from mail.kernel.org ([198.145.29.99]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1iY1si-009xpH-Ct for linux-f2fs-devel@lists.sourceforge.net; Fri, 22 Nov 2019 05:53:25 +0000 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 155102085B; Fri, 22 Nov 2019 05:53:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574401998; bh=ppy15U+nQ8RPSyPX+4WknncCJKj6FCQWxkBQTbeujCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J0q4jZF9aBQc9E4Sfd1aePg5e2IxFWLMvLgBf1pv6zO/RUS0fyIeaiSmpHQk1wYlu JhB9qq4FXWplDGJUl9lwh1PpKoy/RKuEY7nd/dPL9573xMIUWmZ2mp+931IVBl6a7i lhYStzzWZTv16kk0INtHZRk/7SMbajcRP6ovH8w8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Date: Fri, 22 Nov 2019 00:49:07 -0500 Message-Id: <20191122054911.1750-208-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122054911.1750-1-sashal@kernel.org> References: <20191122054911.1750-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-Headers-End: 1iY1si-009xpH-Ct Subject: [f2fs-dev] [PATCH AUTOSEL 4.19 216/219] f2fs: fix to data block override node segment by mistake 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: Sasha Levin , Jaegeuk Kim , linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: zhengliang [ Upstream commit a0770e13c8da83bdb64738c0209ab02dd3cfff8b ] v4: Rearrange the previous three versions. The following scenario could lead to data block override by mistake. TASK A | TASK kworker | TASK B | TASK C | | | open | | | write | | | close | | | | f2fs_write_data_pages | | | f2fs_write_cache_pages | | | f2fs_outplace_write_data | | | f2fs_allocate_data_block (get block in seg S, | | | S is full, and only | | | have this valid data | | | block) | | | allocate_segment | | | locate_dirty_segment (mark S as PRE) | | | f2fs_submit_page_write (submit but is not | | | written on dev) | | unlink | | | iput_final | | | f2fs_drop_inode | | | f2fs_truncate | | | (not evict) | | | | | write_checkpoint | | | flush merged bio but not wait file data writeback | | | set_prefree_as_free (mark S as FREE) | | | | update NODE/DATA | | | allocate_segment (select S) | writeback done | | So we need to guarantee io complete before truncate inode in f2fs_drop_inode. Reviewed-by: Chao Yu Signed-off-by: Zheng Liang Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/super.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index d9106bbe7df63..d01998ed32343 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -890,6 +890,10 @@ static int f2fs_drop_inode(struct inode *inode) sb_start_intwrite(inode->i_sb); f2fs_i_size_write(inode, 0); + f2fs_submit_merged_write_cond(F2FS_I_SB(inode), + inode, NULL, 0, DATA); + truncate_inode_pages_final(inode->i_mapping); + if (F2FS_HAS_BLOCKS(inode)) f2fs_truncate(inode); -- 2.20.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel 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=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 EC55AC432C0 for ; Fri, 22 Nov 2019 05:53:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BDAEF2071B for ; Fri, 22 Nov 2019 05:53:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574402015; bh=ppy15U+nQ8RPSyPX+4WknncCJKj6FCQWxkBQTbeujCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=zOemGC8+SS1V+OcVjvHbzV0yiM5rAfQFWOzu9MLaHI2UcAQjZp349dtqaH3pYPe/s RscxPK4FskYAJe/stRR5weLg/ulpdQFdH1kqo7YNhaL+BaufXijvxHvJBqwlvnagVI CNSx/a6tW5e2ddorgSYBJ91p00mo7LmQro31MdzA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727735AbfKVFx3 (ORCPT ); Fri, 22 Nov 2019 00:53:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:59366 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728834AbfKVFxT (ORCPT ); Fri, 22 Nov 2019 00:53:19 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 155102085B; Fri, 22 Nov 2019 05:53:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1574401998; bh=ppy15U+nQ8RPSyPX+4WknncCJKj6FCQWxkBQTbeujCU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J0q4jZF9aBQc9E4Sfd1aePg5e2IxFWLMvLgBf1pv6zO/RUS0fyIeaiSmpHQk1wYlu JhB9qq4FXWplDGJUl9lwh1PpKoy/RKuEY7nd/dPL9573xMIUWmZ2mp+931IVBl6a7i lhYStzzWZTv16kk0INtHZRk/7SMbajcRP6ovH8w8= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: zhengliang , Chao Yu , Jaegeuk Kim , Sasha Levin , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH AUTOSEL 4.19 216/219] f2fs: fix to data block override node segment by mistake Date: Fri, 22 Nov 2019 00:49:07 -0500 Message-Id: <20191122054911.1750-208-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191122054911.1750-1-sashal@kernel.org> References: <20191122054911.1750-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: zhengliang [ Upstream commit a0770e13c8da83bdb64738c0209ab02dd3cfff8b ] v4: Rearrange the previous three versions. The following scenario could lead to data block override by mistake. TASK A | TASK kworker | TASK B | TASK C | | | open | | | write | | | close | | | | f2fs_write_data_pages | | | f2fs_write_cache_pages | | | f2fs_outplace_write_data | | | f2fs_allocate_data_block (get block in seg S, | | | S is full, and only | | | have this valid data | | | block) | | | allocate_segment | | | locate_dirty_segment (mark S as PRE) | | | f2fs_submit_page_write (submit but is not | | | written on dev) | | unlink | | | iput_final | | | f2fs_drop_inode | | | f2fs_truncate | | | (not evict) | | | | | write_checkpoint | | | flush merged bio but not wait file data writeback | | | set_prefree_as_free (mark S as FREE) | | | | update NODE/DATA | | | allocate_segment (select S) | writeback done | | So we need to guarantee io complete before truncate inode in f2fs_drop_inode. Reviewed-by: Chao Yu Signed-off-by: Zheng Liang Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/super.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index d9106bbe7df63..d01998ed32343 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -890,6 +890,10 @@ static int f2fs_drop_inode(struct inode *inode) sb_start_intwrite(inode->i_sb); f2fs_i_size_write(inode, 0); + f2fs_submit_merged_write_cond(F2FS_I_SB(inode), + inode, NULL, 0, DATA); + truncate_inode_pages_final(inode->i_mapping); + if (F2FS_HAS_BLOCKS(inode)) f2fs_truncate(inode); -- 2.20.1