From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from netronome.com (host-79-78-33-110.static.as9105.net [79.78.33.110]) by dpdk.org (Postfix) with ESMTP id 4EDADFA44 for ; Wed, 18 Jan 2017 13:27:56 +0100 (CET) Received: from netronome.com (localhost [127.0.0.1]) by netronome.com (8.14.4/8.14.4/Debian-4.1ubuntu1) with ESMTP id v0ICRtKx041044 for ; Wed, 18 Jan 2017 12:27:55 GMT Received: (from alucero@localhost) by netronome.com (8.14.4/8.14.4/Submit) id v0ICRtRZ041043 for dev@dpdk.org; Wed, 18 Jan 2017 12:27:55 GMT From: Alejandro Lucero To: dev@dpdk.org Date: Wed, 18 Jan 2017 12:27:55 +0000 Message-Id: <1484742475-41005-1-git-send-email-alejandro.lucero@netronome.com> X-Mailer: git-send-email 1.9.1 Subject: [dpdk-dev] [PATCH] igb_uio: map dummy dma forcing iommu domain attachment X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Jan 2017 12:27:57 -0000 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 --- 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