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=1794817231; b=dCf82pbSWA+aPDEakmZlseo96Z/Jik+KVyAuUeqalcsFkNpSCZHkso+RIfvsEPQRloRT wmkteUQZxoCqsRpVVX7e8wuttwLDcS0cHIHQbquBAqAGqbiexXPA4FmIaLtBIVIgeIcbg dbiQso8SHLi94uztQrQQo1XZog7OhI/Dugur70pBnjBTGDmgx5EDOgS9MdpptDECM/PLA X/5tkn3EkVbqDPxhvN7y7WHDozuWeTHUsgodqmYI5j3Ehpoez5mTmt3f5wfWKv8Sn+Ut/ Xe0RupUunGPbH9KTbWEbOyQcqNOGB5X4PnDWV7dev3VXsqtAK10T6YIehE35CDmJk/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794817231; 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=d6vc/9D3R7nEOZrAkzSCTMboj49KDBCHbsVImfPJ3TOQbupfIB40JfDQSy4uwBbApPeW knHWqiOh8A5tnWv/MSgGimRXWNSs5QMubsMx2/j4/X/u5fXhWQh/FhDa+ZMm7Wuvob3Bu Cl01wrJtOPLJ3wCo7NpyK8ORjeSiT3JcUqpXlYjVWbey5pfCvXvFZe0jvaKXHyhyM8KVr beBfQUNMxqKCrfwLa5oQRIQWKXLCmGYKnApoOoMHyvoGVxW599IAjeWsIJ1x9XoHvvW44 glLP6fds2UJF2lzQPgJJRHhGZ3pJ4nvL5wO5RS2yCcQw0oRzTCHcjYe+4D3baRVrSRQ== 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=K7+GSU6e; 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 50D23606A323; Mon, 16 Nov 2026 08:20:31 +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=K7+GSU6e Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00CE41F000C8; Mon, 16 Nov 2026 08:20:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794817231; bh=G6nve8OImXbOUhJAB05sVM7sigeMpkP3mimf0pLHbPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=K7+GSU6eLfm3kI3Q+jb1ewsduz8ZjfbcxhuXCD5u1/6Us7u/fOWjGVgYUGKC6jgyG 5QGgRXQe97+2n4ovajHJVCymY/p1KHCBUHuvTObHs49QyQ/nqJZQ5Sa7t/7SRh2iCH lhLJkdwQv7cJVjymGIuP/CYWPrUJEYyGooRCkImdZqSn7YJ6Mgpf630OZTDX6vTEX+ yTWPptwGjypwaIuWRZpIgb+HjjtZTJtnNZpuUYMv1UVr1CwqrDiD3bTzxzALC7yw7/ ExyspRqhlW4q7QqoDxnv6icdNufhkMZYB1MYb7luCWuYOB6ZOh/sOEafVbLs6Rxtpa 0vHIp8BOOLjuw== 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 , iommu@lists.linux.dev, Jonathan Cameron , Tom Lendacky , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, linux-tegra@vger.kernel.org, patches@lists.linux.dev, Jason Gunthorpe Subject: [PATCH v9 04/13] iommufd/device: Associate KVM file pointer with iommufd_device Date: Mon, 16 Nov 2026 13:49:26 +0530 Message-ID: <20261116081935.85372-5-aneesh.kumar@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261116081935.85372-1-aneesh.kumar@kernel.org> References: <20261116081935.85372-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