Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp92894lqh; Wed, 27 Mar 2024 16:10:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU/CFnvlV35SFHrdRvLsmMKylIXGtbMx6An/4K2OWzKMheyqbU/vbJLaCYFfdAUh6U8ZiCYFBtDApO2ocmeAzETvgAi2HQGB9oZsi5yQQ== X-Google-Smtp-Source: AGHT+IFypQf0Cybtpmnp4gI74Sk338NsxjRXrD5UU9rfWgMLF6JvqrSwpZO3MpMvX21V8l1g9CLx X-Received: by 2002:a05:6808:120b:b0:3c3:da46:5fe5 with SMTP id a11-20020a056808120b00b003c3da465fe5mr1477195oil.57.1711581000752; Wed, 27 Mar 2024 16:10:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711581000; cv=pass; d=google.com; s=arc-20160816; b=eUO1lwxB+Hw86e30C5b8whjadvyX7QrK0TnhknA0QUaoct3hYy47ljHRunXK45+L2W qTI8UNDETudmrQcE3mIfJEjczK5kM83XsqkBEPLao3E2byvOwEyKyva3XA/xjsLKrVp8 fIEs1kMPt4+tCmndcmTe9zDmCFxobasFfJMsNUlR8UZaV2vSNfk3BM6y8Ae7GtI+K5N9 gBvy2qhXe8ZzWhP3pu4KNj2reE0gcp5wnhyZjyZVbD5z/8JdUwvJLWgEaKiy/oYyQzNp AlGm6wR4j1T+BqSb20DuMlwAYsvPAiHeNI/bs1f/a51STIsb++ALrXTS7MWlOFY+2an0 In5g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=RAFRkwiR6AaIXitW388S7NKcWuf0JtdwPIBXePwyf+A=; fh=aHvEfclEq1BJAt6Etmu9SoeN+jxU/U3O/Kt53Hn22Po=; b=H0hEPgjNbrBEZjmR8AYcqbtFbnLm8dWJesvm2oJ8LlCKFULPmAynbf5b+FxOCVNCdZ 5gOkiNXlmOpuTSzg7xaa5hclf5b5ehh1bqS1LelY0D2CS94YW/gicv1Nib9ppILIrzwg +S6CLToBT7m57TdVItB5mA2hbRtQdNhkcBxl8SsPHftJnSVZSUEgcKwQjhtD80n09fmv iANwqSl31PuM0K30oNEe8TacYfnrQliWqy72pIoL+0Nji2B1o2S52Fre5xopPIfiQm33 7eV2BFyFaj5qP0kt7umLOylu4/BXTDxXT11mvAwTC8hb9wlWhYku7Us9RaTSRqquHi4h 4XkQ==; 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-122140-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122140-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id w14-20020a05622a190e00b00431310f8ba4si176899qtc.340.2024.03.27.16.10.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 16:10:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122140-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=milecki.pl); spf=pass (google.com: domain of linux-kernel+bounces-122140-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122140-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6C8951C276C0 for ; Wed, 27 Mar 2024 23:10:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6B0B6153BF3; Wed, 27 Mar 2024 23:09:54 +0000 (UTC) Received: from 7.mo581.mail-out.ovh.net (7.mo581.mail-out.ovh.net [46.105.43.131]) (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 1BF8B1DA4E for ; Wed, 27 Mar 2024 23:09:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.105.43.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711580993; cv=none; b=MXnVTvX/4ahfI2t4UZYLO+YfFuhQ/nSQ3U+Z00LRJ+hIC+nPK6V95BFq2rL+OqMBx9zUPgigpgjTT6Sx3nWG/ONs0ov7AX3Nzwkw7rHspNEM6kTTMx/lLg8FDUoTr4LgY16QjKhaYLkEGxeHBVUoQ+EXAzeFMBWhIMCo2TxxMKE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711580993; c=relaxed/simple; bh=QjtZY6rB2FF4gyaL9iXzJNDSNIVD0xKrRIo9oJmORcU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=fmF6+4UAhvhMZOBfK7s1yuS3HLH/canLu9g+RlLwXHYzSAiHezr4X9yXdiaKh3j9aVTgIfFP5SiVsKCTwk4CWGqZH5YrEY6QxBU/2Is1tMY1DXow8GNkD9wjni5Dj5+ftE91IAjXVR2ycTSWISzqmQ3NfYCiOc/ou0pnpJuQN34= 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.43.131 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 director1.ghost.mail-out.ovh.net (unknown [10.109.140.166]) by mo581.mail-out.ovh.net (Postfix) with ESMTP id 4V4gQc4xTYz1Fv7 for ; Wed, 27 Mar 2024 21:53:12 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-fsmdr (unknown [10.110.168.247]) by director1.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 63E7A1FD49; Wed, 27 Mar 2024 21:53:09 +0000 (UTC) Received: from milecki.pl ([37.59.142.95]) by ghost-submission-6684bf9d7b-fsmdr with ESMTPSA id WN4WFEWVBGbp2AUAQbJ/Pw (envelope-from ); Wed, 27 Mar 2024 21:53:09 +0000 Authentication-Results:garm.ovh; auth=pass (GARM-95G00185960c84-105b-4035-9ca6-df95b4d75bca, AD8588E3BB83D84E59DEA8CE8674EAB20989D6B2) smtp.auth=rafal@milecki.pl X-OVh-ClientIp:31.11.218.106 Message-ID: Date: Wed, 27 Mar 2024 22:53:07 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] mtd: limit OTP NVMEM Cell parse to non Nand devices 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 References: <20240322040951.16680-1-ansuelsmth@gmail.com> <44a377b11208ff33045f12f260b667dd@milecki.pl> <66042f0a.050a0220.374bd.5e4a@mx.google.com> Content-Language: en-US From: =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= In-Reply-To: <66042f0a.050a0220.374bd.5e4a@mx.google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Ovh-Tracer-Id: 10756847710028540729 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrudduiedguddvlecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemucehtddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthekredttddvjeenucfhrhhomheptfgrfhgrlhcuofhilhgvtghkihcuoehrrghfrghlsehmihhlvggtkhhirdhplheqnecuggftrfgrthhtvghrnhepteetfeejjeeghfeikeevleevkeehtdeghffguddthefhgffgveduheetveejueetnecukfhppeduvdejrddtrddtrddupdefuddruddurddvudekrddutdeipdefjedrheelrddugedvrdelheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomheprhgrfhgrlhesmhhilhgvtghkihdrphhlpdhnsggprhgtphhtthhopedupdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdfovfetjfhoshhtpehmohehkedupdhmohguvgepshhmthhpohhuth On 27.03.2024 15:36, Christian Marangi wrote: > On Wed, Mar 27, 2024 at 03:26:55PM +0100, Rafał Miłecki wrote: >> 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? >> > > Probably made some bad assumption and sorry for it! No problem :) >>> 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) >> > > So the thing was broken all along? Maybe the regression was introduced > when OF support for NVMEM cell was introduced? (and OF scan was enabled > by default?) I went back to the commit 4b361cfa8624 ("mtd: core: add OTP nvmem provider support") from 2021 (it went into 5.14). It seems that even back then nvmem_register() used to call nvmem_add_cells_from_of(). SO maybe this problem is as old as that? > Anyway Sorry for adding the wrong fixes, maybe Miquel can remote the > commit from mtd/fixes and fix the problematic fixes tag? > >> >>> Cc: >>> Signed-off-by: Christian Marangi >