mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: James Hilliard <james.hilliard1@gmail.com>
Cc: Richard Weinberger <richard@nod.at>,
	 Vignesh Raghavendra <vigneshr@ti.com>,
	 linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 Srinivas Kandagatla <srini@kernel.org>,
	Tze Yee Ng <tze.yee.ng@altera.com>,
	 Richard Cochran <richardcochran@gmail.com>,
	 Jonathan Lemon <jonathan.lemon@gmail.com>,
	Vadim Fedorenko <vadim.fedorenko@linux.dev>,
	 Yuqiang Sun <izaiahsun@gmail.com>,
	 Amit Kumar Mahapatra <amit.kumar-mahapatra@amd.com>,
	 Luca Ceresoli <luca.ceresoli@bootlin.com>,
	 Bernhard Frauendienst <kernel@nospam.obeliks.de>,
	 "Gustavo A. R. Silva" <gustavoars@kernel.org>,
	 Kees Cook <kees@kernel.org>,
	linux-hardening@vger.kernel.org,
	 Arseniy Krasnov <AVKrasnov@sberdevices.ru>,
	 Boris Brezillon <bbrezillon@kernel.org>,
	Brian Norris <computersforpeace@gmail.com>,
	 Jernej Skrabec <jernej.skrabec@gmail.com>,
	 linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev,
	 Samuel Holland <samuel@sholland.org>,
	Chen-Yu Tsai <wens@kernel.org>,
	 David Woodhouse <dwmw2@infradead.org>,
	Thomas Gleixner <tglx@kernel.org>,
	 Vitaly Wool <vitalywool@gmail.com>,
	David Woodhouse <David.Woodhouse@intel.com>,
	 Russell King <rmk+kernel@arm.linux.org.uk>,
	 Mike Rapoport <rppt@kernel.org>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	 Christophe Kerello <christophe.kerello@st.com>,
	 Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Jason Roberts <jason.e.roberts@intel.com>,
	 Boris Brezillon <boris.brezillon@collabora.com>,
	 Michal Simek <michal.simek@amd.com>,
	Mason Yang <masonccyang@mxic.com.tw>,
	 Ramuthevar Vadivel Murugan
	<vadivel.muruganx.ramuthevar@linux.intel.com>,
	 Lucas Stach <dev@lynxeye.de>,
	 Dmitry Osipenko <digetx@gmail.com>,
	 Jonathan Hunter <jonathanh@nvidia.com>,
	 linux-tegra@vger.kernel.org,  Stefan Agner <stefan@agner.ch>,
	 Thierry Reding <thierry.reding@kernel.org>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Jorge Ramirez-Ortiz <jorge.ramirez@oss.qualcomm.com>,
	linux-mediatek@lists.infradead.org,
	 Matthias Brugger <matthias.bgg@gmail.com>,
	 Heiko Stuebner <heiko@sntech.de>,
	linux-rockchip@lists.infradead.org,
	 Yifeng Zhao <yifeng.zhao@rock-chips.com>,
	 Alexandre Belloni <alexandre.belloni@bootlin.com>,
	 Claudiu Beznea <claudiu.beznea@tuxon.dev>,
	 Nicolas Ferre <nicolas.ferre@microchip.com>,
	Keguang Zhang <keguang.zhang@gmail.com>,
	 linux-mips@vger.kernel.org, Shan-Chun Hung <schung@nuvoton.com>,
	 Jacky Huang <ychuang3@nuvoton.com>,
	Fabio Estevam <festevam@gmail.com>,  Frank Li <Frank.Li@nxp.com>,
	imx@lists.linux.dev,
	 Pengutronix Kernel Team <kernel@pengutronix.de>,
	Sascha Hauer <s.hauer@pengutronix.de>,  Han Xu <han.xu@nxp.com>,
	linux-renesas-soc@vger.kernel.org,
	 Wolfram Sang <wsa+renesas@sang-engineering.com>,
	 Jerome Brunet <jbrunet@baylibre.com>,
	Kevin Hilman <khilman@baylibre.com>,
	 Liang Yang <liang.yang@amlogic.com>,
	 linux-amlogic@lists.infradead.org,
	 Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
	 Neil Armstrong <neil.armstrong@linaro.org>,
	 linux-arm-msm@vger.kernel.org,
	 Manivannan Sadhasivam <mani@kernel.org>,
	 Broadcom internal kernel review list
	<bcm-kernel-feedback-list@broadcom.com>,
	 Kamal Dasu <kamal.dasu@broadcom.com>,
	 Piotr Wojtaszczyk <piotr.wojtaszczyk@timesys.com>,
	 Vladimir Zapolskiy <vz@mleia.com>,
	Harvey Hunt <harveyhuntnexus@gmail.com>,
	 Paul Cercueil <paul@crapouillou.net>,
	 Maxim Levitsky <maximlevitsky@gmail.com>
Subject: Re: [PATCH v5 00/58] mtd: rawnand: retain chip and controller state across removal
Date: Thu, 03 Dec 2026 11:46:07 +0100	[thread overview]
Message-ID: <878q26k5g0.fsf@bootlin.com> (raw)
In-Reply-To: <CADvTj4opS_oL0AZjL=eBArgpbqtyH-MQxxSC1KdTxDm88OXpKw@mail.gmail.com> (James Hilliard's message of "Sat, 21 Nov 2026 13:41:14 -0700")

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èl

      reply	other threads:[~2026-12-03 10:46 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  6:29 James Hilliard
2026-11-16  6:29 ` [PATCH v5 01/58] nvmem: disconnect provider callbacks before unregister returns James Hilliard
2026-11-17 11:25   ` Paul Cercueil
2026-11-17 19:42     ` James Hilliard
2026-11-16  6:29 ` [PATCH v5 02/58] mtd: acquire an MTD handle from a referenced class device James Hilliard
2026-11-16  6:29 ` [PATCH v5 03/58] mtd: separate class devices from retained backing objects James Hilliard
2026-11-16  6:29 ` [PATCH v5 04/58] mtd: retain virtual concatenations across component removal James Hilliard
2026-11-16  6:29 ` [PATCH v5 05/58] mtd: rawnand: separate hardware disconnection from cleanup James Hilliard
2026-11-16  6:29 ` [PATCH v5 06/58] mtd: rawnand: share retained chip and controller ownership James Hilliard
2026-11-16  6:29 ` [PATCH v5 07/58] mtd: rawnand: sunxi: retain chip state until the final MTD put James Hilliard
2026-11-16  6:29 ` [PATCH v5 08/58] mtd: rawnand: plat_nand: retain open-handle state on removal James Hilliard
2026-11-16  6:29 ` [PATCH v5 09/58] mtd: rawnand: gpio: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 10/58] mtd: rawnand: stm32_fmc2: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 11/58] mtd: rawnand: denali: retain chips across controller removal James Hilliard
2026-11-16  6:29 ` [PATCH v5 12/58] mtd: rawnand: arasan: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 13/58] mtd: rawnand: mxic: retain open-handle state on removal James Hilliard
2026-11-16  6:29 ` [PATCH v5 14/58] mtd: rawnand: intel: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 15/58] mtd: rawnand: tegra: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 16/58] mtd: rawnand: mtk: retain chips across controller removal James Hilliard
2026-11-16  6:29 ` [PATCH v5 17/58] mtd: rawnand: rockchip: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 18/58] mtd: rawnand: atmel: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 19/58] mtd: rawnand: orion: retain open-handle state on removal James Hilliard
2026-11-16  6:29 ` [PATCH v5 20/58] mtd: rawnand: socrates: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 21/58] mtd: rawnand: fsl_upm: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 22/58] mtd: rawnand: pasemi: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 23/58] mtd: rawnand: ams-delta: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 24/58] mtd: rawnand: xway: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 25/58] mtd: rawnand: hisi504: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 26/58] mtd: rawnand: vf610: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 27/58] mtd: rawnand: technologic: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 28/58] mtd: rawnand: loongson: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 29/58] mtd: rawnand: ma35d1: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 30/58] mtd: rawnand: pl35x: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 31/58] mtd: rawnand: mxc: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 32/58] mtd: rawnand: fsmc: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 33/58] mtd: rawnand: gpmi: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 34/58] mtd: rawnand: omap2: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 35/58] mtd: rawnand: marvell: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 36/58] mtd: rawnand: renesas: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 37/58] mtd: rawnand: meson: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 38/58] mtd: rawnand: cadence: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 39/58] mtd: rawnand: qcom: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 40/58] mtd: rawnand: cafe: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 41/58] mtd: rawnand: brcmnand: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 42/58] mtd: rawnand: au1550nd: retain chip state across removal James Hilliard
2026-11-16  6:29 ` [PATCH v5 43/58] mtd: rawnand: sharpsl: " James Hilliard
2026-11-16  6:29 ` [PATCH v5 44/58] mtd: rawnand: davinci: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 45/58] mtd: rawnand: sh_flctl: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 46/58] mtd: rawnand: lpc32xx_slc: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 47/58] mtd: rawnand: lpc32xx_mlc: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 48/58] mtd: rawnand: ndfc: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 49/58] mtd: rawnand: txx9ndfmc: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 50/58] mtd: rawnand: ingenic: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 51/58] mtd: rawnand: mpc5121: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 52/58] mtd: rawnand: bcm47xxnflash: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 53/58] mtd: rawnand: fsl_elbc: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 54/58] mtd: rawnand: fsl_ifc: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 55/58] mtd: rawnand: r852: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 56/58] mtd: rawnand: nandsim: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 57/58] mtd: rawnand: cs553x: " James Hilliard
2026-11-16  6:30 ` [PATCH v5 58/58] mtd: rawnand: diskonchip: " James Hilliard
2026-11-16 15:29 ` [PATCH v5 00/58] mtd: rawnand: retain chip and controller " Miquel Raynal
2026-11-16 18:39   ` James Hilliard
2026-11-19 12:48 ` Miquel Raynal
2026-11-21 20:41   ` James Hilliard
2026-12-03 10:46     ` Miquel Raynal [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878q26k5g0.fsf@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=AVKrasnov@sberdevices.ru \
    --cc=David.Woodhouse@intel.com \
    --cc=Frank.Li@nxp.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=amit.kumar-mahapatra@amd.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=bbrezillon@kernel.org \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=boris.brezillon@collabora.com \
    --cc=christophe.kerello@st.com \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=computersforpeace@gmail.com \
    --cc=dev@lynxeye.de \
    --cc=digetx@gmail.com \
    --cc=dwmw2@infradead.org \
    --cc=festevam@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gustavoars@kernel.org \
    --cc=han.xu@nxp.com \
    --cc=harveyhuntnexus@gmail.com \
    --cc=heiko@sntech.de \
    --cc=imx@lists.linux.dev \
    --cc=izaiahsun@gmail.com \
    --cc=james.hilliard1@gmail.com \
    --cc=jason.e.roberts@intel.com \
    --cc=jbrunet@baylibre.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=jonathan.lemon@gmail.com \
    --cc=jonathanh@nvidia.com \
    --cc=jorge.ramirez@oss.qualcomm.com \
    --cc=kamal.dasu@broadcom.com \
    --cc=kees@kernel.org \
    --cc=keguang.zhang@gmail.com \
    --cc=kernel@nospam.obeliks.de \
    --cc=kernel@pengutronix.de \
    --cc=khilman@baylibre.com \
    --cc=liang.yang@amlogic.com \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=linux-tegra@vger.kernel.org \
    --cc=luca.ceresoli@bootlin.com \
    --cc=mani@kernel.org \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=masonccyang@mxic.com.tw \
    --cc=matthias.bgg@gmail.com \
    --cc=maximlevitsky@gmail.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=michal.simek@amd.com \
    --cc=neil.armstrong@linaro.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=paul@crapouillou.net \
    --cc=piotr.wojtaszczyk@timesys.com \
    --cc=richard@nod.at \
    --cc=richardcochran@gmail.com \
    --cc=rmk+kernel@arm.linux.org.uk \
    --cc=rppt@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=samuel@sholland.org \
    --cc=schung@nuvoton.com \
    --cc=srini@kernel.org \
    --cc=stefan@agner.ch \
    --cc=tglx@kernel.org \
    --cc=thierry.reding@kernel.org \
    --cc=tze.yee.ng@altera.com \
    --cc=vadim.fedorenko@linux.dev \
    --cc=vadivel.muruganx.ramuthevar@linux.intel.com \
    --cc=vigneshr@ti.com \
    --cc=vitalywool@gmail.com \
    --cc=vz@mleia.com \
    --cc=wens@kernel.org \
    --cc=wsa+renesas@sang-engineering.com \
    --cc=ychuang3@nuvoton.com \
    --cc=yifeng.zhao@rock-chips.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®