Skip to contentSkip to conversation

dma/mapping.c: dev_dbg support for dma_addressing_limited

PATCH Applied Balbir Singh 3 participants 3 messages Apr 14, 2025 – Apr 15, 2025 DMA mapping helpers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 dma/mapping.c: dev_dbg support for dma_addressing_limited

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 debug information about the device not being able to address all of memory and thus forcing all accesses through a bounce buffer. Please see[2]

Implement dev_dbg to debug 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 debug prints could be triggered in that check as well (when enabled).

Cc Marek Szyprowski <[email protected]>
Cc Robin Murphy <[email protected]>
Cc "Christian König" <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Kees Cook <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Alex Deucher <[email protected]>
Cc Bert Karwatzki <[email protected]>
Cc Christoph Hellwig <[email protected]>

---
Changelog v2:
- Change the debug message to be factual
- Convert WARN_ONCE to dev_dbg

Testing:
- Limited testing on a VM, could not trigger the debug message on the machine

 kernel/dma/mapping.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
kernel/dma/mapping.c +10 -1
index cda127027e48..67da08fa6723 100644
@@ -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,15 @@ bool dma_addressing_limited(struct device *dev)
 		return false;
 	return !dma_direct_all_ram_mapped(dev);
 }
+
+bool dma_addressing_limited(struct device *dev)
+{
+	if (!__dma_addressing_limited(dev))
+		return false;
+
+	dev_dbg(dev, "device is DMA addressing limited\n");
+	return true;
+}
 EXPORT_SYMBOL_GPL(dma_addressing_limited);
 
 size_t dma_max_mapping_size(struct device *dev)
Signature · 1 line
2.49.0
maintainer Applied
#2 lore raw
In reply to Balbir Singh
Quoted 30 lines · Balbir Singh

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 debug information about the device not being able to address all of memory and thus forcing all accesses through a bounce buffer. Please see[2]

Implement dev_dbg to debug 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 debug prints could be triggered in that check as well (when enabled).

Cc Marek Szyprowski <[email protected]>
Cc Robin Murphy <[email protected]>
Cc "Christian König" <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Kees Cook <[email protected]>
Cc Bjorn Helgaas <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Andy Lutomirski <[email protected]>
Cc Alex Deucher <[email protected]>
Cc Bert Karwatzki <[email protected]>
Cc Christoph Hellwig <[email protected]>
Quoted 1 line

Thanks, applied to dma-mapping-fixes branch.

Quoted 32 lines

---
Changelog v2:
- Change the debug message to be factual
- Convert WARN_ONCE to dev_dbg

Testing:
- Limited testing on a VM, could not trigger the debug message on the machine

  kernel/dma/mapping.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
kernel/dma/mapping.c +3 -1
index cda127027e48..67da08fa6723 100644
@@ -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,15 @@ bool dma_addressing_limited(struct device *dev)
  		return false;
  	return !dma_direct_all_ram_mapped(dev);
  }
+
+bool dma_addressing_limited(struct device *dev)

kernel/dma/mapping.c bool dma_addressing_limited(struct device *dev) · line 944

Quoted 10 lines
kernel/dma/mapping.c +7 -0
+{
+	if (!__dma_addressing_limited(dev))
+		return false;
+
+	dev_dbg(dev, "device is DMA addressing limited\n");
+	return true;
+}
  EXPORT_SYMBOL_GPL(dma_addressing_limited);
 
  size_t dma_max_mapping_size(struct device *dev)

Best regards

Signature · 2 lines
Marek Szyprowski, PhD
Samsung R&D Institute Poland