From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=185.246.84.56 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796294808; b=STo6XsU4K8Q62pBzq4L6IKqFCKDH1YSD3KBOXGx2C6mLQs3qKUxL62d61xm7s5Dr2BRM fjqQJTTR8wpRhfur4FxzH/sL1LskPLwEon+DvUrymZo2SmQsJ2Q6SMqzTBS/wMV6MoBm6 rpdUy71SgwacUbW3+nBv9HFeW/tBE/Cx7wQumqcAnZ3RmOEXqQtD2LD6OWOIJwNo/OIPL h83r+jcvrS47nj9phTiR7ALLDF/RvaZrjgwWWEFVCoGZdiLLJ1V+4wJ61ju+epeXt8aMk 2HYJw9OIPzSERMyadWveA41WZP1Wrlelnurj4KaVIB+GBr60u6ur1PlSFmboxHXAxXg== 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=ZXp/sDu3NpWdYpX3BqIVOgL4/qYN6kYtowks568Mj6+KmP6mzDmPiLo63VKyNmD/ksMf o9OyJ2JvyI9M63w591YUEPQmFjlTicxnbcH70xz83kjnshV7wHIamyOOFRNPTg3WUiwi0 6Rnpbp0U9iSPuA2rj3NLyc2LtrnfA+EfH4YbNHUSvVBOpmOgOkcFMV8pdnGlF9PFLTWQN qkaq9mp6WjNYcwCe+h/x8ANZxbuiSYrS+ZyhXvLgsea/9E/hEICg+rRitsDf9ljphhWC6 sdOQcuVc52zODBevYKP2T+ZOgSff529mt5SilQPIOCfHEEBMdFCWJi/4pc0Vr/O7lkw== 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.84.56 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (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 A2DA8606A32C for ; Thu, 3 Dec 2026 10:46:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A2DA8606A32C 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-02.galae.net (Postfix) with ESMTPS id ABED51A190A; 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: imx@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