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>,
Arseniy Krasnov <AVKrasnov@sberdevices.ru>,
Boris Brezillon <bbrezillon@kernel.org>,
Kyle Roeschley <kyle.roeschley@ni.com>,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH v2 1/2] mtd: rawnand: macronix: serialize OTP access with NAND operations
Date: Thu, 26 Nov 2026 18:34:05 +0100 [thread overview]
Message-ID: <87y0afv6nm.fsf@bootlin.com> (raw)
In-Reply-To: <CADvTj4q79XR9ymtzBHr7TUc+TnuoB2R-sUa+BWOCS1u7UTEUkA@mail.gmail.com> (James Hilliard's message of "Tue, 24 Nov 2026 09:10:06 -0700")
On 24/11/2026 at 09:10:06 -07, James Hilliard <james.hilliard1@gmail.com> wrote:
> On Tue, Nov 24, 2026 at 7:55 AM Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>>
>>
>> > OTP I/O can also run while the chip is suspended.
>>
>> Really? Where does that come from?
>
> I was referring to chip->suspended in nand_base.c. nand_suspend() sets
> that flag even when the chip has no suspend hook. Normal NAND I/O waits
> for resume in nand_get_device(), but MTD calls the Macronix user-OTP
> read and write callbacks directly, bypassing that check.
>
> I haven't observed OTP I/O during system suspend. Userspace is normally
> frozen before device suspend, and the Macronix driver doesn't install
> its deep-power-down hook on the MX30LFxG18AC parts.
>
>>
>> [...]
>>
>> > --- a/drivers/mtd/nand/raw/nand_base.c
>> > +++ b/drivers/mtd/nand/raw/nand_base.c
>> > @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(nand_deselect_target);
>> > *
>> > * Release chip lock and wake up anyone waiting on the device.
>> > */
>> > -static void nand_release_device(struct nand_chip *chip)
>> > +void nand_release_device(struct nand_chip *chip)
>>
>> You export a core helper...
>>
>> > {
>> > /* Release the controller and the chip */
>> > mutex_unlock(&chip->controller->lock);
>> > @@ -336,7 +336,7 @@ static int nand_isbad_bbm(struct nand_chip *chip, loff_t ofs)
>> > *
>> > * Lock the device and its controller for exclusive access
>> > */
>> > -static void nand_get_device(struct nand_chip *chip)
>> > +void nand_get_device(struct nand_chip *chip)
>> > {
>> > /* Wait until the device is resumed. */
>> > while (1) {
>> > diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c
>> > index 16847f28b19d..d7f5a9e7c240 100644
>> > --- a/drivers/mtd/nand/raw/nand_macronix.c
>> > +++ b/drivers/mtd/nand/raw/nand_macronix.c
>> > @@ -380,6 +380,7 @@ static int __macronix_30lfxg18ac_rw_otp(struct mtd_info *mtd,
>> > int ret, cleanup_ret;
>> >
>> > nand = mtd_to_nand(mtd);
>> > + nand_get_device(nand);
>>
>> ...and you use it across the entire OTP operation...
>
> The race doesn't require suspend: an ordinary page read on the same
> chip can issue its command after the OTP callback has enabled OTP mode
> and before it restores normal mode. Locking each command separately
> would still leave that window open.
?
You are using nand_get_device()/nand_release_device(), I am not
disputing that choice. You are using them in each and every otp op
implementation, which does not make any sense. It does not matter if
there is a single user for now.
>> > nand_select_target(nand, 0);
>> >
>> > ret = macronix_30lfxg18ac_otp_enable(nand);
>> > @@ -426,6 +427,7 @@ static int __macronix_30lfxg18ac_rw_otp(struct mtd_info *mtd,
>> > write ? "write" : "read");
>> >
>> > nand_deselect_target(nand);
>> > + nand_release_device(nand);
>> >
>> > return ret ? ret : cleanup_ret;
>> > }
>>
>> ...and in the commit log you mention:
>>
>> > Make the existing NAND serialization helpers available within the raw
>> > NAND core and hold them across the entire OTP transaction
>>
>> Why are you doing the serialization in one vendor driver then? Aren't
>> all the vendors affected by the exact same issue? Why isn't taking the
>> lock once for all in the core a better idea?
>
> Macronix is the only in-tree raw NAND manufacturer that installs MTD
> user-OTP read and write callbacks.
That's not a reason, we don't want the race to re-open every time
someone adds new OTP ops, right?
> Both use the same helper, so taking
> the locks there covers both paths without changing the interface.
You wouldn't be "changing the interface" whatever that actually means.
> A core wrapper could take the chip and controller locks around a
> manufacturer's OTP callback, much as nand_lock() does for
> chip->ops.lock_area. That would give future implementations the same
> locking, but it would mean adding raw NAND OTP hooks where MTD currently
> calls the one implementation directly. Is that the approach you had in
> mind?
That penultimate sentence does not mean anything, you should really
write your own answers. Anyway, I think the answer I should give here is
"yes".
next prev parent reply other threads:[~2026-11-26 17:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 9:25 [PATCH v2 0/2] mtd: rawnand: serialize OTP and BBT recovery operations James Hilliard
2026-11-22 9:25 ` [PATCH v2 1/2] mtd: rawnand: macronix: serialize OTP access with NAND operations James Hilliard
2026-11-24 14:55 ` Miquel Raynal
2026-11-24 16:10 ` James Hilliard
2026-11-26 17:34 ` Miquel Raynal [this message]
2026-11-22 9:25 ` [PATCH v2 2/2] mtd: rawnand: serialize bad-block marker writes during BBT recovery James Hilliard
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=87y0afv6nm.fsf@bootlin.com \
--to=miquel.raynal@bootlin.com \
--cc=AVKrasnov@sberdevices.ru \
--cc=bbrezillon@kernel.org \
--cc=james.hilliard1@gmail.com \
--cc=kyle.roeschley@ni.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
--cc=stable@vger.kernel.org \
--cc=vigneshr@ti.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®