DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] igb_uio: map dummy dma forcing iommu domain attachment
@ 2017-01-18 12:27 Alejandro Lucero
  2017-02-07 15:59 ` Ferruh Yigit
  2017-02-17 12:29 ` Ferruh Yigit
  0 siblings, 2 replies; 10+ messages in thread
From: Alejandro Lucero @ 2017-01-18 12:27 UTC (permalink / raw)
  To: dev

For using a DPDK app when iommu is enabled, it requires to
add iommu=pt to the kernel command line. But using igb_uio driver
makes DMAR errors because the device has not an IOMMU domain.

Since kernel 3.15, iommu=pt requires to use the internal kernel
DMA API for attaching the device to the IOMMU 1:1 mapping, aka
si_domain. Previous versions did attach the device to that
domain when intel iommu notifier was called.

This is not a problem if the driver does later some call to the
DMA API because the mapping can be done then. But DPDK apps do
not use that DMA API at all.

Doing this dma map and unmap is harmless even when iommu is not
enabled at all.

Signed-off-by: Alejandro Lucero <alejandro.lucero@netronome.com>
---
 lib/librte_eal/linuxapp/igb_uio/igb_uio.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c
index df41e45..f79fe6b 100644
--- a/lib/librte_eal/linuxapp/igb_uio/igb_uio.c
+++ b/lib/librte_eal/linuxapp/igb_uio/igb_uio.c
@@ -326,6 +326,8 @@ struct rte_uio_pci_dev {
 {
 	struct rte_uio_pci_dev *udev;
 	struct msix_entry msix_entry;
+	dma_addr_t map_dma_addr;
+	void *map_addr;
 	int err;
 
 	udev = kzalloc(sizeof(struct rte_uio_pci_dev), GFP_KERNEL);
@@ -423,6 +425,25 @@ struct rte_uio_pci_dev {
 	dev_info(&dev->dev, "uio device registered with irq %lx\n",
 		 udev->info.irq);
 
+	/*
+	 * Doing a harmless dma mapping for attaching the device to
+	 * the iommu identity mapping if kernel boots with iommu=pt.
+	 * Note this is not a problem if no IOMMU at all.
+	 */
+	map_addr = dma_zalloc_coherent(&dev->dev, 1024,
+				       &map_dma_addr, GFP_KERNEL);
+
+	if (!map_addr)
+		dev_info(&dev->dev, "dma mapping failed\n");
+	else {
+		dev_info(&dev->dev, "mapping 1K dma=%#llx host=%p\n",
+			 (unsigned long long)map_dma_addr, map_addr);
+
+		dma_free_coherent(&dev->dev, 1024, map_addr, map_dma_addr);
+		dev_info(&dev->dev, "unmapping 1K dma=%#llx host=%p\n",
+			 (unsigned long long)map_dma_addr, map_addr);
+	}
+
 	return 0;
 
 fail_remove_group:
-- 
1.9.1

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

end of thread, other threads:[~2017-03-30 20:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-18 12:27 [dpdk-dev] [PATCH] igb_uio: map dummy dma forcing iommu domain attachment Alejandro Lucero
2017-02-07 15:59 ` Ferruh Yigit
2017-02-08 11:54   ` Alejandro Lucero
2017-02-10 19:03     ` Ferruh Yigit
2017-02-10 19:06       ` Ferruh Yigit
2017-02-13 13:38         ` Alejandro Lucero
2017-02-13 15:54           ` Ferruh Yigit
2017-02-13 13:31       ` Alejandro Lucero
2017-02-17 12:29 ` Ferruh Yigit
2017-03-30 20:20   ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).