From patchwork Wed Jan 16 00:59:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 1025567 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="QjAlf/Mu"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43fTKq6NKgz9sDT for ; Wed, 16 Jan 2019 11:56:15 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=HtNVVtqdqdGXdItNy9flY8SYN0gZEia4elzw/qJywvY=; b=QjAlf/MuVnsNVi uph3h012RNi3DB7s/ryXyRqHYQT4Dq+39ueS3rFshZZQwxkOlyPzx1K7WVLvKqOb8g/hmRiw9+20J kyknamBVPRusrBPB7sUsoB4l4l1NbsPx8kM6WcEblMWFOQYfF0rAAoLkF1OBrUATf9Kd0qvp3JX1t XaTwoGVgTrUxNY03CGPJ3ht/gvG72FvtoNWS+u4qUYSII19kmWYOALnNEniO9HXg89HyCs9xwkyuF SNU2IYJLrcCGwLleuoz1n6LLM4y8ly794IIcBeZtMFcxROoD8vdNehdY2/4A0K1Wj16Hk7NmtPfog oV5PFiFOidatOvKimLwA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gjZV4-0003A3-49; Wed, 16 Jan 2019 00:56:10 +0000 Received: from szxga06-in.huawei.com ([45.249.212.32] helo=huawei.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gjZV0-00039V-MJ for linux-mtd@lists.infradead.org; Wed, 16 Jan 2019 00:56:08 +0000 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 99CB9BA2130A5CB87422; Wed, 16 Jan 2019 08:55:57 +0800 (CST) Received: from huawei.com (10.90.53.225) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.408.0; Wed, 16 Jan 2019 08:55:53 +0800 From: Hou Tao To: Subject: [PATCH] ubi: account the fastmap data blocks when checking found_pebs Date: Wed, 16 Jan 2019 08:59:35 +0800 Message-ID: <20190116005935.141529-1-houtao1@huawei.com> X-Mailer: git-send-email 2.16.2.dirty MIME-Version: 1.0 X-Originating-IP: [10.90.53.225] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190115_165606_903447_89044E41 X-CRM114-Status: GOOD ( 11.12 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [45.249.212.32 listed in list.dnswl.org] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: richard@nod.at, boris.brezillon@bootlin.com, dedekind1@gmail.com Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Now the data blocks used by current fastmap are not tracked by wear-leveling subsystem. So taking these blocks into account when checking found_pebs in ubi_wl_init(), else there will be ubi assertion as shown below when fastmap is enabled on a large NAND Flash (e.g. 2GB): [ 335.877389] UBI assert failed in ubi_wl_init at 1705 (pid 2349) [ 335.878315] CPU: 7 PID: 2349 Comm: ubiattach Not tainted 4.20.0-10912-gd5d655675196-dirty #1 [ 335.879436] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996) [ 335.881012] Call Trace: [ 335.881402] dump_stack+0x5b/0x8b [ 335.881869] ubi_wl_init+0xf8b/0x1500 [ 335.882960] ubi_attach+0x63b/0xaa0 [ 335.883889] ubi_attach_mtd_dev+0x107f/0x2e50 [ 335.887300] ctrl_cdev_ioctl+0x13e/0x1d0 [ 335.888910] do_vfs_ioctl+0x197/0xe60 [ 335.893337] ksys_ioctl+0x66/0x70 [ 335.893788] __x64_sys_ioctl+0x6f/0xb0 [ 335.894309] do_syscall_64+0x91/0x270 [ 335.895337] entry_SYSCALL_64_after_hwframe+0x44/0xa9 Signed-off-by: Hou Tao --- drivers/mtd/ubi/ubi.h | 13 +++++++++++++ drivers/mtd/ubi/wl.c | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index d47b9e436e67..90c28522aa07 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h @@ -1235,4 +1235,17 @@ static inline struct ubi_wl_entry *ubi_find_fm_block(const struct ubi_device *ub return NULL; } +/** + * ubi_fm_data_blocks - return the number of data blocks used by fastmap + * @ubi: UBI device description object + * + * This function returns zero if fastmap is not available. + */ +static inline int ubi_fm_data_blocks(struct ubi_device *ubi) +{ + /* the first block is the super block of fastmap */ + if (ubi->fm) + return ubi->fm->used_blocks - 1; + return 0; +} #endif /* !__UBI_UBI_H__ */ diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c index 6f2ac865ff05..1b8f37ed8063 100644 --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c @@ -1702,7 +1702,8 @@ int ubi_wl_init(struct ubi_device *ubi, struct ubi_attach_info *ai) dbg_wl("found %i PEBs", found_pebs); - ubi_assert(ubi->good_peb_count == found_pebs); + ubi_assert(ubi->good_peb_count == + found_pebs + ubi_fm_data_blocks(ubi)); reserved_pebs = WL_RESERVED_PEBS; ubi_fastmap_init(ubi, &reserved_pebs);