Skip to contentSkip to conversation

dmatest: implement two helpers to unmap dma memory

PATCH In review Andy Shevchenko 4 participants 8 messages Dec 10, 2012 – Dec 14, 2012 dmaengine

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 dmatest: implement two helpers to unmap dma memory

The unmap_src() and unmap_dst() will be used later as well.

---
 drivers/dma/dmatest.c |   27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)
drivers/dma/dmatest.c +17 -10
index 3e777d2..b515343 100644
@@ -236,6 +236,20 @@ static unsigned int min_odd(unsigned int x, unsigned int y)
 	return val % 2 ? val : val - 1;
 }
 
+static inline void unmap_src(struct device *dev, dma_addr_t *addr, size_t len,
+			     unsigned int count)
+{
+	while (count--)
+		dma_unmap_single(dev, addr[count], len, DMA_TO_DEVICE);
+}
+
+static inline void unmap_dst(struct device *dev, dma_addr_t *addr, size_t len,
+			     unsigned int count)
+{
+	while (count--)
+		dma_unmap_single(dev, addr[count], len, DMA_BIDIRECTIONAL);
+}
+
 /*
  * This function repeatedly tests DMA transfers of various lengths and
  * offsets for a given operation type until it is told to exit by
@@ -394,13 +408,8 @@ static int dmatest_func(void *data)
 		}
 
 		if (!tx) {
-			for (i = 0; i < src_cnt; i++)
-				dma_unmap_single(dev->dev, dma_srcs[i], len,
-						 DMA_TO_DEVICE);
-			for (i = 0; i < dst_cnt; i++)
-				dma_unmap_single(dev->dev, dma_dsts[i],
-						 test_buf_size,
-						 DMA_BIDIRECTIONAL);
+			unmap_src(dev->dev, dma_srcs, len, src_cnt);
+			unmap_dst(dev->dev, dma_dsts, test_buf_size, dst_cnt);
 			pr_warning("%s: #%u: prep error with src_off=0x%x "
 					"dst_off=0x%x len=0x%x\n",
 					thread_name, total_tests - 1,
@@ -454,9 +463,7 @@ static int dmatest_func(void *data)
 		}
 
 		/* Unmap by myself (see DMA_COMPL_SKIP_DEST_UNMAP above) */
-		for (i = 0; i < dst_cnt; i++)
-			dma_unmap_single(dev->dev, dma_dsts[i], test_buf_size,
-					 DMA_BIDIRECTIONAL);
+		unmap_dst(dev->dev, dma_dsts, test_buf_size, dst_cnt);
 
 		error_count = 0;
 
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 2/2 dmatest: check for dma mapping error

We get a warning if CONFIG_DMA_API_DEBUG=y

[   28.150631] WARNING: at lib/dma-debug.c:933 check_unmap+0x5d6/0x6ac()
[   28.157058] dw_dmac dw_dmac.0: DMA-API: device driver failed to check map error[device address=0x0000000035698305] [size=14365 bytes] [mapped as single]
---
 drivers/dma/dmatest.c |   22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
drivers/dma/dmatest.c +21 -1
index b515343..7be60f1 100644
@@ -378,15 +378,35 @@ static int dmatest_func(void *data)
 
 			dma_srcs[i] = dma_map_single(dev->dev, buf, len,
 						     DMA_TO_DEVICE);
+			ret = dma_mapping_error(dev->dev, dma_srcs[i]);
+			if (ret) {
+				unmap_src(dev->dev, dma_srcs, len, i);
+				pr_warn("%s: #%u: mapping error %d with "
+					"src_off=0x%x len=0x%x\n",
+					thread_name, total_tests - 1, ret,
+					src_off, len);
+				failed_tests++;
+				continue;
+			}
 		}
 		/* map with DMA_BIDIRECTIONAL to force writeback/invalidate */
 		for (i = 0; i < dst_cnt; i++) {
 			dma_dsts[i] = dma_map_single(dev->dev, thread->dsts[i],
 						     test_buf_size,
 						     DMA_BIDIRECTIONAL);
+			ret = dma_mapping_error(dev->dev, dma_dsts[i]);
+			if (ret) {
+				unmap_src(dev->dev, dma_srcs, len, src_cnt);
+				unmap_dst(dev->dev, dma_dsts, test_buf_size, i);
+				pr_warn("%s: #%u: mapping error %d with "
+					"dst_off=0x%x len=0x%x\n",
+					thread_name, total_tests - 1, ret,
+					dst_off, test_buf_size);
+				failed_tests++;
+				continue;
+			}
 		}
 
-
 		if (thread->type == DMA_MEMCPY)
 			tx = dev->device_prep_dma_memcpy(chan,
 							 dma_dsts[0] + dst_off,
Signature · 1 line
1.7.10.4
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] dmatest: check for dma mapping error

Quoted 6 lines · Andy Shevchenko

We get a warning if CONFIG_DMA_API_DEBUG=y

[   28.150631] WARNING: at lib/dma-debug.c:933 check_unmap+0x5d6/0x6ac()
[   28.157058] dw_dmac dw_dmac.0: DMA-API: device driver failed to check map error[device address=0x0000000035698305] [size=14365 bytes] [mapped as single]
#3 lore raw

Re: [PATCH 2/2] dmatest: check for dma mapping error

In reply to Andy Shevchenko
Quoted 13 lines · On Mon, 10 Dec 2012 13:37:44 +0200 Andy Shevchenko…

We get a warning if CONFIG_DMA_API_DEBUG=y

[   28.150631] WARNING: at lib/dma-debug.c:933 check_unmap+0x5d6/0x6ac()
[   28.157058] dw_dmac dw_dmac.0: DMA-API: device driver failed to check map error[device address=0x0000000035698305] [size=14365 bytes] [mapped as single]

...

drivers/dma/dmatest.c +0 -0
@@ -378,15 +378,35 @@ static int dmatest_func(void *data)
 
 			dma_srcs[i] = dma_map_single(dev->dev, buf, len,
 						     DMA_TO_DEVICE);

drivers/dma/dmatest.c static int dmatest_func(void *data) · line 390

Quoted 10 lines
drivers/dma/dmatest.c +10 -0
+			ret = dma_mapping_error(dev->dev, dma_srcs[i]);
+			if (ret) {
+				unmap_src(dev->dev, dma_srcs, len, i);
+				pr_warn("%s: #%u: mapping error %d with "
+					"src_off=0x%x len=0x%x\n",
+					thread_name, total_tests - 1, ret,
+					src_off, len);
+				failed_tests++;
+				continue;
+			}

The changelog and the code don't match. Which one is out of date?

#4 lore raw

Re: [PATCH 2/2] dmatest: check for dma mapping error

Quoted 12 lines · Andrew Morton
Quoted 9 lines · On Mon, 10 Dec 2012 13:37:44 +0200 Andy Shevchenko…

We get a warning if CONFIG_DMA_API_DEBUG=y

[   28.150631] WARNING: at lib/dma-debug.c:933 check_unmap+0x5d6/0x6ac()
[   28.157058] dw_dmac dw_dmac.0: DMA-API: device driver failed to check map error[device address=0x0000000035698305] [size=14365 bytes] [mapped as single]
drivers/dma/dmatest.c +0 -0
@@ -378,15 +378,35 @@ static int dmatest_func(void *data)
 
Quoted 14 lines

drivers/dma/dmatest.c static int dmatest_func(void *data) · line 390

Quoted 12 lines
drivers/dma/dmatest.c +10 -0
                      dma_srcs[i] = dma_map_single(dev->dev, buf, len,
                                                   DMA_TO_DEVICE);
+                     ret = dma_mapping_error(dev->dev, dma_srcs[i]);
+                     if (ret) {
+                             unmap_src(dev->dev, dma_srcs, len, i);
+                             pr_warn("%s: #%u: mapping error %d with "
+                                     "src_off=0x%x len=0x%x\n",
+                                     thread_name, total_tests - 1, ret,
+                                     src_off, len);
+                             failed_tests++;
+                             continue;
+                     }

The changelog and the code don't match. Which one is out of date?

I'm afraid I didn't get what is wrong.

dmatest maps memory via dma_map_single() call. And it asks dmaengine (at the end the DMA controller driver) to unmap them after usage. Exactly at that time user gets a warning. And this warning is independent of DMA controller in use.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#5 lore raw

Re: [PATCH 2/2] dmatest: check for dma mapping error

Quoted 29 lines · On Fri, 14 Dec 2012 09:06:03 +0200 Andy Shevchenko <[email protected]>…
Quoted 12 lines · Andrew Morton
Quoted 9 lines · On Mon, 10 Dec 2012 13:37:44 +0200 Andy Shevchenko…

We get a warning if CONFIG_DMA_API_DEBUG=y

[   28.150631] WARNING: at lib/dma-debug.c:933 check_unmap+0x5d6/0x6ac()
[   28.157058] dw_dmac dw_dmac.0: DMA-API: device driver failed to check map error[device address=0x0000000035698305] [size=14365 bytes] [mapped as single]
drivers/dma/dmatest.c +0 -0
@@ -378,15 +378,35 @@ static int dmatest_func(void *data)
 
Quoted 14 lines

drivers/dma/dmatest.c static int dmatest_func(void *data) · line 390

Quoted 12 lines
drivers/dma/dmatest.c +10 -0
                      dma_srcs[i] = dma_map_single(dev->dev, buf, len,
                                                   DMA_TO_DEVICE);
+                     ret = dma_mapping_error(dev->dev, dma_srcs[i]);
+                     if (ret) {
+                             unmap_src(dev->dev, dma_srcs, len, i);
+                             pr_warn("%s: #%u: mapping error %d with "
+                                     "src_off=0x%x len=0x%x\n",
+                                     thread_name, total_tests - 1, ret,
+                                     src_off, len);
+                             failed_tests++;
+                             continue;
+                     }

The changelog and the code don't match. Which one is out of date?

Quoted 2 lines

I'm afraid I didn't get what is wrong.

The above code will not emit the string "dw_dmac dw_dmac.0: DMA-API:
device driver failed to check map error[device address=0x0000000035698305] [size=14365 bytes] [mapped as single]".

Oh I see what you did. That string is emitted by the kernel at present, and the patch prevents this. And it also emits a new warning if the mapping attempt failed, and that new warning wasn't described.

I updated the changelog:

: The kernel emits a warning if CONFIG_DMA_API_DEBUG=y:
:
: [ 28.150631] WARNING: at lib/dma-debug.c:933 check_unmap+0x5d6/0x6ac()
: [ 28.157058] dw_dmac dw_dmac.0: DMA-API: device driver failed to check map error[device address=0x0000000035698305] [size=14365 bytes] [mapped as single]
:
: Fix this by adding the required checking of the dma_map_single() return : value.

#6 lore raw

Re: [PATCH 2/2] dmatest: check for dma mapping error

Quoted 34 lines · Andrew Morton
Quoted 29 lines · On Fri, 14 Dec 2012 09:06:03 +0200 Andy Shevchenko <[email protected]>…
Quoted 12 lines · Andrew Morton
Quoted 9 lines · On Mon, 10 Dec 2012 13:37:44 +0200 Andy Shevchenko…

We get a warning if CONFIG_DMA_API_DEBUG=y

[   28.150631] WARNING: at lib/dma-debug.c:933 check_unmap+0x5d6/0x6ac()
[   28.157058] dw_dmac dw_dmac.0: DMA-API: device driver failed to check map error[device address=0x0000000035698305] [size=14365 bytes] [mapped as single]
drivers/dma/dmatest.c +0 -0
@@ -378,15 +378,35 @@ static int dmatest_func(void *data)
 
Quoted 14 lines

drivers/dma/dmatest.c static int dmatest_func(void *data) · line 390

Quoted 12 lines
drivers/dma/dmatest.c +10 -0
                      dma_srcs[i] = dma_map_single(dev->dev, buf, len,
                                                   DMA_TO_DEVICE);
+                     ret = dma_mapping_error(dev->dev, dma_srcs[i]);
+                     if (ret) {
+                             unmap_src(dev->dev, dma_srcs, len, i);
+                             pr_warn("%s: #%u: mapping error %d with "
+                                     "src_off=0x%x len=0x%x\n",
+                                     thread_name, total_tests - 1, ret,
+                                     src_off, len);
+                             failed_tests++;
+                             continue;
+                     }

The changelog and the code don't match. Which one is out of date?

Quoted 2 lines

I'm afraid I didn't get what is wrong.

Quoted 7 lines

The above code will not emit the string "dw_dmac dw_dmac.0: DMA-API:
device driver failed to check map error[device address=0x0000000035698305] [size=14365 bytes] [mapped as single]".

Oh I see what you did. That string is emitted by the kernel at present, and the patch prevents this. And it also emits a new warning if the mapping attempt failed, and that new warning wasn't described.

Ah, okay, thank you.

Quoted 1 line

I updated the changelog:

Yes, you right, the changelog in my case describes only part of the problem.

Quoted 7 lines

: The kernel emits a warning if CONFIG_DMA_API_DEBUG=y:
:
: [ 28.150631] WARNING: at lib/dma-debug.c:933 check_unmap+0x5d6/0x6ac()
: [ 28.157058] dw_dmac dw_dmac.0: DMA-API: device driver failed to check map error[device address=0x0000000035698305] [size=14365 bytes] [mapped as single]
:
: Fix this by adding the required checking of the dma_map_single() return : value.

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy