Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2542877ybk; Tue, 12 May 2020 01:58:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJws86GuwA4TpJqRyO5vKXo8T4RCT61W1Bqlpmp5aMcHH926lIEWGbel5+ovvK3yJuir2DQm X-Received: by 2002:aa7:ce9a:: with SMTP id y26mr1400350edv.160.1589273913108; Tue, 12 May 2020 01:58:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589273913; cv=none; d=google.com; s=arc-20160816; b=keXssRFWeemr1W2BA0sCqCnMCVlbAoLIHf9FlGd9RU/iCZwRIRhzo/cdCWXQsJ95Jn iesH6y5ZspMkfCO4vqXaT+2rKjSid8X2BA0MAlzJHKr6bU+YVdTdv/s7iY+pQLDROaXJ zWiVBFC0uz9+4mftaim+ypN9Ueyg267pMWbJYObFfcig3q1e6Pwl2OV/YQWBbjlaYuCO h0WEIQ/i4hjJ96Il60lAfWHyQymPm1fAJyBQNuqlMtM+667BicQj69PKWuapKq7k2HuZ LDbj9JpLZYdeyBSUYrKeM8I8Yzx8t6S6qmzaTyDMZqT4Z19U98sLp1cb7U17fKDW/Ubb /RbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=3oJ1ScZ4gZnKfEDLi7ATvvlKdSwmslFOX4j3rlIUbAA=; b=DEwN/VMzl0obTc0HNp7U/s8oEjwTJn//ftztWxk00F/En2/FTjMR26rAASdnSRjg2N UfDfO1c0J3AtPAQXkS4/veefYPTXKZUS1J4hnuQEcULxmz5GHubV6g2FCk3aQfs82gXt CPADmEUuIndaoR/H6WrOf4g36ja9Tt+LfU62xHIrB7w8MIA7sqH+gcyq9KoWLOhNBesW joCwseKGMQ3UEHiOWqf0gKcUjngz1EL746vopXywfNSOz0EsokXxXG23lj7bTdykvXo3 frgt+76PsCJIwzlxnFVdIUxIHAkdy/DQY3kuwWsnVSGlbssyhklC0HMVwdZ4dm0GtQdu 7H8Q== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cx2si6724760edb.452.2020.05.12.01.58.09; Tue, 12 May 2020 01:58:33 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729295AbgELIyP convert rfc822-to-8bit (ORCPT + 99 others); Tue, 12 May 2020 04:54:15 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:32886 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729267AbgELIyP (ORCPT ); Tue, 12 May 2020 04:54:15 -0400 Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: bbrezillon) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 3FA352A1F41; Tue, 12 May 2020 09:54:12 +0100 (BST) Date: Tue, 12 May 2020 10:54:09 +0200 From: Boris Brezillon To: Miquel Raynal Cc: =?UTF-8?B?w4FsdmFybyBGZXJuw6FuZGV6?= Rojas , richard@nod.at, vigneshr@ti.com, s.hauer@pengutronix.de, masonccyang@mxic.com.tw, christophe.kerello@st.com, stefan@agner.ch, piotrs@cadence.com, devik@eaxlabs.cz, tglx@linutronix.de, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] nand: raw: use write_oob_raw for MTD_OPS_AUTO_OOB mode Message-ID: <20200512105409.785febfe@collabora.com> In-Reply-To: <20200512104422.4c31f7e0@xps13> References: <20200504094253.2741109-1-noltari@gmail.com> <20200504123237.5c128668@collabora.com> <20200511182923.6a4961ab@xps13> <6F41AA9B-71D6-47FA-BC12-24941F84DA71@gmail.com> <20200512104422.4c31f7e0@xps13> Organization: Collabora X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 12 May 2020 10:44:22 +0200 Miquel Raynal wrote: > Hello, > > Richard, maybe you'll have an idea to fix the situation here? > > Álvaro Fernández Rojas wrote on Tue, 12 May 2020 > 10:36:25 +0200: > > > Hi, > > > > > El 11 may 2020, a las 18:29, Miquel Raynal escribió: > > > > > > Hello, > > > > > > Boris Brezillon wrote on Mon, 4 May > > > 2020 12:32:37 +0200: > > > > > >> On Mon, 4 May 2020 11:42:53 +0200 > > >> Álvaro Fernández Rojas wrote: > > >> > > >>> Some NAND controllers change the ECC bytes when OOB is written with ECC > > >>> enabled. > > >>> This is a problem in brcmnand, since adding JFFS2 cleanmarkers after the page > > >>> has been erased will change the ECC bytes to 0 and the controller will think > > >>> the block is bad. > > >>> It can be fixed by using write_oob_raw, which ensures ECC is disabled. > > >>> > > >>> Signed-off-by: Álvaro Fernández Rojas > > >>> --- > > >>> drivers/mtd/nand/raw/nand_base.c | 2 +- > > >>> 1 file changed, 1 insertion(+), 1 deletion(-) > > >>> > > >>> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c > > >>> index c24e5e2ba130..755d25200520 100644 > > >>> --- a/drivers/mtd/nand/raw/nand_base.c > > >>> +++ b/drivers/mtd/nand/raw/nand_base.c > > >>> @@ -488,7 +488,7 @@ static int nand_do_write_oob(struct nand_chip *chip, loff_t to, > > >>> > > >>> nand_fill_oob(chip, ops->oobbuf, ops->ooblen, ops); > > >>> > > >>> - if (ops->mode == MTD_OPS_RAW) > > >>> + if (ops->mode == MTD_OPS_AUTO_OOB || ops->mode == MTD_OPS_RAW) > > >>> status = chip->ecc.write_oob_raw(chip, page & chip->pagemask); > > >> > > >> The doc says: > > >> > > >> @MTD_OPS_PLACE_OOB: OOB data are placed at the given offset (default) > > >> @MTD_OPS_AUTO_OOB: OOB data are automatically placed at the free areas > > >> which are defined by the internal ecclayout > > >> @MTD_OPS_RAW: data are transferred as-is, with no error > > >> correction; this mode implies %MTD_OPS_PLACE_OOB > > >> > > >> To me, that means MTD_OPS_PLACE_OOB and MTD_OPS_AUTO_OOB do not imply > > >> MTD_OPS_RAW. Anyway those modes are just too vague. We really should > > >> separate the ECC-disabled/ECC-enabled concept (AKA raw vs non-raw mode) > > >> from the OOB placement scheme. IIRC, Miquel had a patchset doing that. > > >> > > >> We also should have the concept of protected OOB-region vs > > >> unprotected-OOB-region if we want JFFS2 to work with controllers that > > >> protect part of the OOB region. Once we have that we can patch JFFS2 > > >> to write things with "ECC-disabled"+"auto-OOB-placement-on-unprotected > > >> area". > > > > > > I see the problem but as Boris said the fix is not valid as-is. > > > Problem is: I don't have a better proposal yet. > > > > > > Is forcing JFFS2 to write cleanmarkers in raw mode only an option? > > > > The doc says that for MTD_OPS_AUTO_OOB "the data is automatically placed at the free areas which are defined by the internal ecclayout”. > > So, if we’re placing this data in the free OOB area left by the ECC bytes it means that this automatically placed data won’t be error correctable, since it’s in the OOB, and the OOB data isn’t error corrected, right? > > No, free bytes sometimes are and sometimes are not covered by the ECC > engine. It depends on the controller. > > > The problem is that "flash_erase -j” uses MTD_OPS_AUTO_OOB to write the OOB JFFS2 clean markers and if this is written with ECC enabled the NAND controller will change the ECC bytes to an invalid value (or at least brcmnand controller). > > > > Another option could be adding another mode, something like MTD_OPS_AUTO_OOB_RAW and using it in mtd-utils and JFFS2. > > No, these modes already are completely wrong, I must resend my series > fixing them. > Totally agree with Miquel on that one: let's fix the write/read/ecc-layout semantics instead of adding more obscure modes.