From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7D8EC43326; Tue, 14 Nov 2023 11:38:59 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6F24B402D4; Tue, 14 Nov 2023 11:38:59 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) by mails.dpdk.org (Postfix) with ESMTP id 278BF4027D; Tue, 14 Nov 2023 11:38:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699958338; x=1731494338; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3EmabzD/mdAxCQ2VTKqAd8dmnlLbDdKm5ln9+Dk+++Q=; b=js8hAQJELV7KwZZG57HhwR2D3nScCeF8NmSA+oGtvqHnuCWbmg1T13rP xfzlM5JwFRN39tTt81KD5VPVVLUH41UUdPhIM/OSMvLf4c2ER5Kynj8S8 Bp/ft0TXdKiHLsA08ugomAF56rpIc5xAKRiZ501OJg2w2C3Wjr8dc2rC0 WuMf4Aj9iMxXbpzwc//NhRE7rKc2t5qnsGoFhurWC9+cv9eXJlNT37RW5 J78943eudHFj4Tb8swI8MFv8ww9fdgPLmRrnO3gK41HK2rXz7PnU9CUef z2gg139FTsX7yo+xoEe1HcRVfXeRsvKLKCFYs9XvBg3acWmUcDBcA//dx w==; X-IronPort-AV: E=McAfee;i="6600,9927,10893"; a="3688459" X-IronPort-AV: E=Sophos;i="6.03,301,1694761200"; d="scan'208";a="3688459" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Nov 2023 02:38:57 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,301,1694761200"; d="scan'208";a="5769586" Received: from unknown (HELO localhost.localdomain) ([10.239.252.253]) by orviesa002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Nov 2023 02:38:55 -0800 From: Mingjin Ye To: dev@dpdk.org Cc: qiming.yang@intel.com, Mingjin Ye , stable@dpdk.org, Anatoly Burakov , Chenbo Xia , Nipun Gupta Subject: [PATCH v6] bus/pci: fix legacy device IO port map Date: Tue, 14 Nov 2023 10:24:18 +0000 Message-Id: <20231114102418.409285-1-mingjinx.ye@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231024020021.116278-1-wenwux.ma@intel.com> References: <20231024020021.116278-1-wenwux.ma@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org When doing IO port mapping for legacy device in secondary process, the region information is missing, so, we need to refill it. Fixes: 4b741542ecde ("bus/pci: avoid depending on private kernel value") Cc: stable@dpdk.org Signed-off-by: Mingjin Ye --- v6: - split patch v5: - adding checks to vfio setup v4: - adjusting commit log v3: - adjusting variable settings v2: - add release of device in pci_vfio_ioport_unmap --- drivers/bus/pci/linux/pci_vfio.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c index 3f3201daf2..a18161c27b 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -1230,6 +1230,32 @@ pci_vfio_ioport_map(struct rte_pci_device *dev, int bar, return -1; } + if (rte_eal_process_type() == RTE_PROC_SECONDARY) { + struct vfio_device_info device_info = { .argsz = sizeof(device_info) }; + char pci_addr[PATH_MAX]; + int vfio_dev_fd; + struct rte_pci_addr *loc = &dev->addr; + + /* store PCI address string */ + snprintf(pci_addr, sizeof(pci_addr), PCI_PRI_FMT, + loc->domain, loc->bus, loc->devid, loc->function); + + vfio_dev_fd = rte_intr_dev_fd_get(dev->intr_handle); + if (vfio_dev_fd < 0) { + return -1; + } else if (vfio_dev_fd == 0) { + if (rte_vfio_get_device_info(rte_pci_get_sysfs_path(), pci_addr, + &vfio_dev_fd, &device_info) != 0) + return -1; + /* we need save vfio_dev_fd, so it can be used during release */ + if (rte_intr_dev_fd_set(dev->intr_handle, vfio_dev_fd)) + return -1; + + if (pci_vfio_fill_regions(dev, vfio_dev_fd, &device_info) != 0) + return -1; + } + } + if (pci_vfio_get_region(dev, bar, &size, &offset) != 0) { RTE_LOG(ERR, EAL, "Cannot get offset of region %d.\n", bar); return -1; -- 2.25.1