Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1460911ybl; Thu, 22 Aug 2019 15:10:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsVVaFYMP2dU7cXDOLRm7g26zwnYDYttd9s3UdY4FP+0z7gdMuyBkT/1JXBVVbA7DNo9fD X-Received: by 2002:a63:29c7:: with SMTP id p190mr1199447pgp.124.1566511828785; Thu, 22 Aug 2019 15:10:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566511828; cv=none; d=google.com; s=arc-20160816; b=oQUfV3HteZj+yenump3kBxZ6Zas/H8EH58RikGz8rHFrptRHdDYBkaCjr/zA3TBOFq d3ubA4g+YG1uSa0zH1tUo+rLn1DW8t1yHworEi/XHmMhBLrbWdvMPSKifcxmu+8BQFQ/ CKGmOB/6itbr37ICEPY86W/Yp9gooE4ICJD9mZXmcNFQ8RKY/OoQc3sVpubD4QGPcA+j 4bQ6ENetmXqbXwEuC15sZpPA44F2WyAO2TyhIhokn1cvNY+3O3I7YKl/2k/VhDqIpD8A 9D5U4PiT3d62kvcZN18s+E/Q6z3WeLOJW3V+k6mcpZYNxe0lCNTfxzPYJAvAlAfJ8hJp Cn1g== 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=mBOcax6fp/YvdpxHC9TfXaal+XhYVyv1/8PZ/1Xlccg=; b=NpAzKomMxUeUM/3TMrU4HMmxD2uCqA4B8wZoO7wnBAL9oemS5D08YtKoZfau0klY1N zLrU3fNtvRYaIdGW+nnXkWcJ9yC22DX8zz23gAHJx4ADghYx6wB3GAIjbCqW9MwB49xo BCFOjR/rGOk7mdq23/rxzLAgjdusD0zQiFqxcGxmEEw0HRNtMscDgITjZQxwa/5d6mGY G/eEgTKOTkU+1dwl1alEOIHGvTi8AC0LcduNF/Scbox6ItpUmNu5M0gV9WrMmaKihVOh MT+eKTyHKctJtfw72gP6OBSn4nDpuiR4OO6gkctIDP3AsjXzXuKl4Iy+ENmlrJcAP1xP 5bsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="OIyUd3a/"; 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 j192si405433pge.393.2019.08.22.15.10.13; Thu, 22 Aug 2019 15:10:28 -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="OIyUd3a/"; 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 S2390468AbfHVRIm (ORCPT + 99 others); Thu, 22 Aug 2019 13:08:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:58456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390440AbfHVRIl (ORCPT ); Thu, 22 Aug 2019 13:08:41 -0400 Received: from sasha-vm.mshome.net (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (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 48A6D2341C; Thu, 22 Aug 2019 17:08:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566493720; bh=gx8SFavgzOTEOESs7rzfvsJIXbtJJ880k7HdXMQfhM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OIyUd3a/cnUdJvGcxv6Be0T4oMNOlAI+8TxottRWM4R5EmWUmmPyJ988PP7tEblpw bE/akwP3R2yldW1KtvtO3kGzAzp7JW7ds0oy1FgzfZTUGwULJ7gv47l1WHECPFyQEi zGPpjAzha56qJ5aY/lsPYD6+06r/iMB7hM3WZDBI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Jaegeuk Kim , Chao Yu , Sasha Levin Subject: [PATCH 5.2 049/135] f2fs: fix to read source block before invalidating it Date: Thu, 22 Aug 2019 13:06:45 -0400 Message-Id: <20190822170811.13303-50-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190822170811.13303-1-sashal@kernel.org> References: <20190822170811.13303-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.2.10-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.2.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.2.10-rc1 X-KernelTest-Deadline: 2019-08-24T17:07+00:00 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: Jaegeuk Kim [ Upstream commit 543b8c468f55f27f3c0178a22a91a51aabbbc428 ] f2fs_allocate_data_block() invalidates old block address and enable new block address. Then, if we try to read old block by f2fs_submit_page_bio(), it will give WARN due to reading invalid blocks. Let's make the order sanely back. Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/gc.c | 70 +++++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 963fb4571fd98..bb6fd5a506d39 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -794,6 +794,29 @@ static int move_data_block(struct inode *inode, block_t bidx, if (lfs_mode) down_write(&fio.sbi->io_order_lock); + mpage = f2fs_grab_cache_page(META_MAPPING(fio.sbi), + fio.old_blkaddr, false); + if (!mpage) + goto up_out; + + fio.encrypted_page = mpage; + + /* read source block in mpage */ + if (!PageUptodate(mpage)) { + err = f2fs_submit_page_bio(&fio); + if (err) { + f2fs_put_page(mpage, 1); + goto up_out; + } + lock_page(mpage); + if (unlikely(mpage->mapping != META_MAPPING(fio.sbi) || + !PageUptodate(mpage))) { + err = -EIO; + f2fs_put_page(mpage, 1); + goto up_out; + } + } + f2fs_allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr, &sum, CURSEG_COLD_DATA, NULL, false); @@ -801,44 +824,18 @@ static int move_data_block(struct inode *inode, block_t bidx, newaddr, FGP_LOCK | FGP_CREAT, GFP_NOFS); if (!fio.encrypted_page) { err = -ENOMEM; - goto recover_block; - } - - mpage = f2fs_pagecache_get_page(META_MAPPING(fio.sbi), - fio.old_blkaddr, FGP_LOCK, GFP_NOFS); - if (mpage) { - bool updated = false; - - if (PageUptodate(mpage)) { - memcpy(page_address(fio.encrypted_page), - page_address(mpage), PAGE_SIZE); - updated = true; - } f2fs_put_page(mpage, 1); - invalidate_mapping_pages(META_MAPPING(fio.sbi), - fio.old_blkaddr, fio.old_blkaddr); - if (updated) - goto write_page; - } - - err = f2fs_submit_page_bio(&fio); - if (err) - goto put_page_out; - - /* write page */ - lock_page(fio.encrypted_page); - - if (unlikely(fio.encrypted_page->mapping != META_MAPPING(fio.sbi))) { - err = -EIO; - goto put_page_out; - } - if (unlikely(!PageUptodate(fio.encrypted_page))) { - err = -EIO; - goto put_page_out; + goto recover_block; } -write_page: + /* write target block */ f2fs_wait_on_page_writeback(fio.encrypted_page, DATA, true, true); + memcpy(page_address(fio.encrypted_page), + page_address(mpage), PAGE_SIZE); + f2fs_put_page(mpage, 1); + invalidate_mapping_pages(META_MAPPING(fio.sbi), + fio.old_blkaddr, fio.old_blkaddr); + set_page_dirty(fio.encrypted_page); if (clear_page_dirty_for_io(fio.encrypted_page)) dec_page_count(fio.sbi, F2FS_DIRTY_META); @@ -869,11 +866,12 @@ static int move_data_block(struct inode *inode, block_t bidx, put_page_out: f2fs_put_page(fio.encrypted_page, 1); recover_block: - if (lfs_mode) - up_write(&fio.sbi->io_order_lock); if (err) f2fs_do_replace_block(fio.sbi, &sum, newaddr, fio.old_blkaddr, true, true); +up_out: + if (lfs_mode) + up_write(&fio.sbi->io_order_lock); put_out: f2fs_put_dnode(&dn); out: -- 2.20.1