Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3389451ybl; Mon, 19 Aug 2019 18:01:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqziCIbCmHQLFyphcPnZoWN1/gWY/6n2kjk2UTCjpsPzdEz0UNrsdjeXu0KHcBSNfiQoV0fK X-Received: by 2002:a62:35c6:: with SMTP id c189mr27186050pfa.96.1566262884382; Mon, 19 Aug 2019 18:01:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566262884; cv=none; d=google.com; s=arc-20160816; b=fhN3lu1UhAqHHReRLFBvNQ003JH/N3XZokf72uMyZRvOMmvzGZf3x56VYeZU6sWULP Z7pGs7swSk7fhsRUqZAHuTU5SQdn+EezqaCpX5vqWbm5zQGD2zh5eylcoxUivIAmChfP CBftXMn1r9fhK5XJnkngwZXjyOOgkRIiGXShrw81IATUnhmiBCAV4FBUGgf+0Eyk9uy+ qru1moyz92qZU79wv65wMDKQxvlamNdcuP4JWBwDzX2f2vA+TCvUdhTDujNO0dkHPqKl YX36po/rg6z2Z4XSmUCrF2U7e1Rmzu4ONzTqkxL5a2pTKMLwZ4Z3WREQ4aOL/qkrRO96 gmzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gwgc3ZJr4NkmKAJ26RhpTUQ2I0vGE7pRfPFOFidEa7w=; b=Nu2uFFu9Ijec6kSf6/04WHfG+51kh4SekiWLUd14D4bLNsE4oallN9tsx1ITDRHrnx MKp7gm1fQt5RAgh7Kg8ojMKsjK7gMUZtHdaGDrvfdg8dOL5Z+An5P+mHo+ikLVBIqtl+ o3oUFM4Q0waS0Jj3sqN6EEB3uyQtN5tdN7mnd/MqQQQLbkYMhsLXbbCgqjbHDxsHBwoO E8EWTIh8P5YV+BQa21NL//L23/hj1CuHh48OuOM2g3bluVD42le5cfOJV7TexaXTpZxJ 1PuFpc08y9eAzX1lwrcrVbrSlWZXcVMv6CqUxt6Ne5QcXsb8nIZCNbN0ZoWuS/FC09sR 241w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kUAUu8VZ; 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 a34si5224710pla.432.2019.08.19.18.01.09; Mon, 19 Aug 2019 18:01:24 -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=kUAUu8VZ; 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 S1728802AbfHTBAD (ORCPT + 99 others); Mon, 19 Aug 2019 21:00:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:48080 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728627AbfHTBAC (ORCPT ); Mon, 19 Aug 2019 21:00:02 -0400 Received: from localhost (unknown [104.132.0.81]) (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 8B2F322CE8; Tue, 20 Aug 2019 01:00:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566262801; bh=3k09FSAiN1EmDJYOwHzqIY0z6rdM/xIPz2fJfXY0Jd0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kUAUu8VZBvG8TphqNQTLtnrtRoyjj9IAiv0JICGK8sVXH8kfovJr0OYIWhDXlU/kO Ra2ZbTLGqBu6qfYh0SaXYzLXT6+WwcVwzI6wccUMKh3be1h/qrXcDI9mEcSpGoVyYE PZpZcRfLUwHiS2krWglhoAYamsiI9UEtADMq1Has= Date: Mon, 19 Aug 2019 18:00:00 -0700 From: Jaegeuk Kim To: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, chao@kernel.org Subject: Re: [PATCH] f2fs: fix to avoid data corruption by forbidding SSR overwrite Message-ID: <20190820010000.GA45681@jaegeuk-macbookpro.roam.corp.google.com> References: <20190816030334.81035-1-yuchao0@huawei.com> <3349ceea-85ac-173a-81a4-1188ce3804ca@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3349ceea-85ac-173a-81a4-1188ce3804ca@huawei.com> User-Agent: Mutt/1.8.2 (2017-04-18) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/19, Chao Yu wrote: > 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") Done. > > 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++; > > } > >