mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2] dma: debug: detect repeated DMA sync
@ 2024-03-07 17:00 Ahmad Fatoum
  2024-03-08  7:06 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-03-07 17:00 UTC (permalink / raw)
  To: barebox; +Cc: lst, rcz, Ahmad Fatoum

dma_map_single will do any necessary cache maintenance to make a buffer
available to a device. Calling debug_dma_sync_single_for_device on such
a buffer is unnecessary, so flag when this happens.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - rename dev_mapped to dev_owned to reduce confusion (Lucas)
---
 drivers/dma/debug.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/debug.c b/drivers/dma/debug.c
index b3bfbff9b2f5..e524dc4127ce 100644
--- a/drivers/dma/debug.c
+++ b/drivers/dma/debug.c
@@ -12,6 +12,7 @@ struct dma_debug_entry {
 	dma_addr_t       dev_addr;
 	size_t           size;
 	int              direction;
+	bool             dev_owned;
 };
 
 static const char *dir2name[] = {
@@ -121,6 +122,7 @@ void debug_dma_map(struct device *dev, void *addr,
 	entry->dev_addr = dev_addr;
 	entry->size = size;
 	entry->direction = direction;
+	entry->dev_owned = true;
 
 	list_add(&entry->list, &dma_mappings);
 
@@ -159,9 +161,17 @@ void debug_dma_sync_single_for_cpu(struct device *dev,
 	struct dma_debug_entry *entry;
 
 	entry = dma_debug_entry_find(dev, dma_handle, size);
-	if (!entry)
+	if (!entry) {
 		dma_dev_warn(dev, "sync for CPU of never-mapped %s buffer 0x%llx+0x%zx!\n",
 			     dir2name[direction], (u64)dma_handle, size);
+		return;
+	}
+
+	if (!entry->dev_owned)
+		dma_dev_warn(dev, "unexpected sync for CPU of already CPU-mapped %s buffer 0x%llx+0x%zx!\n",
+			     dir2name[direction], (u64)dma_handle, size);
+
+	entry->dev_owned = false;
 }
 
 void debug_dma_sync_single_for_device(struct device *dev,
@@ -177,7 +187,15 @@ void debug_dma_sync_single_for_device(struct device *dev,
 	 * corruption
 	 */
 	entry = dma_debug_entry_find(dev, dma_handle, size);
-	if (!entry)
+	if (!entry) {
 		dma_dev_warn(dev, "Syncing for device of never-mapped %s buffer 0x%llx+0x%zx!\n",
 			     dir2name[direction], (u64)dma_handle, size);
+		return;
+	}
+
+	if (entry->dev_owned)
+		dma_dev_warn(dev, "unexpected sync for device of already device-mapped %s buffer 0x%llx+0x%zx!\n",
+			     dir2name[direction], (u64)dma_handle, size);
+
+	entry->dev_owned = true;
 }
-- 
2.39.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] dma: debug: detect repeated DMA sync
  2024-03-07 17:00 [PATCH v2] dma: debug: detect repeated DMA sync Ahmad Fatoum
@ 2024-03-08  7:06 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2024-03-08  7:06 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum; +Cc: lst, rcz


On Thu, 07 Mar 2024 18:00:50 +0100, Ahmad Fatoum wrote:
> dma_map_single will do any necessary cache maintenance to make a buffer
> available to a device. Calling debug_dma_sync_single_for_device on such
> a buffer is unnecessary, so flag when this happens.
> 
> 

Applied, thanks!

[1/1] dma: debug: detect repeated DMA sync
      https://git.pengutronix.de/cgit/barebox/commit/?id=1ad4b32702dd (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-08  7:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-07 17:00 [PATCH v2] dma: debug: detect repeated DMA sync Ahmad Fatoum
2024-03-08  7:06 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox