Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2621525imu; Tue, 6 Nov 2018 18:47:34 -0800 (PST) X-Google-Smtp-Source: AJdET5fykkBhHINuhqyAMdKbmaX7ORu3S847xOTl1XXUfSxsK38hpsNZ7Erj+ceQaBd3yPVuytyY X-Received: by 2002:a62:418a:: with SMTP id g10-v6mr166029pfd.44.1541558853978; Tue, 06 Nov 2018 18:47:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541558853; cv=none; d=google.com; s=arc-20160816; b=v1YeH0aiEj/35BBUySFrxtVIjLI0pUlDkkOFqgISSh1E3ZYJlQY//ZT8Q+qSuyKRfP VJlYlPHZso4i+2ZP3LLi2y+hF4OMLJ2L3IX5FbPgB+bDNq5syh9SQRUDeBypXPBW2qd1 up3xhEd7nHFLtvuy28/JF7jdcJObvdypU061/0oqBxvMCOxLGJnuQhmEWzxW56ldswAK J4CuQ24JOIhVXq7g0h8lClLBIMkixVYjNpQfJAKtJfP8acg4eTHFhj1l3jJoD5kqkZC1 FqlrmtdqrF1St1KtC+hX+OHOV37pcAiV6JseVUWkppqeOGBkhAL0Rq3hQ5rso+sB/487 E0vw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=rT7ZcwyMboZn2PKiA7r+lLZ1EBhjk9tAVFArDQACsDY=; b=GVirfKy7Ugbmz/evB4TKIjmHZa0kLRVY6tt6i1UDwUtlnjAQmbxMh1JGhxj7YDpX1C AC0Knu3idbN6E8BhDp18pXNZAFw4BrUmWbk6jx9Asxe25oeywQcjII6H/Mh4tj6Mmhkk sf50INH5QR2e4nJMEKauQPRZ7kyJyAiRNn4wuF16RzREsbNVFkWJKNJk+r9EpJTBYqDt PJZx5ARyyceKkIKi2UsfZdn9VJlVuL/eKtLPCrv/aYIZXbMv1XIXKlU1+Er//3dLw4zu u6KchGU7P0oaNzOMtulKksPj7UEn/cvyPCZk2oMCt1cnIPUrT3REiFH1nJy3jbrOEE+C ISMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=R2YJglKD; 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 i13si18654913pgc.41.2018.11.06.18.47.15; Tue, 06 Nov 2018 18:47:33 -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=R2YJglKD; 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 S2389130AbeKGMPD (ORCPT + 99 others); Wed, 7 Nov 2018 07:15:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:36776 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727749AbeKGMPC (ORCPT ); Wed, 7 Nov 2018 07:15:02 -0500 Received: from localhost (unknown [104.132.0.71]) (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 9AC252086A; Wed, 7 Nov 2018 02:46:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541558800; bh=HDHmWzN+30iVqGZmEJd5JwKZgDIXvO+W8wBVkOBksjo=; h=From:To:Cc:Subject:Date:From; b=R2YJglKD7WYX8wGQA+0nvjA23I4IosGRW+wd/JKwlyHtYcI1w02Sj3PLYNjO9yyXy nARrylRii7WPiERoaXduknjtrIDrzH3Wlnmh9mJmysoL1jZh7pHrLs3dWlVNWQVeq8 onNWALVH+YctmqG6xH2VKJa2bVCElOl8+lOLWafs= From: Jaegeuk Kim To: linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Cc: Jaegeuk Kim , stable@vger.kernel.org Subject: [PATCH] f2fs: wait writeback before reading data to avoid stale encrypted block Date: Tue, 6 Nov 2018 18:46:39 -0800 Message-Id: <20181107024639.41771-1-jaegeuk@kernel.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If background GC is running very frequently by gc_urgent, the next GC can see unwritten data generated by the previous GC, which incurs to write stale corrupted data in disk. Cc: Signed-off-by: Jaegeuk Kim --- fs/f2fs/gc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index a07241fb8537..49fea136a3f3 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -658,6 +658,9 @@ static int ra_data_block(struct inode *inode, pgoff_t index) fio.page = page; fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr; + /* wait writeback before reading out */ + f2fs_wait_on_block_writeback(inode, dn.data_blkaddr); + fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(sbi), dn.data_blkaddr, FGP_LOCK | FGP_CREAT, GFP_NOFS); @@ -755,6 +758,9 @@ static int move_data_block(struct inode *inode, block_t bidx, fio.page = page; fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr; + /* wait writeback before reading out */ + f2fs_wait_on_block_writeback(inode, fio.old_blkaddr); + if (lfs_mode) down_write(&fio.sbi->io_order_lock); -- 2.19.0.605.g01d371f741-goog