From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.246.85.4 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796294808; b=gh6iwzdrAUgjtZ2wZCe8kxRzdMZbY1Gi5Jp76TfG3fQGqxAeA5IDmM/rh+B4/BAnxq2E tnwBUf2lGQ4SvfHqjXYfDKONzxOoDGpAL3rg001VTTajAQXcfkwRzOYTip+u/c1iwYq8M 7Haj8KxaAduTdhXBOIHg1HJRRWDFJnn0J8vhjTeSyay2YMwF4JPiOtr10gXbFnFoxKK4r HSVAudEwMFM1sa/mpLhjxzx+J7otZoIkNN4nss1Fn/u9htug5P3NkfTt2PziCyEnrM+a2 muNun7ZUbOh/eYJZR7+gFrVM8xIg5yOBq6pCoTpNPB3uBMQb2u6EBIWuq0FXWb2/iuw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796294808; h=DMARC-Filter:Received:Received:Received:DKIM-Signature:From:To:Cc: Subject:In-Reply-To:References:User-Agent:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding: X-Last-TLS-Session-Version; bh=FXFIt1ZcNiolGFAfGp2fXz1N2/eeEFstnTi03NpC18A=; b=4uuH6w/wUgKLNVL/plH7ynlIS1Kj8K5xyaKQwBY468EBz4ziyRAqBCU2ImnCCNwtMCxk mDhib44GnkYZiJfJmqPLVELE20r3K1gy4Bi6r0Y/Eweul8EadBZbAAxxOSisAl/FPVjlQ z874h344RIdzY6AKyiNxE9WqhYPp3qKdTwz2LMpNe2SiYfrUCXnrQPvSreXbmBx6yJAHu 29n9SWFxP5L+TntvpcZaAWm0586kS1kJ1vbCnpaWf75TPzi/MSRS8b94Ke00UVkAH37hj XUMQ1xokhKwk675GyzgkcDTcDsMOhXadnAN9SX10SSX2SmZl5jOv1HLxK5dq6Ov7v0w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=UybTi4ef; arc=none smtp.remote-ip=185.246.85.4 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D93A3606A32D for ; Thu, 3 Dec 2026 10:46:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D93A3606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.a=rsa-sha256 header.s=dkim header.b=UybTi4ef Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id AE0AB4E4185D; Thu, 3 Dec 2026 10:46:45 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 665A660767; Thu, 3 Dec 2026 10:46:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id CC87211EA04BD; Thu, 03 Dec 2026 11:46:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1796294801; h=from:subject:date:message-id:to:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references; bh=FXFIt1ZcNiolGFAfGp2fXz1N2/eeEFstnTi03NpC18A=; b=UybTi4eflF4xsfECjYh6vCkjYLQITA5rta8x3XuKmefafr+0DD8i3a5/1hP5waYHwFfSXB zh7uzunl54rxPvCZPlhu5/GvAMJ0nK0nr56uWH5rqLB8DEbhXHiB19T8b/f7JnOx+E13jx KwWYuOyQS+zAwP1GD/yLI6eQIbP+gJVQUE1/9w88M6IGhkmE5cNJbV6N9l6pGpl4H0qH9b LUpbIkJU2J0EtIGjjYyoWZCEOfVUl/fA+xi/y8MdkamEfi18CXqWNGJI80bI74Q+GkRgus qM+dK7QcFIgUlLQ/NV2+tS+6OtPaNb/iPe8yR2voeFPEnHvVS0Npmn/rzFbPDA== From: Miquel Raynal To: James Hilliard Cc: Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Srinivas Kandagatla , Tze Yee Ng , Richard Cochran , Jonathan Lemon , Vadim Fedorenko , Yuqiang Sun , Amit Kumar Mahapatra , Luca Ceresoli , Bernhard Frauendienst , "Gustavo A. R. Silva" , Kees Cook , linux-hardening@vger.kernel.org, Arseniy Krasnov , Boris Brezillon , Brian Norris , Jernej Skrabec , linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, Samuel Holland , Chen-Yu Tsai , David Woodhouse , Thomas Gleixner , Vitaly Wool , David Woodhouse , Russell King , Mike Rapoport , Alexandre Torgue , Christophe Kerello , Maxime Coquelin , Jason Roberts , Boris Brezillon , Michal Simek , Mason Yang , Ramuthevar Vadivel Murugan , Lucas Stach , Dmitry Osipenko , Jonathan Hunter , linux-tegra@vger.kernel.org, Stefan Agner , Thierry Reding , AngeloGioacchino Del Regno , Jorge Ramirez-Ortiz , linux-mediatek@lists.infradead.org, Matthias Brugger , Heiko Stuebner , linux-rockchip@lists.infradead.org, Yifeng Zhao , Alexandre Belloni , Claudiu Beznea , Nicolas Ferre , Keguang Zhang , linux-mips@vger.kernel.org, Shan-Chun Hung , Jacky Huang , Fabio Estevam , Frank Li , imx@lists.linux.dev, Pengutronix Kernel Team , Sascha Hauer , Han Xu , linux-renesas-soc@vger.kernel.org, Wolfram Sang , Jerome Brunet , Kevin Hilman , Liang Yang , linux-amlogic@lists.infradead.org, Martin Blumenstingl , Neil Armstrong , linux-arm-msm@vger.kernel.org, Manivannan Sadhasivam , Broadcom internal kernel review list , Kamal Dasu , Piotr Wojtaszczyk , Vladimir Zapolskiy , Harvey Hunt , Paul Cercueil , Maxim Levitsky Subject: Re: [PATCH v5 00/58] mtd: rawnand: retain chip and controller state across removal In-Reply-To: (James Hilliard's message of "Sat, 21 Nov 2026 13:41:14 -0700") References: <20261115-submit-rawnand-retained-handle-lifetime-v1-v5-0-cbc49c5c5e74@gmail.com> <87v75tc7i5.fsf@bootlin.com> User-Agent: mu4e 1.12.12; emacs 30.2 Date: Thu, 03 Dec 2026 11:46:07 +0100 Message-ID: <878q26k5g0.fsf@bootlin.com> X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Hi, >> Maybe the problem is MTD refcounting? Maybe the problem is the devm_ >> orderging? I don't know, I haven't looked in depth at all the >> patches. But the current approach is clearly not acceptable. > > The issue is what the MTD reference owns. The change in [1] defers MTD > core cleanup until the last reference is dropped. In raw NAND, though, > the mtd_info is embedded in the nand_chip. An MTD reference doesn't > keep the driver's allocation containing that chip alive. Reordering > devres cleanup can't protect a close that happens after detach. > > One way to keep the fix in the core would be to give consumers an MTD > object whose storage is separate from the chip. At unregister, the core > could disconnect that object from the driver and drain operations that > already have access to it, much like NVMEM does for provider operations > [2]. The driver could then free its private state. Reads and writes on > the old file would return -ENODEV, and close would drop the reference > without calling the driver. The main change for raw NAND is that it > could no longer recover the chip from the consumer's mtd_info by > assuming one is embedded in the other. We already have helpers (nand_to_mtd, mtd_to_nand) doing that, so the transition could be rather smooth. But storing the framework device in the driver data is very common practice, so there must be another way to handle the problem. > The other way to free the chip at removal is to keep the current layout > and have every consumer drop its MTD pointer at unregister. There is already an mtd_unregister* call, so that would be pretty self contained. > That could > work for mtdchar, but it would also have to cover in-kernel consumers > such as UBI. Fixing the close path alone wouldn't be enough. > > A shared allocation helper or a per-provider reference, as proposed for > SPI NOR [3], would keep the allocation until the last put. That's not a > permanent leak, but an idle file could still pin driver-private memory > indefinitely. What's the problem? Isn't that normal behavior? If there is an user, there is an user. I don't get why that's a problem. > Waiting for the last put during removal would instead let > the same file block removal indefinitely. > > Would it make sense to pursue the core-owned MTD object, so an open > file can survive removal without keeping any driver-private memory > alive? You can try, but I will definitely discard v1's idea. Thanks, Miqu=C3=A8l