From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id EA617A00BE; Wed, 8 Jul 2020 11:26:45 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BC6ED1DAC5; Wed, 8 Jul 2020 11:26:45 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 805A41D546 for ; Wed, 8 Jul 2020 11:26:44 +0200 (CEST) IronPort-SDR: Ruliu5xVCq4Auht3RPKElQii3tyaiq+5DOojogx3kHKpZWDvAZtEAWZB4Vt690wAqx16YpZCf6 IFOZraTVF4Pw== X-IronPort-AV: E=McAfee;i="6000,8403,9675"; a="145867386" X-IronPort-AV: E=Sophos;i="5.75,327,1589266800"; d="scan'208";a="145867386" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2020 02:26:43 -0700 IronPort-SDR: cjOWeTjAwhQ9aOG9SucWzf0lI3HMSqDABy3+KXAruOFi56wWd7IhlNiruXFS5UyHP0SYsIlMBa QP/AlWI6effA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,327,1589266800"; d="scan'208";a="315813148" Received: from shwdenpg235.ccr.corp.intel.com ([10.240.182.60]) by fmsmga002.fm.intel.com with ESMTP; 08 Jul 2020 02:26:42 -0700 From: alvinx.zhang@intel.com To: dev@dpdk.org Cc: beilei.xing@intel.com, jia.guo@intel.com Date: Wed, 8 Jul 2020 17:24:35 +0800 Message-Id: <20200708092435.9776-1-alvinx.zhang@intel.com> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] bus/pci: fix mmap PCI resource 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Alvin Zhang When mapping a PCI BAR containing an MSI-X table, some devices do not need to actually map this BAR or only need to map part of them, which may cause the mapping to fail. Now some checks are added and a non-NULL initial value is set to the variable to avoid this situation. Fixes: 2fd3567e5425 ("pci: use OS generic memory mapping functions") Cc: talshn@mellanox.com Signed-off-by: Alvin Zhang --- drivers/bus/pci/linux/pci_vfio.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c index fdeb9a8..9143bfc 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -547,6 +547,14 @@ bar_index, memreg[0].offset, memreg[0].size, memreg[1].offset, memreg[1].size); + + if (memreg[0].size == 0 && memreg[1].size == 0) { + /* No need to map this BAR */ + RTE_LOG(DEBUG, EAL, "Skipping BAR%d\n", bar_index); + bar->size = 0; + bar->addr = 0; + return 0; + } } else { memreg[0].offset = bar->offset; memreg[0].size = bar->size; @@ -556,7 +564,9 @@ bar_addr = mmap(bar->addr, bar->size, 0, MAP_PRIVATE | MAP_ANONYMOUS | additional_flags, -1, 0); if (bar_addr != MAP_FAILED) { - void *map_addr = NULL; + /* Set non NULL initial value for in case of no PCI mapping */ + void *map_addr = bar_addr; + if (memreg[0].size) { /* actual map of first part */ map_addr = pci_map_resource(bar_addr, vfio_dev_fd, -- 1.8.3.1