Skip to contentSkip to conversation

direct-dma: WARN_ON_ONCE when the page is not addressable by device's coherent_dma_mask

PATCH In review John Hsu 2 participants 2 messages Mar 13, 2024

Subsystems (2)
lore
Share & tools
lore

John Hsu

author
#0 lore raw

PATCH 1/1 direct-dma: WARN_ON_ONCE when the page is not addressable by device's coherent_dma_mask

From: JohnHsu <[email protected]>

The dma_direct_alloc() may return null in some cases. For example, the allocated page is not addressable for the device's coherent_dma_mask, and the allocated page will be assigned to null.

This patch can WARN_ON_ONCE() when the returned page is null in dma_direct_alloc. It helps the developers position the root cause of allocation failure rapidly.

---
 kernel/dma/direct.c | 2 ++
 1 file changed, 2 insertions(+)
kernel/dma/direct.c +2 -0
index 9596ae1aa0da..a73b8ad1ef9e 100644
@@ -156,6 +156,8 @@ static struct page *__dma_direct_alloc_pages(struct device *dev, size_t size,
 		}
 	}
 
+	WARN_ON_ONCE(!page);
+
 	return page;
 }
 
Signature · 1 line
2.18.0
reviewer
#1 lore raw
Quoted 9 lines · John Hsu

From: JohnHsu <[email protected]>

The dma_direct_alloc() may return null in some cases. For example, the allocated page is not addressable for the device's coherent_dma_mask, and the allocated page will be assigned to null.

This patch can WARN_ON_ONCE() when the returned page is null in dma_direct_alloc. It helps the developers position the root cause of allocation failure rapidly.

No. Failure to allocate a buffer can happen for any number of reasons, it is not specific to dma-direct, and in some cases it is even expected, hence why DMA_ATTR_NO_WARN exists. And either way it's still not a condition worthy of panicking when panic_on_warn is in use.

Sure, this may well be a handy development hack for debugging a particular driver which isn't handling failure correctly, but it is not suitable for mainline.

Thanks,
Robin.

Quoted 18 lines
---
  kernel/dma/direct.c | 2 ++
  1 file changed, 2 insertions(+)
kernel/dma/direct.c +2 -0
index 9596ae1aa0da..a73b8ad1ef9e 100644
@@ -156,6 +156,8 @@ static struct page *__dma_direct_alloc_pages(struct device *dev, size_t size,
  		}
  	}
 
+	WARN_ON_ONCE(!page);
+
  	return page;
  }