All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/2] Fix dma_addr_t for R5 SPL
@ 2025-08-25 13:32 Anshul Dalal
  2025-08-25 13:32 ` [PATCH v1 1/2] dma: ti: k3-udma: fix dma_addr_t typecasts Anshul Dalal
  2025-08-25 13:32 ` [PATCH v1 2/2] config: arch: k3: enable DMA_ADDR_T_64BIT Anshul Dalal
  0 siblings, 2 replies; 8+ messages in thread
From: Anshul Dalal @ 2025-08-25 13:32 UTC (permalink / raw)
  To: u-boot; +Cc: Anshul Dalal, vigneshr, trini, u-kumar1

Hi all,

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.

Regards,
Anshul
---
Anshul Dalal (2):
  dma: ti: k3-udma: fix dma_addr_t typecasts
  config: arch: k3: enable DMA_ADDR_T_64BIT

 arch/arm/Kconfig         | 1 +
 drivers/dma/ti/k3-udma.c | 6 +++---
 2 files changed, 4 insertions(+), 3 deletions(-)

-- 
2.50.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-08-28 10:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-25 13:32 [PATCH v1 0/2] Fix dma_addr_t for R5 SPL Anshul Dalal
2025-08-25 13:32 ` [PATCH v1 1/2] dma: ti: k3-udma: fix dma_addr_t typecasts Anshul Dalal
2025-08-27 16:14   ` Prasanth Mantena
2025-08-28  5:01     ` Anshul Dalal
2025-08-28  8:13       ` Anshul Dalal
2025-08-28  8:50   ` Kumar, Udit
2025-08-28 10:41     ` Anshul Dalal
2025-08-25 13:32 ` [PATCH v1 2/2] config: arch: k3: enable DMA_ADDR_T_64BIT Anshul Dalal

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.