From patchwork Fri Sep 6 19:49:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1982068 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 4X0myv0JrJz1y1K for ; Sat, 7 Sep 2024 05:49:42 +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 1smexb-0002M5-9z; Fri, 06 Sep 2024 19:49:35 +0000 Received: from mail-mw2nam10on2070.outbound.protection.outlook.com ([40.107.94.70] 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 1smexX-0002Kq-SL for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 19:49:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZBn+e7/G3RdOkyjWyMP6JTXXhkjo0kUIrAwdaOEU9qVH8hAM3JNMXGLtX9nVCugbnQhrvw3lXbPZm+CQLSzfStubA14ziPByI8YLP+eIwPIOzpYrfUp22idFCZ8x2AjzA9YR3nKArUJ/c4GnrPZUw1SWzDYAB7ocQOXd1P44tU48o8rrHFPseFWjN/GouqU2cg7qWdwIsygnWGUSfwAL29KkelkhxKFInvOEzg3/VzNExpVwMJaZuSvFsQUIwcuvTARp9jX4E7xt7rbZYrJFMsbfN9xacVlm9cQFcGgO0iFKNv9O7YeGtsGjTHXXX/NuY7XiNOgbJ8OVDRKNp4v9Gw== 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=ivrFrqOi0+nAjMHGcrv4SfzLHTd0J4OGeaVrN734Nb5PuU9ju1zT7WSgTKVUz4e4fR047RXAMBuqrlLwhDxkpCON8aPyQzccCBgrUyRMYVGMWnGHpNRyiD5ldRWsVQ6d71q+LqJtRmbr6vMPunGrwgnIs+P5DU5nZoMqLDkvI2QHJOTqwPqjV4xq3WzHOmNVxd8SB+T2ZPujnuXhz3b93wbzYCvl4VottO1nGRUSsJA40P/FehnCXabwtRPiYvW8hs4qqiAZhjjhqeyYq1mChtvA3O8lPL28iXeI18yyFY3/rPOOWxJYJ/ZELVv9gmjHTTBk3QgvckJaeY8hDfcSRw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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 SA0PR11CA0131.namprd11.prod.outlook.com (2603:10b6:806:131::16) by IA0PR12MB7601.namprd12.prod.outlook.com (2603:10b6:208:43b::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 19:49:25 +0000 Received: from SN1PEPF00026369.namprd02.prod.outlook.com (2603:10b6:806:131:cafe::4d) by SA0PR11CA0131.outlook.office365.com (2603:10b6:806:131::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.15 via Frontend Transport; Fri, 6 Sep 2024 19:49:25 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SN1PEPF00026369.mail.protection.outlook.com (10.167.241.134) 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 19:49:25 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 6 Sep 2024 12:49:14 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 6 Sep 2024 12:49:13 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 6 Sep 2024 12:49:12 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v3 1/6] UBUNTU: SAUCE: dma-buf: Add dma_buf_try_get() Date: Fri, 6 Sep 2024 19:49:03 +0000 Message-ID: <20240906194908.1127733-2-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906194908.1127733-1-witu@nvidia.com> References: <20240906194908.1127733-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF00026369:EE_|IA0PR12MB7601:EE_ X-MS-Office365-Filtering-Correlation-Id: 76306987-288f-4614-c7be-08dccead02ef X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: mxkpDtHXpe0UizuyKzyn7JlSPvDkekm8UgDFn5ihY1gUi+1kyZH1l7xM2rQsLvrJfTIGsu2gtiwExz3n/FX9q8vTtNuGXFepvePE48eskg54luG/Y6xwLyCyI+hd+XOIZyIOrwBkZpkrrcNvkJgFajt7zGwf55Dngz/Xb8v7QjJgka6pRVnrbyUUs7Zm+BsH3CeUuqy/YR8NdiMtekVHbtWWrbt+sw56ALFbBeHPH7oShConR+1YARiddlBAUjPwJiQKBWUC7jSpJVJ0zIvLvdYyEU81r92QpDgX9WWh34tT3OkvkXus0g0+H54tSX2W40YduFsnWUbeXYAOC19rpTuJmeoaDam0d7ewnWUd2yZUAcO/WBnUTFPzD1cCFhHtrzAuV2Ct/ZNsYCZ5kUT1odtKAUYrm5ItcyRLvuzcIunlIg6CR+X3cdZ19aNu1wZKFnndjHw+LMDicajzLjNh7CoAq444YASRjaK1vJnhcbZHMg9/IMiCwxBdaT6JH+7Y5mT0sMZZygQFY7LvV0qNdQq6aqNu47o5RsRxnxQjKK65Qzqr1AnqC2b8HpIfVeLbXPvSHUOUAdzzNJi9VtH87v7OTwjc+I3VFjUb7W3nJajdYu7+k+RHc8sKpx//bDxAphIE1oNXIWMWR5p+74yIEkmhcfafQXCiVReI0ujXmBTNznwyzPg1NLQL+wsE9JKa2m42gNNVQyFkvti8NezpG9Bz18XWtEgcEEsFYaNrC4ZgsRCBZUy/3PoLlT4mkA8E6jayj0cLPe4YPVe7tDTw59rGyoFk32GOr/6xV9lIydTynPY8dxd0jy3Bj0GAg/Tv7UJFj6tNXnal52DETsqw0tvVi0TCj6A2HoQGflEVlHLHsd9R37qoyuOnmFVVY9YFpbVrTCKCRBew6M5xT8ilEFempAj+LqZVU1IbgYdniV2GOGZowgEtEODPn1kWXJ9IU9R+F0/bHWUDn8/jMouXxaR0yPAJS2HmcDNSq6Ec0OddZhQIhgw+e2A3GhGQ52kGukvXOkCuBbggFEx5LPv0KFB3KyQ18XBQmjlbrPjELLaeULah6zXJEMAIlj8EFthG0UpPLUcVNY2Gr74btEurjLQHPyII+JJQb1e1CyphcDOo6o52ilppdGNx2JyXdSdqnOnpkJvY2Q81wI3ZHf9o6U0Jd2dno8yHomDuP/0fFouBXR1ThjIXHa/nJKwRNjPF9+KPkQ9KZA/KQgu2dLfoLzlYj+UdNw6miOoupBGF2ZFYUEkY6zIQjWaEa6QOL0MA0w7zxjefIsUW2uLZqOxZji2oq/QeERp++Wz6fReCY9IwxPtdyRL6X3aYIoxNquO3FW71x2JjUckyVMlUBRsvhZk4AuG5jwXkVwKYs25LxvHivfgzflJIxw9EfVZH++NFzitHA/BU2AbVENKh8O9WqKynJqW2yFpjmKK/DOGJksYVWPdabkI46IuYXfITITav X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230040)(82310400026)(376014)(36860700013)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 19:49:25.2138 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 76306987-288f-4614-c7be-08dccead02ef X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF00026369.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB7601 Received-SPF: softfail client-ip=40.107.94.70; 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" 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 19:49:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1982070 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 4X0myv0dcTz1y1L for ; Sat, 7 Sep 2024 05:49:42 +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 1smexb-0002Lw-5n; Fri, 06 Sep 2024 19:49:35 +0000 Received: from mail-bn8nam12on2043.outbound.protection.outlook.com ([40.107.237.43] 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 1smexX-0002Ks-QN for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 19:49:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vpn4NUSoBLQdOZsrWCmIlQkL6nh5fCOsPm0VqZRoa8v70+tq5bvvbGG9oKClGCC4YBgqnC04lU5o7FMbJ1frsUAl9f8n0EGmP0f4Tg6NYSDuMFHcn7PrmYGk3v2o6irA0QtjmqQ22uYmEm+whD8KohrA0DhCm4X53APQVH6A2qMUrqMMc/Idv5xv6UK7DikVx9+V+3Xq1QUwIcpWbumTypWbZGpIg8fX9W0QrIsZVyqzV3fJiWlKCWyKtDSs5YvE11zgc7MMcAGKma32RJemU6DGzCniXYfMZSnkFh0cFvHGtqe+qe6mtwvFeCW8Lkv0c/mDNZJTmCq0e/rxj9vOyA== 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=MMZp2cjhaBQXqwLgLlOdTtOoVo67jcVyn2i5FtrEBXxWEjqmhz1umGF5GNcD7D7ad1MKaNcrn87Xf8lkM2yiOUZXygnCP73r6vdWh9yQmaUok9VNIHedU0quPLbHWovm9MfDWrP9zAwGyLLPz0KB2fgu+P322eAV+xxAAKB6JWXaLPX1x4R4YdBezFH0+RweUM7OwXsGHIay6UC/vBe6kb5r9SEs1sLPzAtQYU55hhq8Ffg9y5Hf8tQH3ubBXMBZbHyjO23jpD7SxukujrOP0+1bPsFSFTonSFbvM3siMsG3BWdYS2Ygc7s7xDa2AsaiMMpKCBSXAqQ4VcTSmVjT6Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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 CH0PR03CA0268.namprd03.prod.outlook.com (2603:10b6:610:e5::33) by PH7PR12MB7284.namprd12.prod.outlook.com (2603:10b6:510:20b::18) 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 19:49:26 +0000 Received: from CH2PEPF0000009C.namprd02.prod.outlook.com (2603:10b6:610:e5:cafe::c9) by CH0PR03CA0268.outlook.office365.com (2603:10b6:610:e5::33) 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 19:49:26 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CH2PEPF0000009C.mail.protection.outlook.com (10.167.244.24) 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 19:49:25 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 6 Sep 2024 12:49:15 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 6 Sep 2024 12:49:14 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 6 Sep 2024 12:49:14 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v3 2/6] UBUNTU: SAUCE: vfio: Add vfio_device_get() Date: Fri, 6 Sep 2024 19:49:04 +0000 Message-ID: <20240906194908.1127733-3-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906194908.1127733-1-witu@nvidia.com> References: <20240906194908.1127733-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH2PEPF0000009C:EE_|PH7PR12MB7284:EE_ X-MS-Office365-Filtering-Correlation-Id: cbc9e54c-c48d-4836-a73c-08dccead033c 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: H8z8ydpCoPHh4vRREog0FvdKN9LXOpC3ZhkTGiyshwNAoGEJAFxEfyokMhi0VKF8N88qcXY4lTvxZECynLMpHIt4JkQKAwp26/oHEYqLPoQRKxwOx7oyB//zvRYK8/jqrpzlG7upX4TCGlkl1+duV96w9Xtwgv0oLFj1Sc+CDpNjY/VioLSR38dQHe+k0TQyWIMA2aDrOSeqEbQCV0jvNbFe/cNLZWMKtN8icobTS1TnlvxxrLbpO0bof8/r/NItn/8AFDp7JqVZbgH4E0Ze7d1pzCowOra2x0HS2dM/f08rRtv9h/jzAOLI2+3hGLT/bupIc/Ldrs5C/bkub6A0MJkhA33hGYNN3E4JFOCAsy1k87s5exOnUqB/CMRfB6kT6oDgilJCkteV6bBOIk+zF21KMl9pGguj1RS6UAgPFrdqgxPN92ATaMlESIhde1JI5FpXXJ1P5S8yjwteniFI/XzfEsXUnLoxmkoIhgbbpNIHc9oQDvACad+iAr3aRzozyOIVbdVevPa+HworBFYWw6nUv8yAoB7SyVJvHdznnh6dK+vfPC751+oaV85weX5Mhu03s4qSS9uXgWCAOMTaLhtg7c5ORp/2Xlsskp73Pa2qHtUZeJr9eR8gpj3McEXJa7fze0aMuw/pIbdeJ2kAmAeRrQM5ekpn91xhITbVo19wQFFhZFZXFkuC647TZtIVQiG7UANLG1kaZGBAcD18XZyTysDPD8sMbq1xJ/VoN2gRFJp6S2nfRcVMURcyH6rFkDpvadHvjEBx63qdtw+mPKmVTGodJCH0l3Pi3Px4JWnsi7a5/TvOB9+mCLU2okeV/iBOH4WKZXMTbEIinYJ08bdR+HkXHlCFL8xIUNw5SC4+3dpG4SbslbzMAjaUOPmDnpOG56inbmJFrYjRK9V9TQDGe7ALDSUtMRbr3vzPakmYo/PiQfi51dj0QXNrHdALROzQHMzULgvfDhEz1xVnTIWm9qdWe/+AY0VjRueI1ryH9qQAXucY6hbcfv7/NgynjMIqGgRFyFniaUDH25lWTjSu8jqtDaxx3OhYUqKiGNGdTQaFHslwxgvYum8eV9nIEKxVR15RRa8MbfKZHw4ArFhJk7e1iEnGxYZjdwE8mAWG4p2P3O93ysMpRpt6f3no9KxCV5r74OfQW3lKm49k8Zdmj8sTmZ1jBYQrsKJfZeVVKkk+Ov1pL9zOyEgjcdsRiVIDn3kSujRZQMHThXwz9ixYkowN9DHrJ1/doA/p2xYaDYPYrpTvmObeKvn+8uz4vaIgQDIQ0eyJJvLuRcuD1CfBm04nadII9QoFsRXuza37PUw3R6xWfYyjOVnVkSFVeu7tArnpw6opQOJj2PIe4ODRziRGrQ71Gx89AF5/8jhhVpiHX7JVuk1Vh46fl9r/emOjS1hiWs+wmc9Qk4Fp8mRMrYQBs3+Ea+SvD9SrOg6yMvYDo2KZ1yObO+LExcY9 X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.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 19:49:25.7019 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cbc9e54c-c48d-4836-a73c-08dccead033c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CH2PEPF0000009C.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7284 Received-SPF: softfail client-ip=40.107.237.43; 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 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 19:49:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1982071 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 4X0myx1hZ4z1y1G for ; Sat, 7 Sep 2024 05:49:45 +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 1smexc-0002NB-IE; Fri, 06 Sep 2024 19:49:36 +0000 Received: from mail-dm6nam12on2062.outbound.protection.outlook.com ([40.107.243.62] helo=NAM12-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 1smexb-0002Lk-8k for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 19:49:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qSMj/eBaLT43I7rMLhkPrB6DUvP243B8aOI667wXDMyCtIDA07Qa/LvlqYm/fG9IycfNi2xG8qNtRyQc5+zDkOlX/QywTLr3frSDJhmWGA16PxiovQ3HUUGKM47nT1qNjYHPa4mK7I5E5P5D+TH0nQNuX2GQG8QvnEHr3HqJ8qFC21s4+u1oapYIBOd82z72X1W/EteqtQcQQeAnpHukySYWLf0GyUUilwAGKjigv3XqVhRqlXmdT0kvDelPmbofB6zOH/pYRVURSl8dJD2a8tBhB0DA8ktY03qkAXog0JhCwf+UVhplTafj53J1ncrrjVGDsFPJYyQCEyO1ZO+eCg== 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=PYaEF2hy2qJooJQ2TGgM+cfLoqMWxmcF12r/oAj3fxVT/YZLRsAjS5JZkkrvorRUn/YT4UzXnOBK+V95cI1LdBWi9uqz+kDgVBhLcgI1RBlm+IjY/sqTuLhjrGMKQ26ZSMbKl4Qloo0nGbIzxC83FRHQN7DKPOfRvbBB8Jq+UlloJHApsfSkBKPX9nDvWMtvu/uk7mzoFW4wYh9QRbWM6/3roVEA2olRxGTSlgY9zFfuvpip1dFuBH0f8C3Nf3YIpln+NJyNiOfeJYhdmxtp+QZ0tFyZCbrGsDv2WlTnhvxhGujBFbvxVXBKV4NaWn8M61GbuR6DtfD3rs9khg4M7A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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 SN7PR04CA0063.namprd04.prod.outlook.com (2603:10b6:806:121::8) by LV8PR12MB9261.namprd12.prod.outlook.com (2603:10b6:408:1ed::15) 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 19:49:28 +0000 Received: from SN1PEPF0002636A.namprd02.prod.outlook.com (2603:10b6:806:121:cafe::2a) by SN7PR04CA0063.outlook.office365.com (2603:10b6:806:121::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.19 via Frontend Transport; Fri, 6 Sep 2024 19:49:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SN1PEPF0002636A.mail.protection.outlook.com (10.167.241.135) 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 19:49:27 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 6 Sep 2024 12:49:16 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 6 Sep 2024 12:49:15 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 6 Sep 2024 12:49:15 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v3 3/6] UBUNTU: SAUCE: vfio_pci: Do not open code pci_try_reset_function() Date: Fri, 6 Sep 2024 19:49:05 +0000 Message-ID: <20240906194908.1127733-4-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906194908.1127733-1-witu@nvidia.com> References: <20240906194908.1127733-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636A:EE_|LV8PR12MB9261:EE_ X-MS-Office365-Filtering-Correlation-Id: c99778a2-eba9-432a-5e2c-08dccead0475 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|376014|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: FugRTXxjT3EARsjeTDcZr1TtuNtJJbNG/wa1fACrDaQFsTdoctAipiH2CrXmcV9w8nyghIe/OlC7RLYTzc2h8C5prFSndZ3GXpvpBpeuIg/6MBLaLIkoF9WGiSgkR7MhyybmDXSpdi3t2bpFm6szZ/H9rC1Hutueh2cheXw5JDn5qX6CAqxbxNPSzLKyIpu9iG1/b8waIN4CNJ7jKxnpiaegHunVk7hJLvekemHpMKv+yDLbbaNAeSkud5EcoOaetqKhOhMGnA3eltUc64rPSSHJl6S0L76Uaf+B5wGOLBo/tV7/7qVQ3A2FS0qhJMeluQ/UBjclnbAlb26lE3zvhj0fPa5oKd1HJZ0M8zxEbB/2+65LXUTuF92kFwYPads29aQ18L1FJJWnPeBrvwgcHHqgFvrN0zSNVeUQAGbamTP6e7+NGlGQc+VZiMr6LPIqw/zSKSr8KlcKInA8MhZSaXOJPCofNxTL7ycZSGKNJZlcUEUL45bHzyXTKJjEM1+Ld74FuYuhB6CE+6URmwoR6CCDPWebaltLvjDDsyVEpJXSbr4KWA6Ms+QBuhVQqhKnCnVIVK5piNN7Li6aG8W7ia+eNfMzz8d5y/VAwzjRkv7Tb+zzgWBjQWpfzxZKf6M/3tHyoJYKGADVSc76qDhACnO8KzuYk1TZerViLlZ+XR7BEanB8oj/WK46peoI8Mkc7Eng3FzoDqfkcnBqnjKD3k/pAlba1phjlrjJeb9lbu1RW1oBL8og1Qkv21w4NRjQU08h+qQK9/4NrU0DJTmorDG6WnNuUFMKLvYELXrpBgQVQL6UfCkotdwnxabtriC7YfeLWH4f5gDqn1KrMl2KlU50tt+IJ9SAldwZsTQHNbc8yw/xbXTfwYW4FR9+pTReXMTb4WwZpribAtwYS2c/EYFr8wHC+JZcJUIM9EZ0ajlEj57ZQ6Jqg8iCMTsZklLQ6T75paM1fkDrYa6KUGX7w4/9Wcyyy8iuzv0gnfQwwNsXXfiGi1WK8f5Dv8YRVgzAU/w5+sWHEY1FTzimZoMKv7VbyILd0FF62BtaJ8PL+GXGTzCdL/X3fvtKpAV/H7DFAE34iPkmpQ6cCWrPB1IkBJKVwXXcFTmMbyvjWA3tJcuwq/WPPmTiqgxOA7Ft88watTzudrNdtFY9K3CWZXGi8czFDbi6l5kIqK19EmWDaAgR1YeKbFu4CyTWJ5rENYXo1zTeUM7FlsQNeoPuC0/f4+a/pFiQV3+ENg6JQZ8jQiPHj8pcitb8qA8PiQ2KUQ3M4C3Scw2RtZnaQFEIPxHiPOS1AMn3oB+rpuRu0efzqH9P3BFuMxn9dMf+0mmAqDv0a2cLc5BYvW6O3a83XXef50j+eWKyxv6g55/JxNTt5L0PqnmDYph4Tn6FS0NdWzkAYRbwQuAf3DVfgX0nc6yNRaIOVJ8wEVZOS4Fu0CmN5uyATrv7h2N2stgv8KxI2wui X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230040)(82310400026)(376014)(36860700013)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2024 19:49:27.7982 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c99778a2-eba9-432a-5e2c-08dccead0475 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002636A.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9261 Received-SPF: softfail client-ip=40.107.243.62; envelope-from=witu@nvidia.com; helo=NAM12-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: 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 19:49:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1982072 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 4X0myz05YZz1y1G for ; Sat, 7 Sep 2024 05:49:47 +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 1smexe-0002PL-Mf; Fri, 06 Sep 2024 19:49:38 +0000 Received: from mail-mw2nam10on2086.outbound.protection.outlook.com ([40.107.94.86] 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 1smexc-0002Mm-PO for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 19:49:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tv3v76cEDYR9klKQxvKvftcGYaPQ1uBm5ViBVCi8dzWeugWn8vLjY+cGQzXbQnIfGqUwM9m2+4b7+rK0iwLCwTSYAYia6RVmAAiHreyUTteAdzmVUGkdKGCp5IA81p6Cj/ewVLDV6/pfiCajIIltHKzkBc4vQELQQOX8rx2YU7EFYlUWMze54IICGVRGVJxT8oQ+vdyMGs20TTAEXgUZEn6F43NnqYCkIenc1in83W/y6QnJawIFXvUioKh9eudX7qbiytrZN0JQ7umsuLy1v7W1v2sZ3zSXUTJt3WkusawE8TXXCk4hOqIrRfUWcHAUHc9mSMj/vR9tU7JPtlWBUA== 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=39wD6H/w7feXQfnzn5Th+Y9VJIDIP181II4OliAcCOQ=; b=LUtCsdiu+B935O3ZJ19olTneHnWVnUNBHKGrN81LQ0Eqyoso3Otcx9mINsVA04EI7LfsIKz7OIyY553Ut/2DQxoQRsfY2s0xzl4Y8jwYKMK/g+0Qyp8HJPYvw8+8eoyHfxtzUmrW8P3uxExtc1HoLYvoCNb/+484IntQZphth34+55T5+5pzFICv/DznFJGzwQBouhBvN5TGVvEeSI6dqTPVy11Blp5jgmduG88shKEl3Rr1kmUwv2Hy37rz3ONAO6fZbJHfiwI1wdDbACA/ecwXStXZjOpUr+GNt8DgorNTnMEfyELXCliSDtPQy7gQCZS7XPSDf+B3MabXdqr6Fw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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 SN7PR04CA0081.namprd04.prod.outlook.com (2603:10b6:806:121::26) by DS7PR12MB8292.namprd12.prod.outlook.com (2603:10b6:8:e2::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 19:49:28 +0000 Received: from SN1PEPF0002636A.namprd02.prod.outlook.com (2603:10b6:806:121:cafe::66) by SN7PR04CA0081.outlook.office365.com (2603:10b6:806:121::26) 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 19:49:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SN1PEPF0002636A.mail.protection.outlook.com (10.167.241.135) 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 19:49:28 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 6 Sep 2024 12:49:17 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 6 Sep 2024 12:49:17 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 6 Sep 2024 12:49:16 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v3 4/6] UBUNTU: SAUCE: vfio/pci: Allow MMIO regions to be exported through dma-buf Date: Fri, 6 Sep 2024 19:49:06 +0000 Message-ID: <20240906194908.1127733-5-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906194908.1127733-1-witu@nvidia.com> References: <20240906194908.1127733-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636A:EE_|DS7PR12MB8292:EE_ X-MS-Office365-Filtering-Correlation-Id: ede4ac7e-4436-4c9b-58f9-08dccead04f1 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: MWNmo4TSVN6+ey2ClOp8zPigoS/wggm8WtBWvP7o/Mc+E1A3Kv6CoOtfyKZMcRKypo6M3UEQu9CQ6VJkutKAKts+kBWA9VDY/kaB4YF6M+6tSaVADdXxmsjtEe1lPaqXL99ycMfu5cbl6AJdQVO21a7Ytkzp795xa1tw1wsNiVMZv4hOp9A09EWd2PaI7WitSlSbe3NC2pjbiWwrK1LJawrLPlFo9Y+YpVX/gr71KUUo3CebQe7VmosLucm5v2nAsvklaVMzD/Nbj+bBQ1x7EnA7ouUYkasZh+CvWYTi1/EES/Mo0SHNFUYQob2DtIJKSZUE8cDLaqbkP+d28LhZjvCuklf2/4hqYegOAEqlY5XkM4zQOZIHCvU+K2IApSQyxRkJvizqDRKpPv66Q/GetYiHnQ3G0SSYsD9bnrkiDylwk2DNs/mb/vvze+eFngFsAqeaxUD3qMRF1+An+BMSxp6TbcjtOkpb3qvn1Y5zmBXn8XLXWYtsrJ1M8JbQOxEvhJUix+EzVUfxkvUCBhe0polVq8Ono1sCfH77hS3dVSEdg2XxXmBOPCLHiVl73cUOwFKRmRtPcoFdXUhfSVVf6NsRIO8G62oqZ93C/UH+kzt3Sc3u7eMhptvMxGrB9h+UXGLPqDK4vz5idPXkefq14u0J4JLDJ7y97LzJwgsl5SFXSXm6uln8xVJjaB9e3jaLiSiTjpBInNE0wg8yKFHEh2uDqZ6+hsy+2tykQja1AQ2nVpkd9FwCljDL3q+9RRr/gEgQq/Z2jYYCTw1oImpea08D5STKajkuzuhlkkY0CiDCwhIVfh7JvI6q+3lOcKeeRQpTgaLI5Xdj+IJKbo3dssrsU99AIYbQg+muxeHrl7exNsSXmbUpvqJP54U88chZ5qrW8ZuAwCHE1EOZGQSJxggYXGly2bPCR473NgG+2xfGCuLau+40zK3z3U9CE7LYqqWku2gswKphFX4W3/TLBBm/Os06DMbsPEP1CIzXUFwAHYgycP7yQ/HPguW3KyPFTDrkWq1nRCJeOxrLcC+kyJtOdYTeC9H4/Vp1vDcQPBxzFPJR9c7lkZ2T2tueBRr9ai4WGC5JFD4IbgafkMZyg+ucv//KPQdTCt3n5Xov7+958MfotaDLaaGlyo+YNv67u2XJ+WOWN55kPhp6MRCyXZiNDtbDB+N2O3N+oNQDx7bVaH8WSbhIMl6O+D/cUqfw0B/VzvTkd9Dibu96/n2zcDQ5ObgvE9Wu8qzDLwMQZwBnCTevSO7VOuWvu+5xabba5C9VLT4B6VJgLBBTGqUDNZsY+/4bQDo9qa6jDtSzittNyGDdqYqlm7oHyajcc3uGHbWaVnpU+lVsB6rxJsTTMhUa74l5ZX0Tc9XpvQj2jbNfEgEtULFiuSSDkOVlfbNWyKKFM30ytavFTCbTJVs9iuT1r3RZ7aAvOCPBj33D8mQm7/rEqi+C1H9D6U38aWzc X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.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 19:49:28.5951 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ede4ac7e-4436-4c9b-58f9-08dccead04f1 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002636A.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8292 Received-SPF: softfail client-ip=40.107.94.86; 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" 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. Co-authored-by: William Tu [witu: Add new ioctl uAPI for P2P dma buf] Signed-off-by: Jason Gunthorpe Signed-off-by: William Tu --- drivers/vfio/pci/Makefile | 3 +- drivers/vfio/pci/dma_buf.c | 262 +++++++++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_config.c | 10 +- drivers/vfio/pci/vfio_pci_core.c | 23 ++- drivers/vfio/pci/vfio_pci_priv.h | 21 +++ include/linux/vfio_pci_core.h | 1 + include/uapi/linux/vfio.h | 28 +++ 7 files changed, 343 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..14d32a580190 --- /dev/null +++ b/drivers/vfio/pci/dma_buf.c @@ -0,0 +1,262 @@ +// 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, + struct vfio_device_p2p_dma_buf *p2p_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; + + 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) + 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..096f8303a207 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; @@ -1193,6 +1198,14 @@ long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, 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; @@ -1826,6 +1839,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 +2152,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..d60e9cb99140 100644 --- a/drivers/vfio/pci/vfio_pci_priv.h +++ b/drivers/vfio/pci/vfio_pci_priv.h @@ -4,4 +4,25 @@ 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, + 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, + struct vfio_device_p2p_dma_buf *arg) +{ + 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..18f369426c13 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -1002,6 +1002,34 @@ 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. + */ + +/** + * 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_P2P_DMA_BUF _IO(VFIO_TYPE, VFIO_BASE + 22) + /* -------- API for Type1 VFIO IOMMU -------- */ /** From patchwork Fri Sep 6 19:49:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1982074 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 4X0mz1222gz1y1K for ; Sat, 7 Sep 2024 05:49:49 +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 1smexg-0002St-VX; Fri, 06 Sep 2024 19:49:40 +0000 Received: from mail-bn8nam04on2048.outbound.protection.outlook.com ([40.107.100.48] helo=NAM04-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 1smexf-0002P0-65 for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 19:49:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=e0FapXMsI3zYfWbHrEdMwgcpVKyk/oyCZQsUHKKTU6hfNcHz3A7ykgzfQMpcG4uEjVgSMrJjFmdHEx57FlLNzCxHGSjxTnQYNPtiCzQxcNMyHnQSl+x2T0cG+hrbWXdp4APpacJmkl5K6uslNGeDK9PC+ofbVBNWovWe8UJuxc6erxKKgiQ2zY0wGFzj4zerlgn8iUYU79s0plkp1AtSXw986RHK4uZ6BlkYsrRhNM6BRVA9eGaN2i6lBRVz6jIdA7q8yY9HfkZUUOF0M5IQv0kpPL+7BRXtE+4n4Aw54k+Q8DJFv/OXBxNVvmJ4/UL900c9458OxFhLHQuxvcrvEw== 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=yFC3xmVz1MIRSlx5zQS5CondPztMnj/Qz8Vzpzk8Fqo=; b=jwISTG9WhA1r9eJZU6vZOzSVPMCi65yCBB+Aj9fWk50A1X6yDSouAn4aQ8RgjWLzeqcI4oFV1UGKP9+zpkq+BshACnGxLbPwy4BkJU8qslJum6pjOKKNPlkB2Y5RwZDmXr6V+dNJETy66kaRkm9tsRdlKJWAfB7giSb4z0sIgRNcbCrXxeYmnrlKG3rJgLfcIvHIRNgaWQxxJRcpZwyhBCa0eBWTyp93Q+MphCUMQHvtoP/gl08lgOHJxL5q0BeRxP3u78tu22O6ib+hQHodpmvk4+FtgsFsQLf1D4ypRfBRf7pWb8z04Fl+VLmzM2j6XxC6aiUCgQO5ITv2ACQe0g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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 SN7PR04CA0073.namprd04.prod.outlook.com (2603:10b6:806:121::18) by SA1PR12MB7127.namprd12.prod.outlook.com (2603:10b6:806:29e::18) 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 19:49:33 +0000 Received: from SN1PEPF0002636A.namprd02.prod.outlook.com (2603:10b6:806:121:cafe::93) by SN7PR04CA0073.outlook.office365.com (2603:10b6:806:121::18) 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 19:49:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SN1PEPF0002636A.mail.protection.outlook.com (10.167.241.135) 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 19:49:33 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 6 Sep 2024 12:49:18 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 6 Sep 2024 12:49:18 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 6 Sep 2024 12:49:17 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v3 5/6] UBUNTU: SAUCE: vfio/pci: Fix p2p address Date: Fri, 6 Sep 2024 19:49:07 +0000 Message-ID: <20240906194908.1127733-6-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906194908.1127733-1-witu@nvidia.com> References: <20240906194908.1127733-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636A:EE_|SA1PR12MB7127:EE_ X-MS-Office365-Filtering-Correlation-Id: 784aef13-6249-436a-604e-08dccead07c1 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: G+0W+qKCZstxxL/dUiR8VvLoIexVvK3RiQlg854iMcG6wQJ9B68poyxtVrahxtBbeRD1DDOHDxD4nPIRyCm/recrzze0tKxqDVUJoDLw9+F9DBrB8oRrXWn+blmK2JRW+qZK0jmKtn3sfN1Kbn5YwvLb49pa1f/jjjvEVd+7eYkPdUn0EGr0J89HPFk+eGuh4xxIZM4gBdfBxjzUcKPRDWcopj1xRij8GyrNNGTnmSL+l2mEFKYeMl+dJ8VAZQJogtiKBYexv2FF89SROXhOpEqxmRNuf87RUbQTd0hyTyo/0+HgsLX+9iAVQrYqmK+/nEdhRYKJnDbHpjp0Vw6udepX9D+reUOhd6O3xJjZbzY/fRGm7EOxA8nZ/hgxtMpvevQvU5RR9njrqp4FycVMmH/uVG3slnbZfAIiCcUYfed+e/nAxFsRGLRI41x9wGVur6njvvbRaxyHKQazPaWGewFDntlViTI13076c880RpKuxb1PfvBl4R5SppA2O2ULbp2ez0JE+D2Vf0VlOAAdno4uvkdtnVoShr4gEJwPJN578Iw3PgY16Bdr6UYh0LTP4U0v7f7OLUbGADwpI/F6elIE66HdJviJSY2Qz3B4bKF2PdquflJotmjRxLMKL97nZG2tQNsJ1x/+dgGQXDrexZrucSonNy+8dBMX/LYpqhANRA+IadQ2z8pQjSj+oEc9NFUjyPakSCutTs2+J5QpuJLolr+8gdH0E90vMFZw5O1Bjdlviz3mxCpaNThqiXIjbeVXNx2P3giGFmjixUpnjoh9tZ3j6EGyy9YZE0+amnblv8T36Wk1usI9IeaftAnrFZ3ytOttw6KSiJqE7FTUtcV3ljxgc/rR2ws4Vpxbwyd6Xv1ak5EPYszjEFa05ptxnT6rcFCdFh4iOizFUpyoOtwGCsT5Zpvmx0UOab58YDatJCmTm+WUXw2eT0+1mMtncouhjWIBhKnPrNiUMVLSMy0i7QSBDWa7o/XKdj+sil82OGvPpQ7MIlWRtxT0oJ/YiT+5xYMF/PY308cE/43RimNd0a/jccnxa7/0BI2TyHT6z8wawTDVOG+XCqETQzFsV++RWALCMvPK/r+WnroJd2cYKkR+PbgaD0NIlZU571j+jaZQ81tl1671i4dzGPlCq2f46wgbPHNMKQ0fFYEL0WjcYEAjPSSHm952I0Am7HuMUUNu2/VFwzeGjb4067AfWRD8RE7OXqhnkzXBM0pm9uh0aFq5In3055gde22RuMKQfRIZzNwzgRt/8IXO37g59xclG8/7tQur+oL4cZDdvdd9l3iaNDqSNRQrBz3SVk8p5xtbDI6yfu/tJ5R8sGrMGydZg7/zsvmGU72kd3gZC23Y9E1OG/0rkDLJCo8kcAIhDN3vPvltMoV+MaEtogkbxcRzPrZVe2rUZPhADK+I/Catu5mhP2/y49ECj8MRfMu/UpasEchlCWi3E6HDx5Zy X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.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 19:49:33.3139 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 784aef13-6249-436a-604e-08dccead07c1 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002636A.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB7127 Received-SPF: softfail client-ip=40.107.100.48; envelope-from=witu@nvidia.com; helo=NAM04-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: 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 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/pci/dma_buf.c b/drivers/vfio/pci/dma_buf.c index 14d32a580190..58fd3db9c249 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); From patchwork Fri Sep 6 19:49:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1982073 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 4X0mz10MNsz1y1G for ; Sat, 7 Sep 2024 05:49:49 +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 1smexi-0002Ui-6h; Fri, 06 Sep 2024 19:49:42 +0000 Received: from mail-dm6nam10on2047.outbound.protection.outlook.com ([40.107.93.47] helo=NAM10-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 1smexf-0002QR-WD for kernel-team@lists.ubuntu.com; Fri, 06 Sep 2024 19:49:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=x9IT0S3ofEUfagGqP3KdoG9TA09jsoesPC/AJx7ZSRxB/L01XFAZ0x7rR5djjwaMpfv/hVR2REYMT38eYZvz7Ic5vrO0LYyIVMalZv3WST/YiUjk2rX8HRC5lsb2vYoRnx0TGrJ6/fWrnPKQdtJdOOMPU1QoO/oZUsEnn7k2nQUz+s9p8tOBAuYqmR9XEnLZgbbQl4xxloyH0aJQkh9dMqqrNj+rmlhQAYNQGLcgnpkqbrwzkE9PiHFJEexBNooNpCOy4W7KiF5xfzm039Kb3ydX//WqjLjY2qGDREeDhzxQVEANnzH/OQ/SmEB8pauQjJEBhJNwNfxEWkAyQlEdDw== 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=XFSJgL58Tc3bGT+ZtMVh7C3Gi9ScKuBCfAKWmk4qzXwZaVWK/g74FfiATDBhwAKEO2dxbSQJb3ZaAR6mHVtnbpDomTI4DRADnpMTLft6yy2TnIZow0vYHSu920Vb2DV2krnzH5P79LSnaEGZg4EkBul7QlREpSy7twyQrNWfQr/Lfq2/6DFgdEe1ukNsZ0HtRek2Pj85VFtGAscmumKmhSndMJclSjR5vzr/gbodPcVSD57E/YVMjYYNLWGKYebBJXC5ThinuICT3+Z3puVlJXqhbZpRFoBEJ3uJ/NeKGVMGDke6OItybZP0MU70qWE5DIkoGD1ao+z2bRdPTv4BeQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) 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 SN7PR04CA0086.namprd04.prod.outlook.com (2603:10b6:806:121::31) by CH3PR12MB8756.namprd12.prod.outlook.com (2603:10b6:610:17f::8) 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 19:49:34 +0000 Received: from SN1PEPF0002636A.namprd02.prod.outlook.com (2603:10b6:806:121:cafe::fc) by SN7PR04CA0086.outlook.office365.com (2603:10b6:806:121::31) 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 19:49:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SN1PEPF0002636A.mail.protection.outlook.com (10.167.241.135) 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 19:49:34 +0000 Received: from rnnvmail203.nvidia.com (10.129.68.9) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 6 Sep 2024 12:49:20 -0700 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail203.nvidia.com (10.129.68.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Fri, 6 Sep 2024 12:49:19 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Fri, 6 Sep 2024 12:49:18 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v3 6/6] UBUNTU: [Config] bluefield: add config for VFIO P2P Date: Fri, 6 Sep 2024 19:49:08 +0000 Message-ID: <20240906194908.1127733-7-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240906194908.1127733-1-witu@nvidia.com> References: <20240906194908.1127733-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636A:EE_|CH3PR12MB8756:EE_ X-MS-Office365-Filtering-Correlation-Id: 2598a18d-e390-4ded-cea9-08dccead0871 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: GqfZnn1IyFr+aibojDM1XQayhjnOMy3ayskRyElQ2QCotrklVVleL3a1hp8qeFe59M1uVODc+ItIVGXgO8R32Z82Rgt3msG6vfxdR6QpeYfRXqQzSjoM679MuUYxXqeouoKpt5H/No79BoUQ1P84g3P+636Vh9wkG75vkB2ZBzQKPTzH7NaUH1dPSq+vu/Q3/jeWmyrkK02Q/2nqS6PUts4L5ICvHFSa6RUzAuNWtjN2yeUI7gwsHZe4d+FRNjKIHeVhL9E+rGren1xFt1SfELoz8SPeQshNDp8BQkpL7amtilINb5azRU+k51OJTC1pc1g2u/H/35SdlqNtxKfJojKa9EqAl0KhVfJ87V5Q9ppUpVbu+ub+Y0SIyHwLz0SAv2IYsJP564efGmhyG7m/GFJQzSb8YlZhtheSt74TIEHf2PQLfaRQEbBnqkmMjbsQggpEnuQQjbKBwy7QIf/r2E+eyXvzH7QCFgJ2ygf89SEtI6b0hisD5oK5ickp/l0S9IWS/ybL+6CNds6ipMWDdriSHYEG+rAZuEtgBB8hO+577N4SAG+McR6PyxfBtKxBEhf6WVNPYXZdu3ei0WvGUqLnZ2OJnwH33sSkn3nCP8PPGe4rC/N+WyoS4FCh8cYNtLibbwfU6PsYJPqxINnqgX2tTGr7QhECeBRuiXmlmQ0zuA/sFBZbd1pvptCBQbCTg1XE5iiN+EbRKvlUPsuFMw6QR1HiNN904TZMMKoD5SrltLuZe8FC5y9HT2e6tkY4ppnm67ssXeA/wyesMTIYWz5mrddKAODg2KmNNuEjVqbGq7f9FbNXR69UWT9ntnjSq6sMeBV6icOuKoy7nJaOmQx5FLTZTwOwkwEfPWSmoiTIzxmXDPzIV/N7KOxZPHqQnMxldCy8LaPMrZ1d94N5hLEABWQ80uav2V2aYKb3STEcN4C20K8+G+D4gI8RuGYa5r3V4H2a/yBVtlmbP/bi8vcNjYbC0Nmk0MRctOGhzDrfIm9r1Gfpv3RiupJPT0opKdn2Me26pQOZOdq3j0uWcTW+cOxCmcPZU0p60PQJ2merqtCeK9lwLWx0nRdBuFUxCOfHR5lMNBzMa3kDxACmTD/wcEdyZbb6d7vkzOKHEYSvjGbJtVwhYYrWpk/fOxJ0CQIzfeKZe5/3RctKSf1vEMyHbYleraN/l8tLyvOZmzFhtY79qBFZrVO2LaW7YywBBPU0bfFnhQr5ot1kxqSAYPDwLc0YUB8Z7pl5qSW8HKE1q5okz2+IwN6h+3lnrTVqkXSkl4Gy8vWN+gR9JIPHty0spC4OAPvzXGIif+7JQk6VyiHwIPqH8W87pSsNOpxwNRpVyUiAr8/xKVBVhOxlDfwm7XKVa5tR7PSTpycpuqNnzjqFy5OpQw0S3ZanziYR2Nos2lCgyUoP9oGALeFyF/8L4xKSeZL4ahOOjmy5Fu/7y+g+eiAEiibnCnKIQ97Q X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.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 19:49:34.4701 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2598a18d-e390-4ded-cea9-08dccead0871 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002636A.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8756 Received-SPF: softfail client-ip=40.107.93.47; envelope-from=witu@nvidia.com; helo=NAM10-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" 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': '-'}>