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 75D1545B12 for ; Fri, 11 Oct 2024 13:16:24 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6DE91402DC; Fri, 11 Oct 2024 13:16:24 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.13]) by mails.dpdk.org (Postfix) with ESMTP id B964A40150; Fri, 11 Oct 2024 13:16:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1728645381; x=1760181381; h=from:to:cc:subject:date:message-id:in-reply-to: references:content-transfer-encoding:mime-version; bh=LHGhpyVgBDLmYWM7la4lRXiiDoVQFQZ27ocl1E6uxVA=; b=GWfrwoaDK4+6aQN9kKKdKWS83CrJgkkZb7e2XHMbMGx+awK/aG7kjxOa rI2RGUJCtDRYrqnyCc+KZ8IjY9xUUgTlsRAGnGK2CsMwlmNj/qKVqLgQG jymDUe64rwo84KRZoHm5C9315QemMO2iub5AK4sDW9JVH7RbizbdLXdHV 5hsQHNkWcrhWceub5VJy742qvyQ+4sktRJJqDbrOH0JTv0fvK4Sc6t00I k3iHsLph8Qf79qKu5TmMGCg3bVemi5iwBQtBHdgm0S278FMth8++TLvAc 39dNtgxolutNKI2Ud1CoxtjNmOQ7uwLsfc7benhGQCuQ5GJgSolBFAnph Q==; X-CSE-ConnectionGUID: oSMxrjUeQQmKw+bKJ7o/eg== X-CSE-MsgGUID: WxHZe88vTqOOarJBuyY0sw== X-IronPort-AV: E=McAfee;i="6700,10204,11221"; a="39170415" X-IronPort-AV: E=Sophos;i="6.11,195,1725346800"; d="scan'208";a="39170415" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Oct 2024 04:16:20 -0700 X-CSE-ConnectionGUID: /Ip7Ge5eTN6TWnt7xMt9wA== X-CSE-MsgGUID: VOhUSRCrS7O/1oCSv5BFiw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,195,1725346800"; d="scan'208";a="76790991" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orviesa009.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 11 Oct 2024 04:16:20 -0700 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 11 Oct 2024 04:16:19 -0700 Received: from orsmsx612.amr.corp.intel.com (10.22.229.25) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Fri, 11 Oct 2024 04:16:19 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx612.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39 via Frontend Transport; Fri, 11 Oct 2024 04:16:19 -0700 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (104.47.74.48) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 11 Oct 2024 04:16:18 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AAkBbKB6t2lYq8YZh9qibb7RTMZ44sXA54hbZYga96REMrUjAkvPspvPUu/Us6PgPqLLjKvW//tDmPaRc/eXpx8qjCyTvc3mbi22moV+JpBy864kZLoEip6BQf06mfqMRC9b6ti8O936lRu1QFsTbyh4Ks3imvADSOZ2bp4DE3QDm3dV5GI5vG7b637WYTae5aqkftyMHBcxEU7c4YIuT0y7JRUR+3CoxPPU/AtXLQ7rq7PRxQJtEvrWas0WRBQBDG+wlNl8ZExxGaqaTPsVmMcyHx2UU5b3whe5dzFhr3vRU16xVgB55W86w6U7Oh2jrN98envpTRihwchewl7hyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zB6lkwu6KzBaD7LP5wQu6K48TEUS3kD5TSOX7ZkFLYs=; b=UVpzMtK3n70VcY7ruqOHyLNQRUQcotFgeG0nUx/w4YzNGyyPFcKoyk5YmyfNUrrXhxcyMhtd52DdJUjLY6+1Juw7vUyzmMbRW7m2ALhGzv1s4WbHpC9Be90wXrCR/oeW+n84dHU6TQXSsoodViypH9COlABgq/TbHmNPe1RZSZ26meSssqnOqU7Bt9Y9YXl7szGvJafiJg58kzF4SNhSjatTXBobNCRaUPc0OzSqRXBM3kq6HmriYB15KdEJKyvY2fZeMVusnqOGj3VdhG6P+vwtAb2zCfhhluaenWX7wfuZtMVRT9317zvrTr80yYqWUjacqKW+OSrz8ch4YL6TuQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from CO6PR11MB5569.namprd11.prod.outlook.com (2603:10b6:303:139::20) by DM4PR11MB7325.namprd11.prod.outlook.com (2603:10b6:8:107::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.23; Fri, 11 Oct 2024 11:16:15 +0000 Received: from CO6PR11MB5569.namprd11.prod.outlook.com ([fe80::5e92:7b53:f0be:a18b]) by CO6PR11MB5569.namprd11.prod.outlook.com ([fe80::5e92:7b53:f0be:a18b%4]) with mapi id 15.20.8048.018; Fri, 11 Oct 2024 11:16:15 +0000 From: Konrad Sztyber To: CC: Chaoyong He , Stephen Hemminger , David Marchand , Konrad Sztyber , , Chenbo Xia , Nipun Gupta , Anatoly Burakov , Long Wu , Zerun Fu Subject: [PATCH v3] bus/pci: don't open uio device in secondary process Date: Fri, 11 Oct 2024 13:15:05 +0200 Message-ID: <20241011111533.20746-1-konrad.sztyber@intel.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: <20240829085724.270041-1-konrad.sztyber@intel.com> References: <20240829085724.270041-1-konrad.sztyber@intel.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: AS4PR10CA0011.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:5dc::14) To CO6PR11MB5569.namprd11.prod.outlook.com (2603:10b6:303:139::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO6PR11MB5569:EE_|DM4PR11MB7325:EE_ X-MS-Office365-Filtering-Correlation-Id: 82426249-1bfa-43ca-6678-08dce9e61e6c X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?kMzQT1W9Niett9+ttw9HKHH0JRSQbu5nK40DsXRM7RipGW5NDSbjtgM0u/vw?= =?us-ascii?Q?wFS+H7zF4gUpZ6/atXJwoqBGOJEEDSmC4bO1cjBpqst0jhn0W4AGRUdAXsB9?= =?us-ascii?Q?wbyBmGg5b4gAjJmgG0ubQ6YXVx9Nwcv4BhJKB411uL9aLrZIW252SL6ey2LL?= =?us-ascii?Q?XtyWBoHyVy4DXPPoVlICccczQ4EPCNOcW+4F7s14WqGl5JdeFxRQT6E4JeKH?= =?us-ascii?Q?vzYhfbcaHSejXeeqfpeH6zVwGAAPnBEoec4kcn/5yvc8HVgvPhxz8kKa96dJ?= =?us-ascii?Q?LO3rr86s+9sQgjdT/VVaee4FdQRLUYDze9umsH5Qsr0mwyta59RWvV6g0/By?= =?us-ascii?Q?GVorMIRh4f4vPR/F925gFUUtR4ZF9qV3B81Z2pbpjDtwGhTWztfXS4vwrwK1?= =?us-ascii?Q?hr0NqpzKN0mwWsLOltlADl6sGIXLPK5K+8LN4jkuZgly8HJo9RAtbAIm0O6K?= =?us-ascii?Q?o7tMLD90FyMac9GKaqGxGJHjhKXh7RhTWyhawwnr+0uhtAlWuBpOiGKyvkNz?= =?us-ascii?Q?Jqo/CmC16U/WzfU+Mfy/H/zA8Q5IMffxuC1yoqjybT0kVjbYTjIMhTSOAaC7?= =?us-ascii?Q?tqMIzqffToinuAvi1FNYo79Yq1XymSOfhz56ewK74GnIdw2AqasyTXtTa9i5?= =?us-ascii?Q?t2uDRO/OD+YsZuE9v+PrbVYGRDtOO5yNkJDx6a33GQP1M7cuLns7dQVmm4Of?= =?us-ascii?Q?zByMxqQoUBIcFkq1ybQCqA8UD8TmyGxeZR1BTxXxp28hvcSwtp3iOWtYghGr?= =?us-ascii?Q?wjEoXCsQWoTwhDDgVZoTRj2nQ3vAAVBJ4OQoIiFhppHWtU3VJecRZ/pbmp6z?= =?us-ascii?Q?1bDOvn0At9yrQ80W7GA/xSAx3KHbOUjyXT0qifCAwvJGGrcR4+8oiaiNlaYu?= =?us-ascii?Q?13ZS36J7VxibtGASu266V6qG4rPvU90KOwDH2T7o00AFkEEBN/+AcwZndLMV?= =?us-ascii?Q?VSk2fbmdm93Pe0k3bEharJSMWkhR0gVWc7mitQVLDJbzvPSNDSmxO9GvzjnI?= =?us-ascii?Q?9mePdQNgOx0aoilLkcG4ASKpVPBWoXo8WIkYvK2nphw2peBuMJhuzAdTpB0Y?= =?us-ascii?Q?ULrOKNyeKBX5Bbe4MsnGO5Q+zXudgP2oCnflL1Jy9TF8zspGlE0a9Xeja7ls?= =?us-ascii?Q?bAewEfWnZ9kpM+UnoKvE+4p7Y3YQc8AdxcKer2afKg3ETwMCsaLg4qvme0sG?= =?us-ascii?Q?IsS/EGxllm1wQjHTUTMZ9ga2U9S83Tc11nylxPogNgvAhhvgZzA6N13akiM3?= =?us-ascii?Q?WL+e4HiqqcXaf9myLrP8Lms+MdspUWnQxvfVkBG0eA=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO6PR11MB5569.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(1800799024)(376014)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?o6SdndaWtdP54xumWipi2vl+mLNfwUEQRWoki0fkA03qqb6QYaEbKDcmeBLz?= =?us-ascii?Q?uxt+oY3Ye4i4FgIzMwiMiKPMwq+KaYROPtQwtSK7Sie4wEkcwUA3tinpXE71?= =?us-ascii?Q?7qPcg+i4zVMKuDYwfb6J3YYb54vJfXhxkYB9UOQLgHEKxIhpUVDRHiHbcs3O?= =?us-ascii?Q?wndYcTGLOKwxEg22LxEg/GXCHyVciCSduskuW2BPK4Sp5pjUqHutIEIjkF/a?= =?us-ascii?Q?2Xvh0rtDQMCcHaxoYhcGOwGkwBgwnYsU6KiHGKH8uNvsIZoC5aba1Q4V2gJv?= =?us-ascii?Q?4B5o3dB76pa11OB/BEdR7Oc16yrz5ttHbp34B7D9ePka1kC7KFFWoyoopTBG?= =?us-ascii?Q?FtTwHqhqlXXa9WTbUWGwoAbVA8J5+FZdncnNsEhH5hkSwBiSn0x2wJgFbAyZ?= =?us-ascii?Q?ZnMDdmho0hczDueYcrFt1X39V13tohshdZt5SO/UZNzSMfVIszQtWCZncwsS?= =?us-ascii?Q?0MaC1PSGnUoGkhLdjZvJ+a1zz5nlSzlQV4MDLXLsjL0l4Gj7PcsnP6/LyDJh?= =?us-ascii?Q?kgubB0lht9o7rVYIf/ug7LfHucENo86n4GzGPcpBDtKAhyh8/HOSMK7msiEz?= =?us-ascii?Q?jSvbI8VjvY7UaoB9Vuze3kq2FpeHqPZRc71DINbLIvyJuikXnTqxWvkFKtfi?= =?us-ascii?Q?AbmebmU/vyyAp7d8IftKO8907m+BHNp1Xg6+WI69nOmrmbq6BTRfkYefNow4?= =?us-ascii?Q?Bv27vxVu/kNH1LYwkblMdlEZcQLhbjjLSgj5xW+jHc46IlYeRTUMZZ/aKOjO?= =?us-ascii?Q?phIlIfl9pkcHKkaE3/mgMVBMpveQiFBPPDirtav3igzXkD7TeNtO0cemYPcz?= =?us-ascii?Q?60PfrPso4LBuQ87oKyU5QxNXy2Bh7N2pqf8sGuzyz0qN4gR4rBjDOj7Rtmjn?= =?us-ascii?Q?vdurFSpKTQhzGDACLpe3LzwiHhIX5ERSSBXUaR/rLL963Ribfwt2nXixVcYK?= =?us-ascii?Q?rwh0pE2yR7RL+lGi/F8iS92XQqgq3crq5rFGhhvgAL59sgPWNqQI4GXY6zhI?= =?us-ascii?Q?os9lmrkZoexiPeIQvEh6kzb1Fj/DhySqQb38RliygvoFosTn64/j5G23sgz1?= =?us-ascii?Q?0rNguOvH3SPItFVRESsbwyc4RKhKfk9AAChPGpFQlaSmoo5g2omVxUBSuSEV?= =?us-ascii?Q?Yd+0Ac5KHtGzktA/SDWxO2vLt3GWJeaBcmlasDVMvEf42hITGHJviHI82C35?= =?us-ascii?Q?XFGtsH3A+N2a8h2HEdGuGtXLlrprOILJsvgnFCEzdEXLXVlOkbugyvtCTFYW?= =?us-ascii?Q?H62bYD9OMUk4r375tL0ZqPgsJx7MRuQDwmakfph53LbeShYDjlgNHgyQMwDy?= =?us-ascii?Q?y15AyRNLYFqs+oP66KXSnXqvhqW2N0nhmm0lZflt0LiyR/RIJ+JYt+llDRIH?= =?us-ascii?Q?eP7/klZA049WRKlvyfhN6cLCbxxNKm72nxT5MuoPz2DbJc7ZB1ltqB733NGc?= =?us-ascii?Q?jeIOCgWcwuysQgH28YLFwtjqyV53vYnOLVk7ff3hn+/dOMvEEThbl0dy7Yaf?= =?us-ascii?Q?L6bzY8ugY5cjnHOpXo43celYlqyt6jEg5vXN0JuXjcwjd9hHWOOD2OkeXoCK?= =?us-ascii?Q?YLCagZna0sWm3DEz0V0v+hHEpfCzX8sbWdF0lIt0XcwvIBZBAjablxNQBKJ6?= =?us-ascii?Q?uw=3D=3D?= X-MS-Exchange-CrossTenant-Network-Message-Id: 82426249-1bfa-43ca-6678-08dce9e61e6c X-MS-Exchange-CrossTenant-AuthSource: CO6PR11MB5569.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Oct 2024 11:16:15.2344 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ICkOFHUDprAovXMe/nGn2UNRzVC4EyKgzh3FAH2tHK/kit8GXZt60v5yo5cdCXZGQtDxipvb2uYHqoPzFLf5Zd8QENVUlmBW5TrJtZv9wXs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR11MB7325 X-OriginatorOrg: intel.com X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org The uio_pci_generic driver clears the bus master bit when the device file is closed. So, when the secondary process terminates after probing a device, that device becomes unusable in the primary process. To avoid that, the device file is now opened only in the primary process and the secondary gets it over UNIX domain socket via SCM_RIGHTS. Fixes: 847d78fb9530 ("bus/pci: fix FD in secondary process") Cc: stable@dpdk.org Signed-off-by: Konrad Sztyber --- v3: Use the rte_mp_* infrastructure to pass the uio fd from the primary process to the secondary. v2: Fixed coding style issues. --- drivers/bus/pci/linux/pci_uio.c | 140 ++++++++++++++++++++++++++++---- 1 file changed, 126 insertions(+), 14 deletions(-) diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c index 4c1d3327a9..220390d921 100644 --- a/drivers/bus/pci/linux/pci_uio.c +++ b/drivers/bus/pci/linux/pci_uio.c @@ -21,14 +21,22 @@ #include #include #include +#include +#include #include "eal_filesystem.h" #include "pci_init.h" #include "private.h" void *pci_map_addr = NULL; +static int pci_uio_dev_count; #define OFF_MAX ((uint64_t)(off_t)-1) +#define SEND_FD_MP_KEY "pci_uio_send_fd" + +struct pci_uio_send_fd_param { + struct rte_pci_addr addr; +}; int pci_uio_read_config(const struct rte_intr_handle *intr_handle, @@ -211,6 +219,93 @@ pci_uio_free_resource(struct rte_pci_device *dev, rte_intr_fd_set(dev->intr_handle, -1); rte_intr_type_set(dev->intr_handle, RTE_INTR_HANDLE_UNKNOWN); } + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + assert(pci_uio_dev_count > 0); + pci_uio_dev_count--; + if (pci_uio_dev_count == 0) + rte_mp_action_unregister(SEND_FD_MP_KEY); + } +} + +static int +pci_uio_send_fd(const struct rte_mp_msg *request, const void *peer) +{ + struct rte_pci_device *dev; + const struct pci_uio_send_fd_param *param = + (const struct pci_uio_send_fd_param *)request->param; + struct rte_mp_msg reply = {}; + int fd; + + strlcpy(reply.name, request->name, sizeof(reply.name)); + TAILQ_FOREACH(dev, &rte_pci_bus.device_list, next) { + if (!rte_pci_addr_cmp(&dev->addr, ¶m->addr)) + break; + } + + if (dev == NULL) { + PCI_LOG(ERR, "Could not find PCI device (" PCI_PRI_FMT ")", + param->addr.domain, param->addr.bus, + param->addr.devid, param->addr.function); + goto reply; + } + + fd = rte_intr_fd_get(dev->intr_handle); + if (fd < 0) { + PCI_LOG(ERR, "Could not get fd (" PCI_PRI_FMT ")", + param->addr.domain, param->addr.bus, + param->addr.devid, param->addr.function); + goto reply; + } + + reply.num_fds = 1; + reply.fds[0] = fd; +reply: + if (rte_mp_reply(&reply, peer) != 0) { + PCI_LOG(ERR, "Failed to send reply: %d (" PCI_PRI_FMT ")", + rte_errno, param->addr.domain, param->addr.bus, + param->addr.devid, param->addr.function); + return -1; + } + + return 0; +} + +static int +pci_uio_request_fd(struct rte_pci_device *dev) +{ + struct rte_mp_msg request = {}, *reply; + struct timespec timeout = {.tv_sec = 1, .tv_nsec = 0}; + struct pci_uio_send_fd_param *param = + (struct pci_uio_send_fd_param *)request.param; + struct rte_mp_reply replies; + int rc; + + strlcpy(request.name, SEND_FD_MP_KEY, sizeof(request.name)); + memcpy(¶m->addr, &dev->addr, sizeof(param->addr)); + request.len_param = sizeof(*param); + + rc = rte_mp_request_sync(&request, &replies, &timeout); + if (rc != 0 || replies.nb_received != 1) { + PCI_LOG(ERR, "Failed to request fd from primary: %d (" PCI_PRI_FMT ")", + rte_errno, dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); + return -1; + } + + reply = replies.msgs; + if (reply->num_fds != 1) { + PCI_LOG(ERR, "Received unexpected number of fds: %d (" PCI_PRI_FMT ")", + reply->num_fds, dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); + free(reply); + return -1; + } + + rte_intr_fd_set(dev->intr_handle, reply->fds[0]); + free(reply); + + return 0; } int @@ -220,7 +315,7 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, char dirname[PATH_MAX]; char cfgname[PATH_MAX]; char devname[PATH_MAX]; /* contains the /dev/uioX */ - int uio_num, fd, uio_cfg_fd; + int rc, uio_num, fd, uio_cfg_fd; struct rte_pci_addr *loc; loc = &dev->addr; @@ -232,18 +327,6 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, loc->domain, loc->bus, loc->devid, loc->function); return 1; } - snprintf(devname, sizeof(devname), "/dev/uio%u", uio_num); - - /* save fd */ - fd = open(devname, O_RDWR); - if (fd < 0) { - PCI_LOG(ERR, "Cannot open %s: %s", devname, strerror(errno)); - goto error; - } - - if (rte_intr_fd_set(dev->intr_handle, fd)) - goto error; - snprintf(cfgname, sizeof(cfgname), "/sys/class/uio/uio%u/device/config", uio_num); @@ -270,8 +353,27 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, } } - if (rte_eal_process_type() != RTE_PROC_PRIMARY) + if (rte_eal_process_type() != RTE_PROC_PRIMARY) { + if (pci_uio_request_fd(dev) != 0) + goto error; return 0; + } + + /* + * The uio_pci_generic driver clears the bus master enable bit when the + * device file is closed, so open it only in the primary process. The + * secondary will get it via SCM_RIGHTS. + */ + snprintf(devname, sizeof(devname), "/dev/uio%u", uio_num); + /* save fd */ + fd = open(devname, O_RDWR); + if (fd < 0) { + PCI_LOG(ERR, "Cannot open %s: %s", devname, strerror(errno)); + goto error; + } + + if (rte_intr_fd_set(dev->intr_handle, fd)) + goto error; /* allocate the mapping details for secondary processes*/ *uio_res = rte_zmalloc("UIO_RES", sizeof(**uio_res), 0); @@ -280,6 +382,16 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, goto error; } + if (pci_uio_dev_count == 0) { + rc = rte_mp_action_register(SEND_FD_MP_KEY, pci_uio_send_fd); + if (rc != 0 && rte_errno != ENOTSUP) { + PCI_LOG(ERR, "Failed to register multi-process callback: %d", + rte_errno); + goto error; + } + } + + pci_uio_dev_count++; strlcpy((*uio_res)->path, devname, sizeof((*uio_res)->path)); memcpy(&(*uio_res)->pci_addr, &dev->addr, sizeof((*uio_res)->pci_addr)); -- 2.46.2