From: sashiko-bot@kernel.org
To: "Pratyush Yadav" <pratyush@kernel.org>,
"Michael Walle" <mwalle@kernel.org>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
"Miquel Raynal" <miquel.raynal@bootlin.com>,
"Richard Weinberger" <richard@nod.at>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Takahiro Kuwano" <takahiro.kuwano@infineon.com>,
"Paul Cercueil" <paul.cercueil@bootlin.com>,
"Mark Brown" <broonie@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org,
"Kees Cook" <kees@kernel.org>,
"Tanmay Jagdale" <tanmay@marvell.com>,
"Tony Luck" <tony.luck@intel.com>,
"Guilherme G . Piccoli" <gpiccoli@igalia.com>,
linux-mtd@lists.infradead.org
Subject: Re: [PATCH 2/5] mtd: spi-nor: Add support for panic writes
Date: Mon, 05 Oct 2026 08:23:19 +0000 [thread overview]
Message-ID: <20261005082319.7BFFB1F00893@smtp.kernel.org> (raw)
In-Reply-To: <20261005081141.33688-3-paul.cercueil@bootlin.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] mtd: spi-nor: infinite loop in panic write timeout via jiffies
- [High] mtd: spi-nor: panic write ignores ongoing_pe causing hardware conflict
- [High] mtd: spi-nor: sleep in atomic context during panic write
--
commit 6866cee3049043ab91dbf3b45f823a4010bb97cc
Author: Tanmay Jagdale <tanmay@marvell.com>
mtd: spi-nor: Add support for panic writes
This commit adds support for panic writes to the SPI NOR framework. It
plumbs the oops_panic_write flag through to the SPI controllers,
avoiding mutexes and blocking calls when preemption and IRQs are
disabled.
> diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c
> --- a/drivers/mtd/spi-nor/core.c
> +++ b/drivers/mtd/spi-nor/core.c
[ ... ]
> @@ -729,7 +738,10 @@ static int spi_nor_wait_till_ready_with_timeout(struct spi_nor *nor,
> if (ret)
> return 0;
>
> - cond_resched();
> + if (nor->mtd.oops_panic_write)
> + cpu_relax();
[Severity: High]
In spi_nor_wait_till_ready_with_timeout(), the loop condition relies on:
if (time_after_eq(jiffies, deadline))
Since jiffies does not advance in a panic context because local IRQs are
disabled, does this mean the system will hang indefinitely during a panic
if the flash chip takes time to complete or becomes unresponsive?
> + else
> + cond_resched();
> }
[ ... ]
> @@ -3393,6 +3429,26 @@ static void spi_nor_soft_reset(struct spi_nor *nor)
> usleep_range(SPI_NOR_SRST_SLEEP_MIN, SPI_NOR_SRST_SLEEP_MAX);
> }
>
> +static int spi_nor_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
> + size_t *retlen, const u_char *buf)
> +{
> + struct spi_nor *nor = mtd_to_spi_nor(mtd);
> +
> + /*
> + * At this point preemption and local interrupts are disabled, so we
> + * can't get the lock if it's taken.
> + */
> + if (mutex_is_locked(&nor->lock))
> + return -EPERM;
> +
> + if (spi_nor_use_parallel_locking(nor) &&
> + (nor->rww.ongoing_io || nor->rww.ongoing_rd)) {
> + return -EPERM;
> + }
[Severity: High]
Does this omit checking nor->rww.ongoing_pe?
If a panic occurs while a long-running erase or program operation is in
progress, ongoing_pe will be true. If the lock was released during the
parallel hardware operation, the panic write might proceed and send write
commands while the hardware write in progress bit is set.
The hardware will ignore the commands, but the software will loop in
spi_nor_wait_till_ready() until the original operation finishes, incorrectly
assuming the panic dump was successfully written.
> +
> + return spi_nor_write(mtd, to, len, retlen, buf);
[Severity: High]
Can this sequence lead to a sleep-in-atomic bug?
spi_nor_write() can call down to spi_nor_octal_dtr_write() which does a
sleepable memory allocation when unaligned addresses are passed:
tmp_buf = kmalloc(nor->params->page_size, GFP_KERNEL);
Additionally, the write eventually reaches spi_mem_exec_op() and then
spi_mem_access_start(), which unconditionally takes mutexes:
mutex_lock(&ctlr->bus_lock_mutex);
mutex_lock(&ctlr->io_mutex);
Since mtd->_panic_write operates with local IRQs and preemption disabled,
would these paths cause a recursive panic and completely halt the crash
dump process?
> +}
> +
> /* mtd suspend handler */
> static int spi_nor_suspend(struct mtd_info *mtd)
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261005081141.33688-1-paul.cercueil@bootlin.com?part=2
next prev parent reply other threads:[~2026-10-05 8:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 8:11 [PATCH 0/5] spi: Add support for panic mem writes Paul Cercueil
2026-10-05 8:11 ` [PATCH 1/5] spi: spi-mem: " Paul Cercueil
2026-10-05 8:24 ` sashiko-bot
2026-10-05 8:11 ` [PATCH 2/5] mtd: spi-nor: Add support for panic writes Paul Cercueil
2026-10-05 8:23 ` sashiko-bot [this message]
2026-10-05 8:11 ` [PATCH 3/5] spi: cadence-xspi: Add irq-less support Paul Cercueil
2026-10-05 8:24 ` sashiko-bot
2026-10-05 8:11 ` [PATCH 4/5] spi: cadence-xspi: Don't use infinite timeout in register poll Paul Cercueil
2026-10-05 8:21 ` sashiko-bot
2026-10-05 8:11 ` [PATCH 5/5] spi: cadence-xspi: Add support for panic writes Paul Cercueil
2026-10-05 8:26 ` sashiko-bot
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=20261005082319.7BFFB1F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=broonie@kernel.org \
--cc=gpiccoli@igalia.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=mwalle@kernel.org \
--cc=paul.cercueil@bootlin.com \
--cc=pratyush@kernel.org \
--cc=richard@nod.at \
--cc=sashiko-reviews@lists.linux.dev \
--cc=takahiro.kuwano@infineon.com \
--cc=tanmay@marvell.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=tony.luck@intel.com \
--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®