From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takeshi Yoshimura Subject: [PATCH v3] vfio: fix workaround of BAR0 mapping Date: Fri, 13 Jul 2018 19:11:45 +0900 Message-ID: <20180713101145.4795-1-t.yoshimura8869@gmail.com> References: <20180712030833.4887-1-t.yoshimura8869@gmail.com> Cc: dev@dpdk.org, Takeshi Yoshimura To: Anatoly Burakov Return-path: Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by dpdk.org (Postfix) with ESMTP id 56E492C36 for ; Fri, 13 Jul 2018 12:11:52 +0200 (CEST) Received: by mail-pg1-f194.google.com with SMTP id r5-v6so4813235pgv.0 for ; Fri, 13 Jul 2018 03:11:52 -0700 (PDT) In-Reply-To: <20180712030833.4887-1-t.yoshimura8869@gmail.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The workaround of BAR0 mapping gives up and immediately returns an error if it cannot map around the MSI-X. However, recent version of VFIO allows MSIX mapping (*). I fixed not to return immediately but try mapping. In old Linux, mmap just fails and returns the same error as the code before my fix . In recent Linux, mmap succeeds and this patch enables running DPDK in specific environments (e.g., ppc64le with HGST NVMe) (*): "vfio-pci: Allow mapping MSIX BAR", https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/ commit/id=a32295c612c57990d17fb0f41e7134394b2f35f6 Fixes: 90a1633b2347 ("eal/linux: allow to map BARs with MSI-X tables") Signed-off-by: Takeshi Yoshimura --- Thanks, Anatoly. I updated the patch not to affect behaviors of older Linux and other environments as well as possible. This patch adds another chance to mmap BAR0. I noticed that the check at line 350 already includes the check of page size, so this patch does not fix the check. Regards, Takeshi drivers/bus/pci/linux/pci_vfio.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c index aeeaa9ed8..eb9b8031d 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -348,24 +348,25 @@ pci_vfio_mmap_bar(int vfio_dev_fd, struct mapped_pci_resource *vfio_res, table_start &= PAGE_MASK; if (table_start == 0 && table_end >= bar->size) { - /* Cannot map this BAR */ - RTE_LOG(DEBUG, EAL, "Skipping BAR%d\n", bar_index); - bar->size = 0; - bar->addr = 0; - return 0; + /* Cannot map around this BAR, but try */ + RTE_LOG(DEBUG, EAL, + "Trying to map BAR%d that contains the MSI-X\n", + bar_index); + memreg[0].offset = bar->offset; + memreg[0].size = bar->size; + } else { + memreg[0].offset = bar->offset; + memreg[0].size = table_start; + memreg[1].offset = bar->offset + table_end; + memreg[1].size = bar->size - table_end; + + RTE_LOG(DEBUG, EAL, + "Trying to map BAR%d that contains the MSI-X " + "table. Trying offsets: " + "0x%04lx:0x%04lx, 0x%04lx:0x%04lx\n", bar_index, + memreg[0].offset, memreg[0].size, + memreg[1].offset, memreg[1].size); } - - memreg[0].offset = bar->offset; - memreg[0].size = table_start; - memreg[1].offset = bar->offset + table_end; - memreg[1].size = bar->size - table_end; - - RTE_LOG(DEBUG, EAL, - "Trying to map BAR%d that contains the MSI-X " - "table. Trying offsets: " - "0x%04lx:0x%04lx, 0x%04lx:0x%04lx\n", bar_index, - memreg[0].offset, memreg[0].size, - memreg[1].offset, memreg[1].size); } else { memreg[0].offset = bar->offset; memreg[0].size = bar->size; -- 2.15.1