]> git.ipfire.org Git - thirdparty/u-boot.git/commit
Merge patch series "Fix dma_addr_t for R5 SPL"
authorTom Rini <trini@konsulko.com>
Thu, 11 Sep 2025 16:03:12 +0000 (10:03 -0600)
committerTom Rini <trini@konsulko.com>
Thu, 11 Sep 2025 16:03:12 +0000 (10:03 -0600)
commitc9800dc906ad21a1157ec718f5e450daaf42e4b3
tree5cdca416f0b4afe0db09a7899ad3b572bd180953
parentfd7510e516b519864680c4a56bc14dabdc91607f
parent7bcc604ef80244ac45d8112b823ceff21af61e39
Merge patch series "Fix dma_addr_t for R5 SPL"

Anshul Dalal <anshuld@ti.com> says:

On various TI's K3 platforms boot failure was observed on SPI NOR since the
commit 5609f200d062 ("arm: Kconfig: enable LTO for ARCH_K3"). This issue was
root caused to stack corruption by the 'udma_transfer' function. Where the local
variable 'paddr' of type 'dma_addr_t' was being written to as a 64-bit value
which overwrote the stack frame of the caller (dma_memcpy) as only 32-bits had
been reserved for paddr on the stack, specifically the r4 register in the frame
of dma_memcpy was being overwritten with a 0.

drivers/dma/ti/k3-udma.c:2192:

int udma_transfer(...)
{
...
dma_addr_t paddr = 0;

...
/* paddr was written to as 64-bit value here */
udma_poll_completion(uc, &paddr);
}

drivers/dma/dma-uclass.c:234:

int dma_memcpy(...)
{
dma_addr_t destination;
dma_addr_t source;
int ret;

...

/* This call resolves to udma_transfer */
ret = ops->transfer(...);

...

dma_unmap_single(destination, ...);
dma_unmap_single(...);
return ret;
}

Enabling LTO changed how gcc mapped local variables of dma_memcpy to CPU
registers, where earlier the bug was hidden since the overwritten register
'r4' was allotted to 'ret' but was allotted to 'destination' once LTO was
enabled. And since the overwritten value was 0, the bug remained undetected
as it just meant ret was 0, but having 'destination' set to 0 caused
dma_unmap_single to fail silently leading to boot failures.

The fix entails enabling DMA_ADDR_T_64BIT which changes dma_addr_t from u32 to
u64 for the R5 SPL thus reserving enough space for 'paddr' to prevent the
overflow.

Link: https://lore.kernel.org/r/20250903115207.572304-1-anshuld@ti.com