Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AA753CA0FF2 for ; Wed, 3 Sep 2025 11:54:22 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DCCA5835B3; Wed, 3 Sep 2025 13:54:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="FU9f4cIS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 171F4835C1; Wed, 3 Sep 2025 13:54:19 +0200 (CEST) Received: from lelvem-ot01.ext.ti.com (lelvem-ot01.ext.ti.com [198.47.23.234]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5A1B1834E5 for ; Wed, 3 Sep 2025 13:54:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=anshuld@ti.com Received: from fllvem-sh03.itg.ti.com ([10.64.41.86]) by lelvem-ot01.ext.ti.com (8.15.2/8.15.2) with ESMTP id 583BsExX2822350; Wed, 3 Sep 2025 06:54:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1756900454; bh=kvydaRvBooL8ponhWNZCiDxw6EkyU90+wMNpiHBDqXY=; h=From:To:CC:Subject:Date; b=FU9f4cISxU0e0hKrCAEwzmPougmdxd5AQZXidHydNQP/m6vGSvYf6SRvyJEnPPpgN oTwiTT75oCbnOZeohRzngZQgB1I3A1zrh5qjC8AcTAVMkaf+tY3I410IitqLjYQi3P JKDUFIdONfcPw53hGxnAVnNSfsTIfRfTkYr+GUfQ= Received: from DLEE105.ent.ti.com (dlee105.ent.ti.com [157.170.170.35]) by fllvem-sh03.itg.ti.com (8.18.1/8.18.1) with ESMTPS id 583BsEWR3496009 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=FAIL); Wed, 3 Sep 2025 06:54:14 -0500 Received: from DLEE110.ent.ti.com (157.170.170.21) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55; Wed, 3 Sep 2025 06:54:14 -0500 Received: from lelvem-mr05.itg.ti.com (10.180.75.9) by DLEE110.ent.ti.com (157.170.170.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.55 via Frontend Transport; Wed, 3 Sep 2025 06:54:14 -0500 Received: from localhost (dhcp-172-24-233-105.dhcp.ti.com [172.24.233.105]) by lelvem-mr05.itg.ti.com (8.18.1/8.18.1) with ESMTP id 583BsCKV1516715; Wed, 3 Sep 2025 06:54:13 -0500 From: Anshul Dalal To: CC: Anshul Dalal , , , , Subject: [PATCH v3 0/2] Fix dma_addr_t for R5 SPL Date: Wed, 3 Sep 2025 17:22:04 +0530 Message-ID: <20250903115207.572304-1-anshuld@ti.com> X-Mailer: git-send-email 2.50.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-C2ProcessedOrg: 333ef613-75bf-4e12-a4b1-8e3623f5dcea X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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. This patch is meant for the master branch, Regards, Anshul --- Changes for v3: - Clearer commit description v2: https://lore.kernel.org/u-boot/20250902094037.2121393-1-anshuld@ti.com/ Changes for v2: - Add missing typecasts for usb driver - Reword commit description v1: https://lore.kernel.org/u-boot/20250825133233.2475300-1-anshuld@ti.com/ --- 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 +++--- drivers/usb/dwc3/ep0.c | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) -- 2.50.1