Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1663223ybi; Wed, 17 Jul 2019 19:42:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxXWyyKwmtbcVeX/QNYRgYH+si1ty8A+mfUToyxaXjvF5IbBEsZRYm+RxwT3iwXFIZWh14 X-Received: by 2002:a17:902:7088:: with SMTP id z8mr47990719plk.125.1563417748305; Wed, 17 Jul 2019 19:42:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563417748; cv=none; d=google.com; s=arc-20160816; b=Sgg8b4q3CWxMFCHYJ2Z9dCjVEe43Yf+xJVvELEhPREs2Gs8v2+9BooPZ0YNio52Nww 24lmvGB1TWw2pvleYcc4PMX+gcjqS2LklTOs9cqkoxL8F2eL47AhOBpdUnRtfhZ8fH9X D6ZtONdiN+ZyEi29DzssAbg9lE9rDRqTHhNYWKbhdqbNi//0ErU17rp8oz6xcYfArc52 1RVfs4hcw7AgOJzMtAHUqwmO+E27lgloNd41xeSKH1w7YeQkBBOW1pQQuesgTkJo3rOk 5j67rllCJHvmIAtnY6VxohblumNsBjggx4kSKgPGftFFCcRc8ScG7ylZJ5O/sU5b6doJ I6mg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject; bh=mIvSl0sY5UwcyAKOjxHdbya04QcuevMW9VQAkslc/R4=; b=FcQPR8PRc9vxZqhyWKdH+6UEirJer2ni/JxpgPN0BUFqc2o2Vaibqz3JNqvxA0kez+ EnBQV7e5V/qCyez68d8QLYfmGovXry9NEPccIAz/qf1dvE4nMMM+KjhRzB8sdC+EiI5+ 3bbEmCbCmp8+wlR+y4kgRtQ6kDLX/LJSrOy6dbeOuNrNDJ0sKxUHkZR4BCvyvT/36Qn7 ulO7QtOTVBH/59Hmry1fFTpKGZKX+/fprHFopt5LmifQu6V7XZIvEzMZmd38aJKxHgWH ORlNE0qofa1gaWvw6RkL3J3eDpvaieisylc2PJmuOGWw7J9B52Zp3GvrP9cmtMinN+ip vqtg== ARC-Authentication-Results: i=1; mx.google.com; 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 i32si217375pje.44.2019.07.17.19.41.58; Wed, 17 Jul 2019 19:42: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; 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 S1728590AbfGRCjf (ORCPT + 99 others); Wed, 17 Jul 2019 22:39:35 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:54272 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727804AbfGRCjf (ORCPT ); Wed, 17 Jul 2019 22:39:35 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 9EE5BB0F0EA6FD46A821; Thu, 18 Jul 2019 10:39:33 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.205) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 18 Jul 2019 10:39:30 +0800 Subject: Re: [f2fs-dev] [PATCH] f2fs: fix to read source block before invalidating it To: Jaegeuk Kim , , References: <20190718013718.70335-1-jaegeuk@kernel.org> From: Chao Yu Message-ID: <8049131e-4200-83c8-516a-8fa03a238e29@huawei.com> Date: Thu, 18 Jul 2019 10:39:27 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190718013718.70335-1-jaegeuk@kernel.org> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/7/18 9:37, Jaegeuk Kim wrote: > 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. > > Signed-off-by: Jaegeuk Kim > --- > fs/f2fs/gc.c | 57 ++++++++++++++++++++++++++++------------------------ > 1 file changed, 31 insertions(+), 26 deletions(-) > > diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c > index 6691f526fa40..35c5453ab874 100644 > --- a/fs/f2fs/gc.c > +++ b/fs/f2fs/gc.c > @@ -740,6 +740,7 @@ static int move_data_block(struct inode *inode, block_t bidx, > block_t newaddr; > int err = 0; > bool lfs_mode = test_opt(fio.sbi, LFS); > + bool submitted = false; > > /* do not read out */ > page = f2fs_grab_cache_page(inode->i_mapping, bidx, false); > @@ -796,6 +797,20 @@ 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 put_out; Needs to release io_order_lock. > + > + if (!PageUptodate(mpage)) { > + err = f2fs_submit_page_bio(&fio); > + if (err) { > + f2fs_put_page(mpage, 1); > + goto put_out; Ditto. Thanks, > + } > + submitted = true; > + } > + > f2fs_allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr, > &sum, CURSEG_COLD_DATA, NULL, false); > > @@ -803,44 +818,34 @@ 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; > + goto recover_block; > } > > - err = f2fs_submit_page_bio(&fio); > - if (err) > - goto put_page_out; > - > - /* write page */ > - lock_page(fio.encrypted_page); > + if (!submitted) > + goto write_page; > > - if (unlikely(fio.encrypted_page->mapping != META_MAPPING(fio.sbi))) { > + /* read source block */ > + lock_page(mpage); > + if (unlikely(mpage->mapping != META_MAPPING(fio.sbi))) { > err = -EIO; > + f2fs_put_page(mpage, 1); > goto put_page_out; > } > - if (unlikely(!PageUptodate(fio.encrypted_page))) { > + if (unlikely(!PageUptodate(mpage))) { > err = -EIO; > + f2fs_put_page(mpage, 1); > goto put_page_out; > } > - > 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); >