From: sashiko-bot@kernel.org
To: "Santhosh Kumar K" <s-k6@ti.com>
Cc: robh@kernel.org, "Pratyush Yadav" <pratyush@kernel.org>,
"Richard Weinberger" <richard@nod.at>,
devicetree@vger.kernel.org,
"Takahiro Kuwano" <takahiro.kuwano@infineon.com>,
"Miquel Raynal" <miquel.raynal@bootlin.com>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
"Michael Walle" <mwalle@kernel.org>,
conor+dt@kernel.org
Subject: Re: [PATCH v9 10/18] spi: cadence-quadspi: refactor direct read path for PHY support
Date: Tue, 25 Aug 2026 17:31:10 +0000 [thread overview]
Message-ID: <20260825173110.DDFEF1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260825171737.776052-11-s-k6@ti.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] The custom memory-mapped I/O read loop in cqspi_memcpy_fromio() byteswaps and corrupts data on Big Endian architectures.
- [High] Unaligned I/O memory accesses in cqspi_memcpy_fromio() cause hardware exceptions (Alignment Faults) on architectures like ARM/ARM64.
Pre-existing issues:
- [High] Mixed I/O accessors in cqspi_indirect_write_execute() corrupt partial FIFO writes on big-endian architectures.
--
commit ece753244f464ecb928c830b6abeb4d3b99224f1
Author: Santhosh Kumar K <s-k6@ti.com>
spi: cadence-quadspi: refactor direct read path for PHY support
Extract the DMA transfer code from cqspi_direct_read_execute() into a
new cqspi_direct_read_dma() helper. Add cqspi_memcpy_fromio() to handle
non-DMA transfers, using 2-byte-aligned I/O reads for 8D-8D-8D mode.
> diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c
> index fc33bbf56dd61..58bca15dbd6ec 100644
> --- a/drivers/spi/spi-cadence-quadspi.c
> +++ b/drivers/spi/spi-cadence-quadspi.c
[ ... ]
> @@ -1588,8 +1586,63 @@ static int cqspi_direct_read_execute(struct cqspi_flash_pdata *f_pdata,
> return ret;
> }
>
> +static void cqspi_memcpy_fromio(const struct spi_mem_op *op, void *to,
> + const void __iomem *from, size_t count)
> +{
> + if (op->data.buswidth == 8 && op->data.dtr) {
> + unsigned long from_addr = (unsigned long)from;
> +
> + /* Handle unaligned start with 2-byte read */
> + if (count && !IS_ALIGNED(from_addr, 4)) {
> + put_unaligned_le16(__raw_readw(from), to);
[Severity: High]
Can these MMIO reads cause alignment faults on architectures like ARM/ARM64?
If a user or filesystem requests a SPI read at an unaligned odd byte offset,
the start address from_addr could be odd. If it is odd, !IS_ALIGNED() is true,
and the code executes __raw_readw(from) from an odd device memory address.
Unaligned accesses to device I/O memory are forbidden on some architectures
and can trigger a data abort panic.
> + from += 2;
> + to += 2;
> + count -= 2;
> + }
> +
> + /*
> + * Use an explicit 32-bit read loop for the bulk; this
> + * guarantees the minimum 16-bit AHB transaction width required
> + * in 8D-8D-8D mode on all architectures.
> + */
> + while (count >= 4) {
> + put_unaligned_le32(__raw_readl(from), to);
[Severity: High]
Does combining native-endian __raw_readl() with little-endian
put_unaligned_le32() cause unwanted byte-swapping of stream data on
big-endian platforms?
Because __raw_readl() natively loads a 32-bit word from the bus, and
put_unaligned_le32() forces it into little-endian byte order in memory, the
byte sequence within each chunk gets reversed on big-endian architectures.
This reverses the exact byte stream from device memory, breaking the semantics
guaranteed by the standard memcpy_fromio() fallback.
Additionally, if the initial offset was odd, adding 2 in the block above means
from remains odd. Does executing __raw_readl(from) here also trigger an
unaligned device memory access fault during the 32-bit read?
[ ... ]
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the I/O
accessors, I noticed a pre-existing issue in cqspi_indirect_write_execute():
drivers/spi/spi-cadence-quadspi.c:cqspi_indirect_write_execute() {
...
if (write_words) {
iowrite32_rep(cqspi->ahb_base, txbuf, write_words);
txbuf += (write_words * 4);
}
if (mod_bytes) {
unsigned int temp = 0xFFFFFFFF;
memcpy(&temp, txbuf, mod_bytes);
iowrite32(temp, cqspi->ahb_base);
txbuf += mod_bytes;
}
...
}
Does using iowrite32() for the remainder bytes corrupt partial FIFO writes
on big-endian systems?
The bulk data loop uses iowrite32_rep(), which is a stream accessor that
preserves byte semantics. However, the remainder writes use iowrite32(),
which byte-swaps on big-endian architectures. This mixes stream and register
accessors for the same FIFO base, which can corrupt the final 1-3 bytes
of an indirect write transfer.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260825171737.776052-1-s-k6@ti.com?part=10
next prev parent reply other threads:[~2026-08-25 17:31 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 17:17 [PATCH v9 00/18] spi: cadence-quadspi: add PHY tuning support Santhosh Kumar K
2026-08-25 17:17 ` [PATCH v9 01/18] spi: dt-bindings: add spi-max-post-config-frequency-hz property Santhosh Kumar K
2026-08-25 17:17 ` [PATCH v9 02/18] spi: dt-bindings: add spi-phy-pattern-partition property Santhosh Kumar K
2026-08-25 17:17 ` [PATCH v9 03/18] spi: parse spi-max-post-config-frequency-hz into post_config_max_speed_hz Santhosh Kumar K
2026-08-25 17:30 ` sashiko-bot
2026-08-25 17:17 ` [PATCH v9 04/18] spi: spi-mem: teach spi_mem_adjust_op_freq() about post-config ops Santhosh Kumar K
2026-08-25 17:30 ` sashiko-bot
2026-08-25 17:17 ` [PATCH v9 05/18] spi: spi-mem: add execute_tuning callback and spi_mem_execute_tuning() Santhosh Kumar K
2026-08-25 17:17 ` [PATCH v9 06/18] spi: cadence-quadspi: move cqspi_readdata_capture earlier Santhosh Kumar K
2026-08-25 17:17 ` [PATCH v9 07/18] spi: cadence-quadspi: add DQS support to read data capture Santhosh Kumar K
2026-08-25 17:29 ` sashiko-bot
2026-08-25 17:17 ` [PATCH v9 08/18] spi: cadence-quadspi: add PHY tuning support Santhosh Kumar K
2026-08-25 17:40 ` sashiko-bot
2026-08-26 21:43 ` Mark Brown
2026-08-25 17:17 ` [PATCH v9 09/18] spi: cadence-quadspi: skip DDR PHY tuning for 2-byte-address ops (i2383) Santhosh Kumar K
2026-08-25 17:17 ` [PATCH v9 10/18] spi: cadence-quadspi: refactor direct read path for PHY support Santhosh Kumar K
2026-08-25 17:31 ` sashiko-bot [this message]
2026-08-25 17:17 ` [PATCH v9 11/18] spi: cadence-quadspi: enable PHY for direct reads Santhosh Kumar K
2026-08-25 17:32 ` sashiko-bot
2026-08-25 17:17 ` [PATCH v9 12/18] spi: cadence-quadspi: enable PHY for indirect writes Santhosh Kumar K
2026-08-25 17:32 ` sashiko-bot
2026-08-25 17:17 ` [PATCH v9 13/18] spi: cadence-quadspi: reprogram CS timing on every chip-select switch Santhosh Kumar K
2026-08-25 17:17 ` [PATCH v9 14/18] spi: cadence-quadspi: reprogram PHY DLL on runtime resume Santhosh Kumar K
2026-08-25 17:36 ` sashiko-bot
2026-08-25 17:17 ` [PATCH v9 15/18] mtd: spinand: extract variant ranking logic into spinand_op_find_best_variant() Santhosh Kumar K
2026-08-25 17:17 ` [PATCH v9 16/18] mtd: spinand: negotiate optimal controller operating point before dirmap creation Santhosh Kumar K
2026-08-25 17:43 ` sashiko-bot
2026-08-25 17:17 ` [PATCH v9 17/18] mtd: spi-nor: extract read op template construction into helper Santhosh Kumar K
2026-08-25 17:17 ` [PATCH v9 18/18] mtd: spi-nor: run controller optimization before dirmap creation Santhosh Kumar K
2026-08-25 17:45 ` 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=20260825173110.DDFEF1F00A3A@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=miquel.raynal@bootlin.com \
--cc=mwalle@kernel.org \
--cc=pratyush@kernel.org \
--cc=richard@nod.at \
--cc=robh@kernel.org \
--cc=s-k6@ti.com \
--cc=sashiko-reviews@lists.linux.dev \
--cc=takahiro.kuwano@infineon.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