Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1236549pxf; Fri, 19 Mar 2021 02:25:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1ux6O3Sv/cIT8YdwW3yBdJH8K2rz4BO6OWsbThp/5vL7rwc9GEvAMr5RgCl4RU2GFJcke X-Received: by 2002:a17:906:2816:: with SMTP id r22mr3214718ejc.2.1616145928325; Fri, 19 Mar 2021 02:25:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616145928; cv=none; d=google.com; s=arc-20160816; b=cE2RuMHoac0HoIxfFFj+tTf5l9I7YomeEss0GWR3/JXpb2yCq+8NJ6cEw8kQuDdg1i 2a4K+LRvbm1+hMNgdnnG9qTI5aT7AqVVCU2yzNq2rujtiWNJ71HQhBxANye48FdR9+y6 VTH5W/+9+1fZ/+sGtRqauXk4lgqWWmHY8GvIET47Ci+tjfh2oEQKdPzmodDEkg7Qxodq LsYbb4zM6ytk1se4T15unfC5FI+xYdI33zkiZgzqmh3Ex02P2vySRSM4jamcmD9Hkwxr UDWH1MPCUwqg78pXvevwFyvCcTecuT2apxWxQMKzPUvDvAtpepWS92RTehz3Gmw5dMPN OPIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=vqPoBIR/dbpnUcsZrGy1Wi6ucv3MOTgNAHmdcxiiAtQ=; b=L6PzQIMUdiHAhlZBrcQbRTqQN8I/mzdvmBItaAZAzNBl4qilUOYJy1CcKS0XdCE6O1 85wMIJHIu3a1isZlXfNLgAMKK0SG1XCMqYAxi5OxtNCkkoXfhObmcMnzfinttC1dhEv6 7HmBC2odTMt6swAC1CZlBmP53QiZNlVQvcSMfVBE5OJViC9IsfVX6WMnoXWSLLcLz21t RpsCuuEfV5YHZXg/KEOiH1uRkXcrDiDv2uFOsY2TS/GN0RviHzLBm/e6Wqp4QqnqeHKT m12MsLp9+L5sdJOKBobYZq6nb9q5Cejrv894SOdJP0DYk8uDMtmwWOUBOF7OdARHQyed LBbw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i5si3533190edc.581.2021.03.19.02.25.04; Fri, 19 Mar 2021 02:25:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229736AbhCSJX5 convert rfc822-to-8bit (ORCPT + 99 others); Fri, 19 Mar 2021 05:23:57 -0400 Received: from relay5-d.mail.gandi.net ([217.70.183.197]:58773 "EHLO relay5-d.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229648AbhCSJXn (ORCPT ); Fri, 19 Mar 2021 05:23:43 -0400 X-Originating-IP: 90.89.138.59 Received: from xps13 (lfbn-tou-1-1325-59.w90-89.abo.wanadoo.fr [90.89.138.59]) (Authenticated sender: miquel.raynal@bootlin.com) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 8AD321C0006; Fri, 19 Mar 2021 09:23:39 +0000 (UTC) Date: Fri, 19 Mar 2021 10:23:38 +0100 From: Miquel Raynal To: Yoshio Furuyama Cc: richard@nod.at, vigneshr@ti.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Patrick Doyle Subject: Re: [PATCH v1] mtd: nand: Fix BBT update issue Message-ID: <20210319102117.47774faf@xps13> In-Reply-To: References: <1613435875-6846-1-git-send-email-ytc-mb-yfuruyama7@kioxia.com> Organization: Bootlin X-Mailer: Claws Mail 3.17.7 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Yoshio, + Patrick Yoshio Furuyama wrote on Tue, 16 Feb 2021 09:37:55 +0900: > Fixed issue of manages BBT (Bad Block Table). > It didn't mark correctly when a specific block was bad block. > > This issue occurs when the bad block mark (3-bit chunk) is > crosses over 32 bit (e.g. Block10, Block21...) unit. > Thanks for the patch and sorry for the very long wait period, I wanted to understand better the issue but I didn't had the time to do it. Would you mind having a look at Patrick's fix merged in U-Boot a year ago: commit 06fc4573b9d0878dd1d3b302884601263fe6e85f Author: Doyle, Patrick Date: Wed Jul 15 14:46:34 2020 +0000 Fix corner case in bad block table handling. In the unlikely event that both blocks 10 and 11 are marked as bad (on a 32 bit machine), then the process of marking block 10 as bad stomps on cached entry for block 11. There are (of course) other examples. Signed-off-by: Patrick Doyle Reviewed-by: Richard Weinberger diff --git a/drivers/mtd/nand/bbt.c b/drivers/mtd/nand/bbt.c index 84d60b86521..294daee7b22 100644 --- a/drivers/mtd/nand/bbt.c +++ b/drivers/mtd/nand/bbt.c @@ -127,7 +127,7 @@ int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry, unsigned int rbits = bits_per_block + offs - BITS_PER_LONG; pos[1] &= ~GENMASK(rbits - 1, 0); - pos[1] |= val >> rbits; + pos[1] |= val >> (bits_per_block - rbits); } return 0; It looks both patches fix different errors but I wonder if merging Patrick's patch first would not make more sense. Ideally, could you please send a series with the two patches, perhaps Patrick's patch first, then yours, adding a Fixes and Cc: stable tags to both? > Signed-off-by: Yoshio Furuyama > --- > drivers/mtd/nand/bbt.c | 6 ++++-- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/drivers/mtd/nand/bbt.c b/drivers/mtd/nand/bbt.c > index 044adf913854..979c47e61381 100644 > --- a/drivers/mtd/nand/bbt.c > +++ b/drivers/mtd/nand/bbt.c > @@ -112,18 +112,20 @@ int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry, > ((entry * bits_per_block) / BITS_PER_LONG); > unsigned int offs = (entry * bits_per_block) % BITS_PER_LONG; > unsigned long val = status & GENMASK(bits_per_block - 1, 0); > + unsigned long shift = ((bits_per_block + offs <= BITS_PER_LONG) ? > + (offs + bits_per_block - 1) : (BITS_PER_LONG - 1)); > > if (entry >= nanddev_neraseblocks(nand)) > return -ERANGE; > > - pos[0] &= ~GENMASK(offs + bits_per_block - 1, offs); > + pos[0] &= ~GENMASK(shift, offs); > pos[0] |= val << offs; > > if (bits_per_block + offs > BITS_PER_LONG) { > unsigned int rbits = bits_per_block + offs - BITS_PER_LONG; > > pos[1] &= ~GENMASK(rbits - 1, 0); > - pos[1] |= val >> rbits; > + pos[1] |= (val >> (BITS_PER_LONG - offs)); > } > > return 0; Thanks, Miquèl