Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp146689yba; Thu, 25 Apr 2019 20:03:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqylRtr985pu/SyNsaZAicJUelRnP+6QoIf9oqOEQJzADvXIZ50JlhRwX7vMackomq7aCgFk X-Received: by 2002:aa7:81d0:: with SMTP id c16mr43427110pfn.132.1556247793739; Thu, 25 Apr 2019 20:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556247793; cv=none; d=google.com; s=arc-20160816; b=Jk+k2qC2QC2wD+AvDfrxr8pr/RHsxNu5oTOgYJfYJ8YCQ+HZpvb9qEA5OieW+pHp9s ua5yFryOEdRFYX+74zWJ9hNZcO5GgTZjDeYYsy9vOF9w/aBOHyVdAQzMsEWznKTt6TOv cxe0WYvEFgF4sYXHvn6dDtHxGtNZjvpZWVWYC1Hir2b5F2voyCHNRSg3wDRFnKKJTNGk gCGRJsK1YonAa2IUU8I0cTT/Hyn3ez23CLMCFxLnMFCRVzGci+h/npA2lFqHfO5Z73u+ 26J0blmNKqkCOQ8twDWRr/onokBRWHV2Oh4kGDM1RS5qq88r1wgEVsyrgHCM8UG8TMsE TULg== 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=yfAZU2oV9z48rnBuEpsX5xHFhiKzFuYCOWTvf91Dbw4=; b=R1++wM7V5H/2gL5F/34d+TTodvIMzpnGXm/nAjN7cc0IRVkLq57z1aDcXXs1+imCp+ 9aNHpjuDcRyDh6dhJBbYGv1nepK/vqQXImKM7wQWIGPG/Wr1JrGa+15IspJOLh7j9dyo oxvVmMvJUsXpeZ/S1/gq/1joycskV/jzKqUybuNXHLHTAQG15gVPcUw+7kHJPBW5mPRf l8ZCDcac5gdzE4Zeti/j1euZ2zqvQFO3Yl820mSIp0nPLvtyJ3YCTsF580FCx9OwKrw+ Y79lVjcD2fFamtPvlN0fx45zw1QeKp4ZiWcu/cOdhW3JlrFPOHUkvYw4KAu0wB5hVNFd Lndg== 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 b144si10494391pfb.184.2019.04.25.20.02.57; Thu, 25 Apr 2019 20:03:13 -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 S1728269AbfDZC0D (ORCPT + 99 others); Thu, 25 Apr 2019 22:26:03 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:2942 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728271AbfDZC0C (ORCPT ); Thu, 25 Apr 2019 22:26:02 -0400 Received: from DGGEMM405-HUB.china.huawei.com (unknown [172.30.72.55]) by Forcepoint Email with ESMTP id BBF69B7BD93831104C50; Fri, 26 Apr 2019 10:26:00 +0800 (CST) Received: from dggeme763-chm.china.huawei.com (10.3.19.109) by DGGEMM405-HUB.china.huawei.com (10.3.20.213) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 26 Apr 2019 10:26:00 +0800 Received: from szvp000201624.huawei.com (10.120.216.130) by dggeme763-chm.china.huawei.com (10.3.19.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Fri, 26 Apr 2019 10:25:59 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH v2 2/2] f2fs: relocate chksum_offset for large_nat_bitmap feature Date: Fri, 26 Apr 2019 10:25:54 +0800 Message-ID: <20190426022554.56393-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-ClientProxiedBy: dggeme712-chm.china.huawei.com (10.1.199.108) To dggeme763-chm.china.huawei.com (10.3.19.109) X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For large_nat_bitmap feature, there is a design flaw: Previous: struct f2fs_checkpoint layout: +--------------------------+ 0x0000 | checkpoint_ver | | ...... | | checksum_offset |------+ | ...... | | | sit_nat_version_bitmap[] |<-----|-------+ | ...... | | | | checksum_value |<-----+ | +--------------------------+ 0x1000 | | | nat_bitmap + sit_bitmap | payload blocks | | | | | +--------------------------|<-------------+ Obviously, if nat_bitmap size + sit_bitmap size is larger than MAX_BITMAP_SIZE_IN_CKPT, nat_bitmap or sit_bitmap may overlap checkpoint checksum's position, once checkpoint() is triggered from kernel, nat or sit bitmap will be damaged by checksum field. In order to fix this, let's relocate checksum_value's position to the head of sit_nat_version_bitmap as below, then nat/sit bitmap and chksum value update will become safe. After: struct f2fs_checkpoint layout: +--------------------------+ 0x0000 | checkpoint_ver | | ...... | | checksum_offset |------+ | ...... | | | sit_nat_version_bitmap[] |<-----+ | ...... |<-------------+ | | | +--------------------------+ 0x1000 | | | nat_bitmap + sit_bitmap | payload blocks | | | | | +--------------------------|<-------------+ Related report and discussion: https://sourceforge.net/p/linux-f2fs/mailman/message/36642346/ Reported-by: Park Ju Hyung Signed-off-by: Chao Yu --- v2: - improve hint message suggested by Ju Hyung. - move verification to f2fs_sanity_check_ckpt(). fs/f2fs/f2fs.h | 4 +++- fs/f2fs/super.c | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 119bc5a9783e..aa71c1aa9eaa 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1909,9 +1909,11 @@ static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) int offset; if (is_set_ckpt_flags(sbi, CP_LARGE_NAT_BITMAP_FLAG)) { + unsigned int chksum_size = sizeof(__le32); + offset = (flag == SIT_BITMAP) ? le32_to_cpu(ckpt->nat_ver_bitmap_bytesize) : 0; - return &ckpt->sit_nat_version_bitmap + offset; + return &ckpt->sit_nat_version_bitmap + offset + chksum_size; } if (__cp_payload(sbi) > 0) { diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index fefc8cc6e756..22241bb866df 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2714,6 +2714,19 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) return 1; } + if (__is_set_ckpt_flags(ckpt, CP_LARGE_NAT_BITMAP_FLAG)) { + unsigned int chksum_offset; + + chksum_offset = le32_to_cpu(ckpt->checksum_offset); + if (chksum_offset != CP_MIN_CHKSUM_OFFSET) { + f2fs_msg(sbi->sb, KERN_WARNING, + "using deprecated layout of large_nat_bitmap, " + "please run fsck v1.13.0 or higher to repair, " + "chksum_offset: %u", chksum_offset); + return 1; + } + } + if (unlikely(f2fs_cp_error(sbi))) { f2fs_msg(sbi->sb, KERN_ERR, "A bug case: need to run fsck"); return 1; -- 2.18.0.rc1