Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2724102imj; Mon, 11 Feb 2019 07:32:32 -0800 (PST) X-Google-Smtp-Source: AHgI3IYqAjHQr97rXkYLCouNexwu9xvsJatMCyNkzHB4dv1D7gfmOVz55QCEGCOATd8AsR2y/gdV X-Received: by 2002:a63:be4d:: with SMTP id g13mr29331153pgo.378.1549899151984; Mon, 11 Feb 2019 07:32:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549899151; cv=none; d=google.com; s=arc-20160816; b=V4NjcDwVnHvqrQw/kE0YW1Ty884DaLIkzts5z2zS198Xmc2y3/k5ugkfw/xYG5E7cc gMudrzKgGfzf0+kUNuk4aDSealVSpFPQ7JlX3touvpE9NT77EiNh0UeC6WNMJSJV6lYN PUtD73ocflgRz5PP4C05iWx28x+qiLjexzj2zt74oT4CrjvLwsxwqQru1dNbd7+S6k7C bAj5XLaWlOsDGNpKrnJwJ3PdUs2weDOOxNIbus5fW3ZfLmc/p/ZIR/9tztWGga7omLEp jT1c+y54ljn3la7fVoJ6XPjjQOw/TNSJ/vQ1xdYWCKBohMVxJwSZtJl1cd68z8H19OZs LPUA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7JfNAoWoB2qwwcqcpQ6OVIQx/LvfGq1m0dTUnbZTTas=; b=1CfdFXcyzA1+bf3cV12P+b4mRBtpDvNeWZG+5somzhfZc5z4wGWn0OwRxF5Xd8xIYa pGMEaPELFED5BFvbdhH3mZpLw+dRVGXpN+3MfdkPLSgy1v2NEZRKt7S2dNBpU1IXTUfE 3CBZOv+BjcZgpT0tUrNoqQBZIAesF4LKCac8blHb1vPA5sbxm8T1sE+adM18SxxpI/ED acksATsjJFJxmIk6jKmZ869qNvpGUxVzuckmF8JyQXR2TFNIX4QxUXTE5kTII0KrOQ6N avnuF7X3uGXQWmbisfRKLlBYCuoV4dSM/3Ln7jTnfYz/1n8P8kZflmtWFaCUkpgyKECG Z4VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=AWZcOI7h; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l30si10941310plg.113.2019.02.11.07.32.14; Mon, 11 Feb 2019 07:32:31 -0800 (PST) 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=AWZcOI7h; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389089AbfBKO4C (ORCPT + 99 others); Mon, 11 Feb 2019 09:56:02 -0500 Received: from mail.kernel.org ([198.145.29.99]:43122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388451AbfBKO4A (ORCPT ); Mon, 11 Feb 2019 09:56:00 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E7CAA20700; Mon, 11 Feb 2019 14:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549896959; bh=HEAJCrTb7lbzzCZRNiudwLejyRmoCdZUXndMzNXMpds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AWZcOI7hbDsnw2AJIswQTzdHdj85fSW6ehFbji94hRz9KOQ4XhTX7fq3krO9pRwWQ pElUIUY21TzF7oBuA3HHbR+BILnKExE32CBX/U3oCmFasFoxyWFkHfzl+PgBzwb4ea uCjP1ekzCzamCUOaJGyLL8F6lkJSrIbM2K+lM+DI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sheng Yong , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 4.14 044/205] f2fs: fix race between write_checkpoint and write_begin Date: Mon, 11 Feb 2019 15:17:22 +0100 Message-Id: <20190211141831.738429864@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141827.214852402@linuxfoundation.org> References: <20190211141827.214852402@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 2866fb16d67992195b0526d19e65acb6640fb87f ] The following race could lead to inconsistent SIT bitmap: Task A Task B ====== ====== f2fs_write_checkpoint block_operations f2fs_lock_all down_write(node_change) down_write(node_write) ... sync ... up_write(node_change) f2fs_file_write_iter set_inode_flag(FI_NO_PREALLOC) ...... f2fs_write_begin(index=0, has inline data) prepare_write_begin __do_map_lock(AIO) => down_read(node_change) f2fs_convert_inline_page => update SIT __do_map_lock(AIO) => up_read(node_change) f2fs_flush_sit_entries <= inconsistent SIT finish write checkpoint sudden-power-off If SPO occurs after checkpoint is finished, SIT bitmap will be set incorrectly. Signed-off-by: Sheng Yong Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/data.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index c68b319b07aa..3d37124eb63e 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1880,6 +1880,7 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, bool locked = false; struct extent_info ei = {0,0,0}; int err = 0; + int flag; /* * we already allocated all the blocks, so we don't need to get @@ -1889,9 +1890,15 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, !is_inode_flag_set(inode, FI_NO_PREALLOC)) return 0; + /* f2fs_lock_op avoids race between write CP and convert_inline_page */ + if (f2fs_has_inline_data(inode) && pos + len > MAX_INLINE_DATA(inode)) + flag = F2FS_GET_BLOCK_DEFAULT; + else + flag = F2FS_GET_BLOCK_PRE_AIO; + if (f2fs_has_inline_data(inode) || (pos & PAGE_MASK) >= i_size_read(inode)) { - __do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true); + __do_map_lock(sbi, flag, true); locked = true; } restart: @@ -1929,6 +1936,7 @@ restart: f2fs_put_dnode(&dn); __do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true); + WARN_ON(flag != F2FS_GET_BLOCK_PRE_AIO); locked = true; goto restart; } @@ -1942,7 +1950,7 @@ out: f2fs_put_dnode(&dn); unlock_out: if (locked) - __do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, false); + __do_map_lock(sbi, flag, false); return err; } -- 2.19.1