From patchwork Mon Sep 23 22:35:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1988707 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 4XCHrw1tzwz1xst for ; Tue, 24 Sep 2024 08:36:00 +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 1ssreq-00070P-EN; Mon, 23 Sep 2024 22:35:52 +0000 Received: from mail-bn8nam11on2074.outbound.protection.outlook.com ([40.107.236.74] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1ssren-0006x3-W8 for kernel-team@lists.ubuntu.com; Mon, 23 Sep 2024 22:35:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=l8UCetBXVEJY2Rtr2ElUhTzd9HBVW2rqTwahrZuzkd4ZidOxGg6xvnD/lxUqoDLRHUDJ6uyx12H1m+HUppd5+O/pH6RikjSDG0ImNMK7sTJ1H8YQ4Vtc3Apzl+ceTZag32v0YFNC3X3SNhAslNC3L5DaP6ZrWS8pNHSFZIxJHXZKCRFsZ6ubKkufUiUx0tbCXYOZApIarIIHCZP9tVaqrr/k0N6DN2b1QrxmBwGau9VUqUIDX7cnHJeoRf3f8t8tLNZL0/b3MaR4aRzuDYYYrwu3KIgPwAbc6urPQGucwgAVnsOZcpswgsz1vINEHcsLMkyPhcxUv8hp1/QmZQZmHA== 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=j6mvGrImWA04C/TkKwThKJyNQgOun67A2pVZ0vQsaU9fDry4FcmBxDfOSXtHbyZQekzwCk7dzKUKWvkQkIGWTEtXbsKDEElA5wvzJET3xAOgrEguZb26LP3drSp5yCagm/RfbkJ1t3JXaHy2rgZb4GqBF5YP83IvTrNLWB5bpcuKK8GViOamJ7MbK5Dys8NhTsUWi3D7xIgbdQDLHKY8sF/D7QbaTDBGokEi0gfy4WkaWhrUuRp9UJWZMrDqL8Q9brcBqrSCN4ucXYoig6PiqWY70uEarbFK4qnl4ZmZlaCv8Y3ojYadI+W6PHPycWnktPwYr7d2qLfuFoE03NTUmQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.232) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from BN9PR03CA0794.namprd03.prod.outlook.com (2603:10b6:408:13f::19) by SA1PR12MB8741.namprd12.prod.outlook.com (2603:10b6:806:378::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.25; Mon, 23 Sep 2024 22:35:44 +0000 Received: from BL6PEPF0001AB78.namprd02.prod.outlook.com (2603:10b6:408:13f:cafe::b) by BN9PR03CA0794.outlook.office365.com (2603:10b6:408:13f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.26 via Frontend Transport; Mon, 23 Sep 2024 22:35:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.232) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.232 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.232; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.232) by BL6PEPF0001AB78.mail.protection.outlook.com (10.167.242.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Mon, 23 Sep 2024 22:35:43 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 23 Sep 2024 15:35:28 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 23 Sep 2024 15:35:27 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 23 Sep 2024 15:35:27 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v6 1/6] UBUNTU: SAUCE: dma-buf: Add dma_buf_try_get() Date: Mon, 23 Sep 2024 22:35:17 +0000 Message-ID: <20240923223522.1203691-2-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240923223522.1203691-1-witu@nvidia.com> References: <20240923223522.1203691-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL6PEPF0001AB78:EE_|SA1PR12MB8741:EE_ X-MS-Office365-Filtering-Correlation-Id: c9d6eb2b-6eeb-4487-e67e-08dcdc200f9c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700013|82310400026|376014|1800799024; X-Microsoft-Antispam-Message-Info: lzUrEz6nYAlfjujca3qMJwC6hmE3HQKw6TfF5Gqg85d4g1OfE777slB9BML1p26JsjVgfQWF4Ht3GHyehrihIM3bK9STohs4YiosV7b/dB9+ctDM6vNIWcjZQUi3JtYvKr6yxr6g+ET83bVPeSrZ+wdEtwOoAQp25l3Kw0Elox3HLLaFhSraQ49RHtJytjgZgPh45Wxh7tvLw/0JAcLO6a5fYtZdStIadBUEF7Onr8vLvqekbqX4UbvSb2314H8XVzK0CWumAVH0/d7/SGf2Ydlb5/pMoBxyoZ3hDwDChdXIgsdWaj1jZ6Je+pxWUPQJHdLxjm4tRXC73J9TfTVRPOy/2GzXQmSbHADpnRnX/wVvTcahqJNgIn15V0CbXUux3Icw2PUtU90Gzi9QIL1bGL0nawiOxeCpQz+C+MiAuM2MqrYJO+wMWsz9SHosZgnRewyy3i/gowK3RFAvxqmEVW09O8phgyTT0d8uLU4UEBrM13XlTgFHIBZ1qacbn1CB8GvLSIIZ1ujJVQkIiiKMbj0fzxXs4dS3dPM9GuIK/fNuh1FtDkW2uVbKrZd/4pq3ojRoQtQYKFPDs1GCloS/wys9GnDaIZdvVt/jSJTs92TZ++tSctAJsERrEW9xL9SqY2SaGJZA1+R+Efuwny42gqdxTVZZGVnDEDcybm9yD6gCKWwyJnkDNyuRquPXsznYZyJxgnGiw5iIBkmXZWDW38h2x2iHtW88g814LpKA95ojVKt5CEKHgO3Tihp6edVC9XNagMn+PIVQoMnzHslALOh7kwtcZShYbx3TffU6lCs7UwIFAIZrvXLv0nB59De0nMXWrahoMiyT140Fb3FX4w2U3kHgi5aNvG2mQFOnSjKBBhWhclfTdfgr+KEKy9ateJ7C7sq8EbC1aVWrg+xJDzwHlTUi/S/YBxbqkI4+hIqrZM2VzVpsZlahEQgYTvnehu8zZzo5tOeCeuHxi95wRa9Bs46kylahJH9BaYcV/HkAiHd+GMsBj7AwGu299kAcNqRo+dbLW1tQVNr+8NvpSraTAePfL9lyj/UID7U0RAtxybUQwGbM33BKmpTqJoR94UfWCr+M3nNhwk9U7pCC4DfWD34moTLq9NWba8OsbSnBowh3sE1Y9PDLxwtuTdUDJNmpyc6ine99SJedVPULMNkaNeosrSVwM/2G47BXV49/Oy/53G9GtDSwIYuUJLYBySs9TA0VgcPDsXKwZw683AZPTjTuvsRD0gtvSK7IbiRliNJmbCSiw3b9P8b337ZZnhE7iu+TxjUtFgru4DphNAz2CIh6A57ODjUfNuEfa+zz/uJj7hsP9pXq/cS3PepAf9WKbs6CPCpgf8h21S7Ls80JIQbcxxi49ufyorkrfQ2pVDT6/6I1yfo+NxzNCeIE X-Forefront-Antispam-Report: CIP:216.228.118.232; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge1.nvidia.com; CAT:NONE; SFS:(13230040)(36860700013)(82310400026)(376014)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2024 22:35:43.6897 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c9d6eb2b-6eeb-4487-e67e-08dcdc200f9c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.232]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BL6PEPF0001AB78.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8741 Received-SPF: softfail client-ip=40.107.236.74; envelope-from=witu@nvidia.com; helo=NAM11-BN8-obe.outbound.protection.outlook.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, sergeygo@nvidia.com, jgg@nvidia.com, zwaksman@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Jason Gunthorpe BugLink: https://bugs.launchpad.net/bugs/2077887 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 Mon Sep 23 22:35:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1988702 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 4XCHrt4WNJz1xsw for ; Tue, 24 Sep 2024 08:35:58 +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 1ssrel-0006vA-3u; Mon, 23 Sep 2024 22:35:47 +0000 Received: from mail-bn7nam10on2070.outbound.protection.outlook.com ([40.107.92.70] 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 1ssrej-0006ur-MW for kernel-team@lists.ubuntu.com; Mon, 23 Sep 2024 22:35:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=jrchE9BuEnlFPgGrZxLDPM0gaxcLY1Ln5K1suaJgELVMRH4m7fqGjwe9zu7Oa29zz+aqvmxd+743O/YOLALOrCcrhAzhq4lRc5Hyi0CqIhjIFZYPJqdd8/cdLo2eX8+F6DVyHZ4XiaJ7HkXfRWuZ6MUC7m7tEfmW+nHblKl6LocSZa7nqnGclOosH+sEiqri02HKWVj7rZE0J5ULtWcj2zVY9hjpDUbDLQnfBvArbPSfjJcm8yTVnihhrPaZXIe/SUmdWHbPSXsfcu2Cwh6HH7NB0IGiE82h/fLSJ1uaP9rsKCIGL4cI0QMcAiB/3CEtXOSSOrJGZD3xVjtoaDr0Aw== 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=nB2+Tdw4awXZGqtZsM6YauTcHSx/an3Z3L+Nz+Lg96r61S2RrHKCtrKCU0MHclEVwt2L9j4twhJIfHRHHqL8lMXPvylBcyBdf4gVm3nx40u0e/5divYfX8GVUupBkb2/gWJWf1AAtJQ1soRWnkqW5p1iKmFe3Kg7N7/mci/4+O2+fWpHOtD7r+y5LdFcIVnBto2xN6iea2VW5kL/l/EdS8gPxqf/s/45MOSiadTWOY6SsXHnzFwg2P6mP+Mv5KJDKFVIkQYQwVQoqBSmYxI705AnyJUAIk+JuLRx47UvxifDRaAwsc2nEWd0wA1CZJKk4vLbEnQ1vUjTy0oso3bgHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from SA1P222CA0153.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c3::17) by PH7PR12MB5653.namprd12.prod.outlook.com (2603:10b6:510:132::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.24; Mon, 23 Sep 2024 22:35:40 +0000 Received: from SA2PEPF00003F61.namprd04.prod.outlook.com (2603:10b6:806:3c3:cafe::de) by SA1P222CA0153.outlook.office365.com (2603:10b6:806:3c3::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.25 via Frontend Transport; Mon, 23 Sep 2024 22:35:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SA2PEPF00003F61.mail.protection.outlook.com (10.167.248.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.15 via Frontend Transport; Mon, 23 Sep 2024 22:35:39 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 23 Sep 2024 15:35:29 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 23 Sep 2024 15:35:28 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 23 Sep 2024 15:35:28 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v6 2/6] UBUNTU: SAUCE: vfio: Add vfio_device_get() Date: Mon, 23 Sep 2024 22:35:18 +0000 Message-ID: <20240923223522.1203691-3-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240923223522.1203691-1-witu@nvidia.com> References: <20240923223522.1203691-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F61:EE_|PH7PR12MB5653:EE_ X-MS-Office365-Filtering-Correlation-Id: 6342de4c-e6ef-44b0-02d4-08dcdc200d40 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: I1Ml7VTuoCv0Y53OnL5XkAsWQ+Enz9harB1XJMNsm4xGP880rC2kOT5o4q8bSf0JDv0MxW6ikBxpzockzUwfl4F7ypzKkFGaFAvmfQlYmh0KPJxHVsWUoLRCymsXDwvli7sKJNqhlGbeVPnAqplEL8qwzpM1svopbujbv6lJb8gzxfNL/ojrCHQUH14naOB0Apcmoa6V6vnuFyLyjT8iaS7qYl1WKdFocAXG8HTKNWil/GKtjarDzb+w5n5bFL4mBny6NPNO0acRrqYwAef7FDtHvMKICTtZqY69Cl8+YIpBsAD3DJDLpXGySFujdnP9EQoVYEKqf5yg99jIGRJp2FmU/BFDnaphc8uoYbBfPvB82fGSbS5djjqj13KFUSowm6Fhz+iHnRP32X2ei7WY5npmVkx5BPUu4VibodiAuVRx74id2koFW5JxnlcyKIjeEBTGy3gMveNX248uIY5x0A+QPUnPuk38k1vMeJfnFQdCW1tNwd6zDzHdaaGyW6v+HjBfzpmGxnAoGEZ6zMgZZektyDrEJEurxE+4FGfL5b0b6hZsKTXZqGMfGe08yRoXxxZxuDm0GAF5GcF7feBf5dd+vN5wcr8GUHBKr8DTwIfFsWoEjKtRncexgkiNsYXb6kLpuG0RTmleTPPSlVEzgbinfhQHjbN9W4GcBptx/7Yf+1vQa0MO72ffDpTvkiyXl0R0VlDz98t5V8mQ1tKOPO0uCTy6skpwOVJEEkd7QpOdAP3TTcF/6hOE+bpMr0hJM55/Vv76fPmyRjZwlRAj92D6A4rgFn9CRA+VZBvgp1RaC1o0AO0H6f9aKX4Nz3x6XJJFTFljTpWtzHU/0LN3wNdJGyHIXezDYioNAFBZnLIa/NEUVfcY0gsgc36YG7qWc1mrxKxBhDeKZ9ahLHgiFGv5MRsanDdgddvL4MuaxGu8UUkt54hiyEexr3eFbd+1/Oat0/W84G8GjaSE4OsZXnItu8fdWTXUhA2fe6w8ffSXZv/yUCc8XmzA14UfafKadV36RcKukt5cvqtxHAlXDmYImODsYKgOAVmHusl90QI2RvU676kMoV/mMqIICvETqcK+REYh8+UgbA2TE/VX1ezLFI1DTnSc/zk/dyh1PgZs7N6GUh0aBBVxnH+rvIhuTQm2UE18sViqW2ZJxMNz4HzYeXiKvB9BehTuXei1jeByqpppmjDZSGCqa69oI9NcH+9IG115nd9a7SqKbI1jNWUKYVTLtu77KfHurqpsj+ckaInZSa4M+VqeZi2Z27iYwM6QQp93x6ojTVsmJ3RjkMaJbq+DKXM05FtGsvrky/QHeHlzY8VZastZ9CCN9dMgNScTHAvy2u/jpuD1/zbfB8P0ltSY01ePWeXPvSjtDVOjwGXDvqiFqD95b6SkwqaPD4E/h61sxCOZ0SBFrtYBBulVhiCNwPp41lkyrPR9tXEwgGa0Ji6Gkqsj7PkDgo9z X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(376014)(1800799024)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2024 22:35:39.7880 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6342de4c-e6ef-44b0-02d4-08dcdc200d40 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F61.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5653 Received-SPF: softfail client-ip=40.107.92.70; 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: 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 Mon Sep 23 22:35:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1988705 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 4XCHrt4SKvz1xst for ; Tue, 24 Sep 2024 08:35:58 +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 1ssrem-0006vk-FW; Mon, 23 Sep 2024 22:35:48 +0000 Received: from mail-bn8nam04on2088.outbound.protection.outlook.com ([40.107.100.88] 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 1ssrel-0006v8-Ei for kernel-team@lists.ubuntu.com; Mon, 23 Sep 2024 22:35:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Q4ojEWC5WINYWkeBIT0Fgz7oKygE7bxj8/OZPJTtB87bSHIvkk2mYAK1eqsucKSnfPxOGieoXcK9gwthwLb00W+xRKRuZ+zqTSLqWDggXRGxLF6GCJkjbOcnwwPDz3O4mYIvMop8oQwST9u/WtvnYisBbpBbvWyANtRDU/D+faPv6n23HwWEC/8kIpQp7sAGO/BdfOTwAGz4/DmVcuSA450NF4FfEROWbguUPEJCnBxn/mMuHg2tHFm1VYq5X/FRi5XiDFZNsUsj85voIcWwwaeUVhzdtFdndduk7gVliKIKWGVRtG/yQ7i6PfLndzRU2r1NImJRL34fqxm4UyZ33Q== 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=Y1WVJVRnQpmze+qdR8SVbpjNX2k4p9x/BrnTwN5LLXg=; b=wcx6j8ekDgq2MgGQ7Nlw4/wp4OeQem1yHuq1QPVVVPiFdLLrz39HTBsC5ZtgGVB0SYyfYZmTx16lLgWclwFgZTlSiG+pM20HS+bUvkusaUpBCnoSKBP7YXn7gq2j4D4j3Vk5neO0snfm2CDGjAWmLtZeslI+bYg8VdgJZbR1VTN7+35mBCIDJu4HC0cVV3Qk/aNPR1CYS0nw7QNkxt3eal0S8J+AOkZPaenrVKZd0B3t/qXKbFsJQfCZCsHrw2sfFmnCIi+2g2msPlTK89K+9gqASicWOisA9H5si4rwqs7v2W0jhycryGGoPFa9YM2S5msApnw0eUGF9V2K4w1MTQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from SA1P222CA0177.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c4::25) by MN6PR12MB8541.namprd12.prod.outlook.com (2603:10b6:208:47a::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.24; Mon, 23 Sep 2024 22:35:41 +0000 Received: from SA2PEPF00003F66.namprd04.prod.outlook.com (2603:10b6:806:3c4:cafe::85) by SA1P222CA0177.outlook.office365.com (2603:10b6:806:3c4::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.26 via Frontend Transport; Mon, 23 Sep 2024 22:35:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SA2PEPF00003F66.mail.protection.outlook.com (10.167.248.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Mon, 23 Sep 2024 22:35:40 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 23 Sep 2024 15:35:30 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 23 Sep 2024 15:35:29 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 23 Sep 2024 15:35:29 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v6 3/6] UBUNTU: SAUCE: vfio_pci: Do not open code pci_try_reset_function() Date: Mon, 23 Sep 2024 22:35:19 +0000 Message-ID: <20240923223522.1203691-4-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240923223522.1203691-1-witu@nvidia.com> References: <20240923223522.1203691-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F66:EE_|MN6PR12MB8541:EE_ X-MS-Office365-Filtering-Correlation-Id: d5051c86-7d2e-4bf3-2a69-08dcdc200dad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: tJJysN0PdtY20pn9AefDaX523XFEMI32sSkeVeIjZcjLONC10+pov79A3yIMRRailjHMVuQd5l86WXI4rI+iJDrOsXkpIbsto6LfcmmdO3QBHD7jzjWaS4rC12DFKLSIVTbRqqx+RSARhc9V1hmpPVTYeHSwqDa/yR9LFq+WNrM2HfOINymJSOeX7Xzr1hwzzxZr5hwoGlx+iWkE9+hstz13LJfoEPO+AQf4Gkb6lCSZM49w7f0QiEmBQEcMb5EHXRyyCamBMGDI2KuR+p4zkErifwVNflQgeviwkgT+hmBJ18hFy6JnsEjqx0XU4Kfhi66awtOTkNj0mN9alCWPOfmk80bb+NjS9KoF/yAp6Dml4JAdQVk+FG5gmm9DApGCoTsaK75tNb715VntAv5iWXd9l4hFKUFPhuvSd3QsSYqe1P5mDMDzl8h0+oe17ZkAldrMyG98sccEVRohtr1+ljjuh3wzyKB87uNP/PVKcqHDY1FDRFXxM1U2XMwimjhZJlPxciNumcDHp+gRxeMrzC8Cn+GqFIQVFb2WAAO/IaHHb0yERYnsLWwhia1S+g6/OrN5y/2k/6XvRYSNSqfcL4DHYtCph47AVLSwU8GPiyepcbj367guYDQd6P0BfyagGbwBD1p7HU/0xuy11zCyEhmoZvVWPHsrQoTYOpBSRQkdS9usXN7IuAhbymYbqwdCGW2Jar2YhMWckL/uehy8XCzfJXqxN10420JwmOsd5lh8Dj/oBicwMA3nd8trsMMvoGRBFwvzE87LfmnOV7avIQjeMu0l2TC8WDZubxdKT06fAWbOhqx7SwyHsIJI0+jmnwwWb/47ZkEi6D0yu/FunqLPWZs+OcBpQj7/SLTtv4nETF+6gPl9L98qW3ZWWfhqCDAlNwpHAi1/qrc/hHiY289XoIT38KfNuWZ9PYFjGWkqrWN4IsKrpBdOGH7pVJgZghzZKc3UwgZU+ksGNgksxZ7W8bqdd70Ms4e4XdsP/f13pjP3edeBDzrU3TbO25exyvIstltHgpyE9sO5XYcqe/evhtV0yn5r2Hl7nWDQQELZ5gtq20PWDtCHzdGN+LNmUjpwB5DF3znVg/EdJ/XbsVw4MOVwQ0Zfqs/oLYnBK30vLUnzZOdDnzGnk9n4AwHM5xJ7LKlU7lXFZ9H1m0ZITA7WL425EzyQY5E27G1XuFds3W8xpE6SqBaIwWX7cauYiaGQnwuydwt662uwkWl32K9a01z/SS4zciR95Xwar2fpFzFS5ma6rwCMENrQko8BjjKH71iPHs6U2PW4hU2XyHyA1itGdwWK7zJlYE0tJwjumWHWXT6iVIN0NMOmiwXGZqOf/HlDI2I+841tP5m+IhyKib50HdhrhStC01mA8wo= X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(1800799024)(376014)(36860700013)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2024 22:35:40.5034 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d5051c86-7d2e-4bf3-2a69-08dcdc200dad X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F66.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN6PR12MB8541 Received-SPF: softfail client-ip=40.107.100.88; 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: 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 | 54 +++++++++++++++++------------- drivers/vfio/pci/vfio_pci_priv.h | 7 ++++ 3 files changed, 41 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..a45cdd3cfb84 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,33 @@ 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); + + /* + * 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; +} + long vfio_pci_core_ioctl(struct vfio_device *core_vdev, unsigned int cmd, unsigned long arg) { @@ -929,30 +958,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 Mon Sep 23 22:35:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1988708 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 4XCHrx27qsz1xst for ; Tue, 24 Sep 2024 08:36:01 +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 1ssreq-000702-83; Mon, 23 Sep 2024 22:35:52 +0000 Received: from mail-dm6nam04on2061.outbound.protection.outlook.com ([40.107.102.61] 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 1ssren-0006wM-SK for kernel-team@lists.ubuntu.com; Mon, 23 Sep 2024 22:35:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=A/62Z36eeNgs4cJFl/piK9xXcJtjmkm9uhCRJvjC2OkM7ksP1bPHeETG/0OaYA4NjIAZxfyRaW0rbehIBjaC40GnJktSFO0zA7WNoZE6dIFhyVextKuZ4eAnyr00nJCQWuvZTxl6kdtWeSMuqh4Sus0YVTehoTe9rbhyswgQKsmiaZAG/+MGC2ccAurW40JLFBJkpC3lY1MYcLfn0GPW9dE1dti20BMjlSkr0dieu/V8iGInNIySu8ycgvepIyVrn3gYkCaLN16Io0B/ky9yEfmp7fvUq3bFEQWEcisdHsSXRqH99z5Y3rQUGpOXTxfyi4yBQLR07hSkGNJ3zUuEDg== 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=KMX4G+nP8AAz8HUVQu6RXtkkWkY1T8Buw7EgNwjgqbg=; b=S2LYXbHBCS9vSctSZjrdIIpfUWo2iafcdeb6OEj7ByCIrWVn0r+mpwAaI1Zl0up7Y3DxSD1YrQik8X2FmDVEE5W3MkAIQ6/1S0hvi3BjpWzKo180673noPUzTlutNmXlkdj52fCBpeHS0RZFQvi1AnsrDEQ2gj9TiNG8FAmHO3NvVNqBAKw8blkrX8k2q32ajIyxZc0LFmZedrFNR8NGZkJpwsBKHQPhgglPuauBcVhc71QildIqTntljsMJ39TbmTUqQbxpgQ8OAFkBLmgL8nZ93EL938j98ferc8Kgi+aIxPjDc6mbzZ9RkBGvZUMzcsHTmQgP45IG1HDz2c2LcQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from SA1P222CA0154.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c3::27) by IA1PR12MB7544.namprd12.prod.outlook.com (2603:10b6:208:42c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.25; Mon, 23 Sep 2024 22:35:42 +0000 Received: from SA2PEPF00003F61.namprd04.prod.outlook.com (2603:10b6:806:3c3:cafe::67) by SA1P222CA0154.outlook.office365.com (2603:10b6:806:3c3::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.25 via Frontend Transport; Mon, 23 Sep 2024 22:35:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SA2PEPF00003F61.mail.protection.outlook.com (10.167.248.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.15 via Frontend Transport; Mon, 23 Sep 2024 22:35:41 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 23 Sep 2024 15:35:31 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 23 Sep 2024 15:35:30 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 23 Sep 2024 15:35:30 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v6 4/6] UBUNTU: SAUCE: vfio/pci: Allow MMIO regions to be exported through dma-buf Date: Mon, 23 Sep 2024 22:35:20 +0000 Message-ID: <20240923223522.1203691-5-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240923223522.1203691-1-witu@nvidia.com> References: <20240923223522.1203691-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F61:EE_|IA1PR12MB7544:EE_ X-MS-Office365-Filtering-Correlation-Id: 834709c2-7895-4589-1c23-08dcdc200e7d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: 5xYDCViVWBJcSw3l1JWb1EjKQdSO9R4SzL/zp0Cs55pqOmP/n+Y1M3R0SLdfCBlpVz4fh1iUArPKJUyQm5e8h7Ugwwu1tiqM68YCnXxO1vS+DDOb01lOurptyPh/xYEXzym5oC/mjneFqpeSYzB7ZyX/ouYCBQhb4buYlKR6E3OMazPDIKdMmyiMI6LfTQwyiGXjs/4XaD56a+3zZklxjlMQH/pCKdhxFv5Al0liAEzVQjUAk5usQSc0aKgo5uk02AYu+TLlkbQigASkZ1HtuGs+VY9ZK6n13kuSCQoMOaMfH0wf1KTSChU100vKOK3OE3RW/ZVgPoLNreJOeUw8zAn+pYIedpFPCf7D6J8BtCZ3iX2MjuAv4iLt5vJ2BPwVq0Gahx6sUioO0Y0nFGvObY2Tmi/mkmsMJLcNcCj8pl3tiAbxOSzmzkRgJK6qr1psMLVr1W4ZQe1Abt0ldEVCa2EXus7WU5NhEhuEXaCienHU/GeflG/ak/Gryv+U/mtx3tVhngCz52Qe8ynWffsKJVFOThDyBQarAC2qiivV4pysDOKrPliCsA8Wl9lkvRSODikwmvV7h8acFiWW8RF+P+pmBShGftDM81GyiePvL4KM9k18nAag6Qr3e71dV2ACwYoRSbY5lbjcKBErxdlB5rLC1Viso/ufAJXu3UlK4nQLY0sMxh0sUnqgfzO4f9zguVX1sXDgXAAW9iP8F3wj1vF0aVYlnOnhPBx+/QRtKIeLBuyckf0hnS5AqxgSVEmRsbUqnhxKmQg9+dvFGrYKBXgFy3J1Chy/AhsaPMZyDCC8pTq8afvlOdWt+aZUu/KLDrnD3pmU8YLHSX8ZbS9hmqPXNI1R1yUpuOwET74Y+lEuiQn8gcmPys8oq/k97vWiWSf0Q5ZCex96uGqHYLZ+IX+R2nHityJ1+fdvmyoSxzWYfQ3oDoWdXzTutyB3R0BVNcwjJw0vJF5S1rJZWgRJDKuEM8loOC4TTyxtFA8QOHWrD8gyypW5CbYyNIoECwEOeVyVHmDPO1j+zrAfCsoZUxaHqrjzpb/KqkyFo90fnR3tQd3x0OfFndW/+wDGlB9SH0lvOlaBMmIYP0a50a7nmpBz6wBDxtvmHdozVCtiVv3izRzL+kk5OTDAPliInuTEBk5B1Tw5JP5vuLI2oPyV/bZMai5prHlYGF3kp1fX9+trsy26UXinxTZerl3siMBmifqjX+6VbMAmgCyw/XsjovUdJrRAn8t8ghKcJlLp2cFNe56cdXymxsZ/B/EA2GjpC5q5VukEHRgENN33AproIqvMkc/Dz/5zLrJwjdX/cOuO9w2QkQcVnnQLPerzGD2t9fJYwVESQSLm1W6KkCAm/b0GIos5Oslr7g2825ajL//551rKvdQL6NXCXKDtUM1U X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(376014)(82310400026)(1800799024)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2024 22:35:41.8662 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 834709c2-7895-4589-1c23-08dcdc200e7d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F61.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB7544 Received-SPF: softfail client-ip=40.107.102.61; 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 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 | 18 ++ drivers/vfio/pci/vfio_pci_priv.h | 21 +++ include/linux/vfio_pci_core.h | 1 + include/uapi/linux/vfio.h | 17 ++ 7 files changed, 328 insertions(+), 2 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 a45cdd3cfb84..805fc166dce0 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); @@ -671,7 +673,10 @@ int vfio_pci_try_reset_function(struct vfio_pci_core_device *vdev) */ vfio_pci_set_power_state(vdev, PCI_D0); + 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; @@ -1206,6 +1211,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; @@ -1839,6 +1852,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); @@ -2156,6 +2170,10 @@ static int vfio_pci_dev_set_hot_reset(struct vfio_device_set *dev_set, 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..0f74ddcfc6e3 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -1002,6 +1002,23 @@ struct vfio_device_feature { */ #define VFIO_DEVICE_FEATURE_PCI_VF_TOKEN (0) +/** + * 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 Mon Sep 23 22:35:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1988703 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 4XCHrt4p6bz1xsx for ; Tue, 24 Sep 2024 08:35:58 +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 1ssren-0006xI-Qs; Mon, 23 Sep 2024 22:35:49 +0000 Received: from mail-dm6nam12on2085.outbound.protection.outlook.com ([40.107.243.85] 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 1ssrel-0006v9-UA for kernel-team@lists.ubuntu.com; Mon, 23 Sep 2024 22:35:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=c2zet4pp4pX0P5Yyzs9NMZQ1aBu29fnr/ubFFiYlZDG4FSBjej1ioeq7LucVRsrzGy6Xmyhe45yZEvoLOM4V8m3xRrn8WKwE3qwE9qJCnwDyF7RpLlijQ4l9jtNGMrg+/vLlzlPqKdVaHs5rHjgk5cd8iVSmPHY0KCLrd8+MSjVjiGjc8+kICHFHv0+irHFms8F5puAoTnYKSI/kqXnaGZhW/esYlJp/1lYL4tfA2xMj1AjPbvX3BUM1othnqv/J+G+C+4FaE0Vwr/xNsmemzWufTmoOop4qI6gsknUlMgufbp/iuFJ11WpXiAMF29QI/TCRBHqlRCp62iZ0nterRQ== 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=aW1nVwYFMNXes2J53gKEwAyZKi0rWN+6LR/FA4L2nRiBwEh8ATiowMcDS2OO2yzV1JWE8Uxz8XZsiriO7nE2OipBefVwnJihvhlHpT0i9AAhD8FBBZ6xyKR8YUtM+qIWvL07wGJv1jLZJDnZzS5tl7bpFJlbQTZm0+GuBrqNB9HDdMBHc/VHrl6dTCOZrqr4RNAD37JTo/4kSHWjbrEdCtGFJV8i7g1/gKQZ+PBAYcGPZOdXDLLSB82cqYvhWa5HsEBaDggFOlWXC1NJxV/6GKZ2MOkzU7ZAeS9Mn25pZ5WLMejR7Cum40oGiLchmXXR6fGP4f9XzmkZbmy2bVlT2g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from SA1P222CA0196.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c4::23) by MN2PR12MB4142.namprd12.prod.outlook.com (2603:10b6:208:1dd::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.25; Mon, 23 Sep 2024 22:35:43 +0000 Received: from SA2PEPF00003F66.namprd04.prod.outlook.com (2603:10b6:806:3c4:cafe::2b) by SA1P222CA0196.outlook.office365.com (2603:10b6:806:3c4::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.30 via Frontend Transport; Mon, 23 Sep 2024 22:35:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SA2PEPF00003F66.mail.protection.outlook.com (10.167.248.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Mon, 23 Sep 2024 22:35:43 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 23 Sep 2024 15:35:32 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 23 Sep 2024 15:35:31 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 23 Sep 2024 15:35:31 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v6 5/6] UBUNTU: SAUCE: vfio/pci: Fix p2p address Date: Mon, 23 Sep 2024 22:35:21 +0000 Message-ID: <20240923223522.1203691-6-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240923223522.1203691-1-witu@nvidia.com> References: <20240923223522.1203691-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F66:EE_|MN2PR12MB4142:EE_ X-MS-Office365-Filtering-Correlation-Id: f932771d-8ba4-4ff5-8dad-08dcdc200f55 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: Jf2m+xY9J5aGvupR/Sxfwmhe+j1WsL+Z/WUdy9Z0hUaXDajZuVM/HyCg3ibwsNO8OCyyj8ebMnns/juxQ5nHJsoKbOMfrb+ln7YzH6a+ehIZsN95RmCc/o2zEef+sInPMsGVQq2kN5xWCZ5M8sjv85qkxRMk/e6mlnHgCugvYGq15TWAd+SErzZzjStb6KiAXFnHG1r23Fiw9HbKx02PNEBC5K6nQSUHc7z+1Nv7mT8QL5j/RgEjptN8mA8iObcJUr2MaMMZ9E/Yqy6FPJ1t/5rEPOYYfXrRNIRVs1rM9bYo9D47GjqYvnq1IQ8cGdzGxJjRp7llI0u/4ENwWUTL+QrD/7P/Y9V5MsYFCQ/cMLi5w6sQD8CFB6TZGUhkJQ5tzGjh4Q06E8mQsvJwGtzkUtZEnehoYM1J58pJQPWWaDdUV9EAE0A1u0w2aLhOTn1/YkOWLHnB8AO8F0DGsUgKD0lG1ePAnP2Y7giwTg4lQC+URqAxgD3UMUq53x/jxTovWcA+3WLpBMZZNZvgeOnbz3bOYE6DGhJceu+mRoUfsMyOu6O1bythnM1pC4kcNTjJEHoCl7ucgGB1UrtlGnTUptLHWhV19oTVoloh+ku1c162tdeVLSRwCFhpkIaeVcaTRHsUB1+AIxk16pFifxFIrhD4Y7FMmwvfsToKmLemm8g28ebUuZxc1XIeAYrQL+rzKJkgXQrx9HSBICxOZggmj3765cht1FKX9RDODTxLEi5GldPo7N+RO5tp3gFXMA6Nk+rUvHopRspCNM+zJ1wj06unzoJw7eVSjUYVdy8heLBSiI8outWolnH3nQJfIpOY7xCCV2x8jyA0Ad0bG85sWMOyeS9ZYWMk5E6RnRPRY2gFSey1aih1LXnUzfE2Qo9TbfffUpDGc6J2264ItH0W24o8qeEQTyNwb36MGwJLtHUT+a3TKTN7TR8itbHKXSXMQ6IbDuc/1ms9LxCFwyf8lUwFpBCj62gXW9LxxJikFvLINN9i0X9GCdb4c/man1JCNa/l/VUgQvW8ydMC2uRR07n69vZaK7Dmqyb83K6BD0EhazUo38tBO7eCamc5L+TcJH8DMx79/OfXdVd6EfHUf4Yymws86VfMj9Hvt0cLd9Ev7leoHQdwdMYE51HIjV3QIMSOnDBHWahqx3vBe1EAS9R/zYsNd4X9uKSYmWT8bDmBY770kMdtKxZh0Sz4Msrwq1JyZ2eKtU9lP+dwzBXAoBLDoD7TMVFCG48y2Wf5Kf8f+S+mNUn0lRLwPwZajQpqT6UgMa9AOavENGGrJ0HBWEe0DsxrKbI6n48c0oYYkPE15sXEArAvflOWvFKracrtHDi+YLGrcDLksN7iBO9OI8WL7o5Mg2juTM+D45U6LWQ0uRoY5BdGaiesd02awUsgIVGm0hlo8GGQqs+N+li153OATHZ7K9waMbhCnY/WGzKP6fddSTjUPTo9+BqoTckb X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(376014)(82310400026)(1800799024)(36860700013); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2024 22:35:43.2847 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f932771d-8ba4-4ff5-8dad-08dcdc200f55 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F66.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4142 Received-SPF: softfail client-ip=40.107.243.85; 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: 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 Mon Sep 23 22:35:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1988706 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 4XCHrv0KSSz1xt0 for ; Tue, 24 Sep 2024 08:35:58 +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 1ssrep-0006yZ-0o; Mon, 23 Sep 2024 22:35:51 +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 1ssrem-0006vK-8f for kernel-team@lists.ubuntu.com; Mon, 23 Sep 2024 22:35:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cootT+23so3FfgIb3IU218bI2PUFRf5ZYFMJxeCPjWDdnrcVn9aUooqVZ+qXcdR0aA24K3WuDNxuKkXOqHDdkQlCjDIr39zeWvvsFvLC1EgIJ7BVEW7VOm36r7vKnx/gX/poOyTtDUGWlT9srEzGoHvzXY7viRhUzmxk2fv0BrON2AtIPzeC7A/evHAGT0G/9h2jImu/hD1KWPH0fiDi/S+0Rh3SbMO+QpP/gGfh4KsqgTs0nYGwuNwa+vz11LAGK4lF/di8yWfoGMP4/NFfRjkFnd1LaF4poicj0WLeKfveiS30+eIVt6Z2IRISSgo2r8asu23PaojynDGT0/a/Bg== 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=vmN6ZX8sQT8/R+O0qvnjg/n74QdgbGrbAoTzbx0Xb1fZOecEgDMLa31nwg6loMJTG+BrHv+uZcqxquBwUgi4EiG9CKpQwkbdlWHjwvpd0mBnFCx4RIWHi6nhivRorlkEfHAABYVmB9wlbd5hRXnw4n9YMeVmyBFq4rHO+ZaUkgyLsW1eWroCciIbHrlbgL4mhpWxURvmLYl6HQF3eD6L+5dPuwF4UgG1NLSTjqWAD7LiHIsk3hEVoUysOEUD32AOPzBt8HDFdmpIU2TfIBKEInu92DmY5QR6zy9CDS4FikfEfOqZZl4mZ8nVMrSzf9e1c0ceoOkwcCEfW6yAkOjM0A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=lists.ubuntu.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) Received: from SA1P222CA0183.NAMP222.PROD.OUTLOOK.COM (2603:10b6:806:3c4::7) by PH7PR12MB6636.namprd12.prod.outlook.com (2603:10b6:510:212::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.25; Mon, 23 Sep 2024 22:35:44 +0000 Received: from SA2PEPF00003F66.namprd04.prod.outlook.com (2603:10b6:806:3c4:cafe::19) by SA1P222CA0183.outlook.office365.com (2603:10b6:806:3c4::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.26 via Frontend Transport; Mon, 23 Sep 2024 22:35:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SA2PEPF00003F66.mail.protection.outlook.com (10.167.248.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.13 via Frontend Transport; Mon, 23 Sep 2024 22:35:44 +0000 Received: from drhqmail202.nvidia.com (10.126.190.181) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 23 Sep 2024 15:35:32 -0700 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail202.nvidia.com (10.126.190.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Mon, 23 Sep 2024 15:35:32 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Mon, 23 Sep 2024 15:35:32 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v6 6/6] UBUNTU: [Config] bluefield: add config for VFIO P2P Date: Mon, 23 Sep 2024 22:35:22 +0000 Message-ID: <20240923223522.1203691-7-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240923223522.1203691-1-witu@nvidia.com> References: <20240923223522.1203691-1-witu@nvidia.com> MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA2PEPF00003F66:EE_|PH7PR12MB6636:EE_ X-MS-Office365-Filtering-Correlation-Id: 05b7d9cf-26d9-4b8a-39df-08dcdc200fc3 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: /a29kCJr2fujwEA+XTK55pnLaIXQ3CNqYcj+bzqalWuYV24uKh/i/3k8yEhKI0+kKs5qbYsJoJDUQjw0hHbIlSe8nhHiTidvc13Lve6u/Zt4bbCbWoC32Xq6/78CqftqCzhL5zAZyIEqTwRTdBCrlhImb673PdehdlpGVxD7aVonTI6Brn5aLkk7BsfpTZ2c63a2+Xumo6Zhq3IYFMfRXfhtx9wbeYZm3YkPCfP/MuDdSBOugb7bUhRF+SIaSYc3b9ImuInCbG/cjVE1tbR9S4s6YNLgYu4t0Y0pPmntmP9sB/LV3wOBK0Z7TAqXaRkjKjSGzm1r+ToxCZIglNnyFVE7Wm/xhXFoiO0weHu+9pCvxAsaUEa4Do19N7f9K6U9C22bz05IsVGR7y+7RF2evi+tUCMhu9MeCvVOyTwvhZMOmBw8zNYTNHJkDGNZ9BPKPjfMzMhWXYMDGtRPVvQXvI+PuGoJOw31BgTp83ZGw60gu29/cfvrWDJ8TlovwZ5SYkNa7AywLk+DPyZklNvscn4ezDz4LFvDixz3C0eNRssrdinV7rrufqJNBeEO8KfSQ098UYW4egGu8f3Nw+4uKdBQ/vQo4WeycpSUl+l9OPkpDrntsGWgdq4qDS0R8EY2K3OIYKQdd7B9pRfU39EKbPWXUFpTq6DH7sa7P9kigNhiC6FPPfXXIC6Muu03Sh8FMygrriO6wCsOCvVfkCj5PxOwt1meLBFRgOKLoYpiC6O1+k5f4xCbflx5GDPn8gRSHtOaQkMrFcXzo1zCuER6P6Pwv+LuvdqZj6l9uOtZOhbwDK2JhAJ7CKye6M426EEi4tDxWlWkQzT7CGOTo9PBq7DVQ2lYnNzSrKfPcnGPAhGifXVqYsafMMagmYEOIwopGuEk4NjFWv9zqX6GUvkdM8ln5r3O6W646jJNn6jUuVDt0HW+bO76s0vEMAMg2CgDNWEaWyct3dI6MC5flSxxksQGwsvjL3aBhv0kBpUjw5UhapwP3PVL4yGWLqsl5J4WzfmMlcGK4dr9gqu5msvt49RteRoq6UY1j/BmnFoa/T6bUSF/EnIEE8vH/ChlVYrzZs7rdI6a9FKvPCq/WZoSy9/wYLm+CJX15lOmsRXARAri1DidzE8qZC1UA0cP/JU5DYBGJ99Vd67YKJGEGvQHNe5q+FLz62Tb7Wct4tZFq0CLwRc7fpZpyKkaxpUtDpRY2I29/tWqBEshfQ4PoT+/xIdJfCCCghSFfS/qx6dMiKz4ryuJG9biVwDaz6taPwCnpvfAd9VyIS3ffuiKaRzA6uc9jfe5wG2FduhcZ87UkO/ze9QcjLFxaOgO4qTJTXyBUh25cbi0aLITaDht007NF5/urG8I9myduYpFWr+lToF8xgZf7zSK3CjZJnGjVMqT X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(376014)(36860700013)(1800799024)(82310400026); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2024 22:35:44.0034 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 05b7d9cf-26d9-4b8a-39df-08dcdc200fc3 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SA2PEPF00003F66.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6636 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" 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': '-'}>