From patchwork Fri Sep 6 00:40:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1981467 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X0HTl1v0Cz1yhD for ; Fri, 6 Sep 2024 10:41:14 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1smN24-0001vA-1O; Fri, 06 Sep 2024 00:41:00 +0000 Received: from mail-bn8nam12on2045.outbound.protection.outlook.com ([40.107.237.45] helo=NAM12-BN8-obe.outbound.protection.outlook.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1smN21-0001um-FY for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 00:40:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=UcN06mtwIf3Kv5LLMYC40UiFdnOVNTSMrdWmkPiiIQbyLRLh7bFzvWyybxH6rdWc6ZBDAA4NB8cl9fowkZH15WpRPsMVfiAn/CRfASIymdaf2bXS7sGCybI7FvWucPJaGVblrhXsx4F8T0C0G1RGGg9J9n+bgO0V+Ptao9zJruCaf+Tzwwv4A+8TKftXckzpO3PT07gCOshT1njE/pqGtbHLt73n1qeRfa3stcjSVjVYHg3KYkaxwuQwqP2KLXLdGjko7cQ+FHuFVP9Nl2P9blirZcYxVU9niLX7hAf+K+ClI6Wr7Fp/McelapgHp0Mv8L7aUMy3KwluFu9DuNuDQw== 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=23STIrtpTrBBp//iP2u04AaBgq1/lAD+tvhQ9GGrU1s=; b=HpA21db0mLVo3jWPR8DiPJT3z3al8Slpi2q4+hgZE+aD3RIHmmfYM657nyMAKwf1TnpB1AjZm2GglAb3FmOZId8H75OPKuzI9yzWQpuiu8A7qOKl9XydcQD+I+vqFJPzQqt3gwUFXSczxWO2jOANDqzitiQJSP95UIcUeUy2EZtYhUGpJLquzgf/pjx2nF0CE03LFVAIFAwCgG9oU8QqjRFZeUGl2o/d8TcI67hs7qDi45M0A9PDxgmdasnuHeW6kTRefobw6Hcnr1Coow1flt0Ia8lMTOX9Lhb6KsgqAvGJav99F25+7QsFxCIf+Ze58JP1EdT/SIqM+so8jV6Pbw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from PH0PR07CA0054.namprd07.prod.outlook.com (2603:10b6:510:e::29) by CH3PR12MB8481.namprd12.prod.outlook.com (2603:10b6:610:157::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27; Fri, 6 Sep 2024 00:40:52 +0000 Received: from SN1PEPF0002529D.namprd05.prod.outlook.com (2603:10b6:510:e:cafe::96) by PH0PR07CA0054.outlook.office365.com (2603:10b6:510:e::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.16 via Frontend Transport; Fri, 6 Sep 2024 00:40:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SN1PEPF0002529D.mail.protection.outlook.com (10.167.242.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 6 Sep 2024 00:40:50 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:44 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:44 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 5 Sep 2024 17:40:43 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v2 1/7] UBUNTU: SAUCE: dma-buf: Add dma_buf_try_get() Date: Fri, 6 Sep 2024 00:40:32 +0000 Message-ID: <20240906004038.800613-2-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906004038.800613-1-witu@nvidia.com> References: <20240906004038.800613-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002529D:EE_|CH3PR12MB8481:EE_ X-MS-Office365-Filtering-Correlation-Id: 674798a7-11b0-4fa0-abf7-08dcce0c8ed5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: fpzpc4eDSQxJCxB5IG3R1IrpL0ay+8NcL/jPPH499VNiKqMB3v513TxG+SjuOnC7auMiFgHlsIsKb5o5zCN//I71ys9iwMizQFlOOxGHERDxJEXpRXt0guK+gaL5LAlGjoWabI4pZiF+hHf4pgAUFVUnBcrDeqij9EDt74lfOGlv2R7R55ZnWkK/XqZfJLpC8Ci3MGPw6D2+R2/s5nIE6SDNRBhS9cNz2wMzp6brfh5NMUsT8V6WCoyvz2YBDKsOOQDMmCal/YwS76pNEXd9vvr8M0/WVvge7TkdOnRPSlOpFC36dM0kkC9SgXwkpsFZociGQ9eIXXZBfmeeGnSMY/QOjGBs+2+7OznWu5+G6SlEMSeqlXclyRO129Xr48hLwDqdTEAiaq+vQQzYn7TSDtP8sIoGCZD8QeO3Jj1RO8Lxz5BwGC3zT+Ba6avA/Bg8EFOpN36jFJ+KF4Sq9nbrntPctz7IgTt46mX/0LNLD9fq4Z7TbVjRWjny1FjyYDh5UTmrCmEDhLMskLvYFZShXK0+tOzrI5dR0fjfsF3zFyMi3MB70gS7F8IaEX/jP8BgkqE8hKVy6l0Uol/oFwugRf9UyzrPSQwWj+2wQPZ3pSyj6xR+a75+8R+0X2UgLbxn2brxqezeRcZP8T3BamK9/9DHUDtjaR5puba4nDLvVrjbHXtjAjyI0jjBTt+yCCUxhk4725wGfZFmtpfxS4SccjnoBIe44nxumUyj/Qiw1F/LIqyqq0TwrygYRO9yQ3fKO1/v9CBwzsEAjE2Esv6pW2cWq/jzXZAGl3s/PUyWbxzRWFXPhcjZ+WbWt3fcXU6YwA8zNJB3SyxNhE9GgJo9ubhB1/ZwIQUxxKj7iIAswwPJkDWILUcjDQoAv1rWNS/VpmxM/q2YyVr58uQMsrMgGrEEyflxLmzB60YK9hQKZw19kCg7arIGjt69D3c+cRZyMhKtrjJRsBQTP/NVOyVhhrb7tZgTwX8DmRZZSS+ZVDNgg7RIaT0Jx6bO1Bo6Hcn2iMD4axVF6VKAHFWpQLxg3YdJSLBmObAIFY+IGDQfLaJr5gwSvUBGvdxfHaqKaRLspt6tQIBGvh/9I5s1X69WdOEstqt77hCeFwlgD0/MgGeHPHFqU8HIvffuCB5qcv5O3HHyESlVJ9g2HJTuaHYwJttv83W2/mfP1k9l5gIlcUHwfZ5FnacYp9kIMWa4O1sl2Gapu5FkK971x4UcILeHrprOchh8R2pbb58Le3i9wKvpiklIHYGmRrwjb74gUiaglQ2WxaMWI7pWspmmaqbNds6YeQSoc/66MkY3ms7hwYYilbuEYbBuS5EbBjjOBJJBfrIAoPbcu/NxunJd++e63NjFhdD90nruCeuRLBFBSoh2Bra1eWwY5An0ZUbYJcvwdraPVRBuqHVx2e8GDMxlKbW06vv2m9erJWCRbEu00lhbyKHaJknpduosFpoQvkQu X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(36860700013)(1800799024)(82310400026)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 00:40:50.9658 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 674798a7-11b0-4fa0-abf7-08dcce0c8ed5 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002529D.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8481 Received-SPF: softfail client-ip=40.107.237.45; envelope-from=witu@nvidia.com; helo=NAM12-BN8-obe.outbound.protection.outlook.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, sergeygo@nvidia.com, jgg@nvidia.com, zwaksman@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jason Gunthorpe BugLink: https://bugs.launchpad.net/bugs/2077887 Used to increment the refcount of the dma buf's struct file, only if the refcount is not zero. Useful to allow the struct file's lifetime to control the lifetime of the dmabuf while still letting the driver to keep track of created dmabufs. Signed-off-by: Jason Gunthorpe Signed-off-by: William Tu --- include/linux/dma-buf.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index 3ad636a13b8e..68a4326833d6 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -609,6 +609,19 @@ int dma_buf_fd(struct dma_buf *dmabuf, int flags); struct dma_buf *dma_buf_get(int fd); void dma_buf_put(struct dma_buf *dmabuf); +/** + * dma_buf_try_get - try to get a reference on a dmabuf + * @dmabuf - the dmabuf to get + * + * Returns true if a reference was successfully obtained. The caller must + * interlock with the dmabuf's release function in some way, such as RCU, to + * ensure that this is not called on freed memory. + */ +static inline bool dma_buf_try_get(struct dma_buf *dmabuf) +{ + return get_file_rcu(dmabuf->file); +} + struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *, enum dma_data_direction); void dma_buf_unmap_attachment(struct dma_buf_attachment *, struct sg_table *, From patchwork Fri Sep 6 00:40:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1981469 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X0HTl1rpvz1yh1 for ; Fri, 6 Sep 2024 10:41:14 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1smN27-0001wr-Jz; Fri, 06 Sep 2024 00:41:03 +0000 Received: from mail-bn8nam11on2081.outbound.protection.outlook.com ([40.107.236.81] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1smN23-0001uv-7C for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 00:40:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pv0HEMlLHN6ACEazftkkThYvtZGd2U6UQHsLfsoAgfXf1Ans2wW/uyH9jvdlLGsseuUA6YjIMPRsyNmuTJTjvB4TfbBlYYZx6jRihF3q67rn8Hb3dr0QvYIC5sdELfpFlgSGlnyjnAByQsCV3r3Rz32w2UERro0HEWZwMPacEbXh61h1RTpmncjKD9tu6QGJvi05iF9jNX2jUKOFuaN2LV8GPUQ5QI/e1X4qdiCUwc3YgOHL9mLC09Ns9CdvODIimwrmOAg+i5rl9z8QaEMIYIuOKnkSm1ulR3wwahs7pb9BjUY4thIISVnq5zgzbN01trVt2Kzj8eKvBjkIX9bLLw== 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=/+7ietNGkQpJ/+qv+kMqUKaUn+JbRevpgh6l90Kz4AI=; b=aEu0EY/ONtlk0hw3f9zTRFP3NVP5b3kgI9ZcN0XfAX6HRkqUwOeP9QWFuK3slzqAOxszaDTx3Kfk4CyTTemwvwZpAJ669PR8Y9/DpLvgW6EYt4o7aVU3ZJQZE5vPZL49CHRuT/aEBZuHT8iM/I2fVvvM3s0UySt3l3L/r2T29lZxd1Q9RJ8hJ8CxzTMtsFGPTDfurUiOAsi3gNspv5oQezrSwzVMLMFy+k6drNPGBAf9DxEFzVgVn9PLRruBwpujQyUEVGeM7UQg7skWKcb2fw3CX/LVunXjTuJTfvykt4Xjh1XeUcpS7RGPNGVIJig8Z9brzEY6p4VV5BsAntbuCA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from PH7P222CA0014.NAMP222.PROD.OUTLOOK.COM (2603:10b6:510:33a::16) by DS7PR12MB6008.namprd12.prod.outlook.com (2603:10b6:8:7f::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.28; Fri, 6 Sep 2024 00:40:54 +0000 Received: from SN1PEPF0002529F.namprd05.prod.outlook.com (2603:10b6:510:33a:cafe::e6) by PH7P222CA0014.outlook.office365.com (2603:10b6:510:33a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.27 via Frontend Transport; Fri, 6 Sep 2024 00:40:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SN1PEPF0002529F.mail.protection.outlook.com (10.167.242.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 6 Sep 2024 00:40:53 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:45 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:45 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 5 Sep 2024 17:40:44 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v2 2/7] UBUNTU: SAUCE: vfio: Add vfio_device_get() Date: Fri, 6 Sep 2024 00:40:33 +0000 Message-ID: <20240906004038.800613-3-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906004038.800613-1-witu@nvidia.com> References: <20240906004038.800613-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002529F:EE_|DS7PR12MB6008:EE_ X-MS-Office365-Filtering-Correlation-Id: 2eac0fa9-95bb-4724-de41-08dcce0c9084 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|36860700013|376014; X-Microsoft-Antispam-Message-Info: XzEbI9r/vudvaLbBtTZv1O5D1dHPnMwIziwJ+C+Wa2fMwnnOVXhBC6UYZohB20nYZcIzVL6u7rforRd7O9QvIKrOY4Y1kxIhL+1yopg0B5qV5HN3oawh6QyOUbpJc/nvWwBrX/iHBIKgahVVvZd8+bBCTJnc2V4s70TDrZujqZzl5AMaI6/FWVjwfH980yrrWZTNOx9A8OVOfx4FXbA/5U98YArVmnOPGPna5algbKKoUdB8O4niqOmFk53Y9Mwn+0Y5ZwHB5zS+4XVokukG4TLGocTn7cWLKx98mS5eavyNqLf7JhCcy0E1weOR9BwVYcEgSsky3sBmYx879v8Fd25phE5Gp0HuOXWUyrTS40yloVWhqQM8NNJl5YJHgt+eqmfv6Ymq+8D/CKg3pZxbNw4fKt7mt7P5vZIIizyWApiqS6pz7OD4UhqvSj/3qLyQ9JH8gkUz6s9TcRhS24hjGHx+1UnI5AYqeq2+XwUjIOR0NYPJc1a6afee0BTsHi/nGNW8zBJp+brn5RxtN6LCJAW3CQx0IjDv86Zv1zSfObevi+x7EGEbiQ0D39sG99V+aeaz9TMLBD0Ra0nl0QMQAsw4adir5/v3baQquyr/taQRre/vDc4yHuspHIkFjIT/NpNtnyrmFO7uD2IOlTJb9CuMDH9GKVGrzjjG7RrvsNNr+NNjYetmP1ade3kshbXmSnl6WKu3ihCDpBYqFvKnv4AyoEmxywuWN3eeNfU88HA/b09U0UeR/HIupXYioDYB57Z90KljKeVpXRHCp8wm1Mea1F49FxLc/ZpB3Z4cOYw+Nmdwr/Eg8zXX7KRX/6Y5Tj3xczmoty1ODGzL0xYZy8Bio1Y3ImNFeea4egHzPf64XhrT/r8TP4OgH0T2froIAlvD/2abXLc1pJIehq1tvbg5BsuzLXXrxfKqnqeZWGP5Z4M5X6fHXhuRLQrzetK6rTJHSM8G3nByLWPYvVX8v7h69wBAagTudMbd+XDFEMgjlnZgM/W3bbfc46DYwsePKnSyfInQIWkyvAEdNnZydVlX2zR3+LGrve+gslhb7G10yjaXWL5Jilr+DWSPpX2L1UjQCcdYifu1DMXxcgmeSgGzeRCpn/TNwGu/MCe4ZngvO+dyMxFT+bNREvcWU2h+KbI5uH4bcKbZfmh32BB9euMNl6lDLyr7h2hAiiMLswZ+wHy35KEHkJpqA4yP87FGtJ0PNza/X9LBZJ2zqGhMaA7COEhnUmL65IsU4d8V6zebvTzGfkKkGXKTpVCAGjMDbDYgSPZKCgv5dKkyau4JBaLd6ydnIPaR1cHoKeNYnURYAPCV9G9q44SCJLa+sPgd3hxcy2SQqgo5wWmcoufNNKShdYeDKrE7YjIK25vUWO4BBwYjYPOR8CpY24S97h/w7+8qetbohHLDb6WFoFsxRVqbDAXBJPRslk4cBfkhyBnVB6rIi1UBmJJWEDvTjKoZ X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 00:40:53.7917 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2eac0fa9-95bb-4724-de41-08dcce0c9084 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002529F.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6008 Received-SPF: softfail client-ip=40.107.236.81; envelope-from=witu@nvidia.com; helo=NAM11-BN8-obe.outbound.protection.outlook.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, sergeygo@nvidia.com, jgg@nvidia.com, zwaksman@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jason Gunthorpe BugLink: https://bugs.launchpad.net/bugs/2077887 To increment a reference the caller already holds. Export vfio_device_put() to pair with it. Signed-off-by: Jason Gunthorpe Signed-off-by: William Tu --- include/linux/vfio.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/vfio.h b/include/linux/vfio.h index b7275ed44e4c..071cea3871c9 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -82,6 +82,11 @@ void vfio_unregister_group_dev(struct vfio_device *device); extern struct vfio_device *vfio_device_get_from_dev(struct device *dev); extern void vfio_device_put(struct vfio_device *device); +static inline void vfio_device_get(struct vfio_device *device) +{ + refcount_inc(&device->refcount); +} + int vfio_assign_device_set(struct vfio_device *device, void *set_id); /* events for the backend driver notify callback */ From patchwork Fri Sep 6 00:40:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1981470 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X0HTl1znpz1ynb for ; Fri, 6 Sep 2024 10:41:15 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1smN29-0001yI-TL; Fri, 06 Sep 2024 00:41:05 +0000 Received: from mail-bn8nam11on2052.outbound.protection.outlook.com ([40.107.236.52] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1smN28-0001xZ-UN for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 00:41:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WyqcmYxm4GMh1WztfMgMPqcwhLImUjpdOusFpJXjHQavDWdm/rouVFM6jM8kzmLIzE2LK6KkhzowGb6N5HjjbpnF8I271bfzl0Hrg+lrwUMwkcrYKPMEOr/Cy/FzjNY47QVvBLFQWnu3VnQDHyMPcnOnICGL7Wcp8L2lhJNolf9k/WJwyAQJ33nLf/Mih/k+H+dcBatwRAjzo2uFo9FgMRx5eS5RkxOHKfvFKttMlW4ysfBkKQXTZe6PpiUrc5jK9DlcQG2gzPmLLuCHLgLUyWf6xPSDxFdFWYjJMt2A+7i3XRSVIJbvjgupmTkQHEt1SarPQIjVTWDHi8E6N5L2+g== 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=m2G/P99pVQik1wlMWEET+/Mjy1re1kCvd/vvnwJglj8=; b=Y0zeXqigKzizvmZh56wBaIYPwNlRuimfioXmll5bhF/cbI046olwDTs6LQ+4RfrACBQvyW9bBQSKxYG0yGJrG/KiNW7bxnuPft7mUkNi6gVnyanpUNPcaD1kfdeY2EXqovj4omJ7xKj5vWNCl6boGtPkR27W2a+Ty1NhaUzwcn2rPyLFew4gVY6T7tbpd8kK5bfQzIS4a0O2fQSEob1QhFoLV3MDJK6IhalBG1GfHdbzQ/pvL8QzH9rtM790THjJob3nJvErGbRQQis4/IukafnBZ+Q8xxM7wrXFRwnTIclGJmG3u6TYIre+bTZoe1K8B+8r1n+E4ea0s5hO1w+sbw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from CH2PR18CA0019.namprd18.prod.outlook.com (2603:10b6:610:4f::29) by PH7PR12MB6718.namprd12.prod.outlook.com (2603:10b6:510:1b1::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.25; Fri, 6 Sep 2024 00:40:58 +0000 Received: from DS3PEPF000099E1.namprd04.prod.outlook.com (2603:10b6:610:4f:cafe::29) by CH2PR18CA0019.outlook.office365.com (2603:10b6:610:4f::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.16 via Frontend Transport; Fri, 6 Sep 2024 00:40:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by DS3PEPF000099E1.mail.protection.outlook.com (10.167.17.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 6 Sep 2024 00:40:57 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:46 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:46 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 5 Sep 2024 17:40:45 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v2 3/7] UBUNTU: SAUCE: vfio_pci: Do not open code pci_try_reset_function() Date: Fri, 6 Sep 2024 00:40:34 +0000 Message-ID: <20240906004038.800613-4-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906004038.800613-1-witu@nvidia.com> References: <20240906004038.800613-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099E1:EE_|PH7PR12MB6718:EE_ X-MS-Office365-Filtering-Correlation-Id: 7aecd1b5-42d3-4b1f-4edf-08dcce0c927a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: +oIXmJ+jwMophFvTL88XYPmDvgt3TWF70ckYP3LPpvYgGi4NlQ6qzqYxcK4k18dicZ6UFq1oQIP6RINbXcG6V5jxhxy0WeQdKk/InfUd/8ZVm6mYGikLTE9rSRx/TPgy5N42Tc533wSFfCtKEPFviugSyojuMkhkF8XS2vj4emK8Zb7BHoA++1FURbgPyUzvDPGvM3onlzqGnwfYQVDtvJS4CLTEL37N+diJohtN462g46TCGCgS/stO5w5uI8BN8JZB5GTIvs/dmaQMrGXq8F7g3CTtRyytlyiBHXzOSK5BEW2sVHkuySYFiZpF3Vy0nicsHQDk5TpIP4VlihwYsQazvXn9V5GYGy/YLh8YAxXfZZ7vUJrHv5NfPmRM5KKtTHDXCEw8VC7Xu+h7BzoVs5dFhSy97j9oDxn00I7Rux+SzcjdUmikSCO7rh521OgAhKg7cChk0N2+dZ0dgafIE24mw2JpuXITis+sNlHuCNpWdmAZObA2mxOVH01k80psHCwPOoW5j5Q93BKmA/HRNWXJA35B8LYWRwAIy8EANj90+wGNh+6eIRk0SF5QsSsD78gZLleY4PwA0WpPh2LByKYqeWoAysPVEUQY+c6Jsa8CzlNZWw9zwplK/ZiY5l3RveKi3sF2ZEJYhzrjRi29hXkOLYK2RUCJNnHzS9gcASKyBgtlYaeL0k9XtF1vgsxIP+NP+EPAF/CevTvqklspZf07ADnruTHnL4g/NLw41Yq8mplWOT0moQJYU+4ADc/RL84+a5SFSzde5kY6DEow/+H9K4bzHtMlhB9d0A+5nbyFfgY24f09tZbPeCtbAoPny/tY1fGR6TG0HLdwkCnpoDmjPEJmQH94bsHxR4BhIMlKQZWaHuX9HtLt0GANeAxRqkKHflzAzA5HJICJLoc73LV3q4yxLwT4BoD055FLFYgpaiTctDxzhy/FypdFtR2Lyn2NxP31cXrf4/VOJ1ksO33y8f6mRmyec6xA+ZBZNPpmzAIYrQ2tDsyJq/OFiq8AYtXPNvxVwfWaKv0jnbu1VPlYw3wJ3gHDpjCHsASSTrCM0wor+jdw+kCggGXmGr5ddUkio6x/aTmiL1JEO0V8geZY/r1Yvw8zILc4cPX64dj8M2if+nLYeeFqjMhVv5Qvlwh5Qd0oCe8HKOk7mlPvafgN3tbuWUkOrI4pdy1QwNe+BfAjuycAtDOBXhvOqEQlg2X++CwUisrIl4nvM9hsWA4lR8Sks0crPb3C08aXZZrbuC0BKZFBEWOQu/qA3BCGaN3Ac8lADlMDO25RKWDGLjvvxuY62ZojWo2F8cIM0/I25vWoyRRZRAfh8mGsb7SsoOjcsJytZEfA7pt+1CxZvetLLsy4R/K+AgS1gHyKEwS8m2pbVufN4DaaH5gForIbtHzI/hzAXJm0AUcpUd5Xc50OB5AsYcPgzd8utBIdkGWLVuzOH7J7DfnMDqI/tmp3 X-Forefront-Antispam-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230040)(36860700013)(376014)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 00:40:57.0623 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7aecd1b5-42d3-4b1f-4edf-08dcce0c927a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099E1.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6718 Received-SPF: softfail client-ip=40.107.236.52; envelope-from=witu@nvidia.com; helo=NAM11-BN8-obe.outbound.protection.outlook.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, sergeygo@nvidia.com, jgg@nvidia.com, zwaksman@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jason Gunthorpe BugLink: https://bugs.launchpad.net/bugs/2077887 FLR triggered by an emulated config space write should not behave differently from a FLR triggered by VFIO_DEVICE_RESET, currently the config space path misses the power management. Consolidate all the call sites to invoke a single function. Signed-off-by: Jason Gunthorpe Signed-off-by: William Tu --- drivers/vfio/pci/vfio_pci_config.c | 14 +++------- drivers/vfio/pci/vfio_pci_core.c | 41 +++++++++++++----------------- drivers/vfio/pci/vfio_pci_priv.h | 7 +++++ 3 files changed, 28 insertions(+), 34 deletions(-) create mode 100644 drivers/vfio/pci/vfio_pci_priv.h diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c index 6e58b4bf7a60..78c626b8907d 100644 --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -857,11 +857,8 @@ static int vfio_exp_config_write(struct vfio_pci_core_device *vdev, int pos, pos - offset + PCI_EXP_DEVCAP, &cap); - if (!ret && (cap & PCI_EXP_DEVCAP_FLR)) { - vfio_pci_zap_and_down_write_memory_lock(vdev); - pci_try_reset_function(vdev->pdev); - up_write(&vdev->memory_lock); - } + if (!ret && (cap & PCI_EXP_DEVCAP_FLR)) + vfio_pci_try_reset_function(vdev); } /* @@ -939,11 +936,8 @@ static int vfio_af_config_write(struct vfio_pci_core_device *vdev, int pos, pos - offset + PCI_AF_CAP, &cap); - if (!ret && (cap & PCI_AF_CAP_FLR) && (cap & PCI_AF_CAP_TP)) { - vfio_pci_zap_and_down_write_memory_lock(vdev); - pci_try_reset_function(vdev->pdev); - up_write(&vdev->memory_lock); - } + if (!ret && (cap & PCI_AF_CAP_FLR) && (cap & PCI_AF_CAP_TP)) + vfio_pci_try_reset_function(vdev); } return count; diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 4f1aceadd4fb..5904801f6f77 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -29,6 +29,8 @@ #include +#include "vfio_pci_priv.h" + #define DRIVER_AUTHOR "Alex Williamson " #define DRIVER_DESC "core driver for VFIO based PCI devices" @@ -648,6 +650,20 @@ int vfio_pci_register_dev_region(struct vfio_pci_core_device *vdev, } EXPORT_SYMBOL_GPL(vfio_pci_register_dev_region); +int vfio_pci_try_reset_function(struct vfio_pci_core_device *vdev) +{ + int ret; + + if (!vdev->reset_works) + return -EINVAL; + + vfio_pci_zap_and_down_write_memory_lock(vdev); + ret = pci_try_reset_function(vdev->pdev); + up_write(&vdev->memory_lock); + + return ret; +} + long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, unsigned long arg) { @@ -929,30 +945,7 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, return ret; } else if (cmd == VFIO_DEVICE_RESET) { - int ret; - - if (!vdev->reset_works) - return -EINVAL; - - vfio_pci_zap_and_down_write_memory_lock(vdev); - - /* - * This function can be invoked while the power state is non-D0. - * If pci_try_reset_function() has been called while the power - * state is non-D0, then pci_try_reset_function() will - * internally set the power state to D0 without vfio driver - * involvement. For the devices which have NoSoftRst-, the - * reset function can cause the PCI config space reset without - * restoring the original state (saved locally in - * 'vdev->pm_save'). - */ - vfio_pci_set_power_state(vdev, PCI_D0); - - ret = pci_try_reset_function(vdev->pdev); - up_write(&vdev->memory_lock); - - return ret; - + return vfio_pci_try_reset_function(vdev); } else if (cmd == VFIO_DEVICE_GET_PCI_HOT_RESET_INFO) { struct vfio_pci_hot_reset_info hdr; struct vfio_pci_fill_info fill = { 0 }; diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_priv.h new file mode 100644 index 000000000000..4971cd95b431 --- /dev/null +++ b/drivers/vfio/pci/vfio_pci_priv.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef VFIO_PCI_PRIV_H +#define VFIO_PCI_PRIV_H + +int vfio_pci_try_reset_function(struct vfio_pci_core_device *vdev); + +#endif From patchwork Fri Sep 6 00:40:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1981474 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X0HTr36Snz1yhD for ; Fri, 6 Sep 2024 10:41:20 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1smN2G-00029c-Ua; Fri, 06 Sep 2024 00:41:12 +0000 Received: from mail-mw2nam12on2058.outbound.protection.outlook.com ([40.107.244.58] helo=NAM12-MW2-obe.outbound.protection.outlook.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1smN2D-00020b-FV for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 00:41:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=P2IMQ9RWz47OT8G3TXR0Af9VX8GLP4XQFS7Wacf8H0mVH69xd5nX3hXD7Q1byIS9uLLhnbCAFt9UEK0Upz5PNzaN8gzDSxDtrp7ERas6uhrLLDczgOz2kRQnJkUVhXwistOZOh5WHpnZh9vWulsj05UcbKpqRjXym91XAgVaFhSWrbnfc0p4voQK52HkSI+WkOxqNNn0LVyjlByrRGBkPmDHeufJfnS/+lsfxpsfpCulXdmygJSAxhPkXDcM74Izicpo1ek07yI7+u9PuEd7G9rYt0TI5tAoZwmoOAVArA9l/Z7bNwAYYpzPyqPkaaNj6ILsGF1MLg9c8xuMpDiXPg== 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=NoYgM0bkVB64jg42EjsI/niPdqJcJ7nUL8ZR2McuW1M=; b=b504MSz4lCIT+Vn85JQx3+c5YFBIgQj78uWFXJ952ZKEcBdrJSvHLFAxCvAXTpJABLXMouS7Uq9I/FLQtxKsACFaBw1/CelEOuF0t3YAU6t1USpO0iuwkEj+sbnLUhdIji4a6pxIYtc/ApIOerkvjdilVZ0ZN4eBnKwM5xlq1/NcphGkUmj6iGR0ZWP3C6HRJqlj9EPsQmtoSxVJnNkYXgAIMK8LYcXQnDRAUQEvKtnQSnmUDZWRPtdLWmiH1vOse7CcIfngKU8zkb8Gd3VFMNY5o1YS8/OfO+RVdUJRA/Rg7hMNMvFs7I5ZrO5FsGfdlbS24sh9Fy1NSUU8nP4MxQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from PH7P222CA0004.NAMP222.PROD.OUTLOOK.COM (2603:10b6:510:33a::15) by LV2PR12MB5775.namprd12.prod.outlook.com (2603:10b6:408:179::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.24; Fri, 6 Sep 2024 00:40:58 +0000 Received: from SN1PEPF0002529F.namprd05.prod.outlook.com (2603:10b6:510:33a:cafe::6) by PH7P222CA0004.outlook.office365.com (2603:10b6:510:33a::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.14 via Frontend Transport; Fri, 6 Sep 2024 00:40:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SN1PEPF0002529F.mail.protection.outlook.com (10.167.242.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 6 Sep 2024 00:40:58 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:47 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:46 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 5 Sep 2024 17:40:46 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v2 4/7] UBUNTU: SAUCE: vfio/pci: Allow MMIO regions to be exported through dma-buf Date: Fri, 6 Sep 2024 00:40:35 +0000 Message-ID: <20240906004038.800613-5-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906004038.800613-1-witu@nvidia.com> References: <20240906004038.800613-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002529F:EE_|LV2PR12MB5775:EE_ X-MS-Office365-Filtering-Correlation-Id: cfe25a20-e6d5-44fd-712e-08dcce0c9320 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|36860700013|376014; X-Microsoft-Antispam-Message-Info: Pv7vNKLnTh4icw+3pdxuHRyHMtjPvSIM8j9ABP8/1MJEnxty25cY/HB3LiL3Z9E7hJKXyal/xfrdzXu6OuQjLjWR2UssOzJHtIB8Ci8/8PatyetB7amvPTNmjOYyG1mGJlxzDIO8btsmCwNPE6H3XSOen52cWd14T+URbqaMTzGPwIKWsXUW2k4L0l2VBEvNarmRE41RUJduNAbi2qU4unkKRXvv+Kn0aJJpolGLG3e4zizfiVq6yY/M++rfwUYbOOYjN8yNIk+DooURTVxVvWphA1hfa80aG0lzrhG+aJOB0QHgOiuPnkB7R1eKDkXKhexuEkGUFN4Q/5kN5Sf8vuJS6a9uPiaTPslDmTyiT2ufrSXpAnNUBeS1OeOMfYfBMn+xMiaXhpT4Yexjt09CCmsHuuyKLmhb9hGsGxCDuXnuE7giDHwLZ57zP4xBEhMGF63knOBqQw51MFIl5z5I/vEqBRbZTOA6u2AdF5soO7YI07VrDfXM7hvT2w4OTJ9OuJuraW/xihnVflnwUzVuJPp/2sOAIwMeAl4xmx+VzEkW/CprrTRrr2Zfw6igOxNwYwUgoVgxt7MOQNxjBQ5Ffq2qeTfjhbKaSxXvD5xPmeKfV0sM5rfrWImyWjr5xSZLpd9L4Z6+sxdr+Zl68w9PBXV2cBS5PHOfecqKHuw1dNRqNjlTe+QZBIk2csyA10ggs/P4AgM0mAebcDxCtp0Ds39394xS+B0FTXcGUwHKzW2M72f59vEOP8st9UCg5rteL1gmTZLR/ZZpBgKxzCSkiZTn6jzHvPYa5i9q6t+uh4sPlnyZdW4VgVScuBtESvFH2PcpZADj7hU2TFDvTx0SEZ9QZi2jDWe1gPygf5dJnEaWJJzOya6K2JYK0MaFO3Nut4uPq2WbfwDUk+A+1QLOACZKEJE3hDicv6e5KV+fTT5xDfOpoycU4joMh2CmPp4RwM4hSDiAraw6FfBX8WRQqTtCevluCfC7n05m2tKUtzmEooO5DwGNWr76vxIAsIKQ399+zLYXnb1xwZgInDXk1oUBzTRFrLAhuO1b8D3Mjnv5/3t54U54/OJtEDw6BpPsPKO0+GGzWIpYNPV8uyBozvF/TjH5TUPlfbRQUEA/7+UjKnUWezk2TnzSETw799QsgRCj8KhUoKrqzV0+s+eZ9ikpfwpr8XWjeO4dVrcdena/0HtmJVtln9mz1zIiw8idv2bXeaN4Ib9p7KNjA16dfofX4bdVxKq8JszVC+6SX4btGziEEqwfemTjgtJ3YCLL0prlImqLuFWL6LWAowVXDqWpDSLAO4Tqw5tr7TMYcihEKHFyKMEjPzrXR65vb0FRXsu6A7FUid+1CgUCLpIThkEhNoAqwajyvlzW0d0ODiW4Ljanopff5aNQHMVfFi95iM3tJwPFfHqgPiyyxL3tOcVlr1zlDxd7E67r407JmIjg2EQQfUXN4ELJ9BOgfGin X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 00:40:58.1667 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cfe25a20-e6d5-44fd-712e-08dcce0c9320 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002529F.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV2PR12MB5775 Received-SPF: softfail client-ip=40.107.244.58; envelope-from=witu@nvidia.com; helo=NAM12-MW2-obe.outbound.protection.outlook.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, sergeygo@nvidia.com, jgg@nvidia.com, zwaksman@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jason Gunthorpe BugLink: https://bugs.launchpad.net/bugs/2077887 dma-buf has become a way to safely acquire a handle to non-struct page memory that can still have lifetime controlled by the exporter. Notably RDMA can now import dma-buf FDs and build them into MRs which allows for PCI P2P operations. Extend this to allow vfio-pci to export MMIO memory from PCI device BARs. The patch design loosely follows the pattern in commit db1a8dd916aa ("habanalabs: add support for dma-buf exporter") except this does not support pinning. Instead, this implements what, in the past, we've called a revocable attachment using move. In normal situations the attachment is pinned, as a BAR does not change physical address. However when the VFIO device is closed, or a PCI reset is issued, access to the MMIO memory is revoked. Revoked means that move occurs, but an attempt to immediately re-map the memory will fail. In the reset case a future move will be triggered when MMIO access returns. As both close and reset are under userspace control it is expected that userspace will suspend use of the dma-buf before doing these operations, the revoke is purely for kernel self-defense against a hostile userspace. Signed-off-by: Jason Gunthorpe Signed-off-by: William Tu --- drivers/vfio/pci/Makefile | 3 +- drivers/vfio/pci/dma_buf.c | 269 +++++++++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_config.c | 10 +- drivers/vfio/pci/vfio_pci_core.c | 17 +- drivers/vfio/pci/vfio_pci_priv.h | 23 +++ include/linux/vfio_pci_core.h | 1 + include/uapi/linux/vfio.h | 18 ++ 7 files changed, 336 insertions(+), 5 deletions(-) create mode 100644 drivers/vfio/pci/dma_buf.c diff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile index 74ee55f9c261..3ac2ed7d7a0a 100644 --- a/drivers/vfio/pci/Makefile +++ b/drivers/vfio/pci/Makefile @@ -1,7 +1,8 @@ # SPDX-License-Identifier: GPL-2.0-only vfio-pci-core-y := vfio_pci_core.o vfio_pci_intrs.o vfio_pci_rdwr.o vfio_pci_config.o -vfio-pci-core-$(CONFIG_VFIO_PCI_ZDEV_KVM) += vfio_pci_zdev.o +vfio-pci-core-$(CONFIG_S390) += vfio_pci_zdev.o +vfio-pci-core-$(CONFIG_DMA_SHARED_BUFFER) += dma_buf.o obj-$(CONFIG_VFIO_PCI_CORE) += vfio-pci-core.o vfio-pci-y := vfio_pci.o diff --git a/drivers/vfio/pci/dma_buf.c b/drivers/vfio/pci/dma_buf.c new file mode 100644 index 000000000000..11396aeabff4 --- /dev/null +++ b/drivers/vfio/pci/dma_buf.c @@ -0,0 +1,269 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. + */ +#include +#include +#include + +#include "vfio_pci_priv.h" + +MODULE_IMPORT_NS(DMA_BUF); + +struct vfio_pci_dma_buf { + struct dma_buf *dmabuf; + struct vfio_pci_core_device *vdev; + struct list_head dmabufs_elm; + unsigned int index; + unsigned int orig_nents; + size_t offset; + bool revoked; +}; + +static int vfio_pci_dma_buf_attach(struct dma_buf *dmabuf, + struct dma_buf_attachment *attachment) +{ + struct vfio_pci_dma_buf *priv = dmabuf->priv; + int rc; + + rc = pci_p2pdma_distance_many(priv->vdev->pdev, &attachment->dev, 1, + true); + if (rc < 0) + attachment->peer2peer = false; + return 0; +} + +static void vfio_pci_dma_buf_unpin(struct dma_buf_attachment *attachment) +{ +} + +static int vfio_pci_dma_buf_pin(struct dma_buf_attachment *attachment) +{ + /* + * Uses the dynamic interface but must always allow for + * dma_buf_move_notify() to do revoke + */ + return -EINVAL; +} + +static struct sg_table * +vfio_pci_dma_buf_map(struct dma_buf_attachment *attachment, + enum dma_data_direction dir) +{ + size_t sgl_size = dma_get_max_seg_size(attachment->dev); + struct vfio_pci_dma_buf *priv = attachment->dmabuf->priv; + struct scatterlist *sgl; + struct sg_table *sgt; + dma_addr_t dma_addr; + unsigned int nents; + size_t offset; + int ret; + + dma_resv_assert_held(priv->dmabuf->resv); + + if (!attachment->peer2peer) + return ERR_PTR(-EPERM); + + if (priv->revoked) + return ERR_PTR(-ENODEV); + + sgt = kzalloc(sizeof(*sgt), GFP_KERNEL); + if (!sgt) + return ERR_PTR(-ENOMEM); + + nents = DIV_ROUND_UP(priv->dmabuf->size, sgl_size); + ret = sg_alloc_table(sgt, nents, GFP_KERNEL); + if (ret) + goto err_kfree_sgt; + + /* + * Since the memory being mapped is a device memory it could never be in + * CPU caches. + */ + dma_addr = dma_map_resource( + attachment->dev, + pci_resource_start(priv->vdev->pdev, priv->index) + + priv->offset, + priv->dmabuf->size, dir, DMA_ATTR_SKIP_CPU_SYNC); + ret = dma_mapping_error(attachment->dev, dma_addr); + if (ret) + goto err_free_sgt; + + /* + * Break the BAR's physical range up into max sized SGL's according to + * the device's requirement. + */ + sgl = sgt->sgl; + for (offset = 0; offset != priv->dmabuf->size;) { + size_t chunk_size = min(priv->dmabuf->size - offset, sgl_size); + + sg_set_page(sgl, NULL, chunk_size, 0); + sg_dma_address(sgl) = dma_addr + offset; + sg_dma_len(sgl) = chunk_size; + sgl = sg_next(sgl); + offset += chunk_size; + } + + /* + * Because we are not going to include a CPU list we want to have some + * chance that other users will detect this by setting the orig_nents to + * 0 and using only nents (length of DMA list) when going over the sgl + */ + priv->orig_nents = sgt->orig_nents; + sgt->orig_nents = 0; + return sgt; + +err_free_sgt: + sg_free_table(sgt); +err_kfree_sgt: + kfree(sgt); + return ERR_PTR(ret); +} + +static void vfio_pci_dma_buf_unmap(struct dma_buf_attachment *attachment, + struct sg_table *sgt, + enum dma_data_direction dir) +{ + struct vfio_pci_dma_buf *priv = attachment->dmabuf->priv; + + sgt->orig_nents = priv->orig_nents; + dma_unmap_resource(attachment->dev, sg_dma_address(sgt->sgl), + priv->dmabuf->size, dir, DMA_ATTR_SKIP_CPU_SYNC); + sg_free_table(sgt); + kfree(sgt); +} + +static void vfio_pci_dma_buf_release(struct dma_buf *dmabuf) +{ + struct vfio_pci_dma_buf *priv = dmabuf->priv; + + /* + * Either this or vfio_pci_dma_buf_cleanup() will remove from the list. + * The refcount prevents both. + */ + if (priv->vdev) { + down_write(&priv->vdev->memory_lock); + list_del_init(&priv->dmabufs_elm); + up_write(&priv->vdev->memory_lock); + vfio_device_put(&priv->vdev->vdev); + } + kfree(priv); +} + +static const struct dma_buf_ops vfio_pci_dmabuf_ops = { + .attach = vfio_pci_dma_buf_attach, + .map_dma_buf = vfio_pci_dma_buf_map, + .pin = vfio_pci_dma_buf_pin, + .unpin = vfio_pci_dma_buf_unpin, + .release = vfio_pci_dma_buf_release, + .unmap_dma_buf = vfio_pci_dma_buf_unmap, +}; + +int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags, + struct vfio_device_feature_dma_buf __user *arg, + size_t argsz) +{ + struct vfio_device_feature_dma_buf get_dma_buf; + DEFINE_DMA_BUF_EXPORT_INFO(exp_info); + struct vfio_pci_dma_buf *priv; + int ret; + + ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_GET, + sizeof(get_dma_buf)); + if (ret != 1) + return ret; + + if (copy_from_user(&get_dma_buf, arg, sizeof(get_dma_buf))) + return -EFAULT; + + /* For PCI the region_index is the BAR number like everything else */ + if (get_dma_buf.region_index >= VFIO_PCI_ROM_REGION_INDEX) + return -EINVAL; + + exp_info.ops = &vfio_pci_dmabuf_ops; + exp_info.size = pci_resource_len(vdev->pdev, get_dma_buf.region_index); + if (!exp_info.size) + return -EINVAL; + if (get_dma_buf.offset || get_dma_buf.length) { + if (get_dma_buf.length > exp_info.size || + get_dma_buf.offset >= exp_info.size || + get_dma_buf.length > exp_info.size - get_dma_buf.offset || + get_dma_buf.offset % PAGE_SIZE || + get_dma_buf.length % PAGE_SIZE) + return -EINVAL; + exp_info.size = get_dma_buf.length; + } + exp_info.flags = get_dma_buf.open_flags; + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + INIT_LIST_HEAD(&priv->dmabufs_elm); + priv->offset = get_dma_buf.offset; + priv->index = get_dma_buf.region_index; + + exp_info.priv = priv; + priv->dmabuf = dma_buf_export(&exp_info); + if (IS_ERR(priv->dmabuf)) { + ret = PTR_ERR(priv->dmabuf); + kfree(priv); + return ret; + } + + /* dma_buf_put() now frees priv */ + + down_write(&vdev->memory_lock); + dma_resv_lock(priv->dmabuf->resv, NULL); + priv->revoked = !__vfio_pci_memory_enabled(vdev); + priv->vdev = vdev; + vfio_device_get(&vdev->vdev); + list_add_tail(&priv->dmabufs_elm, &vdev->dmabufs); + dma_resv_unlock(priv->dmabuf->resv); + up_write(&vdev->memory_lock); + + /* + * dma_buf_fd() consumes the reference, when the file closes the dmabuf + * will be released. + */ + return dma_buf_fd(priv->dmabuf, get_dma_buf.open_flags); +} + +void vfio_pci_dma_buf_move(struct vfio_pci_core_device *vdev, bool revoked) +{ + struct vfio_pci_dma_buf *priv; + struct vfio_pci_dma_buf *tmp; + + lockdep_assert_held_write(&vdev->memory_lock); + + list_for_each_entry_safe(priv, tmp, &vdev->dmabufs, dmabufs_elm) { + if (!dma_buf_try_get(priv->dmabuf)) + continue; + if (priv->revoked != revoked) { + dma_resv_lock(priv->dmabuf->resv, NULL); + priv->revoked = revoked; + dma_buf_move_notify(priv->dmabuf); + dma_resv_unlock(priv->dmabuf->resv); + } + dma_buf_put(priv->dmabuf); + } +} + +void vfio_pci_dma_buf_cleanup(struct vfio_pci_core_device *vdev) +{ + struct vfio_pci_dma_buf *priv; + struct vfio_pci_dma_buf *tmp; + + down_write(&vdev->memory_lock); + list_for_each_entry_safe(priv, tmp, &vdev->dmabufs, dmabufs_elm) { + if (!dma_buf_try_get(priv->dmabuf)) + continue; + dma_resv_lock(priv->dmabuf->resv, NULL); + list_del_init(&priv->dmabufs_elm); + priv->vdev = NULL; + priv->revoked = true; + dma_buf_move_notify(priv->dmabuf); + dma_resv_unlock(priv->dmabuf->resv); + vfio_device_put(&vdev->vdev); + dma_buf_put(priv->dmabuf); + } + up_write(&vdev->memory_lock); +} diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c index 78c626b8907d..f14a8b81fe35 100644 --- a/drivers/vfio/pci/vfio_pci_config.c +++ b/drivers/vfio/pci/vfio_pci_config.c @@ -28,6 +28,8 @@ #include +#include "vfio_pci_priv.h" + /* Fake capability ID for standard config space */ #define PCI_CAP_ID_BASIC 0 @@ -581,10 +583,12 @@ static int vfio_basic_config_write(struct vfio_pci_core_device *vdev, int pos, virt_mem = !!(le16_to_cpu(*virt_cmd) & PCI_COMMAND_MEMORY); new_mem = !!(new_cmd & PCI_COMMAND_MEMORY); - if (!new_mem) + if (!new_mem) { vfio_pci_zap_and_down_write_memory_lock(vdev); - else + vfio_pci_dma_buf_move(vdev, true); + } else { down_write(&vdev->memory_lock); + } /* * If the user is writing mem/io enable (new_mem/io) and we @@ -619,6 +623,8 @@ static int vfio_basic_config_write(struct vfio_pci_core_device *vdev, int pos, *virt_cmd &= cpu_to_le16(~mask); *virt_cmd |= cpu_to_le16(new_cmd & mask); + if (__vfio_pci_memory_enabled(vdev)) + vfio_pci_dma_buf_move(vdev, false); up_write(&vdev->memory_lock); } diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 5904801f6f77..4017512f6736 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -465,6 +465,8 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev) vfio_spapr_pci_eeh_release(vdev->pdev); vfio_pci_core_disable(vdev); + vfio_pci_dma_buf_cleanup(vdev); + mutex_lock(&vdev->igate); if (vdev->err_trigger) { eventfd_ctx_put(vdev->err_trigger); @@ -658,7 +660,10 @@ int vfio_pci_try_reset_function(struct vfio_pci_core_device *vdev) return -EINVAL; vfio_pci_zap_and_down_write_memory_lock(vdev); + vfio_pci_dma_buf_move(vdev, true); ret = pci_try_reset_function(vdev->pdev); + if (__vfio_pci_memory_enabled(vdev)) + vfio_pci_dma_buf_move(vdev, false); up_write(&vdev->memory_lock); return ret; @@ -1190,6 +1195,8 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, mutex_unlock(&vdev->vf_token->lock); return 0; + case VFIO_DEVICE_FEATURE_DMA_BUF: + return vfio_pci_core_feature_dma_buf(vdev, flags, arg, argsz); default: return -ENOTTY; } @@ -1826,6 +1833,7 @@ void vfio_pci_core_init_device(struct vfio_pci_core_device *vdev, INIT_LIST_HEAD(&vdev->vma_list); INIT_LIST_HEAD(&vdev->sriov_pfs_item); init_rwsem(&vdev->memory_lock); + INIT_LIST_HEAD(&vdev->dmabufs); } EXPORT_SYMBOL_GPL(vfio_pci_core_init_device); @@ -2138,11 +2146,16 @@ static int vfio_pci_dev_set_hot_reset(struct vfio_device_set *dev_set, * cause the PCI config space reset without restoring the original * state (saved locally in 'vdev->pm_save'). */ - list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list) - vfio_pci_set_power_state(cur, PCI_D0); + list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list) { + vfio_pci_dma_buf_move(cur, true); + } ret = pci_reset_bus(pdev); + list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list) + if (__vfio_pci_memory_enabled(cur)) + vfio_pci_dma_buf_move(cur, false); + err_undo: list_for_each_entry(cur, &dev_set->device_list, vdev.dev_set_list) { if (cur == cur_mem) diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_priv.h index 4971cd95b431..c1ea92c5ec1c 100644 --- a/drivers/vfio/pci/vfio_pci_priv.h +++ b/drivers/vfio/pci/vfio_pci_priv.h @@ -4,4 +4,27 @@ int vfio_pci_try_reset_function(struct vfio_pci_core_device *vdev); +#ifdef CONFIG_DMA_SHARED_BUFFER +int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags, + struct vfio_device_feature_dma_buf __user *arg, + size_t argsz); +void vfio_pci_dma_buf_cleanup(struct vfio_pci_core_device *vdev); +void vfio_pci_dma_buf_move(struct vfio_pci_core_device *vdev, bool revoked); +#else +static int +vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags, + struct vfio_device_feature_dma_buf __user *arg, + size_t argsz) +{ + return -ENOTTY; +} +static inline void vfio_pci_dma_buf_cleanup(struct vfio_pci_core_device *vdev) +{ +} +static inline void vfio_pci_dma_buf_move(struct vfio_pci_core_device *vdev, + bool revoked) +{ +} +#endif + #endif diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h index f22d5a382c15..1136ed4a08f9 100644 --- a/include/linux/vfio_pci_core.h +++ b/include/linux/vfio_pci_core.h @@ -139,6 +139,7 @@ struct vfio_pci_core_device { struct mutex vma_lock; struct list_head vma_list; struct rw_semaphore memory_lock; + struct list_head dmabufs; }; #define is_intx(vdev) (vdev->irq_type == VFIO_PCI_INTX_IRQ_INDEX) diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index ef33ea002b0b..ef716afc9dae 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -1002,6 +1002,24 @@ struct vfio_device_feature { */ #define VFIO_DEVICE_FEATURE_PCI_VF_TOKEN (0) +/** + * Upon VFIO_DEVICE_FEATURE_GET create a dma_buf fd for the + * region selected. + * + * open_flags are the typical flags passed to open(2), eg O_RDWR, O_CLOEXEC, + * etc. offset/length specify a slice of the region to create the dmabuf from. + * If both are 0 then the whole region is used. + * + * Return: The fd number on success, -1 and errno is set on failure. + */ +struct vfio_device_feature_dma_buf { + __u32 region_index; + __u32 open_flags; + __u32 offset; + __u64 length; +}; +#define VFIO_DEVICE_FEATURE_DMA_BUF 3 // FIXME numbers wrong + /* -------- API for Type1 VFIO IOMMU -------- */ /** From patchwork Fri Sep 6 00:40:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1981473 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X0HTq3vq3z1yh1 for ; Fri, 6 Sep 2024 10:41:19 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1smN2F-00026e-NG; Fri, 06 Sep 2024 00:41:11 +0000 Received: from mail-dm6nam04on2084.outbound.protection.outlook.com ([40.107.102.84] helo=NAM04-DM6-obe.outbound.protection.outlook.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1smN2B-0001z5-P2 for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 00:41:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Y9z+KeGn3PI7NYcogINAE7HeBOqDY9LWS+frJBTm6HIwMzxWkf7UUu3ON7iJaop5X3L0vb93BaOP/aZRunD23vY1oXTVvk21y+tZtQbTw+T3tP6NnQwIy287WOU7wHMr5/xjB3EzZFo5HmcLtosh7nAdla8YZkBVJ3mhkCHeBAPsone+fLaoROdem1os6EQXuARyDalV+y1ksX4RWjWx1vN4g50Iyq6zsmFuz5LEpAS+QkBung/1QYgaCY/LMQ8lSYwW+uwmGwtY3GNhBGcUTSRKQF8GtDfdAb3oGkTOsIChz8/iM7dLZ2DDwsmT4s5ortepznRJG/D7HABaLWa8lA== 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=hiLwlBbA9ZrFaQU1hjLvtszVl7Q9oa9qhfy1BGNynfw=; b=SrtF/XWkP/VrFnbyeZgT0iYuUdrS/51zV6gnbjXMPmL/hiLHRzwiBYehskVw1ET5haaDDjUJi6aLMT3M+Re/ef0JLv3xXGt+X6XmilZX2pmtbQHqX03i1lF10+wdqEjkwUjLHp2ti7CmU2yHFovCrcFPyc9+/TD470ySyL3n1tYAZryCRjMHtqowEZbiUgEjRDyXNSEYEdgUi85FWmRt4HXpK2RT/iPVXpsHTaUowCEX2MsYLScemqhEeUWlTIkDI53eLOUtlWr66+emgVFuUWn9iulq1heqSaGU6/2cpAjihDvMsZJAtbjhpkxKYdNScIfzlFyCfHi9cpopEfnz+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from PH7P222CA0008.NAMP222.PROD.OUTLOOK.COM (2603:10b6:510:33a::35) by SN7PR12MB7810.namprd12.prod.outlook.com (2603:10b6:806:34c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.25; Fri, 6 Sep 2024 00:41:01 +0000 Received: from SN1PEPF0002529F.namprd05.prod.outlook.com (2603:10b6:510:33a:cafe::98) by PH7P222CA0008.outlook.office365.com (2603:10b6:510:33a::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.14 via Frontend Transport; Fri, 6 Sep 2024 00:40:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SN1PEPF0002529F.mail.protection.outlook.com (10.167.242.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 6 Sep 2024 00:40:59 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:48 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:47 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 5 Sep 2024 17:40:47 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v2 5/7] UBUNTU: SAUCE: vfio/pci: Fix p2p address Date: Fri, 6 Sep 2024 00:40:36 +0000 Message-ID: <20240906004038.800613-6-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906004038.800613-1-witu@nvidia.com> References: <20240906004038.800613-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002529F:EE_|SN7PR12MB7810:EE_ X-MS-Office365-Filtering-Correlation-Id: 19b4402e-d281-426d-548b-08dcce0c93e6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|1800799024|82310400026|376014; X-Microsoft-Antispam-Message-Info: 2tnCBEpKUYSJ99mWONLO5KGpx7dzwNp7F6/rhBbNevVzskl7q63AwZOPYnOffIGvWPihbdNDSmoYoZCASeudUd9TxZJjdaTe97g1yZIiDcsh5Wpst3zcRGkqkac+FHaOR5dtT6HUU0u3Mu2iZ/PuPkQrzMGS7Q2o87MNW/Uf3BnrghsuPno3efkMUQGKnpplutT0Ab6Bx4HOMWA3fa0Fx5vvaDJH3btV7Y8S+61DT69nJ9rpEqbMryBnvft0zRLyswWs5No9s1yL1qDtRitYna+pd0sSONlar9AlBRb4U4Zn11u7LmoQMGcF7mrpTQzQxSBiWqMujPE0ph5uglF/qpVzJtdJpksiyqrgpFStcRlsaQW/CnyUZi2K7BUtIfy9gjNpGVvwsEYp7smZ7h9UdQ6WTk8OB0lKDkFO6w+RiDk8vldaAY7UqrNM8e1aasGzKFScAAFx6HRzWkb+fo6gDzNDb2HYQSdm563KP0YbHPucSnHp1ug9MZvAwk7VsR8LlJplJmTqngTualaB/yTHFAVC9SsGqmj+40ffVTTlZTn/XPlBXYNcw/5hfj37yIdx3ChTdmMWidIaOzqBR5VUifT4lHKbnSxnMrBG1M1777QZTNW5KR5OWRGnu/yt5mrOtFSULPBMXmJXNiF9XJ7blJfsKF2wTpGpGgBOFdX77IX+b3ve7nayvFjH/JoZOehnyyi1+s7PpqfTdfGjPcwW9DSsNsb828RvFOulBJA3F5gbibihajvqCic+FvObb/54sL1vqQpoeHGLiG+Ak2NnibWV0qf/3q12DFwRQHSuJNAhHuiVkKS9PF6bF4hzfOvVLXNHRF9UoSqF7UhdoSmSVwjjjNlMdSUoW5+0Eps9KI56uZM8K0te1zigfzdGhA+aXOuJEPTRTcCpS9sirc0qtdP2/uuFCwRdUVIzekem3zk3D6+RHlrgZU9OPZTiOeKRRdL1gHW1N/B+8FKCAfwP/j2QLdIF9q28/3MQNVIEn+p4KZFPmmh2oDJ0EOAgWXmRZkt2Q5coUfwOlA+SpNBKKcZVtzmqNCVjCiFPd0I7bGyWxfwNA6XhdFFsF9G9Z1wozCmZRB62yO/Ht8HbUVJUdCJHczqb7s1B73m2/MVHa2ZAGjYbIKYWk/ZDROmut+CbQOajqhIpAuPhXEACvvk+aVJw5Z86E11gIUGR4+L9RgqJAT/VWNwdGZfRzCeAOcztdAN1vetbKZQGCQ/eYnFKd/eN/f+X+pxjEU/uW5NlPdMGlqizJG/iQ+9/HmdHCCy0An1ZOjiqRsSu61L6e0kV/PJ8YgCR1BmXTAJEUpNqUXXjKplRJEWlH540ZUBCfYxn9XTymK4wBzZNxCjL2PPAdK1019H1t/FWnG2ilGnjDHojpC6ij00a9UacsGfThNb+DvS9rigrGs/i/HmZ+NFo1r2Lppa6JFWfFRHU0THUXLxfKCD7HdvCM3W14aTUDPON X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(36860700013)(1800799024)(82310400026)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 00:40:59.4792 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 19b4402e-d281-426d-548b-08dcce0c93e6 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002529F.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7810 Received-SPF: softfail client-ip=40.107.102.84; envelope-from=witu@nvidia.com; helo=NAM04-DM6-obe.outbound.protection.outlook.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, sergeygo@nvidia.com, jgg@nvidia.com, zwaksman@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Sergey Gorenko BugLink: https://bugs.launchpad.net/bugs/2077887 Use pci_bus_address instead of pci_resource_start. Bus address must be used for P2PDMA operations. It is simple for x86_64 because bus address is equal to PA. However, bus address is not equal to PA for ARM (at least for BF, I did not tested the other ARM platforms.). That's why pci_resource_start() work fine on x86_64 and we had to replace it to pci_bus_address() on ARM. Co-authored-by: William Tu Signed-off-by: Sergey Gorenko Signed-off-by: William Tu --- drivers/vfio/pci/dma_buf.c | 10 ++++------ drivers/vfio/pci/vfio_pci_core.c | 4 +++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/vfio/pci/dma_buf.c b/drivers/vfio/pci/dma_buf.c index 11396aeabff4..367fe7077ebf 100644 --- a/drivers/vfio/pci/dma_buf.c +++ b/drivers/vfio/pci/dma_buf.c @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include #include "vfio_pci_priv.h" @@ -81,7 +84,7 @@ vfio_pci_dma_buf_map(struct dma_buf_attachment *attachment, */ dma_addr = dma_map_resource( attachment->dev, - pci_resource_start(priv->vdev->pdev, priv->index) + + pci_bus_address(priv->vdev->pdev, priv->index) + priv->offset, priv->dmabuf->size, dir, DMA_ATTR_SKIP_CPU_SYNC); ret = dma_mapping_error(attachment->dev, dma_addr); @@ -167,11 +170,6 @@ int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags, struct vfio_pci_dma_buf *priv; int ret; - ret = vfio_check_feature(flags, argsz, VFIO_DEVICE_FEATURE_GET, - sizeof(get_dma_buf)); - if (ret != 1) - return ret; - if (copy_from_user(&get_dma_buf, arg, sizeof(get_dma_buf))) return -EFAULT; diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 4017512f6736..6c4c96fc5c54 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -1196,7 +1196,9 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, return 0; case VFIO_DEVICE_FEATURE_DMA_BUF: - return vfio_pci_core_feature_dma_buf(vdev, flags, arg, argsz); + return vfio_pci_core_feature_dma_buf(vdev, feature.flags, + (void __user *)(arg + minsz), + feature.argsz); default: return -ENOTTY; } From patchwork Fri Sep 6 00:40:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1981472 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X0HTn2l9Dz1yh1 for ; Fri, 6 Sep 2024 10:41:17 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1smN2D-00021B-2t; Fri, 06 Sep 2024 00:41:09 +0000 Received: from mail-mw2nam10on2088.outbound.protection.outlook.com ([40.107.94.88] helo=NAM10-MW2-obe.outbound.protection.outlook.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1smN29-0001xp-QC for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 00:41:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Peom0dk7rLODUe7Xcd9tdgUE331V0g1BheHQn4BwE5qXt8ZcU3X7VKVlPx+XWDRaQTpW8/eV9h+yLOyfStudeqgMkTzHyNJgiwOnCbZUNp9dAlrqwLS6qOSM+/08D8qYTMl49+mSZKgh0OSJ2KA4uzkMLSFyfsw27pWQHvVj4XsdJbqUmXnD+PdT4elldkX439ZAafr2TqnKFVsRZdoqo8Hgm3+mD4QA0uwAE+pY1TBun8sixgV1ONOyQWCp8i8VRGJZyReSeIccXjMt8B/HGW8Gr6MtFFfKgB6K5mTM2cuOys7TzWIpQBwVwCn55PXtS0ysabtHtjQZV8e9xEnMAQ== 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=XfnLvop6XiyxWb+rZZFvlA6L6yhjW4B+zHAwS8N7W5U=; b=NA+0/lL6Ddy0Fw+V+st/jzpgS04tWbsVKfZx5xhzH5IajXOsWW6+P2OzMQ+OqRXp3At6TGDSu6B/w33XUYCmsdlJ13STJ5Urr9HSgaE+t12nDMNXK5q2MNugEPnCUlKwOcPJuVkxdfWvdpMH+GMhUhE1syeKnxfoQaZHFg5esWDuwDqsF5HmKkQZ1KomibAhnno3utKE3Gup8DNMirLOidp/H0b0VWV3R9UbCg+i9DnDgE34R+3K1Ccyt4knC4Wsy6KzdBKOm5VaInE0V2+2sTbDs3O9pP4WkeCtb1L7yC2msY1tLfqHDmU2pF+lQ+XLjNT3yzmqNpaishRyi8RPRA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from CH2PR18CA0007.namprd18.prod.outlook.com (2603:10b6:610:4f::17) by PH8PR12MB6771.namprd12.prod.outlook.com (2603:10b6:510:1c6::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.17; Fri, 6 Sep 2024 00:41:01 +0000 Received: from DS3PEPF000099E1.namprd04.prod.outlook.com (2603:10b6:610:4f:cafe::c0) by CH2PR18CA0007.outlook.office365.com (2603:10b6:610:4f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.14 via Frontend Transport; Fri, 6 Sep 2024 00:41:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by DS3PEPF000099E1.mail.protection.outlook.com (10.167.17.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 6 Sep 2024 00:41:00 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:49 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:48 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 5 Sep 2024 17:40:48 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v2 6/7] UBUNTU: [Config] bluefield: add config for VFIO P2P Date: Fri, 6 Sep 2024 00:40:37 +0000 Message-ID: <20240906004038.800613-7-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906004038.800613-1-witu@nvidia.com> References: <20240906004038.800613-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099E1:EE_|PH8PR12MB6771:EE_ X-MS-Office365-Filtering-Correlation-Id: 6aa3f9f5-3d67-4592-d489-08dcce0c9486 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|36860700013|82310400026|376014; X-Microsoft-Antispam-Message-Info: v46dlZaDEX6ne/SVmxiCh8fp77Aj8SLBxBidGmsJpa0S6iHMzF1h7+gtQi5tU9hTnRgk3bmnmjGfnZEjc0GcDkLvHFNqRyvhLhj32+TMsOKnyyKPWYBTdXs5KaJkkvi6UF9b61F15snPb5ylrSPHZTHQIw4uQFJbTicjL+hzdDxra4XdFZoRqqfkcEN9kKiLCrwGGoYRRfT1w185ooc2XS47kf3pkhn9D3DBX8wYAjMUAATBXTGgG8HBFkzx2YIOI+Zz2d8DXh4F5bE691dphPWyRVATshpaL825VhcLolHJ7TBHoY5/eN5eiaQqPSzLXZg2tdII6DmWfGL4llbxHMlEsPGBCfvKrnGXrgnEoZt2hq00Weqdp5kBMT3IyNWPEELj7oVYQ/4vk14T1P2ORwwC0iBsiw2kzyG4jQ5gOlDZoAgpQ89Quazyc+AsAF+M0kJSHmdAa+8KMi0cLIPWRFVtZFIFl7+MgP697VF3cJGO/bT72ija5sMDaobjubQDxPZUlqEHA5HLrbI1bPjEw8yoWDaf3dy5E+WMgB2LM4XPWNv+J3wQSVGEguAhGTKO493LkLF9mZuhQGoS8i6jA6U3ksXGMy6TFxMo0lT+s9mTvPX5IcUB5h3wyH0EfHiJDHCvHFnIepdJSUVjjJG8HeFHOYnZ4Cz923X5OQfs7IG6RYzR2pEdU8BwpzH/Gw00cgXfs+cUrRtMZY5d8L5hRs/L37JYs8VhAgomG3ckysh5kZyho+6HhLHpZ4VtZ3Eq3dBKqvLAS/BAZylOvcS7wwZVyy+u5iBUaWg0oLdnuZPUqqM2EBCV92E91rQpexvmLVNpca619iICI/fxGauHYfHDPsVZVFM3uvNRQ+IcjUhFs84wMUoGS1zb72k5wfJLw3SBTV2jlqPWQRcxJWnlA8yyaHNxLS5aEARZPI4/xlj1cCvwBnOa/sHnlITID+PPuG3NMkdFDxFTK6yjobWLPRKK5RS/bJReMhL+DAFgaRFP6t8ZG1lPDevr5kKZN+kF/upACFxRnJoZpWmaR525jEWLM/i5qrqRJhn9ajQtPBL9sEUPiHIrHpmJVQ//Q1CSPwxP+PacV8RXpbZFk6iHW3BLiU0rSRgRQ/NJlBH8HhffRDlclL7tLBOwu0oXt+zk+7auA3CDQe/VGt3mnik4+cTzQG8DVXzspaqHvPjAAykYJqOJ8XFkrB5ergLLg+0JynOFMkl5ZDRgpVLGtlnrFNwsYtF7Rmyh7DikiLdc04q28JX/ae5XkzimCM5r9DwejXZZ1rGfxqyjwjSJ4NJWofSQ06Hl6MG50AudtT6gw/ih8Hb17FhPbAYNzFY/dFarewEW7BQLvG7UhkyegwyYcLVAWb01WBycrX1MxGZwo7cfUD4PWw3aswME9KXPSY9Tx7OEi7aC0tWohKGZ8oGgi9NnMILnRjMp3TVJF5S5K22Qn9HfVHWXUmlIxjppkQbO X-Forefront-Antispam-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230040)(1800799024)(36860700013)(82310400026)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 00:41:00.5155 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6aa3f9f5-3d67-4592-d489-08dcce0c9486 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099E1.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB6771 Received-SPF: softfail client-ip=40.107.94.88; envelope-from=witu@nvidia.com; helo=NAM10-MW2-obe.outbound.protection.outlook.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, sergeygo@nvidia.com, jgg@nvidia.com, zwaksman@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/2077887 Addd CONFIG_PCI_P2PDMA and CONFIG_DMABUF_MOVE_NOTIFY. PCI_P2PDMA enables support for p2p DMA transactions. DMABUF provides two ways to share a buffer between kernel drivers. CONFIG_DMABUF_MOVE_NOTIFY enables the dynamic way for DMABUF APIs, so no need to pin the memory. Co-authored-by: Sergey Gorenko Signed-off-by: William Tu Signed-off-by: Sergey Gorenko --- debian.bluefield/config/annotations | 2 ++ 1 file changed, 2 insertions(+) diff --git a/debian.bluefield/config/annotations b/debian.bluefield/config/annotations index 553d4d84c1d3..2f405bdb9745 100644 --- a/debian.bluefield/config/annotations +++ b/debian.bluefield/config/annotations @@ -211,6 +211,7 @@ CONFIG_DE2104X policy<{'arm64': '-'}> CONFIG_DE2104X_DSL policy<{'arm64': '-'}> CONFIG_DL2K policy<{'arm64': '-'}> CONFIG_DM9102 policy<{'arm64': '-'}> +CONFIG_DMABUF_MOVE_NOTIFY policy<{'arm64': 'y'}> CONFIG_DNET policy<{'arm64': 'n'}> CONFIG_DPAA_ERRATUM_A050385 policy<{'arm64': '-'}> CONFIG_DPLL policy<{'arm64': 'y'}> @@ -807,6 +808,7 @@ CONFIG_OCTEONTX2_PF policy<{'arm64': '-'}> CONFIG_OCTEONTX2_VF policy<{'arm64': '-'}> CONFIG_OWL_EMAC policy<{'arm64': '-'}> CONFIG_PARMAN policy<{'arm64': '-'}> +CONFIG_PCI_P2PDMA policy<{'arm64': 'y'}> CONFIG_PCMCIA_XIRCOM policy<{'arm64': '-'}> CONFIG_PCNET32 policy<{'arm64': '-'}> CONFIG_PCS_LYNX policy<{'arm64': '-'}> From patchwork Fri Sep 6 00:40:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1981471 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X0HTm6VhPz1yhD for ; Fri, 6 Sep 2024 10:41:16 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1smN2D-00021R-9O; Fri, 06 Sep 2024 00:41:09 +0000 Received: from mail-bn7nam10on2061.outbound.protection.outlook.com ([40.107.92.61] helo=NAM10-BN7-obe.outbound.protection.outlook.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1smN2B-0001z4-Od for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 00:41:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=d1BGtlNl7wFMkPS8YXdarUNPVcq+fPnwN4o3wEryhm3cO8W49p4TXJ3GRuq1ir62E4O2kycGfnnrjyWM3GnMiqgo3dnObwwnKhQqiMfrY3eSwlTsV5TrFejJzQavuDUNjnNWlya6y6Lw+5TUEZCG8/9xyue+uR1VUBE+bhYwPWkeDRPB5iSvlqqomY4CJdyD4eqz5umntiLSW5Y839SJJabTPkMYFdOpcvQDeHZbvPkwGY8gmUXNRuNW+xbXYlAeQ32IF8lSatN9XxRUHvo97yxV24hYNRsLRGJchdF5aPdXOJ7+hQcomEjGDP7pllMPhn6s5nIJQK+D7C4tYwckiQ== 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=PU+ZuwKLQxGkUXsUqsFBlvUUko3sW2UETksO3beg0O4=; b=SQBVD5rgc6gotPGy1+dxa04kVu9g/vhvbDbg4UzCfKYAFTK3b8fTgYnIvtmG+hIBgX7tMhYI1HSupY+82DKk9RiwYnz0gTLxZ3UY/XZKwP6V6uxSEzn2sfiEeri4M57bNx9o2rBWuAfEvqWlPrp/9MH7gEi8KCf0IWUdsjRGfGIEqz32pQTH9G0Il86G2wbed7yYia5pGSkaB9EUptWBVMWp/+YUodn9qsAYSjQAyNacsFmtUMv5ZSmynQA1YQlHbJLPqds6V5m8UxEX2A3oRDOI9m0g5QeMtHK3p1ZgS2UGfPtIcxC0axXO1nX/p8RYkj9C/wlKA40ytHdtQW4Bhg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from CH2PR18CA0020.namprd18.prod.outlook.com (2603:10b6:610:4f::30) by SJ2PR12MB7942.namprd12.prod.outlook.com (2603:10b6:a03:4c3::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.25; Fri, 6 Sep 2024 00:41:02 +0000 Received: from DS3PEPF000099E1.namprd04.prod.outlook.com (2603:10b6:610:4f:cafe::28) by CH2PR18CA0020.outlook.office365.com (2603:10b6:610:4f::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.17 via Frontend Transport; Fri, 6 Sep 2024 00:41:02 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by DS3PEPF000099E1.mail.protection.outlook.com (10.167.17.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Fri, 6 Sep 2024 00:41:02 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:50 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Thu, 5 Sep 2024 17:40:49 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Thu, 5 Sep 2024 17:40:49 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v2 7/7] UBUNTU: SAUCE: vfio/pci: add new ioctl for vfio dma buf Date: Fri, 6 Sep 2024 00:40:38 +0000 Message-ID: <20240906004038.800613-8-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906004038.800613-1-witu@nvidia.com> References: <20240906004038.800613-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099E1:EE_|SJ2PR12MB7942:EE_ X-MS-Office365-Filtering-Correlation-Id: f33fc961-3c60-46e7-c94a-08dcce0c957e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|82310400026|1800799024; X-Microsoft-Antispam-Message-Info: adJbCdYkEzDgNT2Vk/h8hh0Hvi1TmjMkYm7GfFUJ/uopZ6XeDLoin5QLFP8J5E8XifsNAv+Tb3mjYYr+2TPtufhj72luUFvA5AenFmMnKgVu6JiVASas2XJzbfdd6anyLrsvVVINt7zWtM1uhEJ3dK9VPQM7FlI+kcImOkU/rmNtvY9pvKvHIKtomdF4TQKdbzVKLgFteCQNdIrJRGguRv1ptnwwdeLdb1leY/mfeOeciqIgNKExeYzyq1XGW58rtoqa3LZUJ+k8l6F0CbPiFSunIFgkBQAjMqJwIjnT8tM32ACjSYC/Pry+Jn6M1+Rj7Yg9ALZZvEgHXyzXouD7gUvclcd9XAkGFBae+9OPNYbMvLfg2k2yAVied1oR2fgbvFO7ZamI8pHHKBUy2qEfs389NDkTHmlVKSRSpfeimC62IZ0nBcPkmJrLEKWVEM2jYY/9yF3sOuzliqQjt0gnLm4HH5qFfzfRKE8GQB0NrfVCpciTewLmAba2l+UR6OEn/ihKTONYovTuzgL/LqEEkizQwHNTbbyk8nNbUlMjsG4BUdU9djXz2hbpB1vbQ8dl1jyfpRO0YGgjWdKONftNQ11CqN5L6650KufpEhfchmTOHvnDTpIbNTx3OpExF0ua85BTf7rxV6eTK4CR0rHGcqhMd5V4sawPFYy795tMb3bvIFFGfwmdAmJUlR/kIRpXl5LAfiaOG5rwEFMJjnXkDq/QPAtJNmdYyd0REPs+9AZziVoTcp/RI8hcpWCuadP5kdqiOVz/3Go1vJSv9l12LH17Zn1HX5lSICk0rrM6SxBcA446O3kp9TwwypZPx1uKkwt7JQfDxU8t8ZMGbbC8rjwg5fHEnLSl1wc/P6Xfj6KsFwkFpxLReDqH8Y4J9pBNchtRwILium6lyGIbBA25WDkmWiuq2Z0DmjwAQU7MJkvMP7VMQO6fsK4VWQ7cF4y2RQuR9V8IEzWaK/CVNJR66mb6FMbuK5nzz8n79xCIHT8AZZrhePPk16EFAW+GbUEqpjO/ZIN5FLBsmFSkF0sTL45mhqQyy5L+X82pq3KMjQncxUz7Gd58WDq/TN3SrZIQRThcnmRYY18y/2v3es+esjIsMjBTIjQ9auEka0OnIkgzJO6iY8YzdaYgoaf0wIsL0/pi2AtfbK66IdHgZdyU2r5ehpzeiJlsZP1MQw3WBjevHwOBcVbVrrsp9Ws6YPE3XS/kMxC1fEi7Fmnj2sfhpci0VOy03iTW7rlFKfSgLonlL5xQ5aIBfDwJtteSqtzhYKc4znfJkppv3qnybPchhC8/VWWYpc4sic2N0aZ74IlLcgGcb5bUG0I5eSUrss5JQz/tqN1OM3FE+EFE1GylCcwIgoBzPJA20n9BtpH/lqVL5bzl1QKZYt51KIgdPiEY0Tbi8IXuLN8vwzSRxghnCmOpg5wyI1ClL1NmRT7nyZkDgIdFn783NbRLEBGLYhsf X-Forefront-Antispam-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230040)(36860700013)(376014)(82310400026)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 00:41:02.1405 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f33fc961-3c60-46e7-c94a-08dcce0c957e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099E1.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR12MB7942 Received-SPF: softfail client-ip=40.107.92.61; envelope-from=witu@nvidia.com; helo=NAM10-BN7-obe.outbound.protection.outlook.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, sergeygo@nvidia.com, jgg@nvidia.com, zwaksman@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" Introduce new ioctl number for VFIO P2P dmabuf, with ioctl input struct vfio_device_p2p_dma_buf. Signed-off-by: William Tu --- drivers/vfio/pci/dma_buf.c | 10 ++++------ drivers/vfio/pci/vfio_pci_core.c | 12 ++++++++---- drivers/vfio/pci/vfio_pci_priv.h | 10 ++++------ include/uapi/linux/vfio.h | 14 ++++++++++++-- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/drivers/vfio/pci/dma_buf.c b/drivers/vfio/pci/dma_buf.c index 367fe7077ebf..58fd3db9c249 100644 --- a/drivers/vfio/pci/dma_buf.c +++ b/drivers/vfio/pci/dma_buf.c @@ -161,17 +161,15 @@ static const struct dma_buf_ops vfio_pci_dmabuf_ops = { .unmap_dma_buf = vfio_pci_dma_buf_unmap, }; -int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags, - struct vfio_device_feature_dma_buf __user *arg, - size_t argsz) +int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, + struct vfio_device_p2p_dma_buf *p2p_dma_buf) { - struct vfio_device_feature_dma_buf get_dma_buf; + struct vfio_device_p2p_dma_buf get_dma_buf; DEFINE_DMA_BUF_EXPORT_INFO(exp_info); struct vfio_pci_dma_buf *priv; int ret; - if (copy_from_user(&get_dma_buf, arg, sizeof(get_dma_buf))) - return -EFAULT; + memcpy(&get_dma_buf, p2p_dma_buf, sizeof(get_dma_buf)); /* For PCI the region_index is the BAR number like everything else */ if (get_dma_buf.region_index >= VFIO_PCI_ROM_REGION_INDEX) diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c index 6c4c96fc5c54..096f8303a207 100644 --- a/drivers/vfio/pci/vfio_pci_core.c +++ b/drivers/vfio/pci/vfio_pci_core.c @@ -1195,13 +1195,17 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, mutex_unlock(&vdev->vf_token->lock); return 0; - case VFIO_DEVICE_FEATURE_DMA_BUF: - return vfio_pci_core_feature_dma_buf(vdev, feature.flags, - (void __user *)(arg + minsz), - feature.argsz); default: return -ENOTTY; } + } else if (cmd == VFIO_DEVICE_P2P_DMA_BUF) { + struct vfio_device_p2p_dma_buf p2p_dma_buf; + + if (copy_from_user(&p2p_dma_buf, (void __user *)arg, + sizeof(p2p_dma_buf))) + return -EFAULT; + + return vfio_pci_core_feature_dma_buf(vdev, &p2p_dma_buf); } return -ENOTTY; diff --git a/drivers/vfio/pci/vfio_pci_priv.h b/drivers/vfio/pci/vfio_pci_priv.h index c1ea92c5ec1c..d60e9cb99140 100644 --- a/drivers/vfio/pci/vfio_pci_priv.h +++ b/drivers/vfio/pci/vfio_pci_priv.h @@ -5,16 +5,14 @@ int vfio_pci_try_reset_function(struct vfio_pci_core_device *vdev); #ifdef CONFIG_DMA_SHARED_BUFFER -int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags, - struct vfio_device_feature_dma_buf __user *arg, - size_t argsz); +int vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, + struct vfio_device_p2p_dma_buf *arg); void vfio_pci_dma_buf_cleanup(struct vfio_pci_core_device *vdev); void vfio_pci_dma_buf_move(struct vfio_pci_core_device *vdev, bool revoked); #else static int -vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, u32 flags, - struct vfio_device_feature_dma_buf __user *arg, - size_t argsz) +vfio_pci_core_feature_dma_buf(struct vfio_pci_core_device *vdev, + struct vfio_device_p2p_dma_buf *arg) { return -ENOTTY; } diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index ef716afc9dae..18f369426c13 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -1012,13 +1012,23 @@ struct vfio_device_feature { * * Return: The fd number on success, -1 and errno is set on failure. */ -struct vfio_device_feature_dma_buf { + +/** + * VFIO_DEVICE_P2P_DMA_BUF - _IORW(VFIO_TYPE, VFIO_BASE + 22, + * struct vfio_device_p2p_dma_buf) + * + * Set the region index, open flags, offset and length to create a dma_buf + * for p2p dma. + * + * Return 0 on success, -errno on failure. + */ +struct vfio_device_p2p_dma_buf { __u32 region_index; __u32 open_flags; __u32 offset; __u64 length; }; -#define VFIO_DEVICE_FEATURE_DMA_BUF 3 // FIXME numbers wrong +#define VFIO_DEVICE_P2P_DMA_BUF _IO(VFIO_TYPE, VFIO_BASE + 22) /* -------- API for Type1 VFIO IOMMU -------- */