Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp395511ybl; Thu, 15 Aug 2019 20:04:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqyb5i9uFgTsdagrRDNtAltmg9ltGnGa7DPuyB7ineQcHBrQgYbxecA1wa889wVDTgP29SBO X-Received: by 2002:a17:902:543:: with SMTP id 61mr7204646plf.20.1565924693753; Thu, 15 Aug 2019 20:04:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565924693; cv=none; d=google.com; s=arc-20160816; b=ah3rmOLYQCb9J+/Y7wsAbc7xNZ7ZiTeQ3FEZZVchWsfBZJjDHc2Ofavy56EXhtVMhx Tr0so1ITG2JCuAt9ELH6/YewdXRuJnJAtqBI/KrVksj+1tYOecclNEFKQEev2fn10lhW DjGYQK1VcF8DiIZEkWSQZxvczo1Lr0jy4nuLGw/5x8VSTHE7GyH6IaqhDyY60ZZbuNpu Dt88uqJfCBmn3uhA+2sgjiXmPLPZvGSivjxkjmdAgrQwSU5NvtseRwQqKsRHFIkVHMmE MD60hMPCJYbcy2dGhiI15IF3FKFWhwp9tqVB0dlW6lsXIRaK0HqLYE2cmmawGSabsFiI mHsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=lBaRpNg3I4FFT/oJc2BBHj+ZoDhPks0+8rMA3I520E0=; b=cptJNAnRkbrXbKzLEHEhUvjaD74krr/AY8j8hJA3EMs9lNrZ8eYCVjz9BQTeOHXXs1 G8Jssw6LQt8qwcozKXTgMqAorf3zPak9w7z0TPaw9URZwShy+tfHMEnTkGzRvPO7QKWP 7Q3VbNJ0vilHiJ89hbvWVImcjIUKvObuNaIB2cfmQFDrmWuBpAIu+NrfeViZDWXAj1TX 0uh6LGkn2ALo6QJzXpD9vl/h0AQPAVivERZb30AJpa0P6fv2hlKJw7voMjDmvAhO3L1t XI9B2nhFPTHN5K2AXFcfP82wJRZ3cP+5C4rWMZ3eaIL9gRE198y5/dH0yVHbak+O1t5W LqTw== 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 z8si3000284pgr.359.2019.08.15.20.04.36; Thu, 15 Aug 2019 20:04:53 -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 S1726566AbfHPDEA (ORCPT + 99 others); Thu, 15 Aug 2019 23:04:00 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:4698 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726465AbfHPDEA (ORCPT ); Thu, 15 Aug 2019 23:04:00 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 22A01A017554AFE3FD6A; Fri, 16 Aug 2019 11:03:57 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Fri, 16 Aug 2019 11:03:50 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH] f2fs: fix to avoid data corruption by forbidding SSR overwrite Date: Fri, 16 Aug 2019 11:03:34 +0800 Message-ID: <20190816030334.81035-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.18.0.rc1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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++; } -- 2.18.0.rc1