From patchwork Wed Sep 11 20:57: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: 1984208 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 4X3tFp2wHWz1y1y for ; Thu, 12 Sep 2024 06:58:22 +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 1soUPm-0001PD-Ar; Wed, 11 Sep 2024 20:58:14 +0000 Received: from mail-dm6nam04on2069.outbound.protection.outlook.com ([40.107.102.69] 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 1soUPe-0001Ih-Ah for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 20:58:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GD5KZtczdePgHpOB6nPYuONE+ecCLNPBVF1xCwyTBlqB0TJRTSsYr3FoD5LsyNUuP8pef7uIB/5COEaEEWcLxtFBO5bg3VE8JqFLljsICyAjgNqZL3An4P3DNNOP1CuEZG3hfE/0rJnKHe7hKizY8+xiSBxWnrlXyz6AISLTPFt8qsT17qble6o+DvN1s9nuR4scmhPD+eKhdpdUB/2gMDDDABO+MBklveRhAao+yxK+1zQqCfSjMAOm6yU7ni+QRDBRlWBEOmRcu5az9VzetEA/kKNSkScOS/ziyej30XajtTtxb7+KfYwrQD2Qwuxs90xeI4ZWHeFTG1nsTuUNig== 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=mIpLxDWzyLD+CEiWBxaKGGFG+jEj/EciaqGaePYqpjy9ikjlTCI5jkCkcwrrUaJbVRusc44fIqW4DiB4S9M3+ms8B/nD90Dw/ChbP6AOju/J1YdiANN37qjNAHcjLE6MXBA4NFOzvKtDix/B6gAnYeoBqughqDimRRzXA+t1RxZ1Nt0lFiZzSNFF9/eJa0DKkyUqfGmi0q9ywJ/K/U0QrlZ8Tb7PiUxRmd80ZwSRKLVGfGRUkryJwZy+bMoPfsgVX6rAVqK4iv2VzmvqBk0iibnqgalo0fcHi8MBMGMdoXT/BL794veM/+exGiKmUQdrD0stywFnFJA+SAWBfTefZw== 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 BN9PR03CA0068.namprd03.prod.outlook.com (2603:10b6:408:fc::13) by MW6PR12MB9017.namprd12.prod.outlook.com (2603:10b6:303:23b::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.26; Wed, 11 Sep 2024 20:58:00 +0000 Received: from BN2PEPF000044A1.namprd02.prod.outlook.com (2603:10b6:408:fc:cafe::cb) by BN9PR03CA0068.outlook.office365.com (2603:10b6:408:fc::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Wed, 11 Sep 2024 20:58:00 +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 BN2PEPF000044A1.mail.protection.outlook.com (10.167.243.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Wed, 11 Sep 2024 20:58:00 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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; Wed, 11 Sep 2024 13:57:42 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 11 Sep 2024 13:57:41 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 11 Sep 2024 13:57:40 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v3 1/6] UBUNTU: SAUCE: dma-buf: Add dma_buf_try_get() Date: Wed, 11 Sep 2024 20:57:32 +0000 Message-ID: <20240911205737.85029-2-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911205737.85029-1-witu@nvidia.com> References: <20240911205737.85029-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A1:EE_|MW6PR12MB9017:EE_ X-MS-Office365-Filtering-Correlation-Id: 7893f606-ad3e-4ac3-ae95-08dcd2a46bd3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: JDrskzD+N1anLMR2xkVcmTmz59nMy0JyTRm6EEEgz4IdMVCFaFh9DdWqv8AC/YiZwFeY+9oA5AGqv3/lT1cw8gkRPwibBiTBGtEnftnQZvDQPQ6qi87BOXOaU8olqvRORte4RHuzQHa9ITA8H0Xsw+NlYf2R536vGTI4elaQCSVuNl/RsCzgIq0MSTfEWkf7G2err3IFEA0OkSPkR9VLmqcHYMXnCy2zfEJ8wZEJoX7VTui39N0mScFPR4yogqahXEDmqGZaeCZ/IIV3i0dnNtvLJMHDt460ZTrkoS6PIHmslYtSOIThOGg5RlXjKj8VY+epJ+MCzWW+Et1ezzqW4RKHkfGg2Wlah3884qM3VPfeEcSYKfzJhREas0S1Pk25rYYbr59FFwIPs6PNsq8dIsmIoh5uJlHRigMHack3a+Zd9DbxHYmgRxwUdN4s5o3euZcMdDnwc1mLsCALN+Xp8FBcehupmm1C8Vhg6//MMWPpA/eYaRm1Ui/6tmKhFS7iu2H+PhCJLZpnG5mCWHv5823lCru92ihWAtk6yoSr+vM+Lhf5GKrO/0AcAkNG0IwoWsTePPvw3d2FHI69ORGwMwuzF3SDxzNfZVibTT8z14FRizvTVKrwtgkjaTbYdIxPN/n9w2kL60/20yRQpBQjIsOWz43Vty5x/frfQAQCEe9bcUAZhBKp4YzKDDPmyptp/R1YNB8nmCDi9Vez+GbsXFAa3NihfiU/0dARB8up1CRgV6jlLSAciekB5VeoVpbcs6REEof4Ksrtb4YT7ftb/wK+64GXCQQv4kgQwfRBfXIss5QjEzGyf2V8pet3oZXjbmFWYJG6xhZ/fmbTPW+qb0Wly0DRf+iZBwb4s7kTlndzD/57dD1dcg30k2ZYDl5xw8Tus0Qbc+iBZONIUqpCNn+zCxG1zAcV+ar2MhtPR0iP/5OZnt/bFaCvfXqlt9SLKDzpGpf2LK+5TBy0wxsxb4wDOuaDGEqmnZMcAEvTOWAI4n+eb74FiuO2wvNt5EomxU4grbUDWjGZC+TT+UpHHKHA2u2w4JdoyYNF/5mWBH4x5wJpGLA65gafnU5UU5ybnzPOOfYr32NG9fHqCn/3FSWP0yi6PTXi3jZ4ecNngNbWW8RRQ8/e1M6OAJMEflh+1lrlJ6x1fzKu6ndzZG3jOq3Nbx95cUfwB2VFiSOdeOsglWjQhbteNa4Lhhxc7s/W693DTErXbMKFyLDEZ17JIcodW+h4r5sAuwVQ7fRGpt3fIToeDRAPbY9ebZnnC6f/IOiWaRSmlsE5+E8GiI3C7tN/O+ShkUIR4WUaH5XuiQmrN+51j4ZGmIpNVAPGbrBnsIfxnRmD8R1Kbzspygje+Qq8zycxInddsktNiU/MKgBOgjtRaqPVOVA0vauVmMVKk6TxXA/DXxMFUs88d61Ozs9vn7M5wC6XpdjPryHRCtKty1GK6gLkL/0K1RKQTk91 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)(376014)(36860700013)(1800799024)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2024 20:58:00.3240 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7893f606-ad3e-4ac3-ae95-08dcd2a46bd3 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: BN2PEPF000044A1.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB9017 Received-SPF: softfail client-ip=40.107.102.69; 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: 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 Wed Sep 11 20:57: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: 1984205 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 4X3tFl61kMz1y2C for ; Thu, 12 Sep 2024 06:58: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 1soUPg-0001Jb-9X; Wed, 11 Sep 2024 20:58:08 +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 1soUPd-0001Ic-VT for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 20:58:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sGI18ZlPEO+f7XyumvFh6t8gf0BIkp4592vpSP3xN9AQrMNClu6eq+is9u+V2+9c0zF+4vifrkwH7q6aSOmVNuOaYyHYVbt4wBl+n4A/Q2NuOihgzBM9uNna/x+K3pgN3FV8ifbmim0CMMPeCxrkxZiU1mQwGDyCVxQGlbBfkth0jYi1LtBO+sEMSMx3EaX1SHwzoMq1EkjLMDE+vEDDVenwxvjAmUVwH97oMq6TBXjB3EIKDgQxM09ACDNBDuaxY4ZUqpdN++J8rpJBq1xUZVWoeDnFsUwHr+/9tQ3lsQ6gfAZNLuUltmLq3tRjHex+HCFcMzXs1k87yd9YnySFUQ== 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=uUb3uIGBocVtxrmzCZjmkx6VZm0B0vgpn1rkrg0u0nOInf3XGygWtmOAh4bSGb/Ahjiytts0IZiSeP+zvEH5McS7tHKyq5i5/s71QPDKb37+jmR8IU/KOer9BNRPsDpBX56XCDRqKMPE6NSkAlThQuMnQ7E/MpPA8r6YlGmGoQD1AENnUpOXzaPg4usVJkbNFQ9Wm2ykVPFTUOvs/MBPPAjBlDLyqlefy1HJbrhMcT4I2fQiPuw5l31TdVnEARLn6F9ZqTQrkvQCseM23Py4Ay+M8+AULt7z1FxM0SdV35kX3IFyFKiepM7y8iASsPNW+MoKZu15JSXZDIlJZKTyrQ== 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 CH0PR03CA0291.namprd03.prod.outlook.com (2603:10b6:610:e6::26) by CY5PR12MB9054.namprd12.prod.outlook.com (2603:10b6:930:36::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.28; Wed, 11 Sep 2024 20:57:56 +0000 Received: from DS1PEPF00017090.namprd03.prod.outlook.com (2603:10b6:610:e6:cafe::ba) by CH0PR03CA0291.outlook.office365.com (2603:10b6:610:e6::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.25 via Frontend Transport; Wed, 11 Sep 2024 20:57:55 +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 DS1PEPF00017090.mail.protection.outlook.com (10.167.17.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Wed, 11 Sep 2024 20:57:55 +0000 Received: from rnnvmail202.nvidia.com (10.129.68.7) 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; Wed, 11 Sep 2024 13:57:43 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail202.nvidia.com (10.129.68.7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 11 Sep 2024 13:57:42 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 11 Sep 2024 13:57:41 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v3 2/6] UBUNTU: SAUCE: vfio: Add vfio_device_get() Date: Wed, 11 Sep 2024 20:57:33 +0000 Message-ID: <20240911205737.85029-3-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911205737.85029-1-witu@nvidia.com> References: <20240911205737.85029-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017090:EE_|CY5PR12MB9054:EE_ X-MS-Office365-Filtering-Correlation-Id: 37ae498b-ce2c-4682-a315-08dcd2a4691d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: zWnmTHqpWeNsT5X4t1RzgU4M0rpTMnMqyHOntjTjphH01OpCtyvl9UDEV1fDSkC94Lyee22ERYYarJqi1dBAtXAeJcP/xc2LGQfJss2cyJGZ2c5bFzjO7uIlmh2Qi7YJQ3SeKU7SiuCdebOVrGHudZ4Mo0xrex9+J/g0iNvxAGVZ17zHIR+81WUxI2XttBrDZd3U616Hql4xnNrrDS4wsMlzaH9KzwECHydRkvf5sb7w4bPTkzYs2CW6lOacfB6s78B1v2gCTmPik0gOBnPIxXrOFMf6+uFkZzd/wzC2E7NAUl6RuBgaSnPaYwoekjbtjWtYI6z5RQyaia1uxE9HZQkrymElqm/Yb6qVpKlGVNYr0ofLoBAXoePTc2IQr03xtwA+c/kGSWrSkvS7COtt8richOjKHP4HTzOAobaOyPTBXfaOMts6dMmQY3pizxHAYJRZkA6cPVEayXYk+NnPXVuJD60WSV0s6Pm/rSqaZsYxS+6Z0EUvVQV+N3YPA6zrpUd+urdjDe2o040SuiZvhN0OOhAKSg0FPZ3iWT1XW/7wQbW0hYapx80HSVmIpZHDaW8Kl1EZUwndlBCmR+djkRhx4hVlAEctBz3UH0/vhRM4YxOU+oeqGRCq5X5T2+hJN91U743a9g3mq5AAJc5ugSwPPxXZ+yMk4hiIr8cmmu/yOlm2Qa5sudZU5IW91iZWRV0jOGBIb4RkxoEtl/qODQKNt6Gh5LSCxV4b4+jrssDaFTXVp/AZVMoyloRO9pzS9uT23LsCvAhPR/OZhDrwGKQVDc+Gfkb85hOB7WIbvNaV904rzQ4rGxVGQZHrx8KIQw0KcH/xHwexA3TTua1PdFVE8EK08I+6gYXhUVxspTLlBXFqqYzen04cFuj1LEdqd1GzIAAYWv9z+tZ6wFRnVWkeC8Xw7tO/IxzAceyjKIFWoXyxVhvlNvykR7z/rZUrr35YUdayV0gY6ZAdENmkQQJWwQJv00cI0e9yi4RIC++2TvldUHoxa9jvitlMpn6ZUkZfIv8kBvo/SK/JJ3rcv5225t9ehCVwHapBFyUSXiVQMhU3MhVXa9GWTm3KaTQ3e2T4QtjqLDKAqfoIz8BZcUPiuy43zcOkEopqqCWCslR5XEJLG0D+49VvNAyiCN0K8YQ/9QdN4t3aiS91xIaHgDk1hITTd5CL7Us0/Q1JX6lbm3mzdhrx2dSYCpYsI4fbsS7Cg+CGGLlID9o8H1PbmFZa+Ezj5VzYZn1CE4sVT4cjZEzGVVEv6B84GPgb4u6rnh11hicoTNmaiiUdIHRApHLkRLuJ7CO2XFObrhsfDjIiDIYuiykkvVHIpeCNo5mKhIDG3yKjlvNPw32zDOm4oTP6li7ZaJzpCBzZ7g5v6zduyt118ff+feLLPjKwMKAfksipxzb4qMZAzItUhxgjZ1FrySY2RJJYDlt5724CumWujb83Z5780EMTjbjABSr1 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)(82310400026)(376014)(1800799024)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2024 20:57:55.8537 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 37ae498b-ce2c-4682-a315-08dcd2a4691d 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: DS1PEPF00017090.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB9054 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" 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 Wed Sep 11 20:57: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: 1984207 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 4X3tFl6chBz1y2D for ; Thu, 12 Sep 2024 06:58: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 1soUPh-0001L9-Ow; Wed, 11 Sep 2024 20:58:09 +0000 Received: from mail-mw2nam12on2047.outbound.protection.outlook.com ([40.107.244.47] 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 1soUPf-0001J6-Ov for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 20:58:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tWHWq/v4nB8nmssO9QS3iOCfVWRh3YJGNJFtctm7Wrq+VmdQ4+i2b2s0IOocnOUNQiBchF8yIyfVLcb89roXFrVIQgOU43Wd2ICegJz4wcIELW6Fe2F34rJrcZ3EiAzSlNgv0RT8EVOOgh8KprY7gPhsj+J8z5s4QU7tzficmw4g2kMKFmcOf+bUi4cG4EDLgtZDARGmh6fWSNG7Dqmt8FtPCs/1SarviEQL6lk7Qv0v8/aS3uwlUNQ1p2CaSX1u3qfYACDeajwSh2sijqj3a5WUK9cfGnh2P6uB6J2q4IqhZW+snsI0ljd8/xRqk5iGEz6PqILfxrPBZEllAL+1Eg== 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=qLYGHhSns10bIDgYRzVKZ2pN4Xao72VnVNVJGdxvhRf0TP64FJeDiDVQnmT0WeEckocgjaodMn4Jd0ZXxpi1vwAfon6WAHsnONRCmiqnuOelznGumPTKMrTzVHY4Vkrr02ZZ9d1ILeNv8D3Kkf0hZvXflddtrrbyaF8eE7cClnmwuZnpmeoYLAMJWdgIQhYcsqy910mq58SVusiFMHFCI77rzKIV3xBCkL9kMpLzi+0EQaC/nrIMrpDd9g392D1EX2dTonpDQnLLKw2RoIcaCaw2WmcqpaPWO+jpvnqvAHVyW+Buj3UNHL2flBE6KYCx0A4NjJ4Rjp7EAbHGuE6rpQ== 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 BN9PR03CA0062.namprd03.prod.outlook.com (2603:10b6:408:fc::7) by DS7PR12MB8273.namprd12.prod.outlook.com (2603:10b6:8:ed::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.20; Wed, 11 Sep 2024 20:58:01 +0000 Received: from BN2PEPF000044A1.namprd02.prod.outlook.com (2603:10b6:408:fc:cafe::81) by BN9PR03CA0062.outlook.office365.com (2603:10b6:408:fc::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Wed, 11 Sep 2024 20:58:01 +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 BN2PEPF000044A1.mail.protection.outlook.com (10.167.243.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Wed, 11 Sep 2024 20:58:01 +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; Wed, 11 Sep 2024 13:57:44 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Wed, 11 Sep 2024 13:57:43 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 11 Sep 2024 13:57:43 -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: Wed, 11 Sep 2024 20:57:34 +0000 Message-ID: <20240911205737.85029-4-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911205737.85029-1-witu@nvidia.com> References: <20240911205737.85029-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN2PEPF000044A1:EE_|DS7PR12MB8273:EE_ X-MS-Office365-Filtering-Correlation-Id: 5deb2087-3bca-47a5-4350-08dcd2a46c8b 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: oL5FPZmtt62LLT0Gt5M1Aq1yz95nk+OWxUrVBbk98dsCUwKhCfMDM46wCDtVSEgtnZlXThFy/oOoLyk/nM9K64G/dzGJDYRWiTXlNh7w+6sjlKckHo4ndMH/OZYRPnjDgXb2y5G4vFO3upx3DznFlNqETSd3fugek8MhL2Z0yw3mNN+buZRfNJHLKcKuw5WUgwTHlwNHG5SQmtqly2b++1TBvg/8tdp/ju+UvPnrINf7WxyDvABGhVrHEoh+Y3QabadwacEfaQQJJ1OlmsZ80Syhu92u/LaVO2giYTqYNruqe9qtGkzUPIb3W64ed+YygO/jKj+oTn4RRbntR4NSaAhcd/tsx58MqtCDgfPgJc9tCWjOw5hVAGHJm81s4JtblWYgR2ad9u3LcyMHCGLh/eXkiDET89lgRekW9LoHv2BnPq70RZ8UJh0VGtguSP9u/E1brL1LX7fGCWGbQEfXOFoziAG8/bamZVi0aruB0ozBRVgSsqxBIp6DIaitynVEyoc+EMiG5/snTEjpHWwmoN4uMGIIGLzKMIHfzEwmx14Dl2P2WddDK3AaW2tj4ydZwHzFG3TxQcNcTybDRaXAbLcH7r+ZjkA8HIO9m5hiM3cZhX7G8gfDGN7lIysoaHZOAiEq3CoVQ1Ko6KDGKUQ/2q2PEymGBhjKqHQpq6dqsjaLMiYiUVR9TXIJ7+Rt9NB11beSRlmgMTNywLS+ly+Zfw0s1rR51ZCjGNsEva1ooLGI7qR3bO5mdh19pO4YJYA/WMfNRBz6BmIYSB87R/PNlfFxks8H7D6q6nwpLnJsWCHYAxQvAFuc/7urLndxkFVmoGveSOoTYnmYifa5URpzK3Z0rbFA5oEmrh+bGpk0qmQNDxYwgqvx7wS0fbuGsi1bQAJggZFURDhQVmTPduRKPb0deMqPS+qrKQWIPhkdvrP8YhZzPzeFsVAGOoPqT42v2Ymxd8fzKEFiG77dVyY25X000b2oZSc8xQkZN8V5jOKajyurI7CCIH+pVPcd1MeKyECifOiTCedGA81uP1NGx5RN1BmsyQtLb/5/wtyw0N0Rc8bWVi5RkejekD+Dk+WDuU/CKAhPeo1KiGdCKODXPhjF+pqBmsRG1u+FgBSKAU/hTPiNPaugVkB8/T0p2zktAixXu4QjcVEYCzR4/I020j9S7XpC/0uHvtv43+AIiWeKM9esk+rhNVSRi4PDZVKE+/ikP7UpDG3IabOiuAUF4v/7T9uq453fYZ+qtpan89sL1iHu2jVyeBZY5SBB6ZEFiU7NIbpoLD35scabA7B8y5JLa/MEJk2DPdNXJxAXH4yPeQPUoKTI8f4MK70ZPfjeX3CKvVbrDoif1bYx56hq5IaCxIRYO/+AwYiZPlpzdxWCaEtyTpWYS1P2dpakgY6TXhE54e6xlz7SKm97hrQ/BJAdNYaaoF0n1/vOad1mTOTjt2S/ozAMH+RSSnu89Koi 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)(1800799024)(36860700013)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2024 20:58:01.5272 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5deb2087-3bca-47a5-4350-08dcd2a46c8b 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: BN2PEPF000044A1.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8273 Received-SPF: softfail client-ip=40.107.244.47; 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 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 Wed Sep 11 20:57: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: 1984209 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 4X3tFs5G6Jz1y1y for ; Thu, 12 Sep 2024 06:58:25 +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 1soUPo-0001TQ-Od; Wed, 11 Sep 2024 20:58:16 +0000 Received: from mail-mw2nam10on2051.outbound.protection.outlook.com ([40.107.94.51] 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 1soUPf-0001Iu-N3 for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 20:58:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=d1VcQzlK/TZG6J5qfgNuUyGK7wv+hGa5RGJ43RoroKvpvxBz2wC23YwYgm02BUSMIuJcm3ojZ2iSeWyBjmPrOWo66HC2sA/RF4sU7TTeS6tHvUwE8q7G1pqGyHUQ+r1/WKzaad7vG5A3ht6FG84aRPjQPyoMnnSuLYZPpzec2WXmAMh6sfmL83f5nEYuUDmbLix3FuhD14DI7l68Kl9P0aoFvCIHA++m167IAEy+cZ5vl680pDUtFnzYI53JiYUe2SUZIo5HyYZzjjlQ+cIyAxNtrjeQNuXZzoLi5g64roI3rcgWlc15yz7mkLlLnh+2q+8itIXFS2j6ggL3stM0Ow== 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=84BIgDI4OJi1NmmmnLM9/LQARZ7bsMnZhNTomJiRYgg=; b=V6mn0I9BMdc7xrLIn1CLwG6ScxpK7av4h3sRAcYZ4YGy20s9vKMV7T5g945gWwKFQw/A/vW44NXC7DuI9lHYGAbWgcu5MQmjJhxUTo5GLoo3M8wY4ntheMY5gQaTe96TznJO+GZSmW8N3Ey52OJTE2RkFBQjn0R6T4zkZ7e/R+ceGhTDts98h8juG5iNa9DmBPLZeKO+f9/M9mw8uPl3gOOaVqXmp/NOaSdaeMP9tIDVubX93Efa8g+69/8PzE61TCQzOQTnrHeKxxuAYvUcbErh75VweB5//eX65Q+RHGs6LFhzFhTRfdgJyVFc+klOMiIEClkMqX/ykk9wT7BXVw== 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 DS7PR06CA0037.namprd06.prod.outlook.com (2603:10b6:8:54::12) by MN2PR12MB4488.namprd12.prod.outlook.com (2603:10b6:208:24e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24; Wed, 11 Sep 2024 20:58:00 +0000 Received: from DS1PEPF00017092.namprd03.prod.outlook.com (2603:10b6:8:54:cafe::58) by DS7PR06CA0037.outlook.office365.com (2603:10b6:8:54::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.26 via Frontend Transport; Wed, 11 Sep 2024 20:58:00 +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 DS1PEPF00017092.mail.protection.outlook.com (10.167.17.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; Wed, 11 Sep 2024 20:57:59 +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; Wed, 11 Sep 2024 13:57:45 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) 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; Wed, 11 Sep 2024 13:57:44 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 11 Sep 2024 13:57:44 -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: Wed, 11 Sep 2024 20:57:35 +0000 Message-ID: <20240911205737.85029-5-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911205737.85029-1-witu@nvidia.com> References: <20240911205737.85029-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017092:EE_|MN2PR12MB4488:EE_ X-MS-Office365-Filtering-Correlation-Id: bb51e300-524a-4393-391c-08dcd2a46b8c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|376014|36860700013; X-Microsoft-Antispam-Message-Info: JBiVlk5fJWMa/4ucly2hKNFai1Sl1nqlnHV7tGxXvlnH/vGqsrdhOJCBGCLWD5J7P3pev2hXcL/ZmQZKmJEHsYbB+1mgor2CPf5o9+L4ulht41qbkrxWy+38yjlCg2bKP9dz5vqh6BJ7uBx/9WNF76aKP3myQ5VlM3P/k00331jLD1Fco903IZeXSjRD7sRwojQbheoXQGRd/X08Q57ye6MUau4GPd8nfAENyUpfkNXK6jEK/E3PRBMdMWx379qOmeM1gDbcaWQvdTMl3XIaOOnCgLv138eOrOZV4LMev2feBKsp4QbTexe7CdpflQeK8Oqre8KOc7ZQUAQYYp63qJjjDqqp3l7eeqeZn5FWjnxCcuSe7vGJyZCeL/chMHoKe0QPhKv7+dBCLuWJKq4mikEBC6kuft3SXmogO0V4DhAnickhZ4hpuXCKiNZPPlKCbveSEeJHFg6v0W/E+e7xULN8s+oLrBaK7QysiPDUetyaeCTHUwBcV99USODxTaxNtVVKDS8Y+ri1du0EDk/E3jkD55cyJ4Pi69Zfez1CwxbAxbJxBNKKhM+SI776ckDHxFED3S6hsGidb/iMuzEkDM/hOqblrNam/CsP2yIDAVzmR/yVp2pp8duY4cPQOg8Siy8HQKDkXvl398LBqfKQozBykYXZP2mb640lokX0OonwdpGb6sUHQHpdbI2yenwsPNoxW6F2SCy0KoNu32mfrpgSyPh+o7SgHniNylfkCHuN+ca2Rt790NlUxUF5H/FfIW2ROObLVGghHZvqe4XX2I+Y54WlbSlENKfcRsduCf5HQNIXTDCKwJ5DtidfuYYnZG8BQDA9e3UW3SCrdXQWQhgyqLrq0gIpMlTSCJeO404T/TysC1HyK3exqUDqO2tWB/xVpUPK1wm/Hqj/7ww4fLR96AzcfYccmfWVnv1I4kFiGpQhArQnw5gNf9xhCNUMBYQUySEwf4DkZLUaVHGl1p/D8nXFAyXdsa2g8kmOZqNHOXKdiMne40iQnOGsm6wTAx8lkzCweF5cV5DDYWhVKM/EIHLF1biHOPqPODo0zwHuxpCuVa4ufpx9U4JfVsJViUWZrfm25hyKKbPklGAlBSDrTYsYH6HubTZaeUscXWOjvmbCLe7biNvDoDLj6UuI1vAyOF1gSmvg//vVgthHNjzX8owqGMwXS1OTEXV5/ltcONf9UDPsHtJpy1YG/purFiVUoRo1/DcFj6gHWIxtYZKh2IUcz+RkxiiXvgNKMntGZcGHB5TSQtaFfa2FPwKKv74XK0lQUN9zAPZ2/8WqlOZkp7SCntauoQCoS9usYq4jV/CQLWa2nJRbZGZLAZBX7XJ0Ueo1gznsWzys6z8IOVh6exokekb2iHWcw35bCwwScqnzyShigGxqjqj18GaiNaxMsKsXTK8V9IJ/8VofRZEsY+8rIrd+cBljl09TPxMEHB3e6XGwPF8KjtKIU/wz 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)(82310400026)(1800799024)(376014)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2024 20:57:59.8557 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bb51e300-524a-4393-391c-08dcd2a46b8c 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: DS1PEPF00017092.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4488 Received-SPF: softfail client-ip=40.107.94.51; 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 | 1 + 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, 342 insertions(+), 4 deletions(-) create mode 100644 drivers/vfio/pci/dma_buf.c diff --git a/drivers/vfio/pci/Makefile b/drivers/vfio/pci/Makefile index 74ee55f9c261..14f198c9d9ea 100644 --- a/drivers/vfio/pci/Makefile +++ b/drivers/vfio/pci/Makefile @@ -2,6 +2,7 @@ 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_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 Wed Sep 11 20:57: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: 1984204 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 4X3tFl5y3Fz1y28 for ; Thu, 12 Sep 2024 06:58: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 1soUPg-0001Jm-Es; Wed, 11 Sep 2024 20:58:08 +0000 Received: from mail-bn7nam10on2063.outbound.protection.outlook.com ([40.107.92.63] 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 1soUPe-0001Ij-D4 for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 20:58:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JT5RPPnEnlbW2VOFNVLmHnLM/OGNYQ/8+Hek0U3IEVQlI0GU+g31pUFGOoSjrqNcsSNycPuzcgGsycfNz7xSqmBK/HPlGjKKUbiQCUrO05JQxoApwCPYE1ipUUG6C1NQJaHK3H7Fd3d3hVd63CH6cnMYlU1qkJJkcM5dT07Cmxp4txJKDCbZgZTqgb4z0SgLqEDn31fUkRnfOQkdAhbq3DN4UQYn9Bl/ZRkzrXUnONKFtnAMN3CwH+epMBejvCnDMufWC7ZQfJZDNaEkz8oHe+HlLSlhFPn7T76ebah0CW0NK7z4bWCwtabTe+mtJ/UNwHKUbbA1rcrpS9OHTUySWw== 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=ntpbQV9CERUUfDMcECBboyAphCsAuS65H4U++1IyIIUYCdTIbQC6Lod+F/mzwCbywGnM08L98PsOL6A7/sApg6qRpf9DP1IFoIUsgltLYvCW7lLdlpRZEJei6lWDt2Bedl/FiJCVciJ8uEziAIYeAB743DNPGlOLKbLucffZtRzTm6t37S2YVDw8XfSSbhVeMStPgz+ySdCxbrtDcnn4rlB+dO9eVoKq6iOa1mxiWeEATanxejKiypT9SSiZlrqQ2BtaFX/LcGMVBhkPN6vtY/F8ntHY4C8SfLnJ04ku7LQntXuvbsHMsmGvO3CMObUFnPyR1ibVoOTcuEvgWaY6iA== 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 DS7PR06CA0030.namprd06.prod.outlook.com (2603:10b6:8:54::22) by DS7PR12MB8321.namprd12.prod.outlook.com (2603:10b6:8:ec::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.17; Wed, 11 Sep 2024 20:58:01 +0000 Received: from DS1PEPF00017092.namprd03.prod.outlook.com (2603:10b6:8:54:cafe::6) by DS7PR06CA0030.outlook.office365.com (2603:10b6:8:54::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Wed, 11 Sep 2024 20:58:01 +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 DS1PEPF00017092.mail.protection.outlook.com (10.167.17.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; Wed, 11 Sep 2024 20:58:01 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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; Wed, 11 Sep 2024 13:57:46 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 11 Sep 2024 13:57:46 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 11 Sep 2024 13:57:45 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v3 5/6] UBUNTU: SAUCE: vfio/pci: Fix p2p address Date: Wed, 11 Sep 2024 20:57:36 +0000 Message-ID: <20240911205737.85029-6-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911205737.85029-1-witu@nvidia.com> References: <20240911205737.85029-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017092:EE_|DS7PR12MB8321:EE_ X-MS-Office365-Filtering-Correlation-Id: d959eb66-564d-452b-cb21-08dcd2a46c81 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|376014|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: cLbeDmTp9pBfotqzrzag5C1af0gcbA8Q5i/9IZe+Ovc4FY4ZL0Am5vRZAYuY7zV4ZaX5vY7TbVy79ldU15LZm/vW4hmDCBnCC6XpIE62Mb7n1R1nnvFgvMhvlb/1S8KR3TiGPCXrnVmNXockgpIE5cUA8Ke5JFDsl6ylei/QrMlwy6tcB6DUmVDu3Rol0uyUQ9DVaDc9T7990v8ePjNNhNxLGeTm9xeVMjwnRa6ZxrffLJQrUz9xEO8zaJ8foIpClvVkTUnVOrxiJ1F73tXPgQCsSUEzN2dJwyzv7EUydiCCRn7TEXMC3cuv4wEihghhSfbNEXENOxLNyqJaix3rWA0v4HqifenuydiO+MbW09LJAraPQM91/JNKYs4IShjdtkM2aIg9CU7TEm6uda/7cnQk+aTPO3+3+Ps0QDnLf4+xvuRMArMgxy+gtkar1zZ8tLuAnP5Drmb3yNpksPnHYYEc6lfntVMJUlNhSL8WtQ3zAs8TgufHQc84Ps+PM545ymzeIpaNLwQX/VEM1rh+iGLohlIyVMQoSQcN2FDJ71L6/puGGEDo7c6yK9/d4uFXNSK9WhMcd699xOPsKAqFeH44lhzAhWpCJD/mZieXvh7kaRVBnj2KxY18UBSKC8Fa9Sg24J6lfvvb18ibWp7sQT/KRj2cwbXRKyoVQd5VsXNfB8tdGzkWdz1I2XyOVeSuvTqqd486YgFoM+h9rvaNRUV7GvkpjFVMCEObBjqxhZFHhudbR+jSCB80Q+FAnyJSkGwCJA3qPH/jGitFtfDRJr1SJv6yYnwLtZCDkuwRpkTu8aQ9wa75p2qYQ6Cnq5FoCteDKEKz4UJ1zePQWLB7FnMDaTfvYy/ZQqTMJ78dXL4sWdZbdl8/iQEsB0VQwnLukezC47RDyibVoDZtHg1fpOv5ZV4FoJUcLXwRJZ3Z3m0XJrKtxrbMSQt6w7g9pROEDwWd1aCi5kQquGidn3CJWZ/kVVQDkXpXAivh3Upp5NEyZC8JF6qzP1hw9mclCGe4S5PdCdYCc2rPDxIjv7ygSmEAm6eRmTfzh3FgiIjKCWZnL3aF9w+uvbkbpY7MX1Fajxt1uCQSBlqpEjsEAIsSKhnJmmJinLtnFs4zbMgdrpqDSvqftvISRVDayJcvBAvs6U4T2zuMeydBIYgEuL1/2n00QBODtF8eMvNl8XN7EC8uEF3IozMEr2cJ56HJ6HdvA9XzJSTFLhZlbwJdR59pCIry0LVkByvrJkvfdPbLfCRXQB3RBkrgsgCz/ekVJniQ5bnTCHwwDyxIca/B4mYM5c5jr37YvSS2X7gwAWlTmZBnRLbaT5JYh7yaeGje9Rcy2j8frkKD2OkRWroAkecK//vOeWtj3GH2vkOccxllR69aDldcdp9LT2VL8b80yevwAAmx7gsBG8NLR3Z9pcbwWKlooJjLx2l9glV7WCSonlkKirKjGyKMqjzJmJGyg1De 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)(376014)(1800799024)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2024 20:58:01.5589 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d959eb66-564d-452b-cb21-08dcd2a46c81 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: DS1PEPF00017092.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8321 Received-SPF: softfail client-ip=40.107.92.63; 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" 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 Wed Sep 11 20:57: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: 1984206 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 4X3tFm06hKz1y2H for ; Thu, 12 Sep 2024 06:58: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 1soUPi-0001LM-0D; Wed, 11 Sep 2024 20:58:10 +0000 Received: from mail-dm6nam04on2046.outbound.protection.outlook.com ([40.107.102.46] 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 1soUPf-0001J8-QD for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 20:58:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=NIr2SASZZiQkFdX66D+r17zqHrjZDKgJj9tg6QhXU2rzzLpUdL7nAdoaK+QEObLVWrzCTwctznMItDsuy3dzL1sMqR08dbx2mq5PDs+vULxWuYqSGCFcDchT6Wo6jbYbZ4AJ7IoejDKku5pTVNxdvsR0G0tFyIF8UL60vOlp3ZRgCv5FpClW7p3o44SUrIHKiEi+uvUhOVh54Sk38PWsZ3G7g43UVK7EZmmWWWf99vS41DB1ZJjWcY5cJWCTDprxudpGmnyXiktfE7857YEQb2CVJWtOeJV6GKufxIPE/rTOHtdIBBEcHTn7PAFbdrdgrsS3RlbvsyAG272v6w9QwQ== 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=hijYxLweSsL/o603cJ6RavROJgaxFfl7+qlBe65h0aEwobiu9MrCjpwFZjKGORw1ieqw7xBLWsLn2Kov/EEUPZphlAY7o6aKYMwSjXUNAXyNfV3Nc0Fz7M76JJl/BX/cWZ2wP5i1WDWsCBaUKrw2hL4QBYkONkgDh5q0rtJscnstVIHzc/+fUaWQfotTb4jQGHITX/b4p3tNlrDpc9t8UwqyKNBEFtBlszKlHyTB7YWvDL+HeHKQQEDY6ZOAFzrbxBcuSX04KDMdYgcVSUeBbyuQ34Mq7clH8qu+0+iLK7rF+tgJfKXMgFwOInal+7PGYahiLSUfhsn0ZnvktG4NYQ== 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 DS7PR06CA0032.namprd06.prod.outlook.com (2603:10b6:8:54::17) by MN2PR12MB4456.namprd12.prod.outlook.com (2603:10b6:208:266::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.25; Wed, 11 Sep 2024 20:58:03 +0000 Received: from DS1PEPF00017092.namprd03.prod.outlook.com (2603:10b6:8:54:cafe::70) by DS7PR06CA0032.outlook.office365.com (2603:10b6:8:54::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24 via Frontend Transport; Wed, 11 Sep 2024 20:58:02 +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 DS1PEPF00017092.mail.protection.outlook.com (10.167.17.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; Wed, 11 Sep 2024 20:58:02 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) 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; Wed, 11 Sep 2024 13:57:47 -0700 Received: from rnnvmail204.nvidia.com (10.129.68.6) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 11 Sep 2024 13:57:47 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.129.68.6) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 11 Sep 2024 13:57:46 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v3 6/6] UBUNTU: [Config] bluefield: add config for VFIO P2P Date: Wed, 11 Sep 2024 20:57:37 +0000 Message-ID: <20240911205737.85029-7-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911205737.85029-1-witu@nvidia.com> References: <20240911205737.85029-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF00017092:EE_|MN2PR12MB4456:EE_ X-MS-Office365-Filtering-Correlation-Id: 621e4812-4e06-439c-d715-08dcd2a46d2f 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: GGJY6YgqNWs5ZWRyaNsodbZycHcAWUsMTIG7aL9NIjHJlWlMmE9IfgmQg8BGHZVgUHwdmhdjl/FzEJVN0/T6a4HxuQGbfb5+olKh9THamxDN7SL4ZcFefNEtVNL85vRrDmQxbyJn02WKDTrx3ULtkJRLYlldqKUR7G2oH0qERgaChY9wV6YKbajc+CxHHNh53/yv3LstB80bqHjn195iSY8JDZFmfSPHLyClmxNbhGXFQ0aJSqNod6Fiy71zfheim1foeJNHp7Ot+2tvVkDwuqrdffag6PSaolsYBmKSqKscxBJYG+zlUO0UaLWnqX++eNd40t/VLrmM9aVeQEFgWIOqqtXzz6nEDzyHGSHjKPFMmdTJOaDCCAisgzRZzzJKM1NG2IH9tEHuctxUag4oMRxHoDD3LjF3sYoW1K3VZ8++tgbG/p/CIf2OgeLjX4ivFTOnVoDPauS9+NPjDHE26pbf6tj6CSpe25IVClPPLcto+wMfuyljHyIhfCYLio6iewqKJV3MpWszPIYNwA3qct4Nihkyb7ayyHMeuIAIwVqkfyJ7avZWAVsJtHBfU+40r0fPeq46L4qn/vCYuBKcplUxkfv4T13qd7Y1aaIe7qVW7SckQsBT4L54QeyLy08Cwt80B8C2n3v2Kgf99+xjColWHu9sEH1g8WrAq44tummRLiEtOUeZACG4sziuoZAK5EovBLFD8wVZsyWFRMI+M/pNLzGuFxbdTrrMeGPLsUivn5FGN6jJT7IhQ4JjqXApckLb6MauEoyxQOowyLCMu34HHaJhMAgsPHIzt/ImU6M4M65WYxvF0DuL9DRfTQ3OOUY5jXcDWPEizBQBdpr5ezHal/i5TzSd8U5bxmRswLPLBSidVxd7ddNsFL/NF4mUJMGiJGTxffA/1CXftHDJ46+zDwnk5MG2n9sj1c1YozvGKHY44D2DQHdoSQb8EYcrRvkFwk5vPffI7PBD5abZP7A7YwtgVRi6jCXxPL3YQHgFB+6VTXPxxr20r/nTYe89UFT9tHieqpP4RMAPvo4ivRm/IXccaUtX5QDyQ0SP6z5AX4ZMJ8HgxymV+9WCHW8ahwP5JuFd0waREiTUY/BwWF4jRuXtL5J4glsRbLCyOQAIz5QI8MTIi2gu8X65dktIKm/wV6yCt0rrIQqqXKY7cFY4K7u3lRjo7wbov7NDzBnt45JPVmCiYZA9KSkwK53eHgkGb0P4N0mPRENGDOIyjpM/NXUcZ1WsgrKD2mXW/4QVs1o+jkjmNT/Qqp+HwJWJpZvxnFXnJ4iWZxFp+4YExUEzWFrbSCPApztxIFFyF9E4JGdEw68lvuHc7lBFodemCvaiWOHU0GO2czJy8RDSvFAsHLQVQ48zzwXQpi6T5qVqsBmIdu05xhbrc4z2FK4Ns/GgFOpkfCo4S75zzx2qBaHOLOuvBA0RDIbCRvORhFW2RFIjPOEGM5K9voHaU+oD 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)(82310400026)(376014)(36860700013)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2024 20:58:02.6526 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 621e4812-4e06-439c-d715-08dcd2a46d2f 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: DS1PEPF00017092.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4456 Received-SPF: softfail client-ip=40.107.102.46; 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" 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': '-'}>