Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5654608img; Wed, 27 Mar 2019 12:32:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqym8BmkxhaZ5UxJ8LajKfMeWijDeW9rCtaj3O5uArr8KlNnz+SJkssj0yUAmEK9kORWA66u X-Received: by 2002:a17:902:e48c:: with SMTP id cj12mr14937526plb.93.1553715126666; Wed, 27 Mar 2019 12:32:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553715126; cv=none; d=google.com; s=arc-20160816; b=vvw1LxLuUFi91eyzSr6yjt3KC7EeGPiFr/u/zuAV38oWAI7sp+Hxx29A8mQJR7Cby9 XuEuOEAu30acMTUGsipVx0MxzSKtbD5JUuJ5M/8/V+wR/tFl0z0ScgiMgUWZwUKbronX 7wNYsi6mqY6iZEneFwLBTB8LPoFJ01eoSIaFSNp2b0d3ouy11B5oRF54NGs5G+VrDWB/ NRx3YR3xFa4H/yMp71b6R8YFLzTvNcpTyuObRc0WIjPWuwnLdLhB4LyLvkPVDn1yLRRx Z5nvKC4Nf9yGKzOWwBf08kgkSi/ETitho6FJLtIRb18hfaqmlLLabqznYaCAYPSHOJGX CAMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DCdNYv3sIpv4l1zSaFwvP7GyNsJInBYe/3eYZJ3J3Xg=; b=HLfflruyQ3lmo5HWggPmDiNSMKioO+L3nIZ2dTFmZQ8HZXQO2PIXdf89PLHEMy+WTd c6wHM2vlK7emH3Ckv6BZTquyAmbUjyZxXJfp52ycrQsCsKtTgIruqR8crSVCnsETjyHL 7jXwT4YHxTYqkoMATH1lEKeKVQz+ihk8I6svWoe/5fsi5kOWqxikZVBIwArZi3pt+pN5 LnCmVZKRPtLXjg2vhy3ON44VYuAmrEEpJzxwComLDOaVGm2uiYma+8uTofOQvCdrqckC u6Mjeb+KP+Q2MgU2qdEVyZijUJXRaW9qJqFhAAbHQ5aGSqUL6laFk6kLGjL/iqtOxEiU 7gqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dJ2lNcgo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v145si16094901pgb.16.2019.03.27.12.31.51; Wed, 27 Mar 2019 12:32:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dJ2lNcgo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387611AbfC0TbR (ORCPT + 99 others); Wed, 27 Mar 2019 15:31:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:43434 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732220AbfC0SDR (ORCPT ); Wed, 27 Mar 2019 14:03:17 -0400 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 9373921850; Wed, 27 Mar 2019 18:03:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709796; bh=pQMc8UwJA+H5eFO62g4z/4kXtV+8DzCMidso/BFczZc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dJ2lNcgoNqS6sWcBxAorm6Si1VYmFzwJ+5j4ry8SAlUtcVb4fg9hWvTID8NdDq/o7 H8cx/v5k/v2h0evMpBe+4wfVijoiA95lpjc/euOPX9itFghqHg/C39w6HQIX2wCL0v aTC27Dzp1la1KiVhJ+52O7XGvMFLC1MoYlmautxQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: zhengliang , Jaegeuk Kim , Sasha Levin , linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH AUTOSEL 5.0 042/262] f2fs: fix to data block override node segment by mistake Date: Wed, 27 Mar 2019 13:58:17 -0400 Message-Id: <20190327180158.10245-42-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 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 c46a1d4318d4..93d7427d8883 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -915,6 +915,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.19.1