From patchwork Wed Sep 25 17:22:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 1989499 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 4XDNpx6SvRz1xt9 for ; Thu, 26 Sep 2024 03:23:05 +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 1stVip-0007AH-9V; Wed, 25 Sep 2024 17:22:39 +0000 Received: from mail-co1nam11on2064.outbound.protection.outlook.com ([40.107.220.64] helo=NAM11-CO1-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 1stVim-00079l-VU for kernel-team@lists.ubuntu.com; Wed, 25 Sep 2024 17:22:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wRDQ3tc/f6EAjRGaKOAaOI1/Dl+CmgihGC5Y2klE0FbaEgFlyGmsKMYpBtFFC6N84Ddc73jat7vKDTtgM1j7dDElZtxggIULLjTb6yagEKCDxxgv9fNi+PB/pP07ZHAdEqVkp8A24uYY8b3EJFbMg02lZF/pUnLFfbKBThL11vphCizLVY1DOInL+QI1yhtGqgEM9aGNN/VnMkMkdbQC/llUPpHGeCXTdi/LJumorVgcIfSHM1BDwInuZ4CvVaJldubRL5ze1ONsBXNBrygKnunR+nxlm9CjeL+H3kVP78lP+lk1cm5J0T1SQI1iLaC6cfsvV+tdeBknLYAwDyDcvw== 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=kDQ5BuFSo0C7Uv9amKW7yekzVZXOhhGDn+2YPvD2GWQ=; b=s5VZ2VylAWfcOXjtL2Q+9mBAMBnbki/ubsXq6lDga/uL00sHXsWHZO7dPsftFV9W4LS73UfhazFZCaiokxUbZuZSCquNsHTHorHKMnJEeCylJDJs0bGhd6SgSBXIFsBi5ZFcdLVNf7BVLpqw11VOADR+IBYsHOWhxE57B4SF6gKx7ijzi3Yq23LaxKb2zKaH87sU/f2fQQYVTXcpU+JjX2yVP7Qr7YO52poprg5hqVlrZzeJMPLUNQWmz8n15BFxx7dUrMPsQwddA5mJRvZyo4oUPOETTytDuyxNQ9jjYDK/iDOwbAwfMTKP4XafCHSRTVOnJb4vn6txoG2J/dOrQA== 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 SN1PR12CA0073.namprd12.prod.outlook.com (2603:10b6:802:20::44) by BY5PR12MB4097.namprd12.prod.outlook.com (2603:10b6:a03:213::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.25; Wed, 25 Sep 2024 17:22:27 +0000 Received: from SN1PEPF000252A3.namprd05.prod.outlook.com (2603:10b6:802:20:cafe::39) by SN1PR12CA0073.outlook.office365.com (2603:10b6:802:20::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7982.25 via Frontend Transport; Wed, 25 Sep 2024 17:22:27 +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 SN1PEPF000252A3.mail.protection.outlook.com (10.167.242.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.15 via Frontend Transport; Wed, 25 Sep 2024 17:22:27 +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; Wed, 25 Sep 2024 10:22:19 -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; Wed, 25 Sep 2024 10:22:18 -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; Wed, 25 Sep 2024 10:22:17 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v7 0/6] Add VFIO P2P support Date: Wed, 25 Sep 2024 17:22:08 +0000 Message-ID: <20240925172214.1511114-1-witu@nvidia.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF000252A3:EE_|BY5PR12MB4097:EE_ X-MS-Office365-Filtering-Correlation-Id: deda7824-f243-48d0-e3c8-08dcdd86a0b4 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: GAXhSecZbOnxItUBJ5Ujssaij8qVWeCu2kuZ6+Z3xSwrq8gnDAHlXjDWP2deWVVcbzXoAyllIlwt3mTIZ5dMySgqFzITdAL+9upZX1440ADGEq7jBEy34asQqGmB10I2SmImfNpluEB9CdWg5r50bIADGL2z8S9sNv3MZ++qRPakTXc3gb3ajTIGOtsH2qnYd6N97Wmi96yklg7tdmN3PbSNW/KZggfkume5dmNsxq0oMab0vNZ+L5M/EQ3J4qc68pdeb3ysxgG0S8gYWEWgrrVK/KjB+JV16iw3a7NHCOZ0zyofS0jlYeZlQNan6HKcNHRSUMY0GuHUPUSaz1Evu8wVHtNn1Rl8KDarLWVTyh5hk6ZWDN/ixwPERZtj6ISyeRjJuIaSC34stKzsNpUEV60JNPmMV97GiljgCqH85iovTSImEi8tWc5OVDy7l1x9Ef/LmwqST6t3c8DjG1o8T1PWexx2m12VduXNgV/57Mm9tTASpgN+VivKIGBQ+3z5SM6GWkM357LFtpc9uGx50YcHqG373JHqUy3ZThqea4+ZBnY39dNszaTAFf/c1FVleEEDC2t/12epxr3qLLQdMeC1q/oNPJosXZ/I0ypJZAl9HEXufj6zRRmwjuKgeIRtaSV1BR47Of+M2PFWIqotuJgUy8SyOhxgQo0sy2o6V5o/xyZc/fQOUeAfzxuOl+CFTV9jav3jXiH3RfWwJnHP8G04tumPzUleqctqeKSOyFjmB7kk6KfglItfvR0pQCbKsbuXjmo7+QTKbGPujX8xKp6gCaSAIrCfRCRiBkradNSRNargm+UeuTSdgPQFJBd1OlRY81yNy2R7Q1FgNJc0OKP8xOsXIOXN3ir+T8v02ijpsDSlpkkGbij20dXUU6CMGe2d2qYkSZuDZmVfhCoBFtxplDNc1QZZsXKklsxds6HWBDK+B7cd26S2PKs0nOu4817I9LUzNziq2idXd5wHe5xOE67rzv64rLlPPIVKGmwKEWU9b4pWozMxb9JMwM25+DYeP6nDpzKimiJW5TSiTAqWjvjFINyryOClqzTnixTgMLXpRXNXXS+Uq+s8gK6sY4fr76mHMDx/+IIlKfmSnhJamBF5RBoz5kBMoMZzA/ZkGEmgCPZR62pghMqHLpRNAxVHj2qliDOewzxs6W4hGYbJ7d51aNyL5pCpojlH2Tgfgp2EWms3o5DQtOHytN7eAtK4NUssbkI59rvXW3hPHbSEJHF7XHQ7BWA9r7gAorVU9p0b8OwbF8AVD0aSwDuvjD2eViwXK8wTq4smg4JtTZnzfxsbJJiTZozGbAfC6rDyNF1mL3PSypVuCmvCKojnqKKmOA/nz43eD0BushfX8ilcbSUmH2WYnJxY1KU4um9zMGPMACTNK3A2aondYazSSSzam6GuPNdkgH2qpSglQyj9jZlP2xumOMKgwz3ooHKtVnbNMAY+I7m11Djsb5R3 X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(36860700013)(82310400026)(376014)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Sep 2024 17:22:27.0083 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: deda7824-f243-48d0-e3c8-08dcdd86a0b4 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: SN1PEPF000252A3.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4097 Received-SPF: softfail client-ip=40.107.220.64; envelope-from=witu@nvidia.com; helo=NAM11-CO1-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 The series adds support for VFIO P2P feature for NVMe target offload. We took the patch (not upstreamed) below with some fix to make it work. https://patchwork.kernel.org/project/linux-rdma/cover/0-v2-472615b3877e+28f7-vfio_dma_buf_jgg@nvidia.com/ * Kernel Config Need to enable CONFIG_PCI_P2PDMA (enable p2p dma transaction) CONFIG_DMABUF_MOVE_NOTIFY (no need to pin down the memory) The feature doesn't work with IOMMU, so either we disable it for the system, "iommu.passthrough=1 iommu=off" in kernel boot parameter, or conditionally disable it for VFIO. CONFIG_VFIO_NOIOMMU (optional) - You should enable CONFIG_VFIO_NOIOMMU in the kernel config if your vfio module does not have vfio enable_unsafe_noiommu_mode in the parameter list. * /etc/modprobe.d/vfio.conf $ cat /etc/modprobe.d/vfio.conf # The kernel hungs when 0000:06:00.0 (Non-Volatile memory controller: KIOXIA # Corporation Device 0001) is bound to the vfio-pci module, and the following # error is printed: # # vfio-pci 0000:06:00.0: Unable to change power state from D3hot to D0, device inaccessible # # The configuration below is a workarround for the issue. options vfio-pci disable_idle_d3=1 # Allow using VFIO without IOMMU. This is only required when SMMU is disabled. options vfio enable_unsafe_noiommu_mode=1 * Setup and Test 1. For ease of testing, we take a BF3 and boot the OS into mmc instead of NVMe drive. So leaving NVMe drive free to use. 2. use a test program to verify its correctness. The program create ibv rdma program, open nvme drive, create dma vfio buf from nvme, and let the rdma program read (DMA P2P) the version number of the nvme drive. https://gitlab.com/Mellanox/spdk_team/vfio-dmabuf-test * UAPI changes see "vfio/pci: Allow MMIO regions to be exported through dma-buf" for detail v7: - add back the missing vfio_pci_dma_buf_move code, suggested by Bartlomiej v6: - remove comments, fix the vfio_pci_set_power_state code v5: - add back the missing power management code, suggested by Bartlomiej v4: - fix Makefile v1->v2: - introduce new ioctl uAPI for vfio dma-buf v2->v3: - squash the ioctl uapi change into "vfio/pci: Allow MMIO regions to be exported through dma-buf" Jason Gunthorpe (4): UBUNTU: SAUCE: dma-buf: Add dma_buf_try_get() UBUNTU: SAUCE: vfio: Add vfio_device_get() UBUNTU: SAUCE: vfio_pci: Do not open code pci_try_reset_function() UBUNTU: SAUCE: vfio/pci: Allow MMIO regions to be exported through dma-buf Sergey Gorenko (1): UBUNTU: SAUCE: vfio/pci: Fix p2p address William Tu (1): UBUNTU: [Config] bluefield: add config for VFIO P2P debian.bluefield/config/annotations | 2 + drivers/vfio/pci/Makefile | 1 + drivers/vfio/pci/dma_buf.c | 265 ++++++++++++++++++++++++++++ drivers/vfio/pci/vfio_pci_config.c | 24 +-- drivers/vfio/pci/vfio_pci_core.c | 76 +++++--- drivers/vfio/pci/vfio_pci_priv.h | 28 +++ include/linux/dma-buf.h | 13 ++ include/linux/vfio.h | 5 + include/linux/vfio_pci_core.h | 1 + include/uapi/linux/vfio.h | 17 ++ 10 files changed, 395 insertions(+), 37 deletions(-) create mode 100644 drivers/vfio/pci/dma_buf.c create mode 100644 drivers/vfio/pci/vfio_pci_priv.h Acked-by: Bartlomiej Zolnierkiewicz Acked-by: Agathe Porte