From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 491E522538F for ; Sat, 4 Apr 2026 02:04:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775268273; cv=none; b=FcbDtYgxPLKpli5j3rIJNEFumjTxSb2IUw4GnxxXddG8tOmsXdhiznAlZflPDTJa37vZnidbSPbXud0m75+rfZmlgn+tYwGpkMNTc4GorVp+tLquNSpQW1z5UHNhKn5kbt/roCogTKChH4rbCNmvL0mnyH22mKlSU7rEIu4INFg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775268273; c=relaxed/simple; bh=Stf1OK+UYwC4E5fstcRMlG1761VOQPvcXXwCwiZEX70=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=i49RVh5SbeXkj3Q3YSgoxBQ7j/Gxo/4mZaXOTWeOo5+RtkVtjhEsTs/TYfkh0+POQMq9vD9UxkM2oKBZpYONgk0clBNt+d79n/6+hfqcuBd1f2nScxFsCOwUjPntKAKDcbpwaU9OI8HrUdBx2+1QEc6WoJOzvDNEq+0J1MT/RPE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oss.tenstorrent.com; spf=pass smtp.mailfrom=tenstorrent.com; dkim=pass (2048-bit key) header.d=tenstorrent.com header.i=@tenstorrent.com header.b=LZVuxJlg; arc=none smtp.client-ip=209.85.161.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oss.tenstorrent.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tenstorrent.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tenstorrent.com header.i=@tenstorrent.com header.b="LZVuxJlg" Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-67bb19ac35aso1514238eaf.1 for ; Fri, 03 Apr 2026 19:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tenstorrent.com; s=google; t=1775268270; x=1775873070; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=QFX1dhDieBRaAm9qJ2639rNkR3TjfczoXLEWvV+mu0Y=; b=LZVuxJlgGZbO+mV+jZe/3H8oRNcFUso0clh50q4h6FDSbMlWj5YAbZ9c8tMGzb/dGu 9GgSwHvexaLkU+7qsYqqv09vVzyrDZZZ/VKrT8vIzw/mZShLnpCi8qDXUNcKH1ZbvFrt sedzXmE5IzTVRk9+1vJF21TYbiEqVKM8UJZrVF4h4vo1iQCS1TDjSm61z4sTDTZKolOk xMbpg65vFmBNeoXxE0vdH6WtXROsX9D4+bD0pP+Dw6r7CGV/ppJOjZP/x3KTXg6KuMjx kf4idWfkv5viR37dY5rjkvKKHhoTb0I0iL4ozE9SNW5sdsPuskdcOjq2ISfB2edhjNCo S3og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775268270; x=1775873070; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QFX1dhDieBRaAm9qJ2639rNkR3TjfczoXLEWvV+mu0Y=; b=I7S547iFpOzHR1G0jXRIp0KroNqB4Iy70rj9eQTsDAk335I1bHBvVUiu5TaKpvf6Go UVbPhfUy7aUIQDC2tboSuRvI3Q9bSzeGuJpwBgKYi9Zkp1q7wZgPaUZG3dzabeTOx9j8 bEEbZ8OAtM5sTGZzhiweJj+PuRSHZ9571H+LOHZQsFC5nvjiihtBNeqo6FZlSDu6viA0 HvVcXeYfoVdL1zva9spYVtoBUz2ai0r8dkVzAPUc3YZywdv6HGmSaPaMiA1aJ/d12h3t 9g+8gcQgh1M4S5eEGxbX2cUz2R/A3+qAF/ULIFS+iBi6eirtnKMz2AgMeu7I0rJzDMG/ LtqA== X-Forwarded-Encrypted: i=1; AJvYcCXphjvi3BRwtvxuaIl7V1d6yd2a0bNdthzeE8OOGp8rHC43UiF8kOMb7GQR1dFe+lRZaptLzC7aP4OrtUE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/Bts+fo3Fo4GLmlhElsOm2zn/B4n8uWaIeTP/9Nnt2ZRzIKJd 1xe1pjo7shGzlaF6Zrdhygsvjzpif5Md+gxjkxl4MulSHCoXTzThTx92YFMXlfjO/zY= X-Gm-Gg: ATEYQzwR7c8YyyzbQXhZ1GqYQhsoOh/kfkYgHQoi8ArrlcPW5es3KYPo6J7PIHoLcIJ nbLNS38sHBKun2VBhYdkuCLfkxWHXOFjZlhMG1sSFrZDKL2cUzVyomUw45gALS1db2VmKmcdsA2 f+dtcMVZMiyhhwhMJI7BmkMqfIr+a4smmpTaouaj5SazhxCxLO+kuixtt+egLU3CLF75tsncUtR ixakSpEoYeM9sJOlIZ+5E/f/n5X4cLlcnXuBuGiRBeRP8m0nFWYTDxUtslx4rOA5jI0E4/mHbdZ Efnt5+Cv0HZaR11EHJjSDyWqL3IkucovrB+viJOs1OWea7NAtaEUuj9VTe/XeV0afBs3OuITS2o uvN1mZ88akzAEItO4H7U53vQtojZ+eRfTojIJqo4d2oIFVtqtP3lQHECvyYRrTMXGPLUPUyl+T9 GAHKZ1KiEqylybmYhEbh359tbBukyXS+kpaASC6+4jnzyELlVsAOyPBl/jL8GUDcizC/lz X-Received: by 2002:a05:6820:2006:b0:67c:250c:ac4c with SMTP id 006d021491bc7-6821fe6157amr2712135eaf.31.1775268270140; Fri, 03 Apr 2026 19:04:30 -0700 (PDT) Received: from toolbox ([2600:1700:220:59e0:a819:2018:a04a:68a9]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-6822987630bsm2274434eaf.4.2026.04.03.19.04.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2026 19:04:29 -0700 (PDT) Date: Fri, 3 Apr 2026 21:04:06 -0500 From: Anirudh Srinivasan To: Troy Mitchell Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, spacemit@lists.linux.dev Subject: Re: [PATCH] riscv: mm: fix SWIOTLB initialization for systems with DRAM above 4GB Message-ID: References: <20260331-fix-riscv-swiotlb-v1-1-74dd5e6be0f1@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260331-fix-riscv-swiotlb-v1-1-74dd5e6be0f1@linux.dev> On Tue, Mar 31, 2026 at 03:37:22PM +0800, Troy Mitchell wrote: > On RISC-V platforms where the entire physical memory (DRAM) resides > above the 32-bit address space (i.e., above dma32_phys_limit), the > current SWIOTLB initialization logic fails. > > This patch addresses two interconnected issues on such platforms: > > 1. Incorrect 32-bit DMA bounce assumption: > The existing condition `max_pfn > PFN_DOWN(dma32_phys_limit)` assumes > that a 32-bit DMA bounce buffer is required simply because the maximum > PFN exceeds the 32-bit limit. However, if all DRAM starts above 4GB, > no memory exists below the limit to satisfy this allocation. Fix > this by adding a check to ensure `memblock_start_of_DRAM()` is actually > below the 32-bit limit before enforcing 32-bit SWIOTLB. > > 2. kmalloc() bounce buffer allocation failure on non-coherent systems: > For non-coherent hardware, a bounce buffer is still mandatory for > cache-line-aligned kmalloc(), even if 32-bit DMA bouncing is skipped. > Without the `SWIOTLB_ANY` flag, swiotlb_init() defaults to allocating > from low memory, which fails completely when DRAM only exists in high > memory. By appending `SWIOTLB_ANY` to swiotlb_flags, the allocator is > permitted to allocate this alignment buffer from high memory. > > With this patch, systems with non-coherent DMA and DRAM entirely above > 4GB can successfully map the software IO TLB in high memory and boot > normally. > > Signed-off-by: Troy Mitchell > --- > arch/riscv/mm/init.c | 16 +++++++++++----- > 1 file changed, 11 insertions(+), 5 deletions(-) Tested on Tenstorrent Blackhole, which doesn't have any memory < 4GB. With this patch, these lines no longer appear during boot [ 0.000000] software IO TLB: area num 4. [ 0.000000] software IO TLB: swiotlb_memblock_alloc: Failed to allocate 67108864 bytes tlb structure [ 0.000000] software IO TLB: swiotlb_memblock_alloc: Failed to allocate 33554432 bytes tlb structure [ 0.000000] software IO TLB: swiotlb_memblock_alloc: Failed to allocate 16777216 bytes tlb structure [ 0.000000] software IO TLB: swiotlb_memblock_alloc: Failed to allocate 8388608 bytes tlb structure [ 0.000000] software IO TLB: swiotlb_memblock_alloc: Failed to allocate 4194304 bytes tlb structure [ 0.000000] software IO TLB: swiotlb_memblock_alloc: Failed to allocate 2097152 bytes tlb structure [ 0.000000] software IO TLB: swiotlb_memblock_alloc: Failed to allocate 1048576 bytes tlb structure Tested-by: Anirudh Srinivasan Regards Anirudh Srinivasan