From patchwork Wed Sep 11 20:59: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: 1984211 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 4X3tHt5mTgz1y28 for ; Thu, 12 Sep 2024 07:00:10 +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 1soURW-0002k3-Hh; Wed, 11 Sep 2024 21:00:02 +0000 Received: from mail-dm6nam10on2045.outbound.protection.outlook.com ([40.107.93.45] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1soURU-0002iG-RE for kernel-team@lists.ubuntu.com; Wed, 11 Sep 2024 21:00:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=W2kd0X8OSV4p9kQZB5DIfWg0sfXW0h0c8l4Ly4RVzHO8uVIciuqAAzum7u0afgfAEynT338Lg6tTRBncRwAEUM3+OwqVOdCoIi/poB4YxioyWDoJmQDPgW1vJakM2GYAXkTkJVdcBlGljhu95OAY6n477A5TyHrZ2zbHp1LTOEWRPYbt7VroEYF0zSt+V8HIi8vv0M2j1XgMGIoJWPFYUKkMtpHEJEuBC1qx3OlTyYyhIeyj1yorLgE72GdG8DVT4NBF1ZsANiOsf1KMtEMw4Vb1r47Q7VzHSni2I658bjSaG/10ZtkoL5jPcOPrVHz78gT4H+9cmgw99CgsiLj5Yw== 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=ywHS3Kyf9lJ6qEaFpS/c0F3nJohW/xkJUCRv/eEAnsI=; b=drARPAEwDXejmn0m0EEt8O2oSOgYAG+3pWH2HgmxCqh1Pyl1noOCDEwUNHFFLDVDQ92Oz7cYH4pXsRTupy8T8Pt8WjTfKTVixOcLDSrOH7mv4VVDw1zSCzkk5VGW2HVmO4Kg2KL7Sy/6Jua6l4oD64EVPj1XJ7ZbWttRusN/x9tYkn447dAoW1y80fv7nDghR9wY7MFvGrgq3qS0lLcph4FHJVdH8V8OLSU29UXgPLIrbieQ5RLg2A/dSW8948p3qJ0k/yKCLrK5DmSJ8WF65Lq2tXOXG1lspxo7V/zl2rqPuTsnPNU1HDPFGvIDFd/D7KGuGW44GSFAViVespYcXA== 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 BN8PR12CA0014.namprd12.prod.outlook.com (2603:10b6:408:60::27) by MN2PR12MB4224.namprd12.prod.outlook.com (2603:10b6:208:1dd::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7962.18; Wed, 11 Sep 2024 20:59:54 +0000 Received: from BN1PEPF00005FFD.namprd05.prod.outlook.com (2603:10b6:408:60:cafe::96) by BN8PR12CA0014.outlook.office365.com (2603:10b6:408:60::27) 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:59:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by BN1PEPF00005FFD.mail.protection.outlook.com (10.167.243.229) 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:59:54 +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, 11 Sep 2024 13:59:44 -0700 Received: from drhqmail202.nvidia.com (10.126.190.181) 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, 11 Sep 2024 13:59:43 -0700 Received: from vdi.nvidia.com (10.127.8.12) by mail.nvidia.com (10.126.190.181) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 11 Sep 2024 13:59:43 -0700 From: William Tu To: Subject: [SRU][J:linux-bluefield][PATCH v4 0/6] Add VFIO P2P support Date: Wed, 11 Sep 2024 20:59:33 +0000 Message-ID: <20240911205939.85317-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: BN1PEPF00005FFD:EE_|MN2PR12MB4224:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f02804e-cb9e-4baa-176c-08dcd2a4afac 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: 6tqSXFt+D21OqV2vfg6YJjQaxqeJqm0JF1HU4TOe5m1P1LBT3sS7uxrm+ONCnSpmPAXGNQxNaBQ78AykDXtCMGadHBM6PAr+Dbi8OYWW4bzq2MK/gZOQpqVOd05HJBQd13kQWLyB3cGz6vsB8gfNFsWyVKEviTJQogZ91t+5GQ6RFydn5xwAh92Yq5rGvxNZb6n5c6M/fdoLWB+qMdq0hMDa9o1J5OMsS3PBxz+5LX0NnMl5hJvG7JBWKFhfdJy+1AnhpaoRju3MqeNgy/8ua5GO32hcY+1oL/lNMAM4W2/1TueknM2ptuhAee+CiQQ14YohysYgyXeh0QVaz/VOaNUq7tqUzlwm+M4a29FoarL227b+ZyblwS1LHOdI4YChr1FdOaaKcKXojEyHcnX7UXAcXwqbBOiiUH0RGTUYmZ6FIMHALEOT0eJC19F2guZwC5+1P+gs35DojqbjZyTrc8pw64VNlDUcbDvXG3rjZ3OaH3bIKOHiJbJNqjXoH3paC+3XelLS/b3wIHRq+Q1e5aAcEkc3jjl4PmINR19pC2JNhw11ob0gcpEZj1/xxdR90VAg2hNvVdG/UBzH4RBWqC0QnlUU2OaYQS2LG8iRLDBXbsO+tfNYh9SC8CM9yLQCCjhiCFS+ts6CHEPft2MTokIG2fE9zwTAzYBG3Apnsv6oK9jTCyT5YztM2tjKMlk0zTxJTxZJzjj3ntqlAPuzyGsR6BbkepiN8sL1a1YnDnOrgZ8LP5ixxFo2t4a9Eea+rNdNODr/EiBz0yva2k63NOUT141BKdqB68pjfLXN7sUFLryCExh03w5rzjNuPDpHRqm0f0/GV7TurBS/Tf4AcqFxHETrE5eN+WX5uVSw6GnsWhq6MmBQR9vQTAYhksLdzq8cZesi1s25ApC3vkFt8p73eL1UKjI13rkrlVjSIecUUhmFt4ApaYF1L6HZtBxXE3FQkG2pjIQPZFLxhgGMlVVNMPYRjNzQDVrnqLZZ1uD1NE2y6U5kb/KvrVuYtm3eoqpFTuPyVuakrH7tBZTDJXkTMoc1JkFpU0SamoIu2islpLinhSX39cymezjKTJnL8hGn6MXhBdGq2gt9yIAYB28Af+IHwljA23Fo7IJ4tszEuWIG6V+a50xneCjgHukg2C6P+rgtdX3mh9NbClWuAhTjUMrb17JclQMWKtlwt4Vph8WHwf6pUDa+A58vxji5w3LcJM5sYBe9iYbemzu2GPadJolq7HBmBww9nWPbsCznDmkvtYeUZkL3eqzcIe122O5opnAB849/Wt2IRdAJA9mVu4DbuAOs3CVQW96Jw0z45dscdnT1mDgTRF72K0WcxkFOGhfkIXYpTb7aVbtGmVJ2iwb5tzF53Xy05IcH6EvZkiwkkc7qrsXp+3x45uMOjK8tcU0308zVUuErfYMvwHOC17Y+eS/+FoiiZnooRrIYddX2kErT6k18GPnneDjz 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: 11 Sep 2024 20:59:54.1653 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0f02804e-cb9e-4baa-176c-08dcd2a4afac 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: BN1PEPF00005FFD.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4224 Received-SPF: softfail client-ip=40.107.93.45; envelope-from=witu@nvidia.com; helo=NAM10-DM6-obe.outbound.protection.outlook.com X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vlad@nvidia.com, bodong@nvidia.com, sergeygo@nvidia.com, jgg@nvidia.com, zwaksman@nvidia.com Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" BugLink: https://bugs.launchpad.net/bugs/2077887 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 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 | 64 ++++--- 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 | 28 +++ 10 files changed, 393 insertions(+), 38 deletions(-) create mode 100644 drivers/vfio/pci/dma_buf.c create mode 100644 drivers/vfio/pci/vfio_pci_priv.h