Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2316130ybl; Sun, 18 Aug 2019 23:32:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+qNIdsZHdnIerZFouayYknrr7VX+VsoX4sPSeF9nvZxciUm4sIEDgMu5M+EyFjVzF7Tuu X-Received: by 2002:a17:902:141:: with SMTP id 59mr21507767plb.324.1566196365067; Sun, 18 Aug 2019 23:32:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566196365; cv=none; d=google.com; s=arc-20160816; b=JUKgnY+SRNym7s5wDWsnrzobAxSGv3+S63qS/62QlKhIxQvX/iq5LpFfKrve/enXLv VxTpbESkwgwZr/yuulqC5/+9+FlQKE1eUGAXqvZPIpOT2M4+FVXBbPPQohLyTaNZIl36 mYsp0OUwdNcBNg6oYQs62qhidGqHaY77FwOddzL6QhMosUqTtzKSlySa8+nxx9pTK5JN C3bE82F2qJo8xl+siRoZLHThj1d8zZlb6fkj4FWDy5L7/1lePsoLOyQmMwxMBRLSwG05 frhWUG/zRCPo76VXnrjiTc7xHcXFWtw1JD87p2IpVSzZFlb8R2J3AXUBbxb0Xxdg855G EKLw== 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:cc:to:subject; bh=p21ypM+5BNSWS4TrNryo7BPOzVcumu8IQdA+Go1fRPM=; b=FCLL9YvcKS1QoeRV/4jAOYOfIkE+ftRP3ATnB+XtLk+RA88VBoFtLDg/3QKp9GXNkR 4nX4X+4+l57zrJAGzOHZ7EtntDpJZeJrTsWn6RpTrDhgWhVzAkk0vDcaiM647OJKL23S icFjlSZLIliYcVl/VY+D/zpLIcqb53EtD/41Pr5uq1rN8uFltYS5uL8YHw6BDupFtV9o txH2eDj1upT/oKiUE/bBGyXef3c7rA6KmQAw9Xt1K+/sgo+2/yBsqcMmW030CAIMwDy/ OxQnPYpDDWHyCJveoTkxwF/jmGIOdx3gFx+V6uIDZHz+GqM7FRbTTPbvssNJhVLIBS/O ihVA== 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 38si9304378pla.216.2019.08.18.23.32.29; Sun, 18 Aug 2019 23:32:45 -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 S1726721AbfHSGaU (ORCPT + 99 others); Mon, 19 Aug 2019 02:30:20 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:5148 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726174AbfHSGaU (ORCPT ); Mon, 19 Aug 2019 02:30:20 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 434CF35303F54581EDF2; Mon, 19 Aug 2019 14:30:17 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.211) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 19 Aug 2019 14:30:13 +0800 Subject: Re: [PATCH] f2fs: fix to avoid data corruption by forbidding SSR overwrite To: CC: , , References: <20190816030334.81035-1-yuchao0@huawei.com> From: Chao Yu Message-ID: <3349ceea-85ac-173a-81a4-1188ce3804ca@huawei.com> Date: Mon, 19 Aug 2019 14:30:12 +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: <20190816030334.81035-1-yuchao0@huawei.com> 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/8/16 11:03, Chao Yu wrote: > There is one case can cause data corruption. > > - write 4k to fileA > - fsync fileA, 4k data is writebacked to lbaA > - write 4k to fileA > - kworker flushs 4k to lbaB; dnode contain lbaB didn't be persisted yet > - write 4k to fileB > - kworker flush 4k to lbaA due to SSR > - SPOR -> dnode with lbaA will be recovered, however lbaA contains fileB's > data > > One solution is tracking all fsynced file's block history, and disallow > SSR overwrite on newly invalidated block on that file. > > However, during recovery, no matter the dnode is flushed or fsynced, all > previous dnodes until last fsynced one in node chain can be recovered, > that means we need to record all block change in flushed dnode, which > will cause heavy cost, so let's just use simple fix by forbidding SSR > overwrite directly. > Jaegeuk, Please help to add below missed tag to keep this patch being merged in stable kernel. Fixes: 5b6c6be2d878 ("f2fs: use SSR for warm node as well") Thanks, > Signed-off-by: Chao Yu > --- > fs/f2fs/segment.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c > index 9d9d9a050d59..69b3b553ee6b 100644 > --- a/fs/f2fs/segment.c > +++ b/fs/f2fs/segment.c > @@ -2205,9 +2205,11 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del) > if (!f2fs_test_and_set_bit(offset, se->discard_map)) > sbi->discard_blks--; > > - /* don't overwrite by SSR to keep node chain */ > - if (IS_NODESEG(se->type) && > - !is_sbi_flag_set(sbi, SBI_CP_DISABLED)) { > + /* > + * SSR should never reuse block which is checkpointed > + * or newly invalidated. > + */ > + if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED)) { > if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map)) > se->ckpt_valid_blocks++; > } >