From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795594377; b=I4BJftPhlmqazCiG5LXqaO8vhxqy59tpiP36Qt8P23NYI35V38JI8HLUUODJNPRIZPX9 Xw8J8APgX+NSsp5/WgrOd/tVVQhH5O5Tlr3Y21L23InD/TJzovRSBWqt7SSJ5rHXn7RnA pq81FUqZR9IGtuyK29tVDwNOhWBrw7Yo91DmEXsnWCCSTijRVaGuwgOJnXdbeEISISjPR B7VExudDLU6OjSbczC4KLPBCYe/0/8LnjdTx8KjBxbSSj4PfdjtaYvVzkCDdhc8ICLpiF 0327lc+0CAf9aIv6CbZfiXkUNPth77xT0OGmJaPW6Bn5Sy4mTIViv+YQWk9cTsKxYvA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795594377; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=G6nve8OImXbOUhJAB05sVM7sigeMpkP3mimf0pLHbPE=; b=BPThmctY0YNhL6DCgUZurgNPOGsjjrdKCPqNJzTt2a4+HQQ5AgnbW8hOLs6h92yurTVr +ieu9vrsNrlxJaEd4Dz5iR+HVO0B4JHEZglLOd3Zn2H10ux5aoPWgfwMlygRcwEMlvo06 s6T0OymV/BfcNU+OdQruwLGAf/0CkXE2D8cwge/y6FhTuKHpvV2W+xKEUHXiDDwsJKhs/ rQGo4FD1OAyONx3YZhnyMnTSrJ1zFvDv34p6mSEH+sUvBBIk/wQdPeC1D/K6v5uFn2Nw2 NjbaiM4CyvbjQQDJ6DS5Q/QvmZFU2Sc/uuYyeWimkbgppTpxpTOsANTnm9KucL90EOw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AIYIUKEe; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B367B606A32A; Wed, 25 Nov 2026 08:12:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=AIYIUKEe Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66C611F000C4; Wed, 25 Nov 2026 08:12:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795594377; bh=G6nve8OImXbOUhJAB05sVM7sigeMpkP3mimf0pLHbPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AIYIUKEeRUnAh0Jjj/iR+mLVzSu7dkOxXNVaOwC1glRNq3iNzHUsZ0dsCEeyZtV8U /GnEqjSUM/QwipRzD0zc1LARryJOgdQFTQdF+mU9MQ6BlcjK2d4ppPtVcj7v7NdxZR E5v2xIoAGdiddbALAYqZvhOe3xF6f883UeWmRWicq790TSD4igUT08GNqLezZ719hf 1LUAQf+w6vQgxt1NJXg6HT2BOncJNi9EafcEIbQUJ9HXNdsY1rFL04cEEmH2QUIZTg BYJQdTVmlj9Sg1qXYTEjAkWlffuqcY0bg+dLgZBXZxXTDsbfL6WhFTSuPkED+yuxGZ ljfF/peel5ORQ== From: "Aneesh Kumar K.V (Arm)" To: linux-coco@lists.linux.dev Cc: "Aneesh Kumar K.V (Arm)" , Alex Williamson , Alexey Kardashevskiy , Bjorn Helgaas , Catalin Marinas , Jacob Pan , Jason Gunthorpe , Joerg Roedel , Jonathan Cameron , Jonathan Hunter , Kevin Tian , Krishna Reddy , Lukas Wunner , Nicolin Chen , Robin Murphy , Samuel Ortiz , Shameer Kolothum , Steven Price , Suravee Suthikulpanit , Suzuki K Poulose , Thierry Reding , Vasant Hegde , Will Deacon , Xu Yilun , Ashish Kalra , Herbert Xu , Jonathan Cameron , Tom Lendacky , kvm@vger.kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-tegra@vger.kernel.org, patches@lists.linux.dev, Jason Gunthorpe Subject: [PATCH v10 06/18] iommufd/device: Associate KVM file pointer with iommufd_device Date: Wed, 25 Nov 2026 13:41:09 +0530 Message-ID: <20261125081121.379481-7-aneesh.kumar@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261125081121.379481-1-aneesh.kumar@kernel.org> References: <20261125081121.379481-1-aneesh.kumar@kernel.org> X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Shameer Kolothum TSM vDevice support needs access to the KVM associated with a VFIO device after the device has been bound to iommufd. Extend iommufd_device_bind() to accept the device's KVM file and store it in the iommufd_device. The KVM file reference is owned by VFIO and is already held for the duration of the device open path. Reviewed-by: Kevin Tian Reviewed-by: Jason Gunthorpe Signed-off-by: Shameer Kolothum [nicolinc: fix build error in iommufd_test_mock_domain()] Signed-off-by: Nicolin Chen [aneesh.kumar: Switch to use kvm_file] Cc: Jason Gunthorpe Cc: Kevin Tian Cc: Joerg Roedel Cc: Will Deacon Cc: Robin Murphy Cc: Alex Williamson Cc: iommu@lists.linux.dev Signed-off-by: Aneesh Kumar K.V (Arm) --- drivers/iommu/iommufd/device.c | 7 ++++++- drivers/iommu/iommufd/iommufd_private.h | 2 ++ drivers/iommu/iommufd/selftest.c | 2 +- drivers/vfio/iommufd.c | 3 ++- include/linux/iommufd.h | 4 +++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 1b0bdf57ac8a..935f42616a65 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -295,6 +295,7 @@ static int iommufd_bind_noiommu(struct iommufd_device *idev) * iommufd_device_bind - Bind a physical device to an iommu fd * @ictx: iommufd file descriptor * @dev: Pointer to a physical device struct + * @kvm_file: VM file if device belongs to a KVM VM * @id: Output ID number to return to userspace for this device * * A successful bind establishes an ownership over the device and returns @@ -308,7 +309,9 @@ static int iommufd_bind_noiommu(struct iommufd_device *idev) * The caller must undo this with iommufd_device_unbind() */ struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx, - struct device *dev, u32 *id) + struct device *dev, + struct file *kvm_file, + u32 *id) { struct iommufd_device *idev; int rc; @@ -319,6 +322,8 @@ struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx, idev->ictx = ictx; idev->dev = dev; + /* VFIO holds the file reference while the device is open. */ + idev->kvm_file = kvm_file; if (!iommufd_device_is_noiommu(idev)) rc = iommufd_bind_iommu(idev); diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h index eb2e85b27e42..25236caf554a 100644 --- a/drivers/iommu/iommufd/iommufd_private.h +++ b/drivers/iommu/iommufd/iommufd_private.h @@ -509,6 +509,8 @@ struct iommufd_device { struct list_head group_item; /* always the physical device */ struct device *dev; + /* VM file if available */ + struct file *kvm_file; bool enforce_cache_coherency; struct iommufd_vdevice *vdev; bool destroying; diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index 25387969ab75..b17cca7096b6 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -1071,7 +1071,7 @@ static int iommufd_test_mock_domain(struct iommufd_ucmd *ucmd, goto out_sobj; } - idev = iommufd_device_bind(ucmd->ictx, &sobj->idev.mock_dev->dev, + idev = iommufd_device_bind(ucmd->ictx, &sobj->idev.mock_dev->dev, NULL, &idev_id); if (IS_ERR(idev)) { rc = PTR_ERR(idev); diff --git a/drivers/vfio/iommufd.c b/drivers/vfio/iommufd.c index e9893d34d07b..3beb1b1bae36 100644 --- a/drivers/vfio/iommufd.c +++ b/drivers/vfio/iommufd.c @@ -123,7 +123,8 @@ int vfio_iommufd_physical_bind(struct vfio_device *vdev, { struct iommufd_device *idev; - idev = iommufd_device_bind(ictx, vdev->dev, out_device_id); + idev = iommufd_device_bind(ictx, vdev->dev, vdev->kvm, + out_device_id); if (IS_ERR(idev)) return PTR_ERR(idev); vdev->iommufd_device = idev; diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h index 3087f5b2def8..b03ce0187454 100644 --- a/include/linux/iommufd.h +++ b/include/linux/iommufd.h @@ -59,7 +59,9 @@ struct iommufd_object { }; struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx, - struct device *dev, u32 *id); + struct device *dev, + struct file *kvm_file, + u32 *id); void iommufd_device_unbind(struct iommufd_device *idev); int iommufd_device_attach(struct iommufd_device *idev, ioasid_t pasid, -- 2.43.0