Skip to contentSkip to conversation

BUG_ON for DMA-bounce and bidirectional mappings (e100 on IXP4xx)

DISCUSSION Simon Kågström 1 participant 2 messages Mar 4, 2014 – Mar 17, 2014 2 messages not in the archive Arm (32-bit)

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 9 lines · On Tue, 4 Mar 2014 10:45:28 +0000 Russell King - ARM Linux…
Quoted 4 lines · Simon K?gstr?m

We have a IXP4xx-based board which has an e100 NIC. During bootup, we trigger a BUG_ON in dmabounce.c because the mapped direction doesn't match the synced one. e100.c maps buffers bidirectional, but the sync is done fromdevice.

First and foremost, enable DMA API debugging and check whether that complains too (I think it should do, you're not allowed to change the direction argument until a mapping is unmapped.)

Well, you are right, but the warning I get is not for direction:

  WARNING: at /srv/lhome/simkag/devel/nc602/external/kernel/lib/dma-debug.c:986 check_sync+0x14c/0x540()
  e100 0000:00:02.0: DMA-API: device driver tries to sync DMA memory it has not allocated [device address=0x0000000003c01000] [size=16 bytes]
  [...]
  [<c0134b24>] (debug_dma_sync_single_for_device+0x44/0x50) from [<c017a5e8>] (e100_rx_alloc_skb+0x1c4/0x1e8)
  [<c017a5e8>] (e100_rx_alloc_skb+0x1c4/0x1e8) from [<c017c58c>] (e100_rx_alloc_list+0x84/0x164)
  [<c017c58c>] (e100_rx_alloc_list+0x84/0x164) from [<c017e958>] (e100_up+0xc/0x14c)
  [<c017e958>] (e100_up+0xc/0x14c) from [<c017ecc8>] (e100_open+0x14/0x40)
  [<c017ecc8>] (e100_open+0x14/0x40) from [<c019b230>] (__dev_open+0x8c/0x134)

And the dma_debug code explicitly skips the check if the direction is DMA_BIDIRECTIONAL:

static void check_sync(struct device *dev,
struct dma_debug_entry *ref, bool to_cpu)

  {
	[...]
	if (entry->direction == DMA_BIDIRECTIONAL)
		goto out;

	if (ref->direction != entry->direction) {
		err_printk(dev, entry, "DMA-API: device driver syncs "
				"DMA memory with different direction "
				"[device address=0x%016llx] [size=%llu bytes] "
				"[mapped with %s] [synced with %s]\n",
				(unsigned long long)ref->dev_addr, entry->size,
				dir2name[entry->direction],
				dir2name[ref->direction]);
	}
	[...]

}

Krzysztofs patch does the same for dmabounce.c, from the dma-debug code it seems to me that it would make sense there as well?

// Simon

#3 lore raw

Hi again!

Quoted 31 lines · On Tue, 4 Mar 2014 12:37:14 +0100 Simon K?gstr?m…
Quoted 6 lines · On Tue, 4 Mar 2014 10:45:28 +0000 Russell King - ARM Linux…
Quoted 4 lines · Simon K?gstr?m

We have a IXP4xx-based board which has an e100 NIC. During bootup, we trigger a BUG_ON in dmabounce.c because the mapped direction doesn't match the synced one. e100.c maps buffers bidirectional, but the sync is done fromdevice.

[...]

[...]
And the dma_debug code explicitly skips the check if the direction is DMA_BIDIRECTIONAL:

static void check_sync(struct device *dev,
struct dma_debug_entry *ref, bool to_cpu)

  {
	[...]
	if (entry->direction == DMA_BIDIRECTIONAL)
		goto out;

	if (ref->direction != entry->direction) {
		err_printk(dev, entry, "DMA-API: device driver syncs "
				"DMA memory with different direction "
				"[device address=0x%016llx] [size=%llu bytes] "
				"[mapped with %s] [synced with %s]\n",
				(unsigned long long)ref->dev_addr, entry->size,
				dir2name[entry->direction],
				dir2name[ref->direction]);
	}
	[...]
Quoted 4 lines

}

Krzysztofs patch does the same for dmabounce.c, from the dma-debug code it seems to me that it would make sense there as well?

I'd like to bring this issue up again. To me it seems Krzysztofs patch (pasted below again) would align the ARM dmabounce behaviour with the DMA API verifier code. Seems to make sense for my part at least. Comments?

// Simon

arch/arm/common/dmabounce.c +2 -2
@@ -375,7 +375,7 @@ static int __dmabounce_sync_for_cpu(struct device *dev, dma_addr_t addr,
 
 	off = addr - buf->safe_dma_addr;
 
-	BUG_ON(buf->direction != dir);
+	BUG_ON(buf->direction != dir && buf->direction != DMA_BIDIRECTIONAL);
 
 	dev_dbg(dev, "%s: unsafe buffer %p (dma=%#x off=%#lx) mapped to %p (dma=%#x)\n",
 		__func__, buf->ptr, virt_to_dma(dev, buf->ptr), off,
@@ -415,7 +415,7 @@ static int __dmabounce_sync_for_device(struct device *dev, dma_addr_t addr,
 
 	off = addr - buf->safe_dma_addr;
 
-	BUG_ON(buf->direction != dir);
+	BUG_ON(buf->direction != dir && buf->direction != DMA_BIDIRECTIONAL);
 
 	dev_dbg(dev, "%s: unsafe buffer %p (dma=%#x off=%#lx) mapped to %p (dma=%#x)\n",
 		__func__, buf->ptr, virt_to_dma(dev, buf->ptr), off,