lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250412094110.3208838-1-balbirs@nvidia.com>
Date: Sat, 12 Apr 2025 19:41:10 +1000
From: Balbir Singh <balbirs@...dia.com>
To: iommu@...ts.linux.dev
Cc: linux-kernel@...r.kernel.org,
	Balbir Singh <balbirs@...dia.com>,
	Marek Szyprowski <m.szyprowski@...sung.com>,
	Robin Murphy <robin.murphy@....com>,
	Christian König <christian.koenig@....com>,
	Ingo Molnar <mingo@...nel.org>,
	Kees Cook <kees@...nel.org>,
	Bjorn Helgaas <bhelgaas@...gle.com>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Peter Zijlstra <peterz@...radead.org>,
	Andy Lutomirski <luto@...nel.org>,
	Alex Deucher <alexander.deucher@....com>,
	Bert Karwatzki <spasswolf@....de>
Subject: [RFC] dma/mapping.c: WARN_ONCE on dma_addressing_limited() being true

In the debug and resolution of an issue involving forced use of bounce
buffers, 7170130e4c72 ("x86/mm/init: Handle the special case of device
private pages in add_pages(), to not increase max_pfn and trigger
dma_addressing_limited() bounce buffers"). It would have been easier
to debug the issue if dma_addressing_limited() had a warning about a
device not being able to address all of memory and thus forcing all
accesses through a bounce buffer. Please see[2].

A warning would have let the user of the system know that in their
particular case, use_dma32 is set due to the addressing limitation
and this would impact performance of the driver in use.

Implement a WARN_ONCE() to point to the potential use of bounce buffers
when we hit the condition. When swiotlb is used,
dma_addressing_limited() is used to determine the size of maximum dma
buffer size in dma_direct_max_mapping_size(). The warning could be
triggered in that check as well.

Link: https://lore.kernel.org/lkml/20250401000752.249348-1-balbirs@nvidia.com/ [1]
Link: https://lore.kernel.org/lkml/20250310112206.4168-1-spasswolf@web.de/ [2]

Cc: Marek Szyprowski <m.szyprowski@...sung.com>
Cc: Robin Murphy <robin.murphy@....com>
Cc: "Christian König" <christian.koenig@....com>
Cc: Ingo Molnar <mingo@...nel.org>
Cc: Kees Cook <kees@...nel.org>
Cc: Bjorn Helgaas <bhelgaas@...gle.com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Andy Lutomirski <luto@...nel.org>
Cc: Alex Deucher <alexander.deucher@....com>
Cc: Bert Karwatzki <spasswolf@....de>

Signed-off-by: Balbir Singh <balbirs@...dia.com>
---
Testing: Tested lightly with on a virtual machine, I do not have access
to a device where dma_addressing_limited() is true


 kernel/dma/mapping.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index cda127027e48..0f0455fa5bc8 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -918,7 +918,7 @@ EXPORT_SYMBOL(dma_set_coherent_mask);
  * the system, else %false.  Lack of addressing bits is the prime reason for
  * bounce buffering, but might not be the only one.
  */
-bool dma_addressing_limited(struct device *dev)
+static bool __dma_addressing_limited(struct device *dev)
 {
 	const struct dma_map_ops *ops = get_dma_ops(dev);
 
@@ -930,6 +930,17 @@ bool dma_addressing_limited(struct device *dev)
 		return false;
 	return !dma_direct_all_ram_mapped(dev);
 }
+
+bool dma_addressing_limited(struct device *dev)
+{
+	bool ret = __dma_addressing_limited(dev);
+
+	WARN_ONCE((ret == true),
+		"%s might have lower performance due to bounce buffering",
+		dev_name(dev));
+
+	return ret;
+}
 EXPORT_SYMBOL_GPL(dma_addressing_limited);
 
 size_t dma_max_mapping_size(struct device *dev)
-- 
2.49.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ