Received: by 2002:ab2:6991:0:b0:1f2:fff1:ace7 with SMTP id v17csp147683lqo; Wed, 27 Mar 2024 09:07:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV/YThk3gwvLar3kBBZWUAjxWJUutpNcG9l3PS2WDwcbKm+a0fhpYV4qm86jjFOaBQBbdtoZ3qk7h0AWzlYe55P+DRFLr5LFWwat6UG+g== X-Google-Smtp-Source: AGHT+IGqjue47FVXQFGPX+ohiFZ2XEBHg7F625G+vRqW5nV5xbZkqw8u5Rs6FFEujhL7E6ckJxrW X-Received: by 2002:a05:6358:71c5:b0:17c:263a:5b8e with SMTP id u5-20020a05635871c500b0017c263a5b8emr3799101rwu.14.1711555669320; Wed, 27 Mar 2024 09:07:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711555669; cv=pass; d=google.com; s=arc-20160816; b=I4FJUo0+xQU/3XchDyVXHeCO+vd2Pp5q6vYA4UQyus9D5HlDyMiZIcj7PbdrE8fDnm fgri16kANAOwKxstWGZTSHApGTD/mFBQ2TJWlzVm7xSF5lguPacn1PrQk9kTOIW8avMN pLtNPPKZj7SGkNaDEcY4I2iEy91Npozgb17Mx91OBaM/+Yj3V1kpA7386LOU71OM52pl Z74bB1lJvqei8upbns/rmiCKnihRQijHNE+GrYzDrovS527DxH1NDwsVsyfeqNfTJv42 s8l7roQifw6ZBbIHlyRYPBobWP40Xj+0s1McGyYxB99eDEUr/p8MRfc8YXev0JhO83gG gPvg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:message-id:references:in-reply-to:subject :cc:to:from:date:mime-version:list-unsubscribe:list-subscribe :list-id:precedence; bh=U0rVmOxRtdD7ihkEdnhv5HboBd5hBTSdEm99jruGt9s=; fh=aHvEfclEq1BJAt6Etmu9SoeN+jxU/U3O/Kt53Hn22Po=; b=Tg5dNsrcPLAu6OcoT1HsiFccKJ55p1LbeKdEFjKoXUvrLPYtRceH9klb0R0ZYimFtc 4Rm6ajBcIpOh5BvbeTA/XosGH28jLQW+3kyk04XQYdxHeCv1acpRCqL0B+VSBKpWSaIs A7ty+fdXX6xXwGC3+3zFsHO74cOG9+HajKDdJpP+icZJgEIX+yCx5xbbEXIKfqb4Sec6 7p0SZ6SnBw98Szjd49pMBAwgusYEKxIoScgxBRPMjllE0le0UYc0obJvcKA7jjK5I16X ridjj5uj/TcwbVvAbyg+Zs4D+YMaBlUIN6UG+n+gW7/zwTAzW9MlRxjKle3zzUfixp1q SCHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=milecki.pl); spf=pass (google.com: domain of linux-kernel+bounces-121435-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121435-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id n63-20020a632742000000b005ce030a6460si11691674pgn.71.2024.03.27.09.07.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 09:07:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-121435-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=milecki.pl); spf=pass (google.com: domain of linux-kernel+bounces-121435-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-121435-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A1469B2F6B3 for ; Wed, 27 Mar 2024 15:06:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 511AC139567; Wed, 27 Mar 2024 14:27:09 +0000 (UTC) Received: from 10.mo575.mail-out.ovh.net (10.mo575.mail-out.ovh.net [46.105.79.203]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38CC712F5B9 for ; Wed, 27 Mar 2024 14:27:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.105.79.203 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711549628; cv=none; b=sDH8WziJUjQAAM5JnXdEmPtbF7hv/rvGGtSy47N1tLvqENkA6e+BTpL0m1dj1DE9xJfQgQ8wcw4aNiXQz/72rcBjgwLO1x7TVJipIDeun2fVTUgQ99zZQYcp62phCbeoPQQIbwGBvdo2RA4RYsDhhPSyokJhU9/iN8vbq6MRsUw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711549628; c=relaxed/simple; bh=pkuiviAAn0Uftfef1W5rS8J5Melpm/txesyxIQb8HRg=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type; b=XIAfC5L/Is/3YvG0lR8JagLosczmF0QcqZPp7P3p7CqdvSb7dniHzt/5faIDduWhp5desNaOK/eb4ZvUuWWtQCtAKEamKOpZKn0KVOUSmViTUlB8uQbV8hVbUKmWEIpnBNUka/qioVVcYLDVRYtJC8XBqeUWkfB7fF6Wp+sJtaQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=milecki.pl; spf=pass smtp.mailfrom=milecki.pl; arc=none smtp.client-ip=46.105.79.203 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=milecki.pl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=milecki.pl Received: from director10.ghost.mail-out.ovh.net (unknown [10.108.17.93]) by mo575.mail-out.ovh.net (Postfix) with ESMTP id 4V4TWh5Yk6z1SsF for ; Wed, 27 Mar 2024 14:26:56 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-5j6lf (unknown [10.110.96.237]) by director10.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 9D2931FE92; Wed, 27 Mar 2024 14:26:55 +0000 (UTC) Received: from milecki.pl ([37.59.142.103]) by ghost-submission-6684bf9d7b-5j6lf with ESMTPSA id lEULJa8sBGYx4A0AML5+ww (envelope-from ); Wed, 27 Mar 2024 14:26:55 +0000 Authentication-Results:garm.ovh; auth=pass (GARM-103G0051bcccc50-b51a-4dd6-be14-20d89d3369be, AD8588E3BB83D84E59DEA8CE8674EAB20989D6B2) smtp.auth=rafal@milecki.pl X-OVh-ClientIp:178.33.236.78 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Wed, 27 Mar 2024 15:26:55 +0100 From: =?UTF-8?Q?Rafa=C5=82_Mi=C5=82ecki?= To: Christian Marangi Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Jernej Skrabec , Claudiu Beznea , Greg Kroah-Hartman , Srinivas Kandagatla , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v3] mtd: limit OTP NVMEM Cell parse to non Nand devices In-Reply-To: <20240322040951.16680-1-ansuelsmth@gmail.com> References: <20240322040951.16680-1-ansuelsmth@gmail.com> Message-ID: <44a377b11208ff33045f12f260b667dd@milecki.pl> X-Sender: rafal@milecki.pl X-Webmail-UserID: rafal@milecki.pl Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-Ovh-Tracer-Id: 3220073736837835577 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrudduiedggedtucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepggffhffvvefujghfkfigihgtgfesthejjhdttddtvdenucfhrhhomheptfgrfhgrlhcuofhilhgvtghkihcuoehrrghfrghlsehmihhlvggtkhhirdhplheqnecuggftrfgrthhtvghrnhepkeeftefghfetueetveevvddugfelfeevvedvleeljeetfefggfdtteevuddtleeunecukfhppeduvdejrddtrddtrddupdefuddruddurddvudekrddutdeipddujeekrdeffedrvdefiedrjeekpdefjedrheelrddugedvrddutdefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpehrrghfrghlsehmihhlvggtkhhirdhplhdpnhgspghrtghpthhtohepuddprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdpoffvtefjohhsthepmhhoheejhedpmhhouggvpehsmhhtphhouhht On 2024-03-22 05:09, Christian Marangi wrote: > MTD OTP logic is very fragile and can be problematic with some specific > kind of devices. > > NVMEM across the years had various iteration on how Cells could be > declared in DT and MTD OTP probably was left behind and > add_legacy_fixed_of_cells was enabled without thinking of the > consequences. Er... thank you? > That option enables NVMEM to scan the provided of_node and treat each > child as a NVMEM Cell, this was to support legacy NVMEM implementation > and don't cause regression. > > This is problematic if we have devices like Nand where the OTP is > triggered by setting a special mode in the flash. In this context real > partitions declared in the Nand node are registered as OTP Cells and > this cause probe fail with -EINVAL error. > > This was never notice due to the fact that till now, no Nand supported > the OTP feature. With commit e87161321a40 ("mtd: rawnand: macronix: OTP > access for MX30LFxG18AC") this changed and coincidentally this Nand is > used on an FritzBox 7530 supported on OpenWrt. So as you noticed this problem was *exposed* by adding OTP support for Macronix NAND chips. > Alternative and more robust way to declare OTP Cells are already > prossible by using the fixed-layout node or by declaring a child node > with the compatible set to "otp-user" or "otp-factory". > > To fix this and limit any regression with other MTD that makes use of > declaring OTP as direct child of the dev node, disable > add_legacy_fixed_of_cells if we detect the MTD type is Nand. > > With the following logic, the OTP NVMEM entry is correctly created with > no Cells and the MTD Nand is correctly probed and partitions are > correctly exposed. > > Fixes: 2cc3b37f5b6d ("nvmem: add explicit config option to read old > syntax fixed OF cells") It's not that commit however that introduced the problem. Introducing "add_legacy_fixed_of_cells" just added a clean way of enabling parsing of old cells syntax. Even before my commit NVMEM subsystem was looking for NVMEM cells in NAND devices. I booted kernel 6.6 which has commit e87161321a40 ("mtd: rawnand: macronix: OTP > access for MX30LFxG18AC") but does NOT have commit 2cc3b37f5b6d ("nvmem: add explicit config option to read old syntax fixed OF cells"). Look at this log from Broadcom Northstar (Linux 6.6): [ 0.410107] nand: device found, Manufacturer ID: 0xc2, Chip ID: 0xdc [ 0.416531] nand: Macronix MX30LF4G18AC [ 0.420409] nand: 512 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64 [ 0.428022] iproc_nand 18028000.nand-controller: detected 512MiB total, 128KiB blocks, 2KiB pages, 16B OOB, 8-bit, BCH-8 [ 0.438991] Scanning device for bad blocks [ 0.873598] Bad eraseblock 738 at 0x000005c40000 [ 1.030279] random: crng init done [ 1.854895] Bad eraseblock 2414 at 0x000012dc0000 [ 2.657354] Bad eraseblock 3783 at 0x00001d8e0000 [ 2.662967] Bad eraseblock 3785 at 0x00001d920000 [ 2.848418] nvmem user-otp1: nvmem: invalid reg on /nand-controller@18028000/nand@0 [ 2.856126] iproc_nand 18028000.nand-controller: error -EINVAL: Failed to register OTP NVMEM device So to summary it up: 1. Problem exists since much earlier and wasn't introduced by 2cc3b37f5b6d 2. Commit 2cc3b37f5b6d just gives you a clean way of solving this issue 3. Problem was exposed by commit e87161321a40 4. We miss fix for v6.6 which doesn't have 2cc3b37f5b6d (it hit v6.7) > Cc: > Signed-off-by: Christian Marangi