From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C69939B94C;
	Mon,  9 Mar 2026 11:17:27 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773055048; cv=none; b=cw+wWhERnvAXmhT2YfbfzVKoNnwvsdxNT777YVOludNIldzYaZ1k3ULsqJYPCDsAHsbjEcF+4tlQWjdZ/jxUAykgJTj/efgNI52rrbPRdv7Uokf9juPrSRaOV/dJQD2S9YpOUY9Lu/QyhS+Rqs4ZjToup2kRPixjeX4pRUvvEog=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773055048; c=relaxed/simple;
	bh=SnmyFF1XhivWaff3cyVDTm+Im2RbOKLj8Y3ciYszN7k=;
	h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bbijGatOVSmhpI+oUqZ51fwaYT2PrA1jbBHHK7l9gv4005Q0ppPZ5+bqJAXitC9gIfJmO9xg+sx0P2LWBSK7ycc+x8mqNuoRdMGEvjDCsTYck9fH3T6RBUwnRD5swEYBZyapIvflte6hvQ292k+bvTovlTjGqKHonzj5ETG/6V8=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FYkoQYw2; arc=none smtp.client-ip=10.30.226.201
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FYkoQYw2"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06D09C4CEF7;
	Mon,  9 Mar 2026 11:17:25 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=k20201202; t=1773055047;
	bh=SnmyFF1XhivWaff3cyVDTm+Im2RbOKLj8Y3ciYszN7k=;
	h=From:To:Cc:Subject:Date:From;
	b=FYkoQYw2zMbmsB5a4Zg6oMiB50D8VDqvzw9kxL2z1M/Dwv7enDYy+XRKOHOv8d7SQ
	 bQHHRrDxMt69JPyGtYisY29w43KqeS/lbMq21EbJ9BvGc08qu+Az5vsp/O+8eLxQS7
	 opT63/r5Gg7AgFbg3JZGNCUDbtgJRiBRzB6SdbgOQNXlEEMfpN+BuzSBcx61ZHj0Hn
	 qZ3fyDi6yexUItC3vJg8qVafYeQPp2rUk89JqpQ4zW9BRQRwmrfEMXO+8GDG6QtMkV
	 NFZ7Fwegjhy3om6p0e68TJR0ppMj7SJ8aYX9dKS9/zd3yfOsf0BZXXcVWdPjBt724i
	 3i4QrqNmeKGoQ==
From: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
To: iommu@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org
Cc: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
Subject: [PATCH v2 0/3] Add iommufd ioctls to support TSM operations
Date: Mon,  9 Mar 2026 16:47:01 +0530
Message-ID: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
X-Mailer: git-send-email 2.43.0
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

This patch series adds iommufd ioctl support for TSM-related operations.
These ioctls allow VMMs to perform TSM management tasks such as bind/unbind
operations and handling guest requests.

This series is posted separately in v2. The v1 posting is available at:
https://lore.kernel.org/all/20250728135216.48084-8-aneesh.kumar@kernel.org

Changes from v1:
* Rebased onto the latest kernel
* Addressed review feedback
* Dropped the TSM map ioctl; the KVM prefault patch will be used instead to
  ensure private memory is preallocated

Aneesh Kumar K.V (Arm) (3):
  iommufd/viommu: Allow associating a KVM VM fd with a vIOMMU
  iommufd/tsm: add vdevice TSM bind/unbind ioctl
  iommufd/vdevice: add TSM guest request ioctl

 drivers/iommu/iommufd/Makefile          |   2 +
 drivers/iommu/iommufd/iommufd_private.h |  15 ++++
 drivers/iommu/iommufd/main.c            |   6 ++
 drivers/iommu/iommufd/tsm.c             | 115 ++++++++++++++++++++++++
 drivers/iommu/iommufd/viommu.c          |  57 +++++++++++-
 drivers/virt/coco/tsm-core.c            |  33 +++++++
 include/linux/iommufd.h                 |   3 +
 include/linux/tsm.h                     |  44 +++++++++
 include/uapi/linux/iommufd.h            |  54 ++++++++++-
 virt/kvm/kvm_main.c                     |   2 +-
 10 files changed, 328 insertions(+), 3 deletions(-)
 create mode 100644 drivers/iommu/iommufd/tsm.c

-- 
2.43.0


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3D93399032;
	Mon,  9 Mar 2026 11:17:33 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773055053; cv=none; b=UfglHdRhI5zuuWR1e6dFrBIx7q9warDNeQA4eGs9SspKAyGHJAWfNMSPu/heDRWnVDPsdskK8AgMI3+l6bm4t5A71A3YmpOmrVZ3eJWPWrOamMgFXow+XKSIKRhDjEebRxDElLyh30scyxyrhGmgyxTYTHxogQxhV3vMiRq3RW4=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773055053; c=relaxed/simple;
	bh=F5Zm0UVICZbWezI1fp8Hz+Q6fqxqJVOmYIbu8pPJtcE=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version; b=kQVEmCwjDK0oDGwvdoBFLkICu0RgDPyo6CsxZWj52VW3r8wub7IOVrXAHPXs7aagMSFqLa/afRdy47C0cQZoECieNBZjhIOGWK/O7yoq28U2JGR1l/6ubWXA1mrmdS6/ZfCkT9y2tUmehvlDD9pIMtW1Bf2ijsKErILvdqoKLvI=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KThGJ7eq; arc=none smtp.client-ip=10.30.226.201
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KThGJ7eq"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41BE2C2BCAF;
	Mon,  9 Mar 2026 11:17:27 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=k20201202; t=1773055053;
	bh=F5Zm0UVICZbWezI1fp8Hz+Q6fqxqJVOmYIbu8pPJtcE=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
	b=KThGJ7eqNHRweBH21oVCx0yy4L4ILEJTW5ln+J9ETxSGvIy9XH75fDwkOVPSClCH5
	 jhWBbXPc7RVfHIUk0/bbZDBwvFkhvjx1uKastEbT0iEltR2L2LXglSrIywcvASGZlg
	 dFO1lyklF+SFLv/M07dAfaGHPbOVY9Zv4SEcNdWS0SqJJKgMl8TQRUOyQ78y/qg+vR
	 PgRdsHenEV2o1zUtzlWETntx5eiBi2Aa02r/LIL0J9FIijyAj9L7+arvDhFUqP5EfE
	 GVThSMmy3K3nSY40o9P5c6j84WHrFipPaadPfWqNSpzkFaVfrsOYQuDrXbFwlUNdv3
	 4Cp3Dl+1wceYg==
From: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
To: iommu@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org
Cc: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>,
	Kevin Tian <kevin.tian@intel.com>,
	Joerg Roedel <joro@8bytes.org>,
	Will Deacon <will@kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	Steven Price <steven.price@arm.com>
Subject: [PATCH v2 1/3] iommufd/viommu: Allow associating a KVM VM fd with a vIOMMU
Date: Mon,  9 Mar 2026 16:47:02 +0530
Message-ID: <20260309111704.2330479-2-aneesh.kumar@kernel.org>
X-Mailer: git-send-email 2.43.0
In-Reply-To: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Add optional KVM association to IOMMU_VIOMMU_ALLOC by introducing
IOMMU_VIOMMU_KVM_FD and iommu_viommu_alloc::kvm_vm_fd.

When the flag is set, iommufd validates that kvm_vm_fd refers to a KVM
VM file and stores a referenced struct file in the vIOMMU object, so
later iommufd operations can safely resolve the owning VM.

This is preparatory plumbing for subsequent patches that bind TDI state
to the associated KVM VM.

The patch also switch file_is_kvm from EXPORT_SYMBOL_FOR_KVM_INTERNAL to
EXPORT_SYMBOL_GPL so that iommu module can use that.

Cc: Kevin Tian <kevin.tian@intel.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Will Deacon <will@kernel.org>
Cc: Bjorn Helgaas <helgaas@kernel.org>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Alexey Kardashevskiy <aik@amd.com>
Cc: Samuel Ortiz <sameo@rivosinc.com>
Cc: Xu Yilun <yilun.xu@linux.intel.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
Cc: Steven Price <steven.price@arm.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
 drivers/iommu/iommufd/viommu.c | 54 +++++++++++++++++++++++++++++++++-
 include/linux/iommufd.h        |  3 ++
 include/uapi/linux/iommufd.h   | 13 +++++++-
 virt/kvm/kvm_main.c            |  2 +-
 4 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c
index 4081deda9b33..08f8930c86da 100644
--- a/drivers/iommu/iommufd/viommu.c
+++ b/drivers/iommu/iommufd/viommu.c
@@ -2,6 +2,45 @@
 /* Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES
  */
 #include "iommufd_private.h"
+#include <linux/cleanup.h>
+
+#if IS_ENABLED(CONFIG_KVM)
+#include <linux/kvm_host.h>
+
+static int viommu_get_kvm(struct iommufd_viommu *viommu, int kvm_vm_fd)
+{
+	int rc = -EBADF;
+	struct file *filp __free(fput) = fget(kvm_vm_fd);
+
+	if (!file_is_kvm(filp))
+		return rc;
+
+	/* hold the kvm reference via file descriptor */
+	viommu->kvm_filp = no_free_ptr(filp);
+	return 0;
+}
+
+static void viommu_put_kvm(struct iommufd_viommu *viommu)
+{
+	if (!viommu->kvm_filp)
+		return;
+
+	fput(viommu->kvm_filp);
+	viommu->kvm_filp = NULL;
+}
+
+#else
+
+static inline int viommu_get_kvm(struct iommufd_viommu *viommu, int kvm_vm_fd)
+{
+	return -EOPNOTSUPP;
+}
+
+static inline void viommu_put_kvm(struct iommufd_viommu *viommu)
+{
+}
+
+#endif
 
 void iommufd_viommu_destroy(struct iommufd_object *obj)
 {
@@ -12,6 +51,8 @@ void iommufd_viommu_destroy(struct iommufd_object *obj)
 		viommu->ops->destroy(viommu);
 	refcount_dec(&viommu->hwpt->common.obj.users);
 	xa_destroy(&viommu->vdevs);
+
+	viommu_put_kvm(viommu);
 }
 
 int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
@@ -29,7 +70,9 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
 	size_t viommu_size;
 	int rc;
 
-	if (cmd->flags || cmd->type == IOMMU_VIOMMU_TYPE_DEFAULT)
+	if (cmd->flags & ~IOMMU_VIOMMU_KVM_FD)
+		return -EOPNOTSUPP;
+	if (cmd->type == IOMMU_VIOMMU_TYPE_DEFAULT)
 		return -EOPNOTSUPP;
 
 	idev = iommufd_get_device(ucmd, cmd->dev_id);
@@ -100,8 +143,17 @@ int iommufd_viommu_alloc_ioctl(struct iommufd_ucmd *ucmd)
 		goto out_put_hwpt;
 	}
 
+	/* get the kvm details if specified. */
+	if (cmd->flags & IOMMU_VIOMMU_KVM_FD) {
+		rc = viommu_get_kvm(viommu, cmd->kvm_vm_fd);
+		if (rc)
+			goto out_put_hwpt;
+	}
+
 	cmd->out_viommu_id = viommu->obj.id;
 	rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
+	if (rc)
+		viommu_put_kvm(viommu);
 
 out_put_hwpt:
 	iommufd_put_object(ucmd->ictx, &hwpt_paging->common.obj);
diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h
index 6e7efe83bc5d..7c515d3c52db 100644
--- a/include/linux/iommufd.h
+++ b/include/linux/iommufd.h
@@ -12,6 +12,7 @@
 #include <linux/refcount.h>
 #include <linux/types.h>
 #include <linux/xarray.h>
+#include <linux/file.h>
 #include <uapi/linux/iommufd.h>
 
 struct device;
@@ -58,6 +59,7 @@ struct iommufd_object {
 	unsigned int id;
 };
 
+struct kvm;
 struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx,
 					   struct device *dev, u32 *id);
 void iommufd_device_unbind(struct iommufd_device *idev);
@@ -101,6 +103,7 @@ struct iommufd_viommu {
 	struct iommufd_ctx *ictx;
 	struct iommu_device *iommu_dev;
 	struct iommufd_hwpt_paging *hwpt;
+	struct file *kvm_filp;
 
 	const struct iommufd_viommu_ops *ops;
 
diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h
index 1dafbc552d37..b862c3e57133 100644
--- a/include/uapi/linux/iommufd.h
+++ b/include/uapi/linux/iommufd.h
@@ -1071,10 +1071,19 @@ struct iommu_viommu_tegra241_cmdqv {
 	__aligned_u64 out_vintf_mmap_length;
 };
 
+/**
+ * define IOMMU_VIOMMU_KVM_FD - Flag indicating a valid KVM VM file descriptor
+ *
+ * Set this flag when allocating a viommu instance that should be associated
+ * with a specific KVM VM. If this flag is not provided,
+ * @iommu_viommu_alloc::kvm_vm_fd is ignored.
+ */
+#define IOMMU_VIOMMU_KVM_FD	BIT(0)
+
 /**
  * struct iommu_viommu_alloc - ioctl(IOMMU_VIOMMU_ALLOC)
  * @size: sizeof(struct iommu_viommu_alloc)
- * @flags: Must be 0
+ * @flags: Supported flags (IOMMU_VIOMMU_KVM_FD)
  * @type: Type of the virtual IOMMU. Must be defined in enum iommu_viommu_type
  * @dev_id: The device's physical IOMMU will be used to back the virtual IOMMU
  * @hwpt_id: ID of a nesting parent HWPT to associate to
@@ -1082,6 +1091,7 @@ struct iommu_viommu_tegra241_cmdqv {
  * @data_len: Length of the type specific data
  * @__reserved: Must be 0
  * @data_uptr: User pointer to a driver-specific virtual IOMMU data
+ * @kvm_vm_fd: KVM VM file descriptor when IOMMU_VIOMMU_KVM_FD is set
  *
  * Allocate a virtual IOMMU object, representing the underlying physical IOMMU's
  * virtualization support that is a security-isolated slice of the real IOMMU HW
@@ -1105,6 +1115,7 @@ struct iommu_viommu_alloc {
 	__u32 data_len;
 	__u32 __reserved;
 	__aligned_u64 data_uptr;
+	__s32 kvm_vm_fd;
 };
 #define IOMMU_VIOMMU_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VIOMMU_ALLOC)
 
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 1bc1da66b4b0..f076c5a7a290 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -5481,7 +5481,7 @@ bool file_is_kvm(struct file *file)
 {
 	return file && file->f_op == &kvm_vm_fops;
 }
-EXPORT_SYMBOL_FOR_KVM_INTERNAL(file_is_kvm);
+EXPORT_SYMBOL_GPL(file_is_kvm);
 
 static int kvm_dev_ioctl_create_vm(unsigned long type)
 {
-- 
2.43.0


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C15D3A1D1F;
	Mon,  9 Mar 2026 11:17:38 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773055059; cv=none; b=ue9GbiDgHYhUCQ6DEZ9POQvWBhCDmRTtKppSNBeo+VX5c9jRJpEmGF0qvREFe3PsRsO2JI3v5OOcqBLyovZrgabJeF2pMRclJ3GISUdfjmQAJiwAmA6W+6AqlxCb3/IPo/kBf/EQEoaud9GZ0f9ntb1jTWWLVvyhxMyLC2FP6LY=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773055059; c=relaxed/simple;
	bh=FXOwjOtb0lik0JoRc6nz9TJV7sakxmBgRJTv/CV2Al0=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version; b=e48NP+K4LEYbhAnksbA5PJgyfA7m/IgriSdb/Tsq2NNG4XA+yYETklsTqo0NdwOTHBSTE9/W4pc+ESLzO+BxW7gDhcm3b7tyXKumxYPIHIlTJcYgHl8XmTupX05oLP5pd/GiwfjPVEvhRScb7rAEzMsqigbFGOJqYsRL1nuiSf4=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eZm8CLQM; arc=none smtp.client-ip=10.30.226.201
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eZm8CLQM"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id B40F4C4CEF7;
	Mon,  9 Mar 2026 11:17:33 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=k20201202; t=1773055058;
	bh=FXOwjOtb0lik0JoRc6nz9TJV7sakxmBgRJTv/CV2Al0=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
	b=eZm8CLQMQwSuaSi2fIn8FCx4Fm8UFjpb4+EmGP2N2QpqmxPXn1OT87DMFJnUCLiRg
	 37bdD30hy6m7FEd+VVat2QOdoOOTR4gZSBnqdFzvfMhhkhXQsptDRTSAEoNsXjhI0v
	 JxYVOiYvV/8L1yNl1oJiPZ4zFICe5sz611jsxUMqARUJBK8BK4R3BLYauorqa1qOn7
	 9hBlK9Nx0o/TaBGOUAe5+Ab2CbjTjmdjMKdlu1RUrNpIeHAf2mKX1m6ueJPK6GZM31
	 ti0IY+MN/50JfhxOkIgz0p6faEmWt5g9KbFn9FVBN940DkTKECqvG2sewwWqI6eOJS
	 o6a/mDFSxslUw==
From: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
To: iommu@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org
Cc: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>,
	Kevin Tian <kevin.tian@intel.com>,
	Joerg Roedel <joro@8bytes.org>,
	Will Deacon <will@kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	Steven Price <steven.price@arm.com>
Subject: [PATCH v2 2/3] iommufd/tsm: add vdevice TSM bind/unbind ioctl
Date: Mon,  9 Mar 2026 16:47:03 +0530
Message-ID: <20260309111704.2330479-3-aneesh.kumar@kernel.org>
X-Mailer: git-send-email 2.43.0
In-Reply-To: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Introduce IOMMU_VDEVICE_TSM_OP to allow userspace to issue TSM bind/unbind
operations for an iommufd vdevice.

The new ioctl:
- looks up the vdevice object from vdevice_id
- resolves the associated KVM VM from the vIOMMU KVM file reference
- dispatches bind/unbind via tsm_bind()/tsm_unbind()

Also add common TSM helpers in tsm-core and wire vdevice teardown to unbind
the device from TSM state.

This provides iommufd plumbing to bind a TDI to a confidential guest through
the TSM layer.

Cc: Kevin Tian <kevin.tian@intel.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Will Deacon <will@kernel.org>
Cc: Bjorn Helgaas <helgaas@kernel.org>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Alexey Kardashevskiy <aik@amd.com>
Cc: Samuel Ortiz <sameo@rivosinc.com>
Cc: Xu Yilun <yilun.xu@linux.intel.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
Cc: Steven Price <steven.price@arm.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
 drivers/iommu/iommufd/Makefile          |  2 +
 drivers/iommu/iommufd/iommufd_private.h |  8 +++
 drivers/iommu/iommufd/main.c            |  3 ++
 drivers/iommu/iommufd/tsm.c             | 67 +++++++++++++++++++++++++
 drivers/iommu/iommufd/viommu.c          |  3 ++
 drivers/virt/coco/tsm-core.c            | 19 +++++++
 include/linux/tsm.h                     | 18 +++++++
 include/uapi/linux/iommufd.h            | 18 +++++++
 8 files changed, 138 insertions(+)
 create mode 100644 drivers/iommu/iommufd/tsm.c

diff --git a/drivers/iommu/iommufd/Makefile b/drivers/iommu/iommufd/Makefile
index 71d692c9a8f4..431089089ee9 100644
--- a/drivers/iommu/iommufd/Makefile
+++ b/drivers/iommu/iommufd/Makefile
@@ -10,6 +10,8 @@ iommufd-y := \
 	vfio_compat.o \
 	viommu.o
 
+iommufd-$(CONFIG_TSM) += tsm.o
+
 iommufd-$(CONFIG_IOMMUFD_TEST) += selftest.o
 
 obj-$(CONFIG_IOMMUFD) += iommufd.o
diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h
index 6ac1965199e9..aa1ceed924c2 100644
--- a/drivers/iommu/iommufd/iommufd_private.h
+++ b/drivers/iommu/iommufd/iommufd_private.h
@@ -697,6 +697,14 @@ void iommufd_vdevice_destroy(struct iommufd_object *obj);
 void iommufd_vdevice_abort(struct iommufd_object *obj);
 int iommufd_hw_queue_alloc_ioctl(struct iommufd_ucmd *ucmd);
 void iommufd_hw_queue_destroy(struct iommufd_object *obj);
+#ifdef CONFIG_TSM
+int iommufd_vdevice_tsm_op_ioctl(struct iommufd_ucmd *ucmd);
+#else
+static inline int iommufd_vdevice_tsm_op_ioctl(struct iommufd_ucmd *ucmd)
+{
+	return -EOPNOTSUPP;
+}
+#endif
 
 static inline struct iommufd_vdevice *
 iommufd_get_vdevice(struct iommufd_ctx *ictx, u32 id)
diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c
index 8c6d43601afb..d73e6b391c6f 100644
--- a/drivers/iommu/iommufd/main.c
+++ b/drivers/iommu/iommufd/main.c
@@ -432,6 +432,7 @@ union ucmd_buffer {
 	struct iommu_veventq_alloc veventq;
 	struct iommu_vfio_ioas vfio_ioas;
 	struct iommu_viommu_alloc viommu;
+	struct iommu_vdevice_tsm_op tsm_op;
 #ifdef CONFIG_IOMMUFD_TEST
 	struct iommu_test_cmd test;
 #endif
@@ -493,6 +494,8 @@ static const struct iommufd_ioctl_op iommufd_ioctl_ops[] = {
 		 __reserved),
 	IOCTL_OP(IOMMU_VIOMMU_ALLOC, iommufd_viommu_alloc_ioctl,
 		 struct iommu_viommu_alloc, out_viommu_id),
+	IOCTL_OP(IOMMU_VDEVICE_TSM_OP, iommufd_vdevice_tsm_op_ioctl,
+		 struct iommu_vdevice_tsm_op, vdevice_id),
 #ifdef CONFIG_IOMMUFD_TEST
 	IOCTL_OP(IOMMU_TEST_CMD, iommufd_test, struct iommu_test_cmd, last),
 #endif
diff --git a/drivers/iommu/iommufd/tsm.c b/drivers/iommu/iommufd/tsm.c
new file mode 100644
index 000000000000..401469110752
--- /dev/null
+++ b/drivers/iommu/iommufd/tsm.c
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2026 ARM Ltd.
+ */
+
+#include "iommufd_private.h"
+#include <linux/tsm.h>
+
+/**
+ * iommufd_vdevice_tsm_op_ioctl - Handle vdevice TSM operations
+ * @ucmd: user command data for IOMMU_VDEVICE_TSM_OP
+ *
+ * Currently only supports TSM bind/unbind operations
+ * Resolve @iommu_vdevice_tsm_op::vdevice_id to a vdevice and dispatch the
+ * requested bind/unbind operation through the TSM core.
+ *
+ * Return: 0 on success, or a negative error code on failure.
+ */
+int iommufd_vdevice_tsm_op_ioctl(struct iommufd_ucmd *ucmd)
+{
+	int rc;
+	struct kvm *kvm;
+	struct iommufd_vdevice *vdev;
+	struct iommu_vdevice_tsm_op *cmd = ucmd->cmd;
+
+	if (cmd->flags)
+		return -EOPNOTSUPP;
+
+	vdev = container_of(iommufd_get_object(ucmd->ictx, cmd->vdevice_id,
+					       IOMMUFD_OBJ_VDEVICE),
+			    struct iommufd_vdevice, obj);
+	if (IS_ERR(vdev))
+		return PTR_ERR(vdev);
+
+	if (!vdev->viommu->kvm_filp) {
+		rc = -ENODEV;
+		goto out_put_vdev;
+	}
+
+	kvm = vdev->viommu->kvm_filp->private_data;
+	if (!kvm) {
+		rc = -ENODEV;
+		goto out_put_vdev;
+	}
+
+	/* tsm layer will take care of parallel calls to tsm_bind/unbind */
+	switch (cmd->op) {
+	case IOMMU_VDEVICE_TSM_BIND:
+		rc = tsm_bind(vdev->idev->dev, kvm, vdev->virt_id);
+		break;
+	case IOMMU_VDEVICE_TSM_UNBIND:
+		rc = tsm_unbind(vdev->idev->dev);
+		break;
+	default:
+		rc = -EINVAL;
+		goto out_put_vdev;
+	}
+
+	if (rc)
+		goto out_put_vdev;
+
+	rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
+
+out_put_vdev:
+	iommufd_put_object(ucmd->ictx, &vdev->obj);
+	return rc;
+}
diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c
index 08f8930c86da..8eb7a3441a61 100644
--- a/drivers/iommu/iommufd/viommu.c
+++ b/drivers/iommu/iommufd/viommu.c
@@ -3,6 +3,7 @@
  */
 #include "iommufd_private.h"
 #include <linux/cleanup.h>
+#include <linux/tsm.h>
 
 #if IS_ENABLED(CONFIG_KVM)
 #include <linux/kvm_host.h>
@@ -171,6 +172,8 @@ void iommufd_vdevice_abort(struct iommufd_object *obj)
 
 	lockdep_assert_held(&idev->igroup->lock);
 
+	tsm_unbind(idev->dev);
+
 	if (vdev->destroy)
 		vdev->destroy(vdev);
 	/* xa_cmpxchg is okay to fail if alloc failed xa_cmpxchg previously */
diff --git a/drivers/virt/coco/tsm-core.c b/drivers/virt/coco/tsm-core.c
index ae3617abd2ac..f0e35fc38776 100644
--- a/drivers/virt/coco/tsm-core.c
+++ b/drivers/virt/coco/tsm-core.c
@@ -240,6 +240,25 @@ void tsm_ide_stream_unregister(struct pci_ide *ide)
 }
 EXPORT_SYMBOL_GPL(tsm_ide_stream_unregister);
 
+int tsm_bind(struct device *dev, struct kvm *kvm, u64 tdi_id)
+{
+	if (!dev_is_pci(dev))
+		return -EINVAL;
+
+	return pci_tsm_bind(to_pci_dev(dev), kvm, tdi_id);
+}
+EXPORT_SYMBOL_GPL(tsm_bind);
+
+int tsm_unbind(struct device *dev)
+{
+	if (!dev_is_pci(dev))
+		return -EINVAL;
+
+	pci_tsm_unbind(to_pci_dev(dev));
+	return 0;
+}
+EXPORT_SYMBOL_GPL(tsm_unbind);
+
 static void tsm_release(struct device *dev)
 {
 	struct tsm_dev *tsm_dev = container_of(dev, typeof(*tsm_dev), dev);
diff --git a/include/linux/tsm.h b/include/linux/tsm.h
index 7f72a154b6b2..9f2a7868021a 100644
--- a/include/linux/tsm.h
+++ b/include/linux/tsm.h
@@ -124,6 +124,24 @@ struct tsm_dev *tsm_register(struct device *parent, struct pci_tsm_ops *ops);
 void tsm_unregister(struct tsm_dev *tsm_dev);
 struct tsm_dev *find_tsm_dev(int id);
 struct pci_ide;
+struct kvm;
 int tsm_ide_stream_register(struct pci_ide *ide);
 void tsm_ide_stream_unregister(struct pci_ide *ide);
+#ifdef CONFIG_TSM
+int tsm_bind(struct device *dev, struct kvm *kvm, u64 tdi_id);
+int tsm_unbind(struct device *dev);
+
+#else
+
+static inline int tsm_bind(struct device *dev, struct kvm *kvm, u64 tdi_id)
+{
+	return -EINVAL;
+}
+
+static inline int tsm_unbind(struct device *dev)
+{
+	return 0;
+}
+#endif
+
 #endif /* __TSM_H */
diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h
index b862c3e57133..653402e7048a 100644
--- a/include/uapi/linux/iommufd.h
+++ b/include/uapi/linux/iommufd.h
@@ -57,6 +57,7 @@ enum {
 	IOMMUFD_CMD_IOAS_CHANGE_PROCESS = 0x92,
 	IOMMUFD_CMD_VEVENTQ_ALLOC = 0x93,
 	IOMMUFD_CMD_HW_QUEUE_ALLOC = 0x94,
+	IOMMUFD_CMD_VDEVICE_TSM_OP = 0x95,
 };
 
 /**
@@ -1174,6 +1175,23 @@ enum iommu_veventq_flag {
 	IOMMU_VEVENTQ_FLAG_LOST_EVENTS = (1U << 0),
 };
 
+/**
+ * struct iommu_vdevice_tsm_op - ioctl(IOMMU_VDEVICE_TSM_OP)
+ * @size: sizeof(struct iommu_vdevice_tsm_op)
+ * @op: Either TSM_BIND or TSM_UNBIND
+ * @flags: Must be 0
+ * @vdevice_id: Object handle for the vDevice. Returned from IOMMU_VDEVICE_ALLOC
+ */
+struct iommu_vdevice_tsm_op {
+	__u32 size;
+	__u32 op;
+	__u32 flags;
+	__u32 vdevice_id;
+};
+#define IOMMU_VDEVICE_TSM_OP	_IO(IOMMUFD_TYPE, IOMMUFD_CMD_VDEVICE_TSM_OP)
+#define IOMMU_VDEVICE_TSM_BIND		0x1
+#define IOMMU_VDEVICE_TSM_UNBIND	0x2
+
 /**
  * struct iommufd_vevent_header - Virtual Event Header for a vEVENTQ Status
  * @flags: Combination of enum iommu_veventq_flag
-- 
2.43.0


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B0A73A1A4D;
	Mon,  9 Mar 2026 11:17:44 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773055064; cv=none; b=LEewX/pW0qI6N3TpcF/s4JESMvRp0M4RZoRVNaEmaE8CC9Mv6L78v8Rwo8/4HqO6+kIYnSy6vOjjwRJePSlXsV972l7RTtvRDZT1MiiH+knJHY50tmcia1VLoL/1vq/k4WaQEM/KhTc7qs6jdDjZJlWqlpG2kQmZR43EX6mPcc0=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773055064; c=relaxed/simple;
	bh=OtGshxzVApu9OGSwfjeOY5QHAt1HWmJXqthR23/nz0s=;
	h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:
	 MIME-Version; b=oLSMYTFYv6T0n64xMvWfCiJfLPipkxAegm5kd7AOehCeorKPLclr/TC1x+FlvkdnOg0Ea81V5KZx5BUIm+t/szEvqwhKFA3m3ieownTj6wluMxei4aQv1uMmcfCwKhZxQB0E+GYCUUgxPizeJhqqi47Pta/18jkX7hqAqjJAnZU=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=uc2eixKr; arc=none smtp.client-ip=10.30.226.201
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uc2eixKr"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EE39C2BCAF;
	Mon,  9 Mar 2026 11:17:38 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=k20201202; t=1773055064;
	bh=OtGshxzVApu9OGSwfjeOY5QHAt1HWmJXqthR23/nz0s=;
	h=From:To:Cc:Subject:Date:In-Reply-To:References:From;
	b=uc2eixKrtDMbfFAXjIrfoSv/n/itUKbdR0cZhd/Qn8caO1xEjexj6Nkiib+g9XtZc
	 hdMMmoMJh9ZZjINoWj97F0f9w3aROOZfqjR4h3EqZU2KbpJwy6i+hhSnRr64TQcmod
	 OrJCeITA0NDg8Wddphk2cg2PkE9vzAwUOWg25zl82WQytZ6vQISKLJi1u/8An7kobL
	 GE7iwQeReCYfHMvKx0onHaeeTLBVKnV5uJbMEihU64Ns9CEDpdrOAFRlTWl6cLdGQ3
	 p1HxRxOHMY1W4B3Y5c2bWhb4HJNtQirWHwv+8oN7U0HG6kDTamzS6Se+FjD4OxNrbS
	 GiwqRmmV4R3YQ==
From: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
To: iommu@lists.linux.dev,
	linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org
Cc: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>,
	Kevin Tian <kevin.tian@intel.com>,
	Joerg Roedel <joro@8bytes.org>,
	Will Deacon <will@kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	Steven Price <steven.price@arm.com>
Subject: [PATCH v2 3/3] iommufd/vdevice: add TSM guest request ioctl
Date: Mon,  9 Mar 2026 16:47:04 +0530
Message-ID: <20260309111704.2330479-4-aneesh.kumar@kernel.org>
X-Mailer: git-send-email 2.43.0
In-Reply-To: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit

Add IOMMU_VDEVICE_TSM_GUEST_REQUEST for issuing TSM guest request/response
transactions against an iommufd vdevice.

The ioctl takes a vdevice_id plus request/response user buffers and length
fields, and forwards the request through tsm_guest_req() to the PCI TSM
backend. This provides the host-side passthrough path used by CoCo guests
for TSM device attestation and acceptance flows after the device has been
bound to TSM.

Also add the supporting tsm_guest_req() helper and associated TSM core
interface definitions.

Based on changes from: Alexey Kardashevskiy <aik@amd.com>

Cc: Kevin Tian <kevin.tian@intel.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Will Deacon <will@kernel.org>
Cc: Bjorn Helgaas <helgaas@kernel.org>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Alexey Kardashevskiy <aik@amd.com>
Cc: Samuel Ortiz <sameo@rivosinc.com>
Cc: Xu Yilun <yilun.xu@linux.intel.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
Cc: Steven Price <steven.price@arm.com>
Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
---
 drivers/iommu/iommufd/iommufd_private.h |  7 ++++
 drivers/iommu/iommufd/main.c            |  3 ++
 drivers/iommu/iommufd/tsm.c             | 48 +++++++++++++++++++++++++
 drivers/virt/coco/tsm-core.c            | 14 ++++++++
 include/linux/tsm.h                     | 26 ++++++++++++++
 include/uapi/linux/iommufd.h            | 23 ++++++++++++
 6 files changed, 121 insertions(+)

diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h
index aa1ceed924c2..7042993913dd 100644
--- a/drivers/iommu/iommufd/iommufd_private.h
+++ b/drivers/iommu/iommufd/iommufd_private.h
@@ -699,11 +699,18 @@ int iommufd_hw_queue_alloc_ioctl(struct iommufd_ucmd *ucmd);
 void iommufd_hw_queue_destroy(struct iommufd_object *obj);
 #ifdef CONFIG_TSM
 int iommufd_vdevice_tsm_op_ioctl(struct iommufd_ucmd *ucmd);
+int iommufd_vdevice_tsm_guest_request_ioctl(struct iommufd_ucmd *ucmd);
 #else
 static inline int iommufd_vdevice_tsm_op_ioctl(struct iommufd_ucmd *ucmd)
 {
 	return -EOPNOTSUPP;
 }
+
+static inline int
+iommufd_vdevice_tsm_guest_request_ioctl(struct iommufd_ucmd *ucmd)
+{
+	return -EOPNOTSUPP;
+}
 #endif
 
 static inline struct iommufd_vdevice *
diff --git a/drivers/iommu/iommufd/main.c b/drivers/iommu/iommufd/main.c
index d73e6b391c6f..7f4bbdd0bda5 100644
--- a/drivers/iommu/iommufd/main.c
+++ b/drivers/iommu/iommufd/main.c
@@ -433,6 +433,7 @@ union ucmd_buffer {
 	struct iommu_vfio_ioas vfio_ioas;
 	struct iommu_viommu_alloc viommu;
 	struct iommu_vdevice_tsm_op tsm_op;
+	struct iommu_vdevice_tsm_guest_request gr;
 #ifdef CONFIG_IOMMUFD_TEST
 	struct iommu_test_cmd test;
 #endif
@@ -496,6 +497,8 @@ static const struct iommufd_ioctl_op iommufd_ioctl_ops[] = {
 		 struct iommu_viommu_alloc, out_viommu_id),
 	IOCTL_OP(IOMMU_VDEVICE_TSM_OP, iommufd_vdevice_tsm_op_ioctl,
 		 struct iommu_vdevice_tsm_op, vdevice_id),
+	IOCTL_OP(IOMMU_VDEVICE_TSM_GUEST_REQUEST, iommufd_vdevice_tsm_guest_request_ioctl,
+		 struct iommu_vdevice_tsm_guest_request, resp_uptr),
 #ifdef CONFIG_IOMMUFD_TEST
 	IOCTL_OP(IOMMU_TEST_CMD, iommufd_test, struct iommu_test_cmd, last),
 #endif
diff --git a/drivers/iommu/iommufd/tsm.c b/drivers/iommu/iommufd/tsm.c
index 401469110752..6b96d0aef25f 100644
--- a/drivers/iommu/iommufd/tsm.c
+++ b/drivers/iommu/iommufd/tsm.c
@@ -65,3 +65,51 @@ int iommufd_vdevice_tsm_op_ioctl(struct iommufd_ucmd *ucmd)
 	iommufd_put_object(ucmd->ictx, &vdev->obj);
 	return rc;
 }
+
+/**
+ * iommufd_vdevice_tsm_guest_request_ioctl - Forward guest TSM requests
+ * @ucmd: user command data for IOMMU_VDEVICE_TSM_GUEST_REQUEST
+ *
+ * Resolve @iommu_vdevice_tsm_guest_request::vdevice_id to a vdevice and pass
+ * the request/response buffers to the TSM core.
+ *
+ * Return:
+ *  -errno on error.
+ *  positive residue if response/request bytes were left unconsumed.
+ *    if response buffer is provided, residue indicates the number of bytes
+ *    not used in response buffer
+ *    if there is no response buffer, residue indicates the number of bytes
+ *    not consumed in req buffer
+ *  0 otherwise.
+ */
+int iommufd_vdevice_tsm_guest_request_ioctl(struct iommufd_ucmd *ucmd)
+{
+	int rc;
+	struct iommufd_vdevice *vdev;
+	struct iommu_vdevice_tsm_guest_request *cmd = ucmd->cmd;
+	struct tsm_guest_req_info info = {
+		.scope = cmd->scope,
+		.req   = {
+			.user = u64_to_user_ptr(cmd->req_uptr),
+			.is_kernel = false,
+		},
+		.req_len = cmd->req_len,
+		.resp    =  {
+			.user = u64_to_user_ptr(cmd->resp_uptr),
+			.is_kernel = false,
+		},
+		.resp_len = cmd->resp_len,
+	};
+
+	vdev = container_of(iommufd_get_object(ucmd->ictx, cmd->vdevice_id,
+					       IOMMUFD_OBJ_VDEVICE),
+			    struct iommufd_vdevice, obj);
+	if (IS_ERR(vdev))
+		return PTR_ERR(vdev);
+
+	rc = tsm_guest_req(vdev->idev->dev, &info);
+
+	/* No inline response, hence we don't need to copy the response */
+	iommufd_put_object(ucmd->ictx, &vdev->obj);
+	return rc;
+}
diff --git a/drivers/virt/coco/tsm-core.c b/drivers/virt/coco/tsm-core.c
index f0e35fc38776..317fcb53e4bf 100644
--- a/drivers/virt/coco/tsm-core.c
+++ b/drivers/virt/coco/tsm-core.c
@@ -259,6 +259,20 @@ int tsm_unbind(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(tsm_unbind);
 
+ssize_t tsm_guest_req(struct device *dev, struct tsm_guest_req_info *info)
+{
+	ssize_t ret;
+
+	if (!dev_is_pci(dev))
+		return -EINVAL;
+
+	ret = pci_tsm_guest_req(to_pci_dev(dev), info->scope,
+				info->req, info->req_len,
+				info->resp, info->resp_len, NULL);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(tsm_guest_req);
+
 static void tsm_release(struct device *dev)
 {
 	struct tsm_dev *tsm_dev = container_of(dev, typeof(*tsm_dev), dev);
diff --git a/include/linux/tsm.h b/include/linux/tsm.h
index 9f2a7868021a..5231d5abf84d 100644
--- a/include/linux/tsm.h
+++ b/include/linux/tsm.h
@@ -6,6 +6,7 @@
 #include <linux/types.h>
 #include <linux/uuid.h>
 #include <linux/device.h>
+#include <linux/sockptr.h>
 
 #define TSM_REPORT_INBLOB_MAX 64
 #define TSM_REPORT_OUTBLOB_MAX SZ_16M
@@ -131,6 +132,24 @@ void tsm_ide_stream_unregister(struct pci_ide *ide);
 int tsm_bind(struct device *dev, struct kvm *kvm, u64 tdi_id);
 int tsm_unbind(struct device *dev);
 
+/**
+ * struct tsm_guest_req_info - parameter for tsm_guest_req()
+ * @scope: scope for tsm guest request
+ * @req: request data buffer filled by guest
+ * @req_len: the size of @req filled by guest
+ * @resp: response data buffer filled by host
+ * @resp_len: for input, the size of @resp buffer filled by guest
+ *	      for output, the size of actual response data filled by host
+ */
+struct tsm_guest_req_info {
+	u32 scope;
+	sockptr_t req;
+	size_t req_len;
+	sockptr_t resp;
+	size_t resp_len;
+};
+ssize_t tsm_guest_req(struct device *dev, struct tsm_guest_req_info *info);
+
 #else
 
 static inline int tsm_bind(struct device *dev, struct kvm *kvm, u64 tdi_id)
@@ -142,6 +161,13 @@ static inline int tsm_unbind(struct device *dev)
 {
 	return 0;
 }
+
+struct tsm_guest_req_info;
+static inline ssize_t tsm_guest_req(struct device *dev,
+				    struct tsm_guest_req_info *info)
+{
+	return -EINVAL;
+}
 #endif
 
 #endif /* __TSM_H */
diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h
index 653402e7048a..b0d1ecd81638 100644
--- a/include/uapi/linux/iommufd.h
+++ b/include/uapi/linux/iommufd.h
@@ -58,6 +58,7 @@ enum {
 	IOMMUFD_CMD_VEVENTQ_ALLOC = 0x93,
 	IOMMUFD_CMD_HW_QUEUE_ALLOC = 0x94,
 	IOMMUFD_CMD_VDEVICE_TSM_OP = 0x95,
+	IOMMUFD_CMD_VDEVICE_TSM_GUEST_REQUEST = 0x96,
 };
 
 /**
@@ -1367,4 +1368,26 @@ struct iommu_hw_queue_alloc {
 	__aligned_u64 length;
 };
 #define IOMMU_HW_QUEUE_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HW_QUEUE_ALLOC)
+
+/**
+ * struct iommu_vdevice_tsm_guest_request - ioctl(IOMMU_VDEVICE_TSM_GUEST_REQUEST)
+ * @size: sizeof(struct iommu_vdevice_tsm_guest_request)
+ * @vdevice_id: vDevice ID the guest request is for
+ * @scope: scope of tsm guest request
+ * @req_len: the blob size for @req_uptr, filled by guest
+ * @resp_len: the blob size for @resp_uptr, filled by guest
+ * @req_uptr: request data buffer filled by guest
+ * @resp_uptr: response data buffer
+ */
+struct iommu_vdevice_tsm_guest_request {
+	__u32 size;
+	__u32 vdevice_id;
+	__u32 scope;
+	__u32 req_len;
+	__u32 resp_len;
+	__aligned_u64 req_uptr;
+	__aligned_u64 resp_uptr;
+};
+#define IOMMU_VDEVICE_TSM_GUEST_REQUEST _IO(IOMMUFD_TYPE, IOMMUFD_CMD_VDEVICE_TSM_GUEST_REQUEST)
+
 #endif
-- 
2.43.0


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id B39BC175A73
	for <iommu@lists.linux.dev>; Wed, 11 Mar 2026 21:18:12 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773263895; cv=none; b=kFyx9WMTlUZNaDqbNziIiY6CP5mki2419YvKEAyq69iho3tLTn2CEpsL8gOMG83IPLj51cuvcFC7Le63v9AmB2YRJI2f9yEPMlpb71XLCsEaKFCHaK1/EAs+s+C9ZRUnDWQe/aUuOmbFADvP/LRFsHWRrtwahjhrtXcHZYfiQTo=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773263895; c=relaxed/simple;
	bh=C9IWg8sPXyVZA1pXubQVzMAYJDRdSA8nas979A9wH0Q=;
	h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References:
	 MIME-Version:Content-Type; b=jiyKHuoXH1kcPCyHVsEYRBq7ORKYxtRaMv2NhqQf3wrINMZqOrwKB6kbn3XJxzM0BAlfzau4cwBntS6mqqT52Lv/qlyfC1ziddNZWcvIhSiLR3T4eqj2dfMZDjq6Y5fZ2lSaOjJgGVghaWOcemw7ZTMZuaZA2uVk0dZb+roKttE=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com
Received: from mail.maildlp.com (unknown [172.18.224.83])
	by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4fWNrT3fM6zHnGdd;
	Thu, 12 Mar 2026 05:18:01 +0800 (CST)
Received: from dubpeml500005.china.huawei.com (unknown [7.214.145.207])
	by mail.maildlp.com (Postfix) with ESMTPS id DE56040569;
	Thu, 12 Mar 2026 05:18:09 +0800 (CST)
Received: from localhost (10.48.148.123) by dubpeml500005.china.huawei.com
 (7.214.145.207) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 11 Mar
 2026 21:18:08 +0000
Date: Wed, 11 Mar 2026 21:18:07 +0000
From: Jonathan Cameron <jonathan.cameron@huawei.com>
To: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
CC: <iommu@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
	<kvm@vger.kernel.org>, Kevin Tian <kevin.tian@intel.com>, Joerg Roedel
	<joro@8bytes.org>, Will Deacon <will@kernel.org>, Bjorn Helgaas
	<helgaas@kernel.org>, Dan Williams <dan.j.williams@intel.com>, "Alexey
 Kardashevskiy" <aik@amd.com>, Samuel Ortiz <sameo@rivosinc.com>, Xu Yilun
	<yilun.xu@linux.intel.com>, Jason Gunthorpe <jgg@ziepe.ca>, "Suzuki K
 Poulose" <Suzuki.Poulose@arm.com>, Steven Price <steven.price@arm.com>
Subject: Re: [PATCH v2 1/3] iommufd/viommu: Allow associating a KVM VM fd
 with a vIOMMU
Message-ID: <20260311211742.0000391c@huawei.com>
In-Reply-To: <20260309111704.2330479-2-aneesh.kumar@kernel.org>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
	<20260309111704.2330479-2-aneesh.kumar@kernel.org>
X-Mailer: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-w64-mingw32)
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
X-ClientProxiedBy: lhrpeml100010.china.huawei.com (7.191.174.197) To
 dubpeml500005.china.huawei.com (7.214.145.207)

On Mon,  9 Mar 2026 16:47:02 +0530
"Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org> wrote:

> Add optional KVM association to IOMMU_VIOMMU_ALLOC by introducing
> IOMMU_VIOMMU_KVM_FD and iommu_viommu_alloc::kvm_vm_fd.
> 
> When the flag is set, iommufd validates that kvm_vm_fd refers to a KVM
> VM file and stores a referenced struct file in the vIOMMU object, so
> later iommufd operations can safely resolve the owning VM.
> 
> This is preparatory plumbing for subsequent patches that bind TDI state
> to the associated KVM VM.
> 
> The patch also switch file_is_kvm from EXPORT_SYMBOL_FOR_KVM_INTERNAL to
> EXPORT_SYMBOL_GPL so that iommu module can use that.
> 
> Cc: Kevin Tian <kevin.tian@intel.com>
> Cc: Joerg Roedel <joro@8bytes.org>
> Cc: Will Deacon <will@kernel.org>
> Cc: Bjorn Helgaas <helgaas@kernel.org>
> Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Cc: Alexey Kardashevskiy <aik@amd.com>
> Cc: Samuel Ortiz <sameo@rivosinc.com>
> Cc: Xu Yilun <yilun.xu@linux.intel.com>
> Cc: Jason Gunthorpe <jgg@ziepe.ca>
> Cc: Suzuki K Poulose <Suzuki.Poulose@arm.com>
> Cc: Steven Price <steven.price@arm.com>

Hi Aneesh,

Given we don't generally want a massive cc list in the git log,
move them below ---

If you are tracking them in your git tree, just add a --- after your sign off
and put them under that.

Also good to +CC everyone in the CC for patches on the cover letter.
I happened not be subscribed to any of the lists that went to so have to
pull it down by hand from lore.

Fairly minor stuff inline.

Thanks,

Jonathan

> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
> ---
>  drivers/iommu/iommufd/viommu.c | 54 +++++++++++++++++++++++++++++++++-
>  include/linux/iommufd.h        |  3 ++
>  include/uapi/linux/iommufd.h   | 13 +++++++-
>  virt/kvm/kvm_main.c            |  2 +-
>  4 files changed, 69 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c
> index 4081deda9b33..08f8930c86da 100644
> --- a/drivers/iommu/iommufd/viommu.c
> +++ b/drivers/iommu/iommufd/viommu.c
> @@ -2,6 +2,45 @@
>  /* Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES
>   */
>  #include "iommufd_private.h"
> +#include <linux/cleanup.h>

Usually put linux includes before the local ones (though I haven't
checked local conventions in iommufd).

> +
> +#if IS_ENABLED(CONFIG_KVM)

Hmm. Really a question for Jason / Kevin, but so far this file is ifdef free.
Should we keep it that way by spinning this stuff off to a separate .c file,
or maybe use if (IS_ENABLED()) the implementation which I think means
we need a stub for file_is_kvm()?

> +#include <linux/kvm_host.h>
> +
> +static int viommu_get_kvm(struct iommufd_viommu *viommu, int kvm_vm_fd)
> +{
> +	int rc = -EBADF;
> +	struct file *filp __free(fput) = fget(kvm_vm_fd);
> +
> +	if (!file_is_kvm(filp))
> +		return rc;

		return -EBADF;

and drop the local variable.

> +
> +	/* hold the kvm reference via file descriptor */
> +	viommu->kvm_filp = no_free_ptr(filp);
> +	return 0;
> +}
> +
> +static void viommu_put_kvm(struct iommufd_viommu *viommu)
> +{
> +	if (!viommu->kvm_filp)
> +		return;
> +
> +	fput(viommu->kvm_filp);
> +	viommu->kvm_filp = NULL;
> +}
> +
> +#else
> +
> +static inline int viommu_get_kvm(struct iommufd_viommu *viommu, int kvm_vm_fd)
> +{
> +	return -EOPNOTSUPP;
> +}
> +
> +static inline void viommu_put_kvm(struct iommufd_viommu *viommu)
> +{
> +}
> +
> +#endif

> diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h
> index 6e7efe83bc5d..7c515d3c52db 100644
> --- a/include/linux/iommufd.h
> +++ b/include/linux/iommufd.h
> @@ -12,6 +12,7 @@
>  #include <linux/refcount.h>
>  #include <linux/types.h>
>  #include <linux/xarray.h>
> +#include <linux/file.h>

Just based on context in this patch, this smells alphabetical.
I checked it is, so this belongs between errno.h and iommu.h


>  #include <uapi/linux/iommufd.h>
>  

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDF0D2FD68B
	for <iommu@lists.linux.dev>; Wed, 11 Mar 2026 21:36:00 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773264964; cv=none; b=jIayxeAUEPu19jEZF7eDWPs/au3Mgog5+YxTQqiUT9p5NpDlBUCF/+718rdt/ze0TkO9EN/2rjaHh640nBqUInhbrV9CZ9+B2ejST6yUy/HRrvaqId/KTSBn/pxgguDMO/oERiUh0c1iCnHFoJmQXIq12rwSs04uBlFIkR2iwTE=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773264964; c=relaxed/simple;
	bh=KGKIobWW4qHnK1GBXmBm9IZiT2+mrhufqvLwLka5pFw=;
	h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References:
	 MIME-Version:Content-Type; b=rSlFbt9zbm5+JsrywcFso8s/TWz607Z14g0Tl3DsBHfYr7o0LsmZ2Rp0I9Pglc+AQkEV6V4O26s9rAUor0uYCVnREuXzPCDEY3Lnl3VasUVI8BPVy/HvklqfB1ql5f7H6JqGuanK8RkxGgY5ujCiSk+eRU3LBWU0Mu6KzzU4b4o=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com
Received: from mail.maildlp.com (unknown [172.18.224.83])
	by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4fWPF11xPNzHnGcl;
	Thu, 12 Mar 2026 05:35:49 +0800 (CST)
Received: from dubpeml500005.china.huawei.com (unknown [7.214.145.207])
	by mail.maildlp.com (Postfix) with ESMTPS id A79A540569;
	Thu, 12 Mar 2026 05:35:57 +0800 (CST)
Received: from localhost (10.48.148.123) by dubpeml500005.china.huawei.com
 (7.214.145.207) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 11 Mar
 2026 21:35:56 +0000
Date: Wed, 11 Mar 2026 21:35:55 +0000
From: Jonathan Cameron <jonathan.cameron@huawei.com>
To: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
CC: <iommu@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
	<kvm@vger.kernel.org>, Kevin Tian <kevin.tian@intel.com>, Joerg Roedel
	<joro@8bytes.org>, Will Deacon <will@kernel.org>, Bjorn Helgaas
	<helgaas@kernel.org>, Dan Williams <dan.j.williams@intel.com>, "Alexey
 Kardashevskiy" <aik@amd.com>, Samuel Ortiz <sameo@rivosinc.com>, Xu Yilun
	<yilun.xu@linux.intel.com>, Jason Gunthorpe <jgg@ziepe.ca>, "Suzuki K
 Poulose" <Suzuki.Poulose@arm.com>, Steven Price <steven.price@arm.com>
Subject: Re: [PATCH v2 2/3] iommufd/tsm: add vdevice TSM bind/unbind ioctl
Message-ID: <20260311213555.00001064@huawei.com>
In-Reply-To: <20260309111704.2330479-3-aneesh.kumar@kernel.org>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
	<20260309111704.2330479-3-aneesh.kumar@kernel.org>
X-Mailer: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-w64-mingw32)
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
X-ClientProxiedBy: lhrpeml500010.china.huawei.com (7.191.174.240) To
 dubpeml500005.china.huawei.com (7.214.145.207)

On Mon,  9 Mar 2026 16:47:03 +0530
"Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org> wrote:

> Introduce IOMMU_VDEVICE_TSM_OP to allow userspace to issue TSM bind/unbind
> operations for an iommufd vdevice.
> 
> The new ioctl:
> - looks up the vdevice object from vdevice_id
> - resolves the associated KVM VM from the vIOMMU KVM file reference
> - dispatches bind/unbind via tsm_bind()/tsm_unbind()
> 
> Also add common TSM helpers in tsm-core and wire vdevice teardown to unbind
> the device from TSM state.
> 
> This provides iommufd plumbing to bind a TDI to a confidential guest through
> the TSM layer.

> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
Hi Aneesh,

Some superficial code flow suggestions.  I've not gotten
my head around the broader picture yet, so may well come back with
more comments later.

Thanks,
Jonathan

> ---
>  drivers/iommu/iommufd/Makefile          |  2 +
>  drivers/iommu/iommufd/iommufd_private.h |  8 +++
>  drivers/iommu/iommufd/main.c            |  3 ++
>  drivers/iommu/iommufd/tsm.c             | 67 +++++++++++++++++++++++++
>  drivers/iommu/iommufd/viommu.c          |  3 ++
>  drivers/virt/coco/tsm-core.c            | 19 +++++++
>  include/linux/tsm.h                     | 18 +++++++
>  include/uapi/linux/iommufd.h            | 18 +++++++
>  8 files changed, 138 insertions(+)
>  create mode 100644 drivers/iommu/iommufd/tsm.c
> 
> diff --git a/drivers/iommu/iommufd/Makefile b/drivers/iommu/iommufd/Makefile
> index 71d692c9a8f4..431089089ee9 100644
> --- a/drivers/iommu/iommufd/Makefile
> +++ b/drivers/iommu/iommufd/Makefile
> @@ -10,6 +10,8 @@ iommufd-y := \
>  	vfio_compat.o \
>  	viommu.o
>  
> +iommufd-$(CONFIG_TSM) += tsm.o
> +
Probably no blank line here. Style choices in these are a bit random
though so this is kind of a taste thing.

>  iommufd-$(CONFIG_IOMMUFD_TEST) += selftest.o
>  
>  obj-$(CONFIG_IOMMUFD) += iommufd.o

> diff --git a/drivers/iommu/iommufd/tsm.c b/drivers/iommu/iommufd/tsm.c
> new file mode 100644
> index 000000000000..401469110752
> --- /dev/null
> +++ b/drivers/iommu/iommufd/tsm.c
> @@ -0,0 +1,67 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2026 ARM Ltd.
> + */
> +
> +#include "iommufd_private.h"
> +#include <linux/tsm.h>
> +
> +/**
> + * iommufd_vdevice_tsm_op_ioctl - Handle vdevice TSM operations
> + * @ucmd: user command data for IOMMU_VDEVICE_TSM_OP
> + *
> + * Currently only supports TSM bind/unbind operations
> + * Resolve @iommu_vdevice_tsm_op::vdevice_id to a vdevice and dispatch the
> + * requested bind/unbind operation through the TSM core.
> + *
> + * Return: 0 on success, or a negative error code on failure.
> + */
> +int iommufd_vdevice_tsm_op_ioctl(struct iommufd_ucmd *ucmd)
> +{
> +	int rc;
> +	struct kvm *kvm;
> +	struct iommufd_vdevice *vdev;
> +	struct iommu_vdevice_tsm_op *cmd = ucmd->cmd;
> +
> +	if (cmd->flags)
> +		return -EOPNOTSUPP;
> +
> +	vdev = container_of(iommufd_get_object(ucmd->ictx, cmd->vdevice_id,
> +					       IOMMUFD_OBJ_VDEVICE),
> +			    struct iommufd_vdevice, obj);

I'd be tempted to do something with a helper function to simplify flow.

	obj = iommufd_get_object();...

	if (IS_ERR(obj) //I think it can be?
		return PTR_ERR(obj);

	rc = iommufd_vdevice_do_tsm_op_ioctl(obj, ...) //name could be improved
	iommufd_put_object(ucmd->ictx, &vdev->obj);

	return rc;

Then the helper function can do direct returns on errors given the
iommfd_object is managed in outer function.

> +	if (IS_ERR(vdev))
> +		return PTR_ERR(vdev);
> +
> +	if (!vdev->viommu->kvm_filp) {
> +		rc = -ENODEV;
> +		goto out_put_vdev;
> +	}
> +
> +	kvm = vdev->viommu->kvm_filp->private_data;
> +	if (!kvm) {
> +		rc = -ENODEV;
> +		goto out_put_vdev;
> +	}
> +
> +	/* tsm layer will take care of parallel calls to tsm_bind/unbind */
> +	switch (cmd->op) {
> +	case IOMMU_VDEVICE_TSM_BIND:
> +		rc = tsm_bind(vdev->idev->dev, kvm, vdev->virt_id);
> +		break;
> +	case IOMMU_VDEVICE_TSM_UNBIND:
> +		rc = tsm_unbind(vdev->idev->dev);
> +		break;
> +	default:
> +		rc = -EINVAL;
> +		goto out_put_vdev;
> +	}
> +
> +	if (rc)
> +		goto out_put_vdev;
> +
> +	rc = iommufd_ucmd_respond(ucmd, sizeof(*cmd));
> +
> +out_put_vdev:
> +	iommufd_put_object(ucmd->ictx, &vdev->obj);
> +	return rc;
> +}

> diff --git a/include/linux/tsm.h b/include/linux/tsm.h
> index 7f72a154b6b2..9f2a7868021a 100644
> --- a/include/linux/tsm.h
> +++ b/include/linux/tsm.h
> @@ -124,6 +124,24 @@ struct tsm_dev *tsm_register(struct device *parent, struct pci_tsm_ops *ops);
>  void tsm_unregister(struct tsm_dev *tsm_dev);
>  struct tsm_dev *find_tsm_dev(int id);
>  struct pci_ide;
> +struct kvm;

Why up here? struct pci_ide is here for the next two calls, so no need
to group with that.

>  int tsm_ide_stream_register(struct pci_ide *ide);
>  void tsm_ide_stream_unregister(struct pci_ide *ide);

Feels like the forwards def belongs here.

> +#ifdef CONFIG_TSM
> +int tsm_bind(struct device *dev, struct kvm *kvm, u64 tdi_id);
> +int tsm_unbind(struct device *dev);
> +
White space is a bit inconsistent. I don't mind seeing some
here, but if so, add some around the ifdef above.

> +#else
> +
> +static inline int tsm_bind(struct device *dev, struct kvm *kvm, u64 tdi_id)
> +{
> +	return -EINVAL;
> +}
> +
> +static inline int tsm_unbind(struct device *dev)
> +{
> +	return 0;
> +}
> +#endif
> +
>  #endif /* __TSM_H */


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6845035A3A6
	for <iommu@lists.linux.dev>; Wed, 11 Mar 2026 21:43:47 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773265428; cv=none; b=jPGuslr8sxxqAzDTYem3G2tsdomYk/9c5InD17GWLXPFU+U5NH2JCvzFBK6jKo+UIVpR2kZKPbLKmuFlvI1omq+FgkG5mFM9b5rfngB797xzjEWm5Z8/pQfHreohw3aQB9L+9pK73nTlXzMGPsOIMBM+AQwOxTleenvwh4awoeQ=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773265428; c=relaxed/simple;
	bh=JfBpj4dEkTYducYw7y5PCtskpRaxhM6t1NTd2/Qgris=;
	h=Date:From:To:CC:Subject:Message-ID:In-Reply-To:References:
	 MIME-Version:Content-Type; b=n9AFdjXggGXpZpLksDCFOhoREkebXVePgAuODulXKjTMmUb1Ie2V5BxbZxErm+5Xkb6wqT/PdAFL9c1YZWwRsGoUNpNQNUDr4aAkmVfMskG9p725vo5I+PcNjxv2IE9eguQUkQ/ECnf1OAAtHSr7+zM8gQvIOAwdHFING7KccKg=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com
Received: from mail.maildlp.com (unknown [172.18.224.107])
	by frasgout.his.huawei.com (SkyGuard) with ESMTPS id 4fWPQ10wSpzHnGd9;
	Thu, 12 Mar 2026 05:43:37 +0800 (CST)
Received: from dubpeml500005.china.huawei.com (unknown [7.214.145.207])
	by mail.maildlp.com (Postfix) with ESMTPS id 896C940584;
	Thu, 12 Mar 2026 05:43:45 +0800 (CST)
Received: from localhost (10.48.148.123) by dubpeml500005.china.huawei.com
 (7.214.145.207) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 11 Mar
 2026 21:43:44 +0000
Date: Wed, 11 Mar 2026 21:43:43 +0000
From: Jonathan Cameron <jonathan.cameron@huawei.com>
To: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
CC: <iommu@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
	<kvm@vger.kernel.org>, Kevin Tian <kevin.tian@intel.com>, Joerg Roedel
	<joro@8bytes.org>, Will Deacon <will@kernel.org>, Bjorn Helgaas
	<helgaas@kernel.org>, Dan Williams <dan.j.williams@intel.com>, "Alexey
 Kardashevskiy" <aik@amd.com>, Samuel Ortiz <sameo@rivosinc.com>, Xu Yilun
	<yilun.xu@linux.intel.com>, Jason Gunthorpe <jgg@ziepe.ca>, "Suzuki K
 Poulose" <Suzuki.Poulose@arm.com>, Steven Price <steven.price@arm.com>
Subject: Re: [PATCH v2 3/3] iommufd/vdevice: add TSM guest request ioctl
Message-ID: <20260311214343.00004641@huawei.com>
In-Reply-To: <20260309111704.2330479-4-aneesh.kumar@kernel.org>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
	<20260309111704.2330479-4-aneesh.kumar@kernel.org>
X-Mailer: Claws Mail 4.3.0 (GTK 3.24.42; x86_64-w64-mingw32)
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset="US-ASCII"
Content-Transfer-Encoding: 7bit
X-ClientProxiedBy: lhrpeml500010.china.huawei.com (7.191.174.240) To
 dubpeml500005.china.huawei.com (7.214.145.207)

On Mon,  9 Mar 2026 16:47:04 +0530
"Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org> wrote:

> Add IOMMU_VDEVICE_TSM_GUEST_REQUEST for issuing TSM guest request/response
> transactions against an iommufd vdevice.
> 
> The ioctl takes a vdevice_id plus request/response user buffers and length
> fields, and forwards the request through tsm_guest_req() to the PCI TSM
> backend. This provides the host-side passthrough path used by CoCo guests
> for TSM device attestation and acceptance flows after the device has been
> bound to TSM.
> 
> Also add the supporting tsm_guest_req() helper and associated TSM core
> interface definitions.
> 
> Based on changes from: Alexey Kardashevskiy <aik@amd.com>

> Signed-off-by: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
Minor stuff inline.

thanks,

Jonathan

> diff --git a/drivers/iommu/iommufd/tsm.c b/drivers/iommu/iommufd/tsm.c
> index 401469110752..6b96d0aef25f 100644
> --- a/drivers/iommu/iommufd/tsm.c
> +++ b/drivers/iommu/iommufd/tsm.c
> @@ -65,3 +65,51 @@ int iommufd_vdevice_tsm_op_ioctl(struct iommufd_ucmd *ucmd)
>  	iommufd_put_object(ucmd->ictx, &vdev->obj);
>  	return rc;
>  }
> +
> +/**
> + * iommufd_vdevice_tsm_guest_request_ioctl - Forward guest TSM requests
> + * @ucmd: user command data for IOMMU_VDEVICE_TSM_GUEST_REQUEST
> + *
> + * Resolve @iommu_vdevice_tsm_guest_request::vdevice_id to a vdevice and pass
> + * the request/response buffers to the TSM core.
> + *
> + * Return:
> + *  -errno on error.
> + *  positive residue if response/request bytes were left unconsumed.
> + *    if response buffer is provided, residue indicates the number of bytes
> + *    not used in response buffer
> + *    if there is no response buffer, residue indicates the number of bytes
> + *    not consumed in req buffer
> + *  0 otherwise.
> + */
> +int iommufd_vdevice_tsm_guest_request_ioctl(struct iommufd_ucmd *ucmd)
> +{
> +	int rc;
> +	struct iommufd_vdevice *vdev;
> +	struct iommu_vdevice_tsm_guest_request *cmd = ucmd->cmd;
> +	struct tsm_guest_req_info info = {
> +		.scope = cmd->scope,
> +		.req   = {
> +			.user = u64_to_user_ptr(cmd->req_uptr),
> +			.is_kernel = false,
> +		},
> +		.req_len = cmd->req_len,
> +		.resp    =  {
> +			.user = u64_to_user_ptr(cmd->resp_uptr),
> +			.is_kernel = false,
> +		},
> +		.resp_len = cmd->resp_len,
> +	};
> +
> +	vdev = container_of(iommufd_get_object(ucmd->ictx, cmd->vdevice_id,
> +					       IOMMUFD_OBJ_VDEVICE),

As in previous, can the object be PTR_ERR()?  Maybe not, but I'd
be surprised if the static analysis tools are convinced.
This might work for now if obj is first element but that's not
elegant or matainable.

> +			    struct iommufd_vdevice, obj);
> +	if (IS_ERR(vdev))
> +		return PTR_ERR(vdev);
> +
> +	rc = tsm_guest_req(vdev->idev->dev, &info);

This is otherwise effectively the pattern I'm suggesting for previous patch.

> +
> +	/* No inline response, hence we don't need to copy the response */
> +	iommufd_put_object(ucmd->ictx, &vdev->obj);
> +	return rc;
> +}
> diff --git a/drivers/virt/coco/tsm-core.c b/drivers/virt/coco/tsm-core.c
> index f0e35fc38776..317fcb53e4bf 100644
> --- a/drivers/virt/coco/tsm-core.c
> +++ b/drivers/virt/coco/tsm-core.c
> @@ -259,6 +259,20 @@ int tsm_unbind(struct device *dev)
>  }
>  EXPORT_SYMBOL_GPL(tsm_unbind);
>  
> +ssize_t tsm_guest_req(struct device *dev, struct tsm_guest_req_info *info)
> +{
> +	ssize_t ret;
> +
> +	if (!dev_is_pci(dev))
> +		return -EINVAL;
> +
> +	ret = pci_tsm_guest_req(to_pci_dev(dev), info->scope,
> +				info->req, info->req_len,
> +				info->resp, info->resp_len, NULL);
> +	return ret;

return pci_tsm....

Given there are no more patches in this series that much change that.


> +}
> +EXPORT_SYMBOL_GPL(tsm_guest_req);



From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from BL2PR02CU003.outbound.protection.outlook.com (mail-eastusazon11011015.outbound.protection.outlook.com [52.101.52.15])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98D0B36C0CB
	for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 06:15:36 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.52.15
ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773382538; cv=fail; b=PfflSWuOIp7Q8sj0zX+g0ye41S7s6Odv6siFVRcE7dVrnq5ghc+RwElPojTlQ57Wbl46gCqcCoLEO7xLXplB6npXBNWQ3IiGPBNCoMymuTuJ2VsWFpPx19x01CEzzW2IkDg6dWRidgd5OlBEgEkCdKQ41+fAe5er+CjB8MooaiY=
ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773382538; c=relaxed/simple;
	bh=cbtk/6YZh1W6lbvAZwSLHtYQPzQWd8UU7dznpko991E=;
	h=Date:From:To:CC:Subject:Message-ID:References:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To; b=nWVgxXB0TainNe213q/az5QM+AU1kXPcIDi3K05ySvO2J5AQLKdPf59pYiHwPQQkgMUa69g9m6nl/5P4fFCFknClq/OAwahJpiQogddpG7x5apdU4TuGXHWxGO+vDmGLqPHzguE+6LqDA3zVOcb51bYiA3DXu7cMQL39KL5U9ow=
ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=UwqhZGd9; arc=fail smtp.client-ip=52.101.52.15
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com
Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="UwqhZGd9"
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
 b=YqAH4sfKh/zcJT1ftIi543pgzumZDUxs33c8CL6qzymdSXeP1rEcT13VAWe/n79lHHXHoEdP/5eUBAM5nfw2Hrq/ErQzb3jCFed1tpmdoBWI4qTAAS4XACmC9D9EpVtNoOMsK0bvzw+UZ347Jxts19r+RH/mt+YBNsPtVcpg5K13njoQ08KlJL98+Dby0gvxN7sOjiNcYG3MQ35qmr82qaFF05vDEY2NfOilitzgAJNpGaBWKWRsjKBGhl1fqzkw8IbiDbTnkyNoOdcnLpGFot1lhehuDNf0zcFyWX40wjbS5ZhTWMXtdLF9SlLIH69WZhc8GhXnQIT2pczaoRSBAw==
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=udzWFtsE6qTwor2FAZ2/vI1IVqlawgkVRMukh7/+c54=;
 b=fbHv6U+X/YHme0mrcfC1jxIx0N3QDBD7IbhyJ/TpuBEvZOMD8sUoI/zoS+6bCpha9/MSpG3w2ARugnqvqNtt+clyED6jpnSwKm4uMTAAKseJ2mVvvUqNroLgiBIRSE9wXQu7lJDEPPdjojebqla+jnlO0wunRqEW23f7DEWAXX89ySIs4IxJmm0oeXfQXTtimjDYnETOj+9t5HOxZAw+zQWkZ3s+rQgC81ptbffBOknMZ+mewfyjZAcWVnASrqtB1ne5qjqjhYdtmvLoMF2QCnvC8dWxb++P8+zWY03P9Uqmu54weGFBDHYmepmTCGGTgWdp8VfXrq1mNwBYPvdMHg==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is
 216.228.117.161) smtp.rcpttodomain=kernel.org 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)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com;
 s=selector2;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=udzWFtsE6qTwor2FAZ2/vI1IVqlawgkVRMukh7/+c54=;
 b=UwqhZGd9qRyAmv3zkn6NhqJM3ltzXpYdHYz15f7WFDTc5P18+UTbq6h8x2t8zvs/W14XgntDCAxH2l9JUyIXNq/9XBMrzB1V8oJO/T4Ux5oxVhbQJuyUApeeEVdt0ZdpLXHRTA7nskWPtCzsbquKkog5lWVwc+OK2SpO2AOVMbbqBjQRlOR9XQbrPx2K9bGzvGKevP9W8kmhmrlithPaL4ujJDIXoppa0N6oCPyLj9oyJb0iJgqPEULOWz3N1s7I2c9XaRLEOq6ykLNIvQ0NXF3zEaB0zo0SHtGuFQCihlY/2NKJpVg+D25Lcp55nRyBZnbqPVmFcamzFmQ9lFLOlg==
Received: from SJ0PR13CA0045.namprd13.prod.outlook.com (2603:10b6:a03:2c2::20)
 by MW4PR12MB6801.namprd12.prod.outlook.com (2603:10b6:303:1e8::8) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9723.6; Fri, 13 Mar
 2026 06:15:31 +0000
Received: from SJ1PEPF000026C9.namprd04.prod.outlook.com
 (2603:10b6:a03:2c2:cafe::86) by SJ0PR13CA0045.outlook.office365.com
 (2603:10b6:a03:2c2::20) with Microsoft SMTP Server (version=TLS1_3,
 cipher=TLS_AES_256_GCM_SHA384) id 15.20.9678.22 via Frontend Transport; Fri,
 13 Mar 2026 06:15:30 +0000
X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161)
 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.117.161 as permitted sender) receiver=protection.outlook.com;
 client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C
Received: from mail.nvidia.com (216.228.117.161) by
 SJ1PEPF000026C9.mail.protection.outlook.com (10.167.244.106) with Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.9678.18 via Frontend Transport; Fri, 13 Mar 2026 06:15:31 +0000
Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com
 (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Thu, 12 Mar
 2026 23:15:18 -0700
Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com
 (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Thu, 12 Mar
 2026 23:15:18 -0700
Received: from Asurada-Nvidia (10.127.8.14) by mail.nvidia.com (10.129.68.8)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20 via Frontend
 Transport; Thu, 12 Mar 2026 23:15:17 -0700
Date: Thu, 12 Mar 2026 23:15:16 -0700
From: Nicolin Chen <nicolinc@nvidia.com>
To: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
CC: <iommu@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
	<kvm@vger.kernel.org>, Kevin Tian <kevin.tian@intel.com>, Joerg Roedel
	<joro@8bytes.org>, Will Deacon <will@kernel.org>, Bjorn Helgaas
	<helgaas@kernel.org>, Jonathan Cameron <Jonathan.Cameron@huawei.com>, "Dan
 Williams" <dan.j.williams@intel.com>, Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>, Xu Yilun <yilun.xu@linux.intel.com>,
	"Jason Gunthorpe" <jgg@ziepe.ca>, Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	"Steven Price" <steven.price@arm.com>
Subject: Re: [PATCH v2 1/3] iommufd/viommu: Allow associating a KVM VM fd
 with a vIOMMU
Message-ID: <abOrdFR4L2n334MR@Asurada-Nvidia>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-2-aneesh.kumar@kernel.org>
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: inline
In-Reply-To: <20260309111704.2330479-2-aneesh.kumar@kernel.org>
X-NV-OnPremToCloud: ExternallySecured
X-EOPAttributedMessage: 0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: SJ1PEPF000026C9:EE_|MW4PR12MB6801:EE_
X-MS-Office365-Filtering-Correlation-Id: 6330ab7f-bd7d-49e4-2861-08de80c7ee1a
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam:
	BCL:0;ARA:13230040|82310400026|376014|7416014|36860700016|1800799024|13003099007|56012099003|18002099003|22082099003;
X-Microsoft-Antispam-Message-Info:
	 
X-Forefront-Antispam-Report:
	CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230040)(82310400026)(376014)(7416014)(36860700016)(1800799024)(13003099007)(56012099003)(18002099003)(22082099003);DIR:OUT;SFP:1101;
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0:
	YtAOJ3n497EgWwcWR9ULhkjeybMDv6EIYKh95h4qte+JKTKaeHg5R0J1owRNPWuUHQM5VYDNDRiWSSFkmnS//uXC7utSpjGGTwmGTFn4iFNJ8TmQ/K3oEg4zh6N/dZ/egBQRCJotGZHRgVnTGjcLWOzK8xezdyvrDwwUwdpFqxuK/9xMkNs0RiIDsz2cntX9dXBUWJS9RDX31ynIdkazYpATpjvRJ0vC65M6V9Uof2JrzQwPpONMqOZublaYTHJEPXn8HEmI7vPiFwbG2LDtv33X27iYSTcOh5Hko9o5sWoNmmRnPOCwsi1+MMfMnPjIR+Dz5NguJv/wOppEQ23t909PS89FD4wwbNKA8eUobuE2lyV3813P3KcX9z+GBrH/pq3mTFTDYa0T0HigDFS2a2DHlWs8ilxD1DqAtpgkAw3suDJX/7hVg9DZyBqrnZxW
X-OriginatorOrg: Nvidia.com
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2026 06:15:31.4301
 (UTC)
X-MS-Exchange-CrossTenant-Network-Message-Id: 6330ab7f-bd7d-49e4-2861-08de80c7ee1a
X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a
X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com]
X-MS-Exchange-CrossTenant-AuthSource:
	SJ1PEPF000026C9.namprd04.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Anonymous
X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem
X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6801

On Mon, Mar 09, 2026 at 04:47:02PM +0530, Aneesh Kumar K.V (Arm) wrote:
> Add optional KVM association to IOMMU_VIOMMU_ALLOC by introducing
> IOMMU_VIOMMU_KVM_FD and iommu_viommu_alloc::kvm_vm_fd.
> 
> When the flag is set, iommufd validates that kvm_vm_fd refers to a KVM
> VM file and stores a referenced struct file in the vIOMMU object, so
> later iommufd operations can safely resolve the owning VM.
> 
> This is preparatory plumbing for subsequent patches that bind TDI state
> to the associated KVM VM.
> 
> The patch also switch file_is_kvm from EXPORT_SYMBOL_FOR_KVM_INTERNAL to
> EXPORT_SYMBOL_GPL so that iommu module can use that.

struct vfio_device has the kvm pointer already. So, I think it
could be forwarded from VFIO side v.s. via userspace ioctl.

Shammer had two patches before and Jason partially reviewed. I
took those for a side project but haven't sent anywhere. Would
you please check if they for you?

https://github.com/nicolinc/iommufd/commits/wip/viommu_kvm

Nicolin

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-qv1-f44.google.com (mail-qv1-f44.google.com [209.85.219.44])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19B443D811A
	for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 18:27:27 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.44
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773426448; cv=none; b=lz3e3K3Dui+/nyKOys/m7notYna6+tO5VqelE2edbtYlE7rwxeVvzoCgB/ktSmrA2G85+FSXgoi2X3vcOU+PtQZzYUJO3LyeBHp4pySeArjOcdSHxmOxfR61br/oNi/QEt7iBhG/yiYb2+QoVvlHGrOqxggOwYbTwYzklZJTdbA=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773426448; c=relaxed/simple;
	bh=r+8WDj17D0ahzMmsV26yBAG5Il5FyUsQjbgg7T++RDQ=;
	h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To; b=EkUDOMEkEx0w5PeS46yczgxqUIiFFkgvc4trQVYWiAWB35ClStCr4NBzDtG/5ATOr25tBxOGeGl7qxXlWCe58tySZEtiU9WeMRYqKL9A5rao+5s+lqZF5vtg0ysFbFRPeLdkGWukqscPvJq8siZBgsoqhf+hsis1EtK0G/BbsTM=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=ON0eic2n; arc=none smtp.client-ip=209.85.219.44
Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="ON0eic2n"
Received: by mail-qv1-f44.google.com with SMTP id 6a1803df08f44-899ed41208fso24959006d6.1
        for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 11:27:26 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=ziepe.ca; s=google; t=1773426446; x=1774031246; darn=lists.linux.dev;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to;
        bh=sD7gZdLIbR12oWsuwP0hMyRwjWKcXWNRvnOkCD9lgq8=;
        b=ON0eic2nellfY/+XoqFV6h/Xi74RY3Vwvcm5hDt/+3vMwbWfI6ewBA4KyokfOQ2gTJ
         3KAAg9qCYbLvc1gpDJyD8Ueu+cV9J+BFOj2Ci7FUlfaJ1eiRuYZHoPKNJqAqr/Bj8oWP
         pXxrX5yhgfAE5Dyk6EKrkvqO7P4SLcVKAYsXh6KnAxAlvb+Db7iARv9yC6hao56anCEp
         ES26b4CYgyq9QqsC+inv8AtBiAVJVw2SG4P7zLFQC+mcgAiARIzujqqjXqbr3k6Xym8S
         clxGUVrrhhgzBNTM3wyxl0bY1zO+GW4IcTKjKtYWgYvBNUmjI1KX9H0Ove9A0fplz22N
         n+7A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20251104; t=1773426446; x=1774031246;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=sD7gZdLIbR12oWsuwP0hMyRwjWKcXWNRvnOkCD9lgq8=;
        b=GK88SYwbWTeXvQSg64hvm9tCPtEsXXk5bcJryGQ75h/yTXfr3K2qccfXPmOiFNuOGI
         03YuMAJqiet4BXz2YzawTckf/y481iWXswlh0khGXpuV2S4vdKet3uW2ZXi10urzG+Zo
         EgRH9hhHJR9kK8UrNhAzxmTZqqT5hBZDvHXJIMLLj71iq4Hr0I5GYe7DkRH4QbM5Fazt
         oKS3l/jCEFlc6dhFMBTdE2NKsz0kUFvc7CMQTJY6cGuEVCa3EsgxUJWfJCWbuP0Y/Thd
         M+GUcD/P9SdnCx+NHUxUJ21zTbpINPva44Z0pKr7QMARgfxxmvzkExtty/ajy/v02Oys
         e+tw==
X-Forwarded-Encrypted: i=1; AJvYcCVLrPmy/kQIYxCIUgq5Sm6JUl/YBMJYuMvqNRzHrvFtBENQsKs8dpmxgFjijq+I226kQj0nig==@lists.linux.dev
X-Gm-Message-State: AOJu0YyPUH//LFdVw495weUai2QIBvNyZoprmryX0YZIARe+sgGWgg7D
	pui6TYvrIVORRR7vZNKNaHNrZ+6n+g52skt7nFxy6oozQBu2dR3D8jgfG5JoQ+DhFhM=
X-Gm-Gg: ATEYQzw1RBDLQjCMj9xk/a8IHp0hTnrXl/VTD/NmlWEHFBGAdj8j4WFRt8oOLa0iox/
	tSKyxqgun8hrzjwkPePzXw/XghAk+nr3SCoubs4ybY4So96i/MvEV21s+e+SfxO4/vEVtQaORTZ
	p2or12yt/i8G8PMI5SlEpHn+5r5UcrspEo7hzfVv6Ij3b71dMzGyNCjR32K5hBIVvA08UboQCyr
	rn9gsASRpzERh+TDpi+FT94RqMc4PJveJqJWQNYE+psFlQnXRniWIXB2xohhTTUDyJVFeqLrrO+
	16du3QjS5Xas+hEwTDrIQTk5E3iH0V4xopACHGl69rE1ZpvmEXp9pIfpczvfSCFy1fqoMCgYF0r
	I4zwnXz5X0g31CN2AqNjK1oTUF+W4emqm0RMoswEdijYQN7f+7OJ2wzhpsjYJL8uQCNZWvm+00Y
	1nIqXZL04btt08viJ3eLDqHjaOf8A766dHBllKYV4E9mLrCSKIBVWwqOPf5B+uahFDMKS8Ws1Ed
	tcBRlvS
X-Received: by 2002:a05:6214:1d26:b0:896:f61e:15f7 with SMTP id 6a1803df08f44-89a81d942f0mr61721186d6.15.1773426446090;
        Fri, 13 Mar 2026 11:27:26 -0700 (PDT)
Received: from ziepe.ca (hlfxns017vw-142-162-112-119.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.112.119])
        by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89a65d2ab43sm61664086d6.53.2026.03.13.11.27.25
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 13 Mar 2026 11:27:25 -0700 (PDT)
Received: from jgg by wakko with local (Exim 4.97)
	(envelope-from <jgg@ziepe.ca>)
	id 1w17EK-00000007Ln4-3lxb;
	Fri, 13 Mar 2026 15:27:24 -0300
Date: Fri, 13 Mar 2026 15:27:24 -0300
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Jonathan Cameron <jonathan.cameron@huawei.com>
Cc: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, Kevin Tian <kevin.tian@intel.com>,
	Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Dan Williams <dan.j.williams@intel.com>,
	Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	Steven Price <steven.price@arm.com>
Subject: Re: [PATCH v2 1/3] iommufd/viommu: Allow associating a KVM VM fd
 with a vIOMMU
Message-ID: <20260313182724.GJ1704121@ziepe.ca>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-2-aneesh.kumar@kernel.org>
 <20260311211742.0000391c@huawei.com>
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20260311211742.0000391c@huawei.com>

On Wed, Mar 11, 2026 at 09:18:07PM +0000, Jonathan Cameron wrote:
> > +#if IS_ENABLED(CONFIG_KVM)
> 
> Hmm. Really a question for Jason / Kevin, but so far this file is ifdef free.
> Should we keep it that way by spinning this stuff off to a separate .c file,
> or maybe use if (IS_ENABLED()) the implementation which I think means
> we need a stub for file_is_kvm()?

I'd prefer we add the stub, then you don't need any of these ifdefs
either..

Jason

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83A463DD52C
	for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 18:31:26 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773426687; cv=none; b=oniAZFkYQkIArCChnPM63SyCDf2RdrGIuikZxBnDEXQdZZNHSaSAkVhamsTqXKrbvH5sUFdH+Gnl+VQqCfkK5ATFMeErmnqm3PQfJLJN6/FJLiXfEdO4sjMRZvNBxRKgddhIIo6Wx1CS6RKlmjt1K1qBxE3kzKZOwnPObEx9CNw=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773426687; c=relaxed/simple;
	bh=0qxNb0CImZ7Y6yg+F786kCKDYDie+t88orCSqmVuTBQ=;
	h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To; b=Q06mJj3KKGkPXwS1SdInvqSpYwwRYFKP2OtXX4f5UJahXA9imxDfPKmZxk+2XVYicDDpoDKSU60ezpIV/NGtn0g080b4jeWTOlpDEWjhewW2M05K7BYulwCZUqR0PJHP5WV0UQDiWTquGXxZtQTFuzBUtDEbN7PVbRO1r41A918=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=fX09w0lW; arc=none smtp.client-ip=209.85.222.170
Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="fX09w0lW"
Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-8cd7ecedf2cso255806985a.3
        for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 11:31:26 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=ziepe.ca; s=google; t=1773426685; x=1774031485; darn=lists.linux.dev;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to;
        bh=zQGCXWZbNaSYnb2f/K2OJx848xGu9ABhmecVVHvXBkw=;
        b=fX09w0lWkrQ3wbdI4TTvaTym7d5MtSBYKsP1u4amEDL0OXpsaha1Vm3txVuP6efgLb
         +vKPZaNAb8u5hox6tN6mb6WnqYSmduMdWP45yU+khaXFjAdCxu1FBcV/1F9Ei4S0G4ya
         0hD/cR2czbEOVMWlWWreKRiPBtiF/+r4aSJrC8YRf0ADHO1kwCsFox1ogSs+boSL23id
         SpeqFs5x/L1+P0f0k5gBlS9vazxE1YnkEr37ikJ/0IF9qDtz0SSkYVb/284mM249cFoE
         zW1yqtj5nWaHACKOkrSPe7E1Nhr4F9LqdR4VRv6awiHS2Pv2iXVbd+htRWz5sZsdu12q
         FXnA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20251104; t=1773426685; x=1774031485;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=zQGCXWZbNaSYnb2f/K2OJx848xGu9ABhmecVVHvXBkw=;
        b=AtH36a8HFtRsd5UcD/EEaVlrwC2NlQEDvXh9BAHcGb7JcWtymSelbkv1dM1+9Usa1x
         mQk+ZGCLRTHziMKnTP0Kvqg//Tys5hQmd6iE6KcAzg+lBu+gvdu6Z+ptaW7ti5mN6hQf
         VeznIx3MrQT4BvM9LAcvcnHjNd7FeaPEWar6x6SZTGEa8/ceyiVXhGY7Qve/24H+HNGL
         nQE0WMSW/hFyCTBClVi0M4v3sZGmsgRF3eUXqX2kJFz3tQ4bTW612Uv2ZcheoPXYXHBP
         0z6Bfg5cmOFeQQLFEHvvs4Q6ImhA/xYprcDA0egIZM183mvEyJPHW6n7IUUrja2Ah+bz
         XGwg==
X-Gm-Message-State: AOJu0Yxqdx2TjSb1JkQvsnkrYFLc4WV0qRxMQ4261nunFpOVapOiDot7
	C5JYSGbUDlPdWp/2tm2mv9wAcnv7CtZGQAP3a7h7feH0wXXd4IruUWQZGkSotT440mE=
X-Gm-Gg: ATEYQzyB1fL2tZSFPIIoC043/ac4ZGtuzZSp7P5u4ctYt/hNYntgEfX4KOsW2on4Iew
	o0jcnB/+9/rbjhU66eSX+hWOo67zAVmqNZmmmYpqo6rvMqVKu5wbrPH+YjC7QOlYO4u2IKUZt3r
	/qpUW/xjcUW+cnV6gQCBuvYTt00ZmPgLX97P2SkJ6CSH9ciI7jEFlNdnf8jLy1ZjrPMFZ6iWi2r
	DWLcyH9VMAbPOFDBMFOMxasJOAyPVLtOoiXsjtHEp1ASTabDhp04oa7B7mNxc20VUYI3no6TsjY
	lg9mcbukXMe38stDPa8m0ZI5CqNWKe+S09Mf1Y1yR7N0S/hFEfOi85wXbb3GxHm8zOg+RVcuzNG
	jnaTQ+35jPWPaHFwQ7OR5NsashmZMtqdZlf8yDJ9w3RNAbCh0EIHkivA/LNBgC8B9m+W/ngH4Ym
	kGr+riOhY5FsUBTRfcmEtQRqNWW+u397IFxG2SDPCDS6u1E1qQvPZEImXTyN8K0sxROWeBmP03f
	EJ0cPzk
X-Received: by 2002:a05:620a:254f:b0:883:c768:200a with SMTP id af79cd13be357-8cdb5ab3617mr580862385a.32.1773426685412;
        Fri, 13 Mar 2026 11:31:25 -0700 (PDT)
Received: from ziepe.ca (hlfxns017vw-142-162-112-119.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.112.119])
        by smtp.gmail.com with ESMTPSA id af79cd13be357-8cda2152a41sm611787885a.43.2026.03.13.11.31.24
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 13 Mar 2026 11:31:24 -0700 (PDT)
Received: from jgg by wakko with local (Exim 4.97)
	(envelope-from <jgg@ziepe.ca>)
	id 1w17IB-00000007Lp5-3hF7;
	Fri, 13 Mar 2026 15:31:23 -0300
Date: Fri, 13 Mar 2026 15:31:23 -0300
From: Jason Gunthorpe <jgg@ziepe.ca>
To: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, Kevin Tian <kevin.tian@intel.com>,
	Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	Steven Price <steven.price@arm.com>
Subject: Re: [PATCH v2 1/3] iommufd/viommu: Allow associating a KVM VM fd
 with a vIOMMU
Message-ID: <20260313183123.GK1704121@ziepe.ca>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-2-aneesh.kumar@kernel.org>
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20260309111704.2330479-2-aneesh.kumar@kernel.org>

On Mon, Mar 09, 2026 at 04:47:02PM +0530, Aneesh Kumar K.V (Arm) wrote:
> Add optional KVM association to IOMMU_VIOMMU_ALLOC by introducing
> IOMMU_VIOMMU_KVM_FD and iommu_viommu_alloc::kvm_vm_fd.
> 
> When the flag is set, iommufd validates that kvm_vm_fd refers to a KVM
> VM file and stores a referenced struct file in the vIOMMU object, so
> later iommufd operations can safely resolve the owning VM.
> 
> This is preparatory plumbing for subsequent patches that bind TDI state
> to the associated KVM VM.
> 
> The patch also switch file_is_kvm from EXPORT_SYMBOL_FOR_KVM_INTERNAL to
> EXPORT_SYMBOL_GPL so that iommu module can use that.

I'd want Sean to approve this..

But given we once discussed it is better to hold on to the file * than
the kvm as it leaks less kvm stuff I think this is the right approach.

>  #include <linux/types.h>
>  #include <linux/xarray.h>
> +#include <linux/file.h>
>  #include <uapi/linux/iommufd.h>
>  
>  struct device;
> @@ -58,6 +59,7 @@ struct iommufd_object {
>  	unsigned int id;
>  };
>  
> +struct kvm;

That is a weird place to put the forward declaration? How about at the
top of the file with the others?

> +/**
> + * define IOMMU_VIOMMU_KVM_FD - Flag indicating a valid KVM VM file descriptor
> + *
> + * Set this flag when allocating a viommu instance that should be associated
> + * with a specific KVM VM. If this flag is not provided,
> + * @iommu_viommu_alloc::kvm_vm_fd is ignored.
> + */
> +#define IOMMU_VIOMMU_KVM_FD	BIT(0)

BIT isn't used in this uapi header, lets not start.

Other cases are using an enum to group the flags

>  /**
>   * struct iommu_viommu_alloc - ioctl(IOMMU_VIOMMU_ALLOC)
>   * @size: sizeof(struct iommu_viommu_alloc)
> - * @flags: Must be 0
> + * @flags: Supported flags (IOMMU_VIOMMU_KVM_FD)

So you can say 'see enum xyz' here

> @@ -1105,6 +1115,7 @@ struct iommu_viommu_alloc {
>  	__u32 data_len;
>  	__u32 __reserved;
>  	__aligned_u64 data_uptr;
> +	__s32 kvm_vm_fd;

Add padding to keep to 8 byte alignment


> @@ -5481,7 +5481,7 @@ bool file_is_kvm(struct file *file)
>  {
>  	return file && file->f_op == &kvm_vm_fops;
>  }
> -EXPORT_SYMBOL_FOR_KVM_INTERNAL(file_is_kvm);
> +EXPORT_SYMBOL_GPL(file_is_kvm);

Probably put this in its own patch 

Jason

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 586B93DE444
	for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 18:34:06 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.52
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773426849; cv=none; b=FQXZTo5PCAIOztxoXejBFSDz5zjqTQ8hfBWtKLjIvWAJL+tfHSPzHnk6/zlYvIZCV3A7R6qrlPf+DyKIcS7tcbwVqXHv/aBOTvSQekTW0Tlx0KgHU2djQObT1jZSIrABZ1rIHFBpM7XUT5++I0334i7MOeuzqVTYMyz7IYsthfM=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773426849; c=relaxed/simple;
	bh=ixTPhrH4yxjOjUAI1IZHEE8s/TP9E8YXfjx9uEw6cE8=;
	h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To; b=hY8D5ncMuTOBoxBbeoneLluPSXdShoAXLoQRp1uypZkUWdaHF6607v8As0S6dbz6VHbGnW8IGouaMKUeEsY0nroa2XUg6rJe62V4N5sHe4v+8ORNcyqb8L2Qjyep7eFYfezFETy3fctyqnqvwn65EU6ETBP1kOIJm0Awx4LGufE=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=ajVwyTUr; arc=none smtp.client-ip=209.85.219.52
Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="ajVwyTUr"
Received: by mail-qv1-f52.google.com with SMTP id 6a1803df08f44-89a465bd7edso19069296d6.0
        for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 11:34:06 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=ziepe.ca; s=google; t=1773426845; x=1774031645; darn=lists.linux.dev;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to;
        bh=ETmpjYkPNXw5/q7d3Ssx+upItrwKqh5NDijfiDruMZ0=;
        b=ajVwyTUrvJzp737bTwnag3qGPvsc1BxBJye1lOakfPkw0KmAHM4YVdqHPS7LRahJiI
         s64iB0KtGzhmjjw8xCMfl79As9mteaMQfI0a+tc5TNUye0BSw75Km7bNXJYjUPuragtY
         9HzUYnLAIT78fMbrvu07Yukn1VybTdytDixBjBNwmlU7KQp1sh7gxj1usJOgcorxZTbF
         ovQMjTpjVQ6Nrub6qYvqenRgNJ00C9I9oOvdpKvtIgaONdAYDAQXy1u1p9XyXcFItKff
         Nau7KDY/2hjbKlUo5irvzeVi0fmLwn+cSprotuT2LdOXSXFv7lJjNWTe2KVBgCTCzSoy
         y2yg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20251104; t=1773426845; x=1774031645;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=ETmpjYkPNXw5/q7d3Ssx+upItrwKqh5NDijfiDruMZ0=;
        b=QSAS7oaMC7qq2jfher4+aBimwerW2nnAh1DI63qppMfH889/eI/2Z3gQPVdN5sFEVH
         vVVDD7u1RbrW2l3CFx/bUl24+m76iMflxrOCzEYSnJygZpL5ePJozGb+WM8zIZgAswGS
         4C+XAof/NVAi6+FK/jFEAfbvZWojYm14uQOqSTSZwkEo5ldlRdGPcMjS7H4IVcldRmrP
         n77ell2kcytRrbF9G7ruwkdhcJurqgdrIV3ACp2FcpJhwcv6FRv23zXjpmzRrtt8KSoE
         LTV3O6g7+WWJ4eQqfMzNx56botf1hvGnK3/bZHKrjUqKd+iBbyZA1ZEO+25f9jm7C7vg
         nvPg==
X-Forwarded-Encrypted: i=1; AJvYcCUSi/XLdojFgQIoUpgT5pRrYuAyasGgHSWmRGl2lHi5l4CmKnPSnM8kSXa+2bp0NqQc/qkGhQ==@lists.linux.dev
X-Gm-Message-State: AOJu0YxLDdiGEC0LhHEWKWddwW9a9M2oFN9lOHFhr01C1qWwWNkE7Qcy
	U30njsFWt7l6xy8R/6Zmj6yBl0CAJu9tvWcn7T7Eod2US7yJZwjZgvdA+En8scMhldo=
X-Gm-Gg: ATEYQzy4P1HZpPpuEJwqshpH0N/3UWwoFQr+3YcajWal/FZ8pxS7TPw+ZtYnEiWGZ/E
	vLIelpDif//YOXmv7KYY7mmHbCEukcQsUG+uXc++PYfkzJAp7SCsMaD8nJnwu+GXyBhhIUhCmA6
	e0PrCKwmTfx9+e5J7pHoH0YNfPhLtISxbJ4PB4mPI+FmbFGL7UJmgaYY04IUeDYhacV/XzSuX8T
	2I1AmpjkQ85ocrXaeUwDVdlacEGOhyZunk5y/HCJuc8mMhCV98gRQ62KbjSnwJc/A/5fOPmSmmt
	ydRQyLaNtwrY8S7MDWxtioAdlEgoeTq9uo9py6SVcdFVAhGnIj74DPK2BD72wXLUcAu4v2XOVV9
	GqtxEoSLl5Jd43FsOTFsGRWog1S/BK0puX+yMWvlC6nRzA7gEDOxj1Z/5TUiUEi/EjEZFP8Ij65
	bzwdTKvS6+s15Qf/YyBNsqytKkj63pFLYHQYv6mbmf31FzlNTlihulrHGfy2ZvN/v4BJ9f36UD/
	Rn/bxat
X-Received: by 2002:a05:6214:5010:b0:89a:502:6060 with SMTP id 6a1803df08f44-89a81d4cb1fmr61055306d6.25.1773426844964;
        Fri, 13 Mar 2026 11:34:04 -0700 (PDT)
Received: from ziepe.ca (hlfxns017vw-142-162-112-119.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.112.119])
        by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89a65d0289dsm58661806d6.40.2026.03.13.11.34.04
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 13 Mar 2026 11:34:04 -0700 (PDT)
Received: from jgg by wakko with local (Exim 4.97)
	(envelope-from <jgg@ziepe.ca>)
	id 1w17Kl-00000007Lsf-2UJ3;
	Fri, 13 Mar 2026 15:34:03 -0300
Date: Fri, 13 Mar 2026 15:34:03 -0300
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Nicolin Chen <nicolinc@nvidia.com>
Cc: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, Kevin Tian <kevin.tian@intel.com>,
	Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	Steven Price <steven.price@arm.com>
Subject: Re: [PATCH v2 1/3] iommufd/viommu: Allow associating a KVM VM fd
 with a vIOMMU
Message-ID: <20260313183403.GL1704121@ziepe.ca>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-2-aneesh.kumar@kernel.org>
 <abOrdFR4L2n334MR@Asurada-Nvidia>
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <abOrdFR4L2n334MR@Asurada-Nvidia>

On Thu, Mar 12, 2026 at 11:15:16PM -0700, Nicolin Chen wrote:
> On Mon, Mar 09, 2026 at 04:47:02PM +0530, Aneesh Kumar K.V (Arm) wrote:
> > Add optional KVM association to IOMMU_VIOMMU_ALLOC by introducing
> > IOMMU_VIOMMU_KVM_FD and iommu_viommu_alloc::kvm_vm_fd.
> > 
> > When the flag is set, iommufd validates that kvm_vm_fd refers to a KVM
> > VM file and stores a referenced struct file in the vIOMMU object, so
> > later iommufd operations can safely resolve the owning VM.
> > 
> > This is preparatory plumbing for subsequent patches that bind TDI state
> > to the associated KVM VM.
> > 
> > The patch also switch file_is_kvm from EXPORT_SYMBOL_FOR_KVM_INTERNAL to
> > EXPORT_SYMBOL_GPL so that iommu module can use that.
> 
> struct vfio_device has the kvm pointer already. So, I think it
> could be forwarded from VFIO side v.s. via userspace ioctl.
> 
> Shammer had two patches before and Jason partially reviewed. I
> took those for a side project but haven't sent anywhere. Would
> you please check if they for you?
> 
> https://github.com/nicolinc/iommufd/commits/wip/viommu_kvm

That looks pretty reasonable

Raises the point we should not allow mixing kvm pointers, so no matter
what the vfio, idev, viommu all need to agree, and the code should
check that too, eg when associating an idev with a viommu

Jason

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCB9036166A
	for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 18:43:01 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.182
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773427383; cv=none; b=Y4dviAtXl/zMZ6AufyUoJJEHYnE3G+n9WK5np5mYQAUaEdA1gR0hd6UOQcR4fgxAeeyggLcpGQXU37H/TfCmYsjzrZsbZ6IOUV7e+PQl5nU3RX3UE8uMqpjzw0ZZzuOYW3X8So+z2ByAHsijjZrHVKKNl9l136npV7WyklimePE=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773427383; c=relaxed/simple;
	bh=qG79F3bBT6jsj5MyZ+DmjyLvwJgCGA1ee7wOQ7HnB2c=;
	h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To; b=P+cJZTFhDNgNKl559aMKKZSbJXjdHOAeZN3DfdpLqL1dh4lFp3J250j9W2v02pwKdeLL2DgyZg9SLO1Tkgr5VQCROxW0NDYoIRbhNwp4BjbSTzLcXhYjjikFhFUg8Q5sv+kL3gSdCYRgwgZtU6yBZL+yYeKKfrgU7rB+drsjcL0=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=pP3Gbi7+; arc=none smtp.client-ip=209.85.160.182
Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="pP3Gbi7+"
Received: by mail-qt1-f182.google.com with SMTP id d75a77b69052e-50905b779dfso28671981cf.3
        for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 11:43:01 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=ziepe.ca; s=google; t=1773427381; x=1774032181; darn=lists.linux.dev;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to;
        bh=33LRHogpGiDAoJ0hSgyq37DznMxJ4ZqKispiDKsO2iw=;
        b=pP3Gbi7+3LB1/HsiEqbs9EnqFlgC4A/hScjkhjCS0NeSC5c+CjKvw09LTbzQvvwXoG
         oyNv6EabiwwWfU47h0/7oGbga+SoM5zkWFcFo0UDlZDF2h/TDoIxzqCEHKfCIDXg1WdU
         Ui3dym7LPVdmHEftkerfUwdK6EYGV0JUi7uoetsXTOHLbkeIctiEQcbkqBYRoyC+/oQb
         tMfro6+JhBuQwIGZShQicgB5VuFmwdbbqOpqlJzYD8GeSYQxHijmW8FHdSD8jedvtMi6
         ZGutP+0NjCSo/hkORyfJE+bIJJltzqmAKWC53/ujnlSvpE+oE54ItYppuwbv97+4bVAt
         j4gg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20251104; t=1773427381; x=1774032181;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=33LRHogpGiDAoJ0hSgyq37DznMxJ4ZqKispiDKsO2iw=;
        b=r1pOnJJzLJf3Dfb7VgfYCDjuhHSAz75iFDSwvz41iy/sPMcK9aaw7tt8kkrUNu4ft6
         EutKk7Q4XZ/E/BXFnGwM66mv1+ZfBqmsWsfBphYkM2JMK89yFG36NLud5O1xiThCz3K+
         +uUCubZQtUVfELVd+4TxppoZ0KEYl48JQsgoUHHv89M/nzmp2TManZhMey/BIEBDa8d+
         GXDOi6SVpYvYGy+dLzTA1ABo2wVb6IeTZPu/7xNsTaE8HkX9QsJnI5+zUCEEbS8F7s+u
         PYYybvH9Pzrbneosh12rgamSFSdWPRbNkVTZVyW6qO452ge2Ml2leOcH/uxkImNGpnkC
         pICw==
X-Forwarded-Encrypted: i=1; AJvYcCXPo5AfL2Xi6XrfeIerdTETNqZv7E75gpeK8ot82mwka1qirUhlH2fb1u87CfAp0RjsU5QxqQ==@lists.linux.dev
X-Gm-Message-State: AOJu0YxFbuaMzAlLwkinQRjMWO2XXzoc2rI+KG5VLX4icg04Q/FE70ry
	UUBIl043K2khDmaOCC29upbWd4CmMnLo3QN95uJNAAA86Jm2WjnYOIF4ZcFj8Nxt/FI=
X-Gm-Gg: ATEYQzyAZ9j7wivGNrZL8YZhNXFHwbJE2a1gMsnfjN34X6OAE4aLwHbj81s1EPgp7yz
	Hi8aUmO+7XiHMo3Aflg6Ze4XgEEY7uyFQ8167J8CEN7GYr8aRJn80oQuJn9hNYM6uAoO1zzAyR5
	ApYhfctEczKwYLAC6fjIzlQz6rKdcLxhXSav+h9MkjsCl/i+qff/QYV31QqArtqh1BQ3IMcYcSE
	oaHh04SxeMfNrnguUtWhyk5kg8zQZ/RnwWkUfCcsYRmqylqi/iifoY7fgvE/Sj4TAokcAeeqs5a
	iY4DJ8FvRKd9nqeCqdmiPx6uyMP72WeJZTTzMuKhxc/rZrbry9Oo2s4zsQ2VABljUFb9uNPGnED
	sXGxzuq54gGci4FFw3n+igCw86m2gMTaxbRAazTqCA5yVDtj44VPMWONqYO7boIMxgWcPLKtlbI
	PkqmGkLp2bC+V+dcN6vod1lBHKbAOXJyUGYD5FYJ4wMToRTLRtQaLUzV1GisXUvy1KHEPLFkDTu
	oIWG2zh
X-Received: by 2002:a05:622a:1301:b0:509:2822:6701 with SMTP id d75a77b69052e-50957cc0c69mr54001261cf.28.1773427380808;
        Fri, 13 Mar 2026 11:43:00 -0700 (PDT)
Received: from ziepe.ca (hlfxns017vw-142-162-112-119.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.112.119])
        by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89a65c071d4sm60555916d6.21.2026.03.13.11.43.00
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 13 Mar 2026 11:43:00 -0700 (PDT)
Received: from jgg by wakko with local (Exim 4.97)
	(envelope-from <jgg@ziepe.ca>)
	id 1w17TP-00000007M0D-311H;
	Fri, 13 Mar 2026 15:42:59 -0300
Date: Fri, 13 Mar 2026 15:42:59 -0300
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Jonathan Cameron <jonathan.cameron@huawei.com>
Cc: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, Kevin Tian <kevin.tian@intel.com>,
	Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Dan Williams <dan.j.williams@intel.com>,
	Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	Steven Price <steven.price@arm.com>
Subject: Re: [PATCH v2 2/3] iommufd/tsm: add vdevice TSM bind/unbind ioctl
Message-ID: <20260313184259.GM1704121@ziepe.ca>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-3-aneesh.kumar@kernel.org>
 <20260311213555.00001064@huawei.com>
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20260311213555.00001064@huawei.com>

On Wed, Mar 11, 2026 at 09:35:55PM +0000, Jonathan Cameron wrote:
> > +int iommufd_vdevice_tsm_op_ioctl(struct iommufd_ucmd *ucmd)
> > +{
> > +	int rc;
> > +	struct kvm *kvm;
> > +	struct iommufd_vdevice *vdev;
> > +	struct iommu_vdevice_tsm_op *cmd = ucmd->cmd;
> > +
> > +	if (cmd->flags)
> > +		return -EOPNOTSUPP;
> > +
> > +	vdev = container_of(iommufd_get_object(ucmd->ictx, cmd->vdevice_id,
> > +					       IOMMUFD_OBJ_VDEVICE),
> > +			    struct iommufd_vdevice, obj);
> 
> I'd be tempted to do something with a helper function to simplify flow.

It is already

static inline struct iommufd_vdevice *
iommufd_get_vdevice(struct iommufd_ctx *ictx, u32 id)
{
        return container_of(iommufd_get_object(ictx, id,
                                               IOMMUFD_OBJ_VDEVICE),
                            struct iommufd_vdevice, obj);
}

> Then the helper function can do direct returns on errors given the
> iommfd_object is managed in outer function.

Use cleanup.h ? It is not the iommufd style the break things up into
little functions for error unwind reasons
 
> > +	if (!vdev->viommu->kvm_filp) {
> > +		rc = -ENODEV;
> > +		goto out_put_vdev;
> > +	}
> > +
> > +	kvm = vdev->viommu->kvm_filp->private_data;
> > +	if (!kvm) {

Ah this I don't think you should be doing. That needs a helper from
kvm

Jason

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id CAFF434C123
	for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 18:46:25 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773427587; cv=none; b=KaRX0965vbPsabzkhtuM0RmwITxNEfrVrShEY/XUbK7IBZN3Vl0Vfv0u9hQuf5DHsD1ZTze+JRuIVBDMUgWZSZubOt1JvQMBoXynjvL0EmaYu9/bYoTU8vXr/DYe4+WpgAB+F8YzvLjRtkjt8JG1ntrszuzBFYw9K2egrHNncms=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773427587; c=relaxed/simple;
	bh=igi61PaIIZaH3Qas+vZAstXrvDO675CFw3Ylscc89LI=;
	h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To; b=ZUTmnlHgr1QViHadPz+GvC8fFTtmT/GAoHJP4lJxDv/BgETDqTToJIBfq1RLR7NEnTOGClXysyPsGXhCMjTTk5V6TIn5FNSlEsccvv5K+nK0Ti4fsmwwvqqOhp4OLg4gpAn7Pi+IWQ0OtRxybBLFNO4eRlRE8nhbfuX4ct/J5so=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=fD7xyly6; arc=none smtp.client-ip=209.85.222.173
Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="fD7xyly6"
Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-8cd785a8783so268162485a.0
        for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 11:46:25 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=ziepe.ca; s=google; t=1773427585; x=1774032385; darn=lists.linux.dev;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to;
        bh=Zy0pIPV9+PAUwjJhdgFY70jKRdcmmf+kMol++AzSeUw=;
        b=fD7xyly6FDXud86eA8+dqpvQ9b12U9wAtA/mKxuM0aX0Fv8sRzbsnzD7plX3U82m9K
         4amAn6lVtp6pjBlSys2fA5Jq0McQ9u1aNr+284bbTzK9Gq2ffzOehg7gcvJQVQsLdULx
         9j5hXv7ocMlpFQyDJPXLD+FdWG+lyqW7J2yU584Y3ITKqip3L7qkRv0o5J4tOvsMe1ch
         PTdPoou5nTmtG7vBPXsSnKRpRacO7YV//rrFN8nWgXFeHwg711Oxs1ll07yPSQTiA+zt
         k0D7wC+q2GVsQNCExZdzq3mindn5e+l+CwTn1MqOzCGgBSI0T6reC/3z0r54xnpU8aLa
         dPnw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20251104; t=1773427585; x=1774032385;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=Zy0pIPV9+PAUwjJhdgFY70jKRdcmmf+kMol++AzSeUw=;
        b=jpHjcQ++BnBuEaohkMOFY4ZblxDMyFD9foCx/gCp3oZENDmVbX4U1+i8+AYTWSxgNW
         1QqbaSytuH6RnRP7Fo1Cn4ZpOM1bnTmpE1HN3ijqlu9FP4JWHSxDvLwDeDUKT8VY0la7
         iwak/O7iR2NdiZeasONXU5OyDu9d5LEhvhXUMBZiinH8/I1ty9B9GmRcvJXqeP0KUWuW
         gUN/AsJ8q6YVuhjHWaRq9erSATkgWn4wmx00V3OLAa4YIF96KrPZgaIRvCkqJ+T1dG+m
         jTN0Y+TXT9fBtbs0Vr1Zf5WHgL/aoOoxFL+7WcsVRig3zpFfyz/eHsWe+C6vcMN4v50f
         yWsw==
X-Forwarded-Encrypted: i=1; AJvYcCU6WY/w3oIJ7vAOYKocsq0V+/9RvyPqFv0nAFSexbvgXha2YCBr6ygGTLb3adbJUDjxopEUbA==@lists.linux.dev
X-Gm-Message-State: AOJu0Yyby0XKFaxjZMp6xRAMtkZdfxijuFWI9NL0D2t2lL5jL7vKy23B
	29xINo+4IMF21lJ9OXC7M1ZMeacCjzWExxIgHlyctU96+Qm86LQVFplP+7YyqMs8v1Y=
X-Gm-Gg: ATEYQzxrThv6LZF1QqyXr1E0GxbRf9cXs2u1vzDFP2vmNL2CTupcoYUbDcI0MiNWB0m
	tFUHqv6jdgGSpoR76AkQ3rVgg3WQm/3jXnAmbsUu26aYEMAbiEG/+1qRWvjw36Y/1g+wqu0/a6i
	54hIn2YGJyZbHEeF5Ds/8LoCUz3CXvDF+Utltk6x7vwZxIHICTPAGJGMZbzHD1kxUPLn6ZrgJee
	IVS9rWGfv263nHPFpUxeYaCSEz8L2hpsbk7la1sKPQvr+plq5M7vPiMeMhxPeEZ1UxyUS49F2aw
	rIaurKtJqnBKdI+z9jZ8v5LFLsFJZpNa34mCJssn1i4s8rE750joJHEK/gUbV3K+oUkaNI7cXCW
	M2ybBB2kw/EcvS2tRD7r9yENCdqYaH0iHtTXi9UT9yjF4RgVlyM28uTofOMirQrnJbgzAAu2DVU
	Gm455Y4O/9F/26OywBwMlqfcd+NjKXBizN58+2B46m2kpYdRLi5Dq9OBCgD7hxwrg/mTIN58s2N
	WKwbxqgX206fdwy/Bw=
X-Received: by 2002:a05:620a:4625:b0:8cd:6175:9b17 with SMTP id af79cd13be357-8cdb5a3f7c2mr586273385a.3.1773427584802;
        Fri, 13 Mar 2026 11:46:24 -0700 (PDT)
Received: from ziepe.ca (hlfxns017vw-142-162-112-119.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.112.119])
        by smtp.gmail.com with ESMTPSA id af79cd13be357-8cda1fbcd23sm701747085a.1.2026.03.13.11.46.24
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 13 Mar 2026 11:46:24 -0700 (PDT)
Received: from jgg by wakko with local (Exim 4.97)
	(envelope-from <jgg@ziepe.ca>)
	id 1w17Wh-00000007M3T-2Qkk;
	Fri, 13 Mar 2026 15:46:23 -0300
Date: Fri, 13 Mar 2026 15:46:23 -0300
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Jonathan Cameron <jonathan.cameron@huawei.com>
Cc: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>,
	iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, Kevin Tian <kevin.tian@intel.com>,
	Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Dan Williams <dan.j.williams@intel.com>,
	Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	Steven Price <steven.price@arm.com>
Subject: Re: [PATCH v2 3/3] iommufd/vdevice: add TSM guest request ioctl
Message-ID: <20260313184623.GN1704121@ziepe.ca>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-4-aneesh.kumar@kernel.org>
 <20260311214343.00004641@huawei.com>
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20260311214343.00004641@huawei.com>

On Wed, Mar 11, 2026 at 09:43:43PM +0000, Jonathan Cameron wrote:
> > +	vdev = container_of(iommufd_get_object(ucmd->ictx, cmd->vdevice_id,
> > +					       IOMMUFD_OBJ_VDEVICE),
> 
> As in previous, can the object be PTR_ERR()?  Maybe not, but I'd
> be surprised if the static analysis tools are convinced.
> This might work for now if obj is first element but that's not
> elegant or matainable.

The compiler enforces first element:

#define __iommufd_object_alloc(ictx, ptr, type, obj)                           \
        container_of(_iommufd_object_alloc(                                    \
                             ictx,                                             \
                             sizeof(*(ptr)) + BUILD_BUG_ON_ZERO(               \
                                                      offsetof(typeof(*(ptr)), \
                                                               obj) != 0),     \
                             type),                                            \
                     typeof(*(ptr)), obj)

I have a lovely little series 

https://github.com/jgunthorpe/linux/commits/container_of/

For this that I keep meaning to send but then never do

Jason

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FFF1367F5B
	for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 18:48:17 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.181
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773427699; cv=none; b=d9m8afYgwAzSchR1J16VPqhbAoOjMW3jghw+RsTDVXMKPoc0ZCMLuHzgOtxFLWFsi3QrXQS57gglJfWFS86x35fpUuoUh2tB48OKvVu4/oGo4N2M4bkNUh8m5IWZV6wYxszGEV/8U04yITz8vmu2H07V3u63zaK6ysgC/yfuoZY=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773427699; c=relaxed/simple;
	bh=bDMn+pND6C8k5z/VxMRY1ADpxIk5K4fL3QB8DYqqNso=;
	h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To; b=cwOlsdE/TczE/Ai2DtNGnjEf1xgnVLsNSwAAU/1tFvJZZD8oCk2b6Qnd19IyIl45D3SEgWkvnkplb2L5RU4mM62z2B/V0G24MBtJISlHCpH1goDXJsco/039S5SXAA+AIKGHsJVo+dQpFlhAkFqC748nxP2Urz8yx5hSo6bsGn4=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=V/HzrUe+; arc=none smtp.client-ip=209.85.222.181
Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="V/HzrUe+"
Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-8cb4136d865so324583485a.1
        for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 11:48:17 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=ziepe.ca; s=google; t=1773427697; x=1774032497; darn=lists.linux.dev;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to;
        bh=01fjBoYSqV223rYI33+jsswxHzATZtFRcSWT+x97rj0=;
        b=V/HzrUe+AMR46DpKU7FTvAij6nNhJsggxUi9FRdtc2bBT9R5CvKLYNEgZcOI+k6CEx
         H/VUlAnyfOgPtRPA/PtY2XT/6qXwnkJtnLZ8/AXG/JbDTk52YEXk3A6QC9YfRowIM1BG
         hrokmBm6OyNjp40DmruC87YtzrgxW9wkelNy7etL2ybckjTtqtt6sjQQDlVZHhM+UlfF
         oGNBpewCDV+RQJp53G7rJEjs/bLzKJPcPJVDJ5+DyxHd/YNblgmNuL+U0TPEkAg92a9M
         hWyxuyfLqtuFVCcxMkHSpwWpAqQUISXCEUiKX/eER5LFini+kV9iALlhorjW3HWOBqR6
         JLwA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20251104; t=1773427697; x=1774032497;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=01fjBoYSqV223rYI33+jsswxHzATZtFRcSWT+x97rj0=;
        b=svfekLG0kfcjnQ/35Ot9pgq0Zv7EJ6j5QLaltKeL/rQBwxfpn1Pf1oXVBzbG/7L39b
         bbvtanTnRuzS4Jd0NTcLromKAcuo0BlfvO/1wk3mrQq+XfMrgtykS+MdKvrUL9X/v2Vu
         tmZFPl5ZTob+ceRFSK9q/+QqXHycPBZdYruPVldaAuK05xo/S7axqj1iV/QzBFhL6mjG
         um51cXhmeNAdsiVub/vLcFNwQko79L34qrdiawXMIuFpHHGfm2YP0vnFs2dPqwLvJ42y
         cazd6I7LXpNOdFEFmCX0/bw8ZsU1/QDDDxQ3jgu9EMcUcFUoEiJncodegeyooANavQaX
         jyqA==
X-Gm-Message-State: AOJu0YxV5mNtSJBwLAfdgD7fW24tQc0R1Au953KBxcdi+dounf91zU+v
	JLt49eGkQ+I3w9t33AMqO15gVOavGtNtMmzeTQK3rYck9CImsRv47hEbTXjOLllPtEs=
X-Gm-Gg: ATEYQzyoIxNMmu7nZHda1bYm1sBgqdG0pcLA/bNW2FXjFmtocOm6gNHFMYh4+F3mJc7
	czUz80Go/e9KXBWREvUuMJDIQAOMKs63JSw9TrIn0o61qMHjxycJeL/Qh+poKUDoCLe0FM8qVV4
	IZA63hwyaRMC9l9fCzsm45++AfK8c9dunuFs0XqYb9IndaJ3JMiIS3RVTOoec7GwROyAuzXV21i
	IHjVW9PCLUofxQkmgDmo1Z2ZbQOn7llPu4Ks34vkJ8073+pxY2iSdjaN4JNMl7F35RIkoq3ze1o
	VujPJI5cuqk1+0o+pdUz3UkqmmpyMzAw7PzNs8zeee0ENzXUZvQL1s9OXtwqSjNy6/nyjb7GRyl
	K68i85HYr4pNSy7Q1nUxBluyBhrQS9H93Q8Oe0XIb9Iid/cqU3eJxHNknJb7uqLl4Xv6SpZ9mMt
	wsGzsQTOCZUy0bY3YvTcvYRVCjGHzEN0OhRQVgP2f+PEpdnOL2XEQP5SLOuRodiwA7nZNIe38p2
	0zNdSYT
X-Received: by 2002:a05:620a:4510:b0:8cd:b52c:5983 with SMTP id af79cd13be357-8cdb5b59a6emr636703785a.42.1773427697122;
        Fri, 13 Mar 2026 11:48:17 -0700 (PDT)
Received: from ziepe.ca (hlfxns017vw-142-162-112-119.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.112.119])
        by smtp.gmail.com with ESMTPSA id af79cd13be357-8cda212cac1sm715538585a.33.2026.03.13.11.48.16
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 13 Mar 2026 11:48:16 -0700 (PDT)
Received: from jgg by wakko with local (Exim 4.97)
	(envelope-from <jgg@ziepe.ca>)
	id 1w17YV-00000007M4R-42dz;
	Fri, 13 Mar 2026 15:48:15 -0300
Date: Fri, 13 Mar 2026 15:48:15 -0300
From: Jason Gunthorpe <jgg@ziepe.ca>
To: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, Kevin Tian <kevin.tian@intel.com>,
	Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	Steven Price <steven.price@arm.com>
Subject: Re: [PATCH v2 2/3] iommufd/tsm: add vdevice TSM bind/unbind ioctl
Message-ID: <20260313184815.GO1704121@ziepe.ca>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-3-aneesh.kumar@kernel.org>
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20260309111704.2330479-3-aneesh.kumar@kernel.org>

On Mon, Mar 09, 2026 at 04:47:03PM +0530, Aneesh Kumar K.V (Arm) wrote:
> @@ -1174,6 +1175,23 @@ enum iommu_veventq_flag {
>  	IOMMU_VEVENTQ_FLAG_LOST_EVENTS = (1U << 0),
>  };
>  
> +/**
> + * struct iommu_vdevice_tsm_op - ioctl(IOMMU_VDEVICE_TSM_OP)
> + * @size: sizeof(struct iommu_vdevice_tsm_op)
> + * @op: Either TSM_BIND or TSM_UNBIND
> + * @flags: Must be 0
> + * @vdevice_id: Object handle for the vDevice. Returned from IOMMU_VDEVICE_ALLOC
> + */
> +struct iommu_vdevice_tsm_op {
> +	__u32 size;
> +	__u32 op;
> +	__u32 flags;
> +	__u32 vdevice_id;
> +};
> +#define IOMMU_VDEVICE_TSM_OP	_IO(IOMMUFD_TYPE, IOMMUFD_CMD_VDEVICE_TSM_OP)
> +#define IOMMU_VDEVICE_TSM_BIND		0x1
> +#define IOMMU_VDEVICE_TSM_UNBIND	0x2

use enum for an op, put it before the struct, add kdocs for the enum
members.

Jason

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 186613C3BED
	for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 18:49:59 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.42
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773427801; cv=none; b=NMsnrzQgiel8lQd3pBlawWNkvD964bSmU6KTxS1k46qInCRjh7K8Sn6wN7d6SJ0TkC3BQXop1pQ+/7Cb484MVcFvbTUnCh5mV6xmZqG7tG3nzW0O3zsbuiQY1r95z/3b34lnCU7uWUCxHvpKBlXZOJoQdeeBK2RGXRwz7dUtd3M=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773427801; c=relaxed/simple;
	bh=Cgw7rgg052jBwsBm6FVNyDCSrT6homGIa8xXe2Nl/LM=;
	h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:
	 Content-Type:Content-Disposition:In-Reply-To; b=EWgK43LatbHYD1aVKP59w3ZqkcxX9gcyQ7om8J7Xix6DqZf78U0mlnoTARuUu8Sg6GeV4RRyoIz8JZLKpeDvjyIQb1GnPiDaDhINxHcH5uue6y50HRGxbLe90PFS0oYKKk9012uh40E/oO3bgJuhh4y9qyl2LkOVPwT0EUtXh4g=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=dTE6kyi9; arc=none smtp.client-ip=209.85.219.42
Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="dTE6kyi9"
Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-89a14be4733so30770366d6.2
        for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 11:49:59 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=ziepe.ca; s=google; t=1773427799; x=1774032599; darn=lists.linux.dev;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to;
        bh=OmAqHdmpJRsgkjLn2CzcNC2LkQHnurZaGunyWBb1R7Y=;
        b=dTE6kyi9i6DHvy5cRvHsjWFkOxVcCLxu9heQRv6hkqGi7K+wMX4eBBRZigM60+BywL
         asTkAKhSDoUnTLNGBM9O/97/6izNOt86HMiqfUtCzXEwL/TSpSSutyIoQgnJP/vEpP01
         CVWJSZRJ86/CugSapSStO6g+4rWphFZWqO4uL8a/jqD+gFDO7kMbCisDlmd1ZoeNOsbm
         12zKEQNdbTTRgETAwF585/PkjyMxc0+1O9QQrDJvYIFKBtbCLXLVkSKuLUByOBcJvO15
         lh072RjD70iPDsgQyzVlJPLspLIeVI78+yrFGbn96CO1ni43W6E6y3+OfckK07HcrdY8
         sNnA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20251104; t=1773427799; x=1774032599;
        h=in-reply-to:content-disposition:mime-version:references:message-id
         :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc
         :subject:date:message-id:reply-to;
        bh=OmAqHdmpJRsgkjLn2CzcNC2LkQHnurZaGunyWBb1R7Y=;
        b=MXqXvuCsdv+QQkHOWT6VH0+vVCSYRpf40w4amvEY4aiuZ2CY3x2YCdK4NsB4fkLAPq
         Bq8tsknF9NO/rNO9Z8hlxQdEfrGOCWoYwH97cPJ95EF71pcDCZKe8t6aEQRMgOD2WNO4
         44amMEBrSFSf/T6pEpcsNMeHJB6N7Kkyu8YNmTjH72dYJUYv6aavw5aAh8ZgxwcTZogY
         dGXZTvPxAYXDjk3jf1v3BOj5GP1QUoUsM2kePhsQrw2A4ySXvPQ2DDC8eelv5skPuD1Q
         bE8arHfPhnSJYeflZQvKoX0MAX3aJdDjNwvEqk+VehU69YARNyrhJ0aHkiPcdFJY5zNj
         fJKw==
X-Gm-Message-State: AOJu0YwgiPVUoJ0c9gfriW5Xs7uYSMwnRpx+aIedqPHo2wGER7fvRlww
	Gn4KBEB28HEi0jnYfud7dHTC4wGQQqOpaWZMqoSxS9c1AMtvS1pEX8geoHdvdc6FdoM=
X-Gm-Gg: ATEYQzzCV5RjvMo9uCcFYEhqFuZfE0RTkkYJvjQ+agBU4XsrUqnrOqA7tog1kaXcd2P
	TOPNwRz6Uao7kyyBCQJ3DDsy4WKFn7VVyzt/ODEgfh6vIZv3b9+BocPKFFCfmPy/se/GMln9kju
	0xkdyrZmCPrYZ8et/G66svqq3J6qs8b5pYaIqHxhmWzktXuFIE3DRicnIdWFbAu1Ar2IR8QaVCo
	19qrD020Ht/okqEsIYW+pV4z0fmQPerhxoX0B2z72/d3tBigERWUTGXTEeyJJJzmpYvm0Qt3YZg
	X8/kFM+kOqL7NVRnldAfAjRVjZhoYsaRilc8PGoQFRr4JVHBcpiHN8hso42kx3+lxYB9vmYiuUn
	CtChgq0r+aqiP2NBmfdKBU0c7fgCdZRsSIwvc+fkBgt+2sn4IZOFL3XgrUT9kpwKR14xW4S1bly
	GaSxSiVXm79ZIpQRDfAZByuxSj3WmUPkou3yseCtAW/p6E0UEu3fatUhe5cLPVfqSKT4D84lKJ8
	EiR2Ivd
X-Received: by 2002:a05:6214:1c0b:b0:89a:ff2:b8d4 with SMTP id 6a1803df08f44-89a81ef3356mr69685496d6.36.1773427799050;
        Fri, 13 Mar 2026 11:49:59 -0700 (PDT)
Received: from ziepe.ca (hlfxns017vw-142-162-112-119.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.162.112.119])
        by smtp.gmail.com with ESMTPSA id 6a1803df08f44-89a65bd318fsm60836326d6.8.2026.03.13.11.49.58
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Fri, 13 Mar 2026 11:49:58 -0700 (PDT)
Received: from jgg by wakko with local (Exim 4.97)
	(envelope-from <jgg@ziepe.ca>)
	id 1w17a9-00000007M5A-3jdN;
	Fri, 13 Mar 2026 15:49:57 -0300
Date: Fri, 13 Mar 2026 15:49:57 -0300
From: Jason Gunthorpe <jgg@ziepe.ca>
To: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, Kevin Tian <kevin.tian@intel.com>,
	Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	Steven Price <steven.price@arm.com>
Subject: Re: [PATCH v2 3/3] iommufd/vdevice: add TSM guest request ioctl
Message-ID: <20260313184957.GP1704121@ziepe.ca>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-4-aneesh.kumar@kernel.org>
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20260309111704.2330479-4-aneesh.kumar@kernel.org>

On Mon, Mar 09, 2026 at 04:47:04PM +0530, Aneesh Kumar K.V (Arm) wrote:
> +/**
> + * struct iommu_vdevice_tsm_guest_request - ioctl(IOMMU_VDEVICE_TSM_GUEST_REQUEST)
> + * @size: sizeof(struct iommu_vdevice_tsm_guest_request)
> + * @vdevice_id: vDevice ID the guest request is for
> + * @scope: scope of tsm guest request
> + * @req_len: the blob size for @req_uptr, filled by guest
> + * @resp_len: the blob size for @resp_uptr, filled by guest
> + * @req_uptr: request data buffer filled by guest
> + * @resp_uptr: response data buffer
> + */

This needs a much better kdoc.

Refer to specs that define this.

Explain WTF scope is

> +struct iommu_vdevice_tsm_guest_request {
> +	__u32 size;
> +	__u32 vdevice_id;
> +	__u32 scope;
> +	__u32 req_len;
> +	__u32 resp_len;

do not leave implicit padding, add a reserved, and check it is 0

Jason

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC0D8241665
	for <iommu@lists.linux.dev>; Fri, 13 Mar 2026 22:17:52 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=192.198.163.10
ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773440274; cv=fail; b=Df6IeTE9mp13ZZoXgX1Nb8k8p4IuS+gHY29NUKc7SFkbDZ8QFkazZyayPjKJfONJPway5Mh9r1rsbQJLnwDowNVhk7h/3de2Y7NYj0SrD4A44HEAbWPqiQKfbQLEhgO3VsZOHPaPOofWTaDK/5cUJEaZKg1p66AkaVpV++Hnrwo=
ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773440274; c=relaxed/simple;
	bh=gK9kV1zh6lZ7ltPhVX2JQ59iyHwIl+ZfdyyUKp9tbYg=;
	h=From:Date:To:CC:Message-ID:In-Reply-To:References:Subject:
	 Content-Type:MIME-Version; b=tEadVRiFSA3anA/oX3Bsdy0vYwrc1QPMd9Q5Ga340wRXgO3EpSW/liV7pLtSlpOk/KtgjTXuiKRAjzbNPgESFocXipEtp0kLtzoi2OlSBV1DBsUum/Lrf1FPyNexxGpr3juv04E7gm75FO0Os7+6Cyrhw0xYPctm3oLne7CINjI=
ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=hTKh8Tt4; arc=fail smtp.client-ip=192.198.163.10
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hTKh8Tt4"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
  t=1773440273; x=1804976273;
  h=from:date:to:cc:message-id:in-reply-to:references:
   subject:content-transfer-encoding:mime-version;
  bh=gK9kV1zh6lZ7ltPhVX2JQ59iyHwIl+ZfdyyUKp9tbYg=;
  b=hTKh8Tt4s+7mxds8EhCnSMij2LW+eOVRJLUVba0KHYiKnH8Jk7yOaiIc
   PxrcI6EswwRbLJZAJeRY/4sUFYCLmXHj3h0exDAaDvL0lnZqLrIdKrKpF
   4YEFRyyiojATPBSReljcRaHlkNiocJ0T/k0uTpSbdMymtWqD1OcBwYAER
   DT7JVlfi5SDw0nNXQ3CKAi6GM+0dqAkF0RUy01glfYf5tO/0z53YCovFy
   gbhDXj31gYZkIq+CxjJV532/+Sk+eJwUPu3Er0I4qrroslMtZEZjJ4kQd
   vBebFinS0M1b1q3MvXAZ+FMQ8/hEjkbTlwPqP1f2cHD0oVgr4Jj/7BblD
   g==;
X-CSE-ConnectionGUID: pEUc8es4TuKstEx2Lvpkvg==
X-CSE-MsgGUID: 68GX+MwJQJKMATZUZL2DRw==
X-IronPort-AV: E=McAfee;i="6800,10657,11728"; a="85909367"
X-IronPort-AV: E=Sophos;i="6.23,118,1770624000"; 
   d="scan'208";a="85909367"
Received: from orviesa003.jf.intel.com ([10.64.159.143])
  by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2026 15:17:52 -0700
X-CSE-ConnectionGUID: fDRul27+SIOdODpNtBZ/jQ==
X-CSE-MsgGUID: ofEzsMjzQ3Sq2t3+jmidzw==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="6.23,118,1770624000"; 
   d="scan'208";a="225407275"
Received: from orsmsx902.amr.corp.intel.com ([10.22.229.24])
  by orviesa003.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Mar 2026 15:17:52 -0700
Received: from ORSMSX902.amr.corp.intel.com (10.22.229.24) by
 ORSMSX902.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.2562.37; Fri, 13 Mar 2026 15:17:51 -0700
Received: from ORSEDG901.ED.cps.intel.com (10.7.248.11) by
 ORSMSX902.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.2562.37 via Frontend Transport; Fri, 13 Mar 2026 15:17:51 -0700
Received: from PH0PR06CU001.outbound.protection.outlook.com (40.107.208.22) by
 edgegateway.intel.com (134.134.137.111) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.2562.37; Fri, 13 Mar 2026 15:17:50 -0700
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
 b=a/U6eAKmeFWvnHry360+8jsW0sEcoEHwSDtxlaweYXFkMjNqDM/un0FE5Gj81lX9jsvLyIuF14uIYOIhx+lCzx8CdCBZEavuhPQNoxUPXeCRU3ZQ8T3Uv0peVrJj+WDhX1e/i2hdrHUMbN+uJ9QK3l1tKcYYEWUTK1FZLi/VqOONK7FWLmcrI21/+CfzDVTMDnvyPbIkzcEr+QVJMosaiilB/n4UD99ziqYyIjqkw4JiLrpynpOZcvePjglIfmQSGjaq5GXRWQd7cbtXTubycKtlWLwzbuw06Chnv+qD4bXyxG1KUeenx6Oy1fQXorppFvCrsMSBf82hN0WTiObz0A==
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=tDOOjL7UL4Kj+QEmk4viQLwuRELtEiApnVzc4K/9bkY=;
 b=Aa3es6R0HEogZMj2OXjuJ6wW6LVxSZDdHtQN++plDtulcDnInoE2kwVi8wgbfhyj+8tTfRI0LpDT9K4VxKlq/tzG7QyyC/2Lgi5DFfH7eEXTX3WOsqmrVjRx2jJUMukqlQnK7Itp8HSXoX0rScnXXQAF959SBXHoJ13U6Y/yzDAiiQmpssy5pi6X4EZz2GuZc31DcIuBfg/wTyyl1zWxGbruj4EzzuR1LvXeJvXdmagBqQKJ4D6YokZsSxPWAmJWaRB8drbaplQL/2MFElpiEcgUhvIMF/MoLWP5x1LfJovYFO3FRfw2o/EB0JJOFemNBRYuHCzALwrKy0ozb+8pYw==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
 smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com;
 dkim=pass header.d=intel.com; arc=none
Authentication-Results: dkim=none (message not signed)
 header.d=none;dmarc=none action=none header.from=intel.com;
Received: from PH8PR11MB8107.namprd11.prod.outlook.com (2603:10b6:510:256::6)
 by SA0PR11MB4669.namprd11.prod.outlook.com (2603:10b6:806:99::21) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9723.8; Fri, 13 Mar
 2026 22:17:48 +0000
Received: from PH8PR11MB8107.namprd11.prod.outlook.com
 ([fe80::1ff:1e09:994b:21ff]) by PH8PR11MB8107.namprd11.prod.outlook.com
 ([fe80::1ff:1e09:994b:21ff%3]) with mapi id 15.20.9723.008; Fri, 13 Mar 2026
 22:17:48 +0000
From: Dan Williams <dan.j.williams@intel.com>
Date: Fri, 13 Mar 2026 15:17:46 -0700
To: Jason Gunthorpe <jgg@ziepe.ca>, "Aneesh Kumar K.V (Arm)"
	<aneesh.kumar@kernel.org>
CC: <iommu@lists.linux.dev>, <linux-kernel@vger.kernel.org>,
	<kvm@vger.kernel.org>, Kevin Tian <kevin.tian@intel.com>, Joerg Roedel
	<joro@8bytes.org>, Will Deacon <will@kernel.org>, Bjorn Helgaas
	<helgaas@kernel.org>, Jonathan Cameron <Jonathan.Cameron@huawei.com>, "Dan
 Williams" <dan.j.williams@intel.com>, Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>, Xu Yilun <yilun.xu@linux.intel.com>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>, Steven Price
	<steven.price@arm.com>
Message-ID: <69b48d0a374a_b2b6100eb@dwillia2-mobl4.notmuch>
In-Reply-To: <20260313184957.GP1704121@ziepe.ca>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-4-aneesh.kumar@kernel.org>
 <20260313184957.GP1704121@ziepe.ca>
Subject: Re: [PATCH v2 3/3] iommufd/vdevice: add TSM guest request ioctl
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
X-ClientProxiedBy: BYAPR06CA0031.namprd06.prod.outlook.com
 (2603:10b6:a03:d4::44) To PH8PR11MB8107.namprd11.prod.outlook.com
 (2603:10b6:510:256::6)
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
X-MS-PublicTrafficType: Email
X-MS-TrafficTypeDiagnostic: PH8PR11MB8107:EE_|SA0PR11MB4669:EE_
X-MS-Office365-Filtering-Correlation-Id: dcb2e1a3-1dbd-42c5-0ed6-08de814e5c15
X-MS-Exchange-SenderADCheck: 1
X-MS-Exchange-AntiSpam-Relay: 0
X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|7416014|22082099003|18002099003|56012099003;
X-Microsoft-Antispam-Message-Info:  
X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR11MB8107.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(7416014)(22082099003)(18002099003)(56012099003);DIR:OUT;SFP:1101;
X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1
X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?eWxnL3JJNy9QdURYM1lYaU9zQ0wyUTVCSnIyMlkvYjBDS3VZbDlpemJxN0tn?=
 =?utf-8?B?UmZqS3VlTWwwRDdHbnZvL0MybjF2d290RzZCMyt6OU1KOG56UHZKRnkyY0Fp?=
 =?utf-8?B?WjFDQUpFZVRkTy9kb0dJeWhaYm5ZVmlTQ1EzdVVzVDd5bGdIZ01wblpuTUs3?=
 =?utf-8?B?a2pBWUE2M0Y4cHE3dm9BUXVrSnorWUE4MXdDN01TMElKYTNPNCtLZTlJeGpY?=
 =?utf-8?B?UUQxbmFCQVd1NVc4dWJPaXJ5WE1RU0loUUNIM1NOaGtNTTlsMkVpZkJxZGZh?=
 =?utf-8?B?MzJaS2pndGJuOUQ5YklDaFkyd2FvZ1IrSjNBWVdFdUxkK3hKV1oxU0J6eFly?=
 =?utf-8?B?WWNyNGpvSXdnVEtVS0d4T3NyVm1xNVZhSHFILzc4YVI3L3cydDBMdEs3T1Jq?=
 =?utf-8?B?ditmMkpSWHRFTFNrSVdmOGJQYjhoNlpKTkU0SENTODcwdlAxMlJyVFZWKzNW?=
 =?utf-8?B?dHpQWUN5N0VCK1BxQjBaTnJ4ZFVaMGZleGdaUE5ncGErOXdKaVhJTGZKQXNp?=
 =?utf-8?B?KzVmckpaT0FBeHlNSWdlWGlEYllFS25haHFxVENSa2dRa2tUYTV1eFdxTVNY?=
 =?utf-8?B?SjV1aHlkZGI1S2dzNVNkazJwRmJGdzRwekxGVzcrdWpzeFVKK3dSeXRYZFhu?=
 =?utf-8?B?K1puMHR4Z3FvOTZnSldmZXFuWVp6Wkd2MmZaM3lXK0p4Q2dmQ2ZTazl0YytV?=
 =?utf-8?B?MFNWd2MvV3lXb1RkUXR6OEFFc0FhYjdiMkdoZnJ2a3VPY25XdDFKWGdFTU8y?=
 =?utf-8?B?R1JNYTlvdDV6TkpTdnIwK3dwM0Q2UHkzRWFLWFlsMDVTSEIwVU92QUtDMlph?=
 =?utf-8?B?VURVYUFiRWRpY3p0QVFzam80WmVNTEtEMlBSZHJsdUV2KzN5OTVieTc4MWFY?=
 =?utf-8?B?NkhxOVljNGpISGduOXhIaklCanl3QmJ2MGgyUmtkNDV6VkpCSk1xMlpVQ0xp?=
 =?utf-8?B?d1dMUWxNQXA5aERNN1YvQ2hQaktBbTM1NWhGUXZ0Q3lNdjIvdzJQRG9OTmpD?=
 =?utf-8?B?K0RNYjNZS09ia01kMGRVUTk1UTIvTjdEdHV0Y2xrRmdvMWJMeWcxUmQ4UzNY?=
 =?utf-8?B?RHpNUkVlMFR1WWtQN3ltWVdpVncvb3ZPZFBxRVNLMnh0NTM4NFY0U05ZTzA2?=
 =?utf-8?B?SWJyVWN3SklnMGswQmw5TFhqR2ZweUlRaDYyV3hmUGF4b3RJTDZOTldSYzlj?=
 =?utf-8?B?eVowQ29ndUk1ZXJZQTNHVlROaEh0MDdBVGFreVFNN2N3ZW9leTFEMkVmVGZi?=
 =?utf-8?B?TFBncGVWYUh5c09mdnFrWFp0WmdVU3Y3TE1nY0ZhS1pTS3NOWGMwKzNkcGQz?=
 =?utf-8?B?NzVQb0lYbHNtaHBhWDVRWFp2K25XZUJsbXpDNlowdW9obkYwRm5KdXdFakUy?=
 =?utf-8?B?TlZtNDB2NGtTdmhySi9wWEcwV2g5VExDV0Njb3Y5RjkzajlaQkU1ZzNucVNM?=
 =?utf-8?B?SHBraFRzK0ZUYjRtYTRPcjdVTllsakVJYktoV0tOR2dwQmhXMVFlU1FGS0pM?=
 =?utf-8?B?NDl0cDBrRi92NkNPVmRsN1pXSEd2VDNPbGVtWmxYNDdBM1FUT3NNWnNjTXdl?=
 =?utf-8?B?MFk0c3JSanJMVGxESDlTVSt1OWxWYWJBdW5JVHQvRG5obHU3MlVTTFBRSmtH?=
 =?utf-8?B?MU9RMkRGQkYzRzBoNXZNRkExdkFZbVNKSTRwSko2bC8zSDdteGV4ckwyQjBR?=
 =?utf-8?B?WHdFUmUxUkpLL3ZpaWk5V3E5TTlPMmtqZU50azdxWXZkYVE1NmgwVEF0MFdS?=
 =?utf-8?B?VDdkNnhIaWdjcGVGT1d2ejRhL2RJTDdRU2xNc2RnZUlaTndxMjN3azdVNGkz?=
 =?utf-8?B?ckw3OUFtbjR4ZTcwaVhkZjlZbUtkZDZFVzRBZjg3andMRWdlcmdOY25MSFBI?=
 =?utf-8?B?VDIyVVpJbHVtYWRuWmxGbmYzWFI0NVIvQ2E5Ylo2TFNGM2xGWEhPWEgvanBj?=
 =?utf-8?B?OVlxU3IxOEIzNjFKbWNGdElVWlVhaENaTzBQazdOaFVYZDFOZnArL1hWR1Ir?=
 =?utf-8?B?NmhkTUxlOHdRS0U2VlNESTY5c1lYNE9aT1hseHljckFiNEhvc2FZTUM1c0hq?=
 =?utf-8?B?SHgrSzlUZVpYb1FzN0tPUm9HWUFwQjAyUEdHTGdqenB4ZWNuVXBHeXV6ZU4y?=
 =?utf-8?B?UkE3dHQ2bFRYTlE3UmlYZ0FlNmUxWWVITm5oQWlYSE9VT0VLZmI2VitUbDQv?=
 =?utf-8?B?bzBFWHkwY25ZMis1dkV0b29kR29oTS9BczFKMU1XM2pHdFBBa3JqL0puZkxk?=
 =?utf-8?B?MW9leXZ1OE9Vbi83ejNROCtCRUdscGdVdXRDMnJkYmpmTTVYSGo1MUhKQm56?=
 =?utf-8?B?ZTZJRDBDemZDMDdSU2dzR0EvOXh5eDJYbWtTcW5hZ2VqeFpVemkvRmhySlRa?=
 =?utf-8?Q?0CVrHhJyEME80qVs=3D?=
X-Exchange-RoutingPolicyChecked: MT/imE/qkRU97/BWAPc6OH2VjBvM6+OFBhrM78pUtV4qkjUi2XG1KUaBOeS9+Yru6HnRr6ovunqEtEN+34eckP7U52KJAlXZ+RbUlOmF0WzD1QbT2LC+IaffZGs5KeJny9nvohjw3jabDqc08/0DdEoGNflQ769RedOKDN9AjHmY6run87m90pdkgHxm+tDZVMaU/YSdxFmzuZINzakD2Sdd3HKmK+B3r3ScvzpZzBRIPMW4ZdbowYzixXQoCOefNnJeKhBzIY7dzwSOJ0Om5kDcz3W4WG9AMjS/zvJH0llibKKsmBk6t3jyrib9joeb56QiVkJPbH42dZBgaGSl+g==
X-MS-Exchange-CrossTenant-Network-Message-Id: dcb2e1a3-1dbd-42c5-0ed6-08de814e5c15
X-MS-Exchange-CrossTenant-AuthSource: PH8PR11MB8107.namprd11.prod.outlook.com
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Mar 2026 22:17:48.7435
 (UTC)
X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted
X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d
X-MS-Exchange-CrossTenant-MailboxType: HOSTED
X-MS-Exchange-CrossTenant-UserPrincipalName: ftBoBCxzizPknMnCARWv0JGX4iPV9W5mM52bcpxmXTP/Zdf7FFgcJ/wPul2HVV1rE0FgIgrgUGrOq48gYN1NLLi+QL1Acf1wo4WtGOnga0M=
X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR11MB4669
X-OriginatorOrg: intel.com

Jason Gunthorpe wrote:
> On Mon, Mar 09, 2026 at 04:47:04PM +0530, Aneesh Kumar K.V (Arm) wrote:
> > +/**
> > + * struct iommu_vdevice_tsm_guest_request - ioctl(IOMMU_VDEVICE_TSM_GUEST_REQUEST)
> > + * @size: sizeof(struct iommu_vdevice_tsm_guest_request)
> > + * @vdevice_id: vDevice ID the guest request is for
> > + * @scope: scope of tsm guest request
> > + * @req_len: the blob size for @req_uptr, filled by guest
> > + * @resp_len: the blob size for @resp_uptr, filled by guest
> > + * @req_uptr: request data buffer filled by guest
> > + * @resp_uptr: response data buffer
> > + */
> 
> This needs a much better kdoc.
> 
> Refer to specs that define this.
> 
> Explain WTF scope is

I proposed @scope, yes this needs more documentation, but really it
needs more discussion first. It was inspired by 'enum fwctl_rpc_scope'

Guests that are moving the device through the TDISP setup state machine
need to ask for host services because only the host passes messages over
SPDM in all of these architectures. That is, one SPDM session per
physical device, not per assigned virtual function. In the AMD case
there is less guest direct access to the TSM so it needs to pass
additional messages that the CPU mode based TSMs do not.

Those requests are varying degrees of: host kernel cares, host kernel
does not care but can see the contents of the message, and host kernel
does not care and can not see the contents of the message beyond
envelope.

As far as the host kernel security model is concerned this becomes a
opaque implementation specific passthrough. So the role of @scope is to
have the TSM drivers declare the security model for various messages.
Put the explicit onus on the implmentations to declare that the
guest_request operation being executed in response to a KVM exit is
contained within a given security scope. See 'enum pci_tsm_req_scope'.

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4666B78F4A;
	Mon, 16 Mar 2026 05:47:47 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773640067; cv=none; b=miSOYz3nxXcEF8eU2btu2CM2sGKl3LVi7ft5mj9VcgS1lV+aDm+Mnr1V+4Dvn3o3UWOBkoTyLl5HYUFPKdYsWolQczOysLE5+8u2+yTtrWh+EJGGt3dMK6KiLuCTA8XgIXJAXV8INPDXSUX/87Wr9dZx7CokNQFCIDX+PyCyUtk=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773640067; c=relaxed/simple;
	bh=+BbWevT0Swja6eb2FmIWQ32cxIjaS3zQmKU+0N869yU=;
	h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:
	 MIME-Version:Content-Type; b=FgTYmChsmPEOxiRX2N5TpFFEnOZjDySC5ZUFZ4lpIS2lK6FtbMXtLDRBuyEiGqbmY9PgN1lnvJtNBHquiAMVEAKbrufRuSsxc7cQNXxXIx0qHpxYM126owD/oh0VgdfSNdSR7YoPwv9YjSSPcWeLxfqw9e0ZAIEfzyBJxeoUg6o=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QRAZ+9S2; arc=none smtp.client-ip=10.30.226.201
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QRAZ+9S2"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id C39C5C19425;
	Mon, 16 Mar 2026 05:47:41 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=k20201202; t=1773640066;
	bh=+BbWevT0Swja6eb2FmIWQ32cxIjaS3zQmKU+0N869yU=;
	h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
	b=QRAZ+9S2ToIhD4En/rF/Fav+iFK0Gqf7O41v2eKfD6R6JhNM0/fsyMo9wiQxpfuqP
	 6u+UOBsbpaS9LIPlDF7HEI3LB1HBgxAsNzpPM8j94DvdySmc3/YgupF6x1xqXhR8G6
	 v6wq0Ds+vY0I4E3Zc+c5wONPJg8wocVg5r9CjojN9XwbTHO5L3KrwzYtsK+vvmELWy
	 ADkVF0EOK9axLrx4iNl5LRByS5vxPmWx7VVw3/Hw412e4hX9tyMuWsWIYSA+DZGQu8
	 qDK3kF+j3JZRY5kXRWDai3DG4t2CFgy0y6n4+dL1oyqLhPISIoN8JGpAAYxyN5Bl/b
	 VDmIaqi5RCFsg==
X-Mailer: emacs 30.2 (via feedmail 11-beta-1 I)
From: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, Kevin Tian <kevin.tian@intel.com>,
	Joerg Roedel <joro@8bytes.org>,
	Will Deacon <will@kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	Steven Price <steven.price@arm.com>
Subject: Re: [PATCH v2 3/3] iommufd/vdevice: add TSM guest request ioctl
In-Reply-To: <20260313184957.GP1704121@ziepe.ca>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-4-aneesh.kumar@kernel.org>
 <20260313184957.GP1704121@ziepe.ca>
Date: Mon, 16 Mar 2026 11:17:37 +0530
Message-ID: <yq5a4img8gw6.fsf@kernel.org>
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Type: text/plain

Jason Gunthorpe <jgg@ziepe.ca> writes:

> On Mon, Mar 09, 2026 at 04:47:04PM +0530, Aneesh Kumar K.V (Arm) wrote:
>> +/**
>> + * struct iommu_vdevice_tsm_guest_request - ioctl(IOMMU_VDEVICE_TSM_GUEST_REQUEST)
>> + * @size: sizeof(struct iommu_vdevice_tsm_guest_request)
>> + * @vdevice_id: vDevice ID the guest request is for
>> + * @scope: scope of tsm guest request
>> + * @req_len: the blob size for @req_uptr, filled by guest
>> + * @resp_len: the blob size for @resp_uptr, filled by guest
>> + * @req_uptr: request data buffer filled by guest
>> + * @resp_uptr: response data buffer
>> + */
>
> This needs a much better kdoc.
>
> Refer to specs that define this.
>
> Explain WTF scope is
>
>> +struct iommu_vdevice_tsm_guest_request {
>> +	__u32 size;
>> +	__u32 vdevice_id;
>> +	__u32 scope;
>> +	__u32 req_len;
>> +	__u32 resp_len;
>
> do not leave implicit padding, add a reserved, and check it is 0
>
> Jason
 
How about this change?

modified   drivers/iommu/iommufd/tsm.c
@@ -94,6 +94,9 @@ int iommufd_vdevice_tsm_guest_request_ioctl(struct iommufd_ucmd *ucmd)
 		.resp_len = cmd->resp_len,
 	};
 
+	if (cmd->__reserved)
+		return -EOPNOTSUPP;
+
 	vdev = iommufd_get_vdevice(ucmd->ictx, cmd->vdevice_id);
 	if (IS_ERR(vdev))
 		return PTR_ERR(vdev);
modified   include/uapi/linux/iommufd.h
@@ -1370,11 +1370,27 @@ struct iommu_hw_queue_alloc {
  * struct iommu_vdevice_tsm_guest_request - ioctl(IOMMU_VDEVICE_TSM_GUEST_REQUEST)
  * @size: sizeof(struct iommu_vdevice_tsm_guest_request)
  * @vdevice_id: vDevice ID the guest request is for
- * @scope: scope of tsm guest request
- * @req_len: the blob size for @req_uptr, filled by guest
- * @resp_len: the blob size for @resp_uptr, filled by guest
- * @req_uptr: request data buffer filled by guest
- * @resp_uptr: response data buffer
+ * @scope: Scope classification of the guest request, one of enum
+ *         pci_tsm_req_scope values accepted by pci_tsm_guest_req()
+ * @req_len: Size in bytes of the input payload at @req_uptr
+ * @resp_len: Size in bytes of the output buffer at @resp_uptr
+ * @__reserved: Must be 0
+ * @req_uptr: Userspace pointer to the guest-provided request payload
+ * @resp_uptr: Userspace pointer to the guest response buffer
+ *
+ * Forward a guest request to the TSM bound vDevice. This is intended for
+ * guest TSM/TDISP message transport where the host kernel only marshals
+ * bytes between userspace and the TSM implementation.
+ *
+ * @scope limits requests to TDISP state management, or limited debug.
+ * Requests outside the allowed scope are rejected.
+ *
+ * The request payload is read from @req_uptr/@req_len. If a response is
+ * expected, userspace provides @resp_uptr/@resp_len as writable storage for
+ * response bytes returned by the TSM path.
+ *
+ * The ioctl is only suitable for commands and results that the host kernel
+ * has no use, the host is only facilitating guest to TSM communication.
  */
 struct iommu_vdevice_tsm_guest_request {
 	__u32 size;
@@ -1382,6 +1398,7 @@ struct iommu_vdevice_tsm_guest_request {
 	__u32 scope;
 	__u32 req_len;
 	__u32 resp_len;
+	__u32 __reserved;
 	__aligned_u64 req_uptr;
 	__aligned_u64 resp_uptr;
 };

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6350B223708;
	Mon, 16 Mar 2026 05:49:37 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773640177; cv=none; b=eRxyA133TYEvwyv02Swm3nAhxlmwCHiZesyA204cxV/TrU0Bg/mWcBPpfMCx5fSbRXtxSi3LGOly0N7Qj2ES657LuJRBs2gSkNq+GigVOSFi/qcbFTQoRmg+fUMBmU4qZZv9DzI3mghaq2vY+iRJq4lo9HMA095WdyVSF00iHlQ=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773640177; c=relaxed/simple;
	bh=pZiSm+008sCbaEsRnc7ZhunJgxcEmN5bsNlaJsNR6IQ=;
	h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:
	 MIME-Version:Content-Type; b=h5Z5Xl0G8Pffq3zr223sPYer59lBAS/2yW2clYW6pEuNsxyLivTiYoF9WdW6AEuQ3M9VcYU1JDMdFVaCv0SRYImeCF4EOAe483/2dO8JfQs4uV/k67UGmD7EypgHj2dNj8PmxTOgozpcyU/dUGXe7ad0930lzhoyaVLQUJoFZYs=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SIUW6NGC; arc=none smtp.client-ip=10.30.226.201
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SIUW6NGC"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id 836A5C19425;
	Mon, 16 Mar 2026 05:49:31 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=k20201202; t=1773640177;
	bh=pZiSm+008sCbaEsRnc7ZhunJgxcEmN5bsNlaJsNR6IQ=;
	h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
	b=SIUW6NGCDj7drWksNlvLLOgEGhgBMLx63Kkt9AQYyu/REgCYx8tIaLlwEP+ITCybA
	 TRXAAjDfeMryGzmiNu3a47BP2AbC1U31uKttcX37YIbNyDzCwwlOp/CuFpVFVrKHhb
	 uTBoYDw8vJ4oG28UAALkMmtk1IAMyge25KiNdLey49OPwtkO9rzukStLcwtmtHWsHb
	 V5MpS5W0xyqYTgqrzXLO0/xf1hvHuTtG+o7kC5BGLMqa+vhYjiWSCG33vQtFp2DtvS
	 l1+ZEUqfspDQH+zZdH1+CFid6Z5pz4fZbs5lpZleQ6mJzt+1AmrBSCK+6s9uPjgRBB
	 PeT3MOvjSaPJA==
X-Mailer: emacs 30.2 (via feedmail 11-beta-1 I)
From: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
To: Nicolin Chen <nicolinc@nvidia.com>
Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, Kevin Tian <kevin.tian@intel.com>,
	Joerg Roedel <joro@8bytes.org>,
	Will Deacon <will@kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	Steven Price <steven.price@arm.com>
Subject: Re: [PATCH v2 1/3] iommufd/viommu: Allow associating a KVM VM fd
 with a vIOMMU
In-Reply-To: <abOrdFR4L2n334MR@Asurada-Nvidia>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-2-aneesh.kumar@kernel.org>
 <abOrdFR4L2n334MR@Asurada-Nvidia>
Date: Mon, 16 Mar 2026 11:19:28 +0530
Message-ID: <yq5a1phk8gt3.fsf@kernel.org>
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Type: text/plain

Nicolin Chen <nicolinc@nvidia.com> writes:

> On Mon, Mar 09, 2026 at 04:47:02PM +0530, Aneesh Kumar K.V (Arm) wrote:
>> Add optional KVM association to IOMMU_VIOMMU_ALLOC by introducing
>> IOMMU_VIOMMU_KVM_FD and iommu_viommu_alloc::kvm_vm_fd.
>> 
>> When the flag is set, iommufd validates that kvm_vm_fd refers to a KVM
>> VM file and stores a referenced struct file in the vIOMMU object, so
>> later iommufd operations can safely resolve the owning VM.
>> 
>> This is preparatory plumbing for subsequent patches that bind TDI state
>> to the associated KVM VM.
>> 
>> The patch also switch file_is_kvm from EXPORT_SYMBOL_FOR_KVM_INTERNAL to
>> EXPORT_SYMBOL_GPL so that iommu module can use that.
>
> struct vfio_device has the kvm pointer already. So, I think it
> could be forwarded from VFIO side v.s. via userspace ioctl.
>
> Shammer had two patches before and Jason partially reviewed. I
> took those for a side project but haven't sent anywhere. Would
> you please check if they for you?
>
> https://github.com/nicolinc/iommufd/commits/wip/viommu_kvm
>

I will use these patches and add additional patches on top of it.

-aneesh

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A7DE2FE075
	for <iommu@lists.linux.dev>; Mon, 16 Mar 2026 07:12:07 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=198.175.65.18
ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773645129; cv=fail; b=t/QpOmFU17R+6oMeEEBbmssFuoBEZ4waXsvb58sHXlQaFtfyoAsnwjwT+vKo79da1xdMjmR2Z7zvmk7zmJKFG2R3DrUFkJdXb3g1GOZ1R/dJxo8k8uGpuLzia12eieaZoBFqj+bRqhk3i7aVnxlMaAJWQ2NkRFmH7YcT8oDFTFw=
ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773645129; c=relaxed/simple;
	bh=IJcAOQxNxNCHm/5hmaDIjNJrN9sAVwnHpJzd4cWsxAw=;
	h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To:
	 Content-Type:MIME-Version; b=MNV8CnDFsmCDaTPRLNi78mihYDu+DTcE62Yuh2Y4LSpDohskNG/D8XQICZpKzz5vQIuwUKPA962iYPPe54PaOV6xBQI56erlkN8opdZc8yeO+Me9bZNs/IGR/Fo3kSV6UvcA0k1HZp/irkdxiT0MYKn9M3CwWuitEFa3tCdPwdw=
ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Ws3EWRsu; arc=fail smtp.client-ip=198.175.65.18
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ws3EWRsu"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
  t=1773645128; x=1805181128;
  h=from:to:cc:subject:date:message-id:references:
   in-reply-to:content-transfer-encoding:mime-version;
  bh=IJcAOQxNxNCHm/5hmaDIjNJrN9sAVwnHpJzd4cWsxAw=;
  b=Ws3EWRsuPVb9eCNtSvyoO0JilpoGDsJiGTXZOse8k3qHIHmGTzb+xIdS
   3UwjzKqEVBz0CxgLkAHhgejBjxmWUFU1q5jNLou9VLCI87wszqZ3rJWwq
   ZcT/GD58paD8NyLDJTEz1DcwPF6VH9VX8QOibyBFTMRCCInFAaxI38OuB
   Nfyxyg7dcaViAp+8jL408GoN+ZBJBAy3d84V9bblwMzT4MvvMGG+KyPnx
   nlO8Pk7yM6IBdRC7pw4zY+DhTN0GpB7pBn1rJ/9Ab19ezwkb3JOdi1ctG
   +5M6DbzOrrfCHhreZVItp2k5iYB8bazndnbaOSU65U1VTZWBg9nRL68s/
   A==;
X-CSE-ConnectionGUID: KQhvWgTqQBK7MECWhVepcA==
X-CSE-MsgGUID: cJbGvsoySbCDE5Qf+fEfBQ==
X-IronPort-AV: E=McAfee;i="6800,10657,11730"; a="74690494"
X-IronPort-AV: E=Sophos;i="6.23,123,1770624000"; 
   d="scan'208";a="74690494"
Received: from fmviesa008.fm.intel.com ([10.60.135.148])
  by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2026 00:12:08 -0700
X-CSE-ConnectionGUID: lM7D82F/Su6a5aKf+U68wA==
X-CSE-MsgGUID: 7tko6e+rQd+4SZU69OeGxg==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="6.23,123,1770624000"; 
   d="scan'208";a="219425364"
Received: from orsmsx903.amr.corp.intel.com ([10.22.229.25])
  by fmviesa008.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2026 00:12:04 -0700
Received: from ORSMSX902.amr.corp.intel.com (10.22.229.24) by
 ORSMSX903.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.2562.37; Mon, 16 Mar 2026 00:12:04 -0700
Received: from ORSEDG901.ED.cps.intel.com (10.7.248.11) by
 ORSMSX902.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.2562.37 via Frontend Transport; Mon, 16 Mar 2026 00:12:04 -0700
Received: from MW6PR02CU001.outbound.protection.outlook.com (52.101.48.52) by
 edgegateway.intel.com (134.134.137.111) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.2562.37; Mon, 16 Mar 2026 00:12:03 -0700
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
 b=nTYSXUHSodQj6rSotAVV0twNMFF0IJCjv5GdgKzEYQC/InTBSyVqvERBUd/2A151gGrPm6+pXtWal+10aXKWdHX6v0Uc6KA1AZNwfKAb3qLywnuA5DAaaMGFL0ovuR5XUVhrwkTHcKWi+Bt8xLvN9u/50+PrmLgNo60NSqB0fKhPYaS//jpENlzQiF72UIj2mQbaRBAWIQdpTHwVnNj12n04YYo0ZT+SO0LPXv1G5jYPuJviIp1PtEZcKg+H+faA+DQayHWUSRfgAhRaWPSOzosUYSOR/ZGa2JwbYCtLkjynY9GRhNmA3Sv2j+TsUUfOJaww+4OpKOQbFcr1j3g4ag==
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=ajgrsTt7oPfiFmK0fwXevjNHLzUe9s3PKgqXaRqJyF8=;
 b=ZypsyItaNdIVVgUIIsix0F8XxQNIh0aSWllNJIL3GIfEFaJtO45/C5SeeKiqiZaxxNv2ijlC/FYZa61DS9CnWoUUDHm8F0ju16mIiLkqwhJrpPgWtlfFVo+sxtc/ydilL45WZ9krjV2nzkqWNWlLhVfMv4b4k2NLX320BdxHzWxiB8Ps6efGNRKfBiqBqdnjqTcQH2h2ysFCdsgoMVL8P2z8cfbh5jg9KQBMf7FTKGqvyUOZJnHBxU5sc3cNpIZqbGhZB/tr0y/ZHsIvARNn3R8lA6GnTsjcT8ZOjCtRlmLZaXDmUwOagyxVhsTfnuNFzHDY9c5s4b5wIgo7LAboAA==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
 smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com;
 dkim=pass header.d=intel.com; arc=none
Received: from BN9PR11MB5276.namprd11.prod.outlook.com (2603:10b6:408:135::18)
 by BN9PR11MB5322.namprd11.prod.outlook.com (2603:10b6:408:137::18) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9723.17; Mon, 16 Mar
 2026 07:12:02 +0000
Received: from BN9PR11MB5276.namprd11.prod.outlook.com
 ([fe80::f997:762f:f079:134f]) by BN9PR11MB5276.namprd11.prod.outlook.com
 ([fe80::f997:762f:f079:134f%5]) with mapi id 15.20.9723.016; Mon, 16 Mar 2026
 07:12:01 +0000
From: "Tian, Kevin" <kevin.tian@intel.com>
To: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>,
	"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>
CC: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>, "Bjorn
 Helgaas" <helgaas@kernel.org>, Jonathan Cameron
	<Jonathan.Cameron@huawei.com>, "Williams, Dan J" <dan.j.williams@intel.com>,
	Alexey Kardashevskiy <aik@amd.com>, Samuel Ortiz <sameo@rivosinc.com>, "Xu
 Yilun" <yilun.xu@linux.intel.com>, Jason Gunthorpe <jgg@ziepe.ca>, "Suzuki K
 Poulose" <Suzuki.Poulose@arm.com>, Steven Price <steven.price@arm.com>
Subject: RE: [PATCH v2 2/3] iommufd/tsm: add vdevice TSM bind/unbind ioctl
Thread-Topic: [PATCH v2 2/3] iommufd/tsm: add vdevice TSM bind/unbind ioctl
Thread-Index: AQHcr7Zd6PCT7CXd3U+POC29TSGUorWwxrMg
Date: Mon, 16 Mar 2026 07:12:01 +0000
Message-ID: <BN9PR11MB5276585EAEC4C80D4D45DD8A8C40A@BN9PR11MB5276.namprd11.prod.outlook.com>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-3-aneesh.kumar@kernel.org>
In-Reply-To: <20260309111704.2330479-3-aneesh.kumar@kernel.org>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
authentication-results: dkim=none (message not signed)
 header.d=none;dmarc=none action=none header.from=intel.com;
x-ms-publictraffictype: Email
x-ms-traffictypediagnostic: BN9PR11MB5276:EE_|BN9PR11MB5322:EE_
x-ms-office365-filtering-correlation-id: fa26d838-749f-4329-0b00-08de832b5205
x-ms-exchange-senderadcheck: 1
x-ms-exchange-antispam-relay: 0
x-microsoft-antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016|38070700021|22082099003|56012099003|18002099003;
x-microsoft-antispam-message-info:  
x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN9PR11MB5276.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(366016)(38070700021)(22082099003)(56012099003)(18002099003);DIR:OUT;SFP:1101;
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?bH7euxc4oi2OBgjSa6jsEqfbPi+BLMXkg9VVTCKY5Y0az5Hpd+cv3n3NIofj?=
 =?us-ascii?Q?SMZQ8N7nW6G5hDQQ+zNTukGNr03Za+SpbOBQ2hxOPg1EewGTubrwZX7mjyv8?=
 =?us-ascii?Q?doqws5r8/xj5UtRvAVrhozrhliixISgWRw9MXzRpb6buvbGdwA28hi2TaqUN?=
 =?us-ascii?Q?Tj4EO5iKw7IFjc5u4LeREAbmQt+JzNLvcKT0RRRg5efsoZxO4/uKC522LaL1?=
 =?us-ascii?Q?lyc9IWEDOMsmcifd1OyUta7Y2u0ZCXVCLsE8q8wpB8KMUPITsdL4bu5kQ3G7?=
 =?us-ascii?Q?ecMmZT8inhujENyoERMHCHq2VeGXanEOte7YpoCDP9beMm4BCqVxJGhrsfx3?=
 =?us-ascii?Q?FcDddsX289qUHXfrbFxYh7qzprritsB0KlXXo7Prvtd2udKXoZPkSet6p0G5?=
 =?us-ascii?Q?Zx3Yvlq3XYKkWcyaT48dr1gwquaV+bygiQ8Cg/jX67W/ZNbL0RHmnsHM33YZ?=
 =?us-ascii?Q?SfCsPWMo6hcgMjZnQepURo8MYdcCCfwfofgCPckSqVlpJq3GLx3AFSokjVUL?=
 =?us-ascii?Q?EZmvWiFfArCxNBElnC371eGSEbBFYwNjcBLYD7Hq+yYU1C3/EjpivpRzkTif?=
 =?us-ascii?Q?/dSvN62n9v2woQ9JPqHR7y+HD3nI5eX/SMRKTrwCc9YMno5EZOGG6xUFTuu6?=
 =?us-ascii?Q?BgWuYZaYLviOgUNjpbBB2A7hj4yLKQSezjA6JenCyV6W1UECV9S3tMf0xyiV?=
 =?us-ascii?Q?thzpR9dgAcbeiAuwxvD3ywYIri4ePYggGPA8O+YykwGBJFFKpkWnPLQ5Ahqm?=
 =?us-ascii?Q?uYIeOZipL6I+MXQu3mb/H/lUXK0UWPY1O3Pq3ZMyTJIIsu6V5xGU4haTJ5eV?=
 =?us-ascii?Q?G3kcKSsgh8tR3s/Eehcfh+P8+1hyIuGxfIetTzCcT+s1yD1xkjfLQ8BLXTbR?=
 =?us-ascii?Q?3yGw/pwsCOg/1+DCap4VhgZXh+x4SwVseQ3AN9Bv8JVCKvW9h/rTE2a3WzeL?=
 =?us-ascii?Q?DnFi/tVXd0jr5T3yR/ZMrcKFyDkq7/bsZad6Q9lDL1Z5k/XEXlKKtJQBN26z?=
 =?us-ascii?Q?D3F7yjdZ65QRjk29JaLYf+w3KBAdN/EAhgWcEMAGip6tEPsASRQlZ6eCaEEO?=
 =?us-ascii?Q?QivK6e/vlhfk73DCepRwNm+r0giPwWU1MUN5mtsfa2s6tKjycGuuUtF+7kxL?=
 =?us-ascii?Q?g4jWSVyRZRbOOQhxLZNCjOX4Qo5RLww0A+HIcBF7Jfvr+jnUwxlP93X9RFOc?=
 =?us-ascii?Q?iMSF3SkE6Gfqul5eiUk5I5Lvi64iLpifB/Kga/wiwsZzXywC7qJPLDcYl2G6?=
 =?us-ascii?Q?W93CK5fyZRhyPITlb5+QfRCSPWBtQe1PiR78NZ8k0kF9sw/Rf1ANOz0kgK5g?=
 =?us-ascii?Q?dJWIiXrtMzrC+yJcBbxLZz6d6a0AzKROMvxTwBbYPil21EmbVh2H24gPJUah?=
 =?us-ascii?Q?f85U90YiSqYRlxKOWcYsIPFV3OXDLhulUBuuZRaL4XvoZ/woj+krjUIIsBqg?=
 =?us-ascii?Q?R1nc2pdrjik1Y5eREl1mhCwH4lxLsXjwA+fTlBqxkyz247vTJ6DEYu+X3Cdc?=
 =?us-ascii?Q?HCbryVjZMB3FhujR5iMS9IV08V037BvY9wmk2jQ/hpNn8P5ix+8R4N20TEAP?=
 =?us-ascii?Q?HJ8aT8F1tRU63Y//26cSedW0Lb1bafpIrpM6WnSE27usJ98AVrk0evd2IwAv?=
 =?us-ascii?Q?ulYrbFyrCPA3Yfi6gvLNWomJhJQTVXoXe3l6nV61TCH8wu0cZtmDZP/VJe6L?=
 =?us-ascii?Q?OcoZLeZn3TlL7KzgTLemfONXobY2mxEeOocNf91KPYUpkngv8pomxjn9n24t?=
 =?us-ascii?Q?YCAXuLZvmQ=3D=3D?=
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
X-Exchange-RoutingPolicyChecked: q73Evblu8znCIwHG+rKfUBmlWMbFpOCjscb/G+pQfTrDTXnRjQZpHtt/H1FQ0DyWkO9OcmbcPoniZUQ6W+FrH4/jV1NDvIL7WIhIPYHxZWXOCbeJW5CRifSqQsxdvZMQhnV19al0d62WdMpbW+nnhjzcGatk2qYgMvNn62AYSrQD7tPT5FMXJWj8Q7nUQ0IQx1VaXrAD0EwYonU0VJxiFRbRCMIc2DYimc/CIq5F9MCFALHwcaDBMCS8krcqVw4Xf99Wksj/xlkIJ20eThH9fhBujxaqnP7hQNvSbWWNPynBkVF2lRNZxmAGQhN7xZOJLRY8eEhyPe/wbi+3uzQ0nQ==
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: BN9PR11MB5276.namprd11.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: fa26d838-749f-4329-0b00-08de832b5205
X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Mar 2026 07:12:01.4946
 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: rDESAK6KxvoEOIMu/LIUxAxza2iffB24qYQNi7SYq7w1dHIAZbgSHorpemgVVdkg9zj0vNZ5zpCwfHPodyYSjg==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR11MB5322
X-OriginatorOrg: intel.com

> From: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
> Sent: Monday, March 9, 2026 7:17 PM
>=20
> Introduce IOMMU_VDEVICE_TSM_OP to allow userspace to issue TSM
> bind/unbind
> operations for an iommufd vdevice.

How many ops are planned? If just a few I'd prefer to openly defining
it:

	IOMMU_VDEVICE_ALLOC,
	IOMMU_VDEVICE_TSM_BIND,
	IOMMU_VDEVICE_TSM_UNBIND,

just like how we did for IOAS.

> @@ -432,6 +432,7 @@ union ucmd_buffer {
>  	struct iommu_veventq_alloc veventq;
>  	struct iommu_vfio_ioas vfio_ioas;
>  	struct iommu_viommu_alloc viommu;
> +	struct iommu_vdevice_tsm_op tsm_op;

please follow the alphabetical order

> @@ -493,6 +494,8 @@ static const struct iommufd_ioctl_op
> iommufd_ioctl_ops[] =3D {
>  		 __reserved),
>  	IOCTL_OP(IOMMU_VIOMMU_ALLOC, iommufd_viommu_alloc_ioctl,
>  		 struct iommu_viommu_alloc, out_viommu_id),
> +	IOCTL_OP(IOMMU_VDEVICE_TSM_OP,
> iommufd_vdevice_tsm_op_ioctl,
> +		 struct iommu_vdevice_tsm_op, vdevice_id),

ditto

> +int iommufd_vdevice_tsm_op_ioctl(struct iommufd_ucmd *ucmd)
> +{
> +	int rc;
> +	struct kvm *kvm;
> +	struct iommufd_vdevice *vdev;
> +	struct iommu_vdevice_tsm_op *cmd =3D ucmd->cmd;
> +
> +	if (cmd->flags)
> +		return -EOPNOTSUPP;
> +
> +	vdev =3D container_of(iommufd_get_object(ucmd->ictx, cmd-
> >vdevice_id,
> +					       IOMMUFD_OBJ_VDEVICE),
> +			    struct iommufd_vdevice, obj);
> +	if (IS_ERR(vdev))
> +		return PTR_ERR(vdev);
> +
> +	if (!vdev->viommu->kvm_filp) {
> +		rc =3D -ENODEV;
> +		goto out_put_vdev;
> +	}
> +
> +	kvm =3D vdev->viommu->kvm_filp->private_data;
> +	if (!kvm) {
> +		rc =3D -ENODEV;
> +		goto out_put_vdev;
> +	}

	if (!vdev->viommu->kvm_filp ||
	    !vdev->viommu->kvm_filp->private_data) {
		rc =3D -ENODEV;
		goto out_put_vdev;
	}

	kvm =3D vdev->viommu->kvm_filp->private_data;


From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 75873349B02
	for <iommu@lists.linux.dev>; Mon, 16 Mar 2026 07:25:13 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=192.198.163.19
ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773645914; cv=fail; b=OLs2fbtoKA4YkJc/5HNmoQa/eAoCOGYIVlZYxpz85vTQ/xIvah5oeohQtwWZhK8wh4+bjY3nlUN1dF6UCPK9bwx6Le4dLdrt1ztc/tL1tHiQd4Ff/IBqBChd66hUhvBJ8QCS50RmC42Uya8REAMulH4X4/mCKlxTOgCuyK6jv5k=
ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773645914; c=relaxed/simple;
	bh=a5axQFOCGw/9w1Mqu1k64E+sWeY2sntNS+p0XI0z56s=;
	h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To:
	 Content-Type:MIME-Version; b=Why5bWlJRgbhE+Vz2KnK0AOtRGaNcQhJ60RucCJQ867VW0GPgjcm+TvoPX0RgAoSAEoH2LSEs6PS2gsbGnfN2FX4HwpAkMCory6ke7G+C1GNsdF/MOJ2Q/haLwzlbg+VhQ+dDhCNkZDzORUpv8vnotOwL2TpKhsZKYKe9XMgMpg=
ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=DDPW75rl; arc=fail smtp.client-ip=192.198.163.19
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="DDPW75rl"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
  t=1773645913; x=1805181913;
  h=from:to:cc:subject:date:message-id:references:
   in-reply-to:content-transfer-encoding:mime-version;
  bh=a5axQFOCGw/9w1Mqu1k64E+sWeY2sntNS+p0XI0z56s=;
  b=DDPW75rlHsylmW0uvxN9EOuqwVgwKssoLwL/vivYU2qA5TLmzxASXsyx
   oLpHCQpv0vHdnKAgyc+bsrJP8wl/O/BzaYyn1m6d3lSqVbercYW1gX1+Y
   bk+YlJpjhFoC6JFNlqX4vgAWlJjcQxdl12KR6uYn2L6IDspfTBKqrdfPO
   sHKl+WcB16ymHuEQcTbEmyVcNQTMuDlpVHNJ2hZAnVSkTGrNFxLQ84k+n
   NXyc12c7LqG4YNFOpgkZn5yPNa/29Xwa6/k3Qy1fOtMN6w1LMBkKm1GGS
   EgGQaIMt0EWHQPCpFhuY8H0FAWjFxI4036DBqtknbiJmu39YcqGm5pheN
   w==;
X-CSE-ConnectionGUID: Eb+6ZzRZS+m+taAQE2CUeg==
X-CSE-MsgGUID: T/UAX4b8R92ngrkP5KHWZg==
X-IronPort-AV: E=McAfee;i="6800,10657,11730"; a="73670086"
X-IronPort-AV: E=Sophos;i="6.23,123,1770624000"; 
   d="scan'208";a="73670086"
Received: from fmviesa004.fm.intel.com ([10.60.135.144])
  by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2026 00:25:12 -0700
X-CSE-ConnectionGUID: cJvHp5QDQPKy6yxdVQ3sWg==
X-CSE-MsgGUID: T7F1h2GoQI6KTVq8YvhkLw==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="6.23,123,1770624000"; 
   d="scan'208";a="224070242"
Received: from fmsmsx902.amr.corp.intel.com ([10.18.126.91])
  by fmviesa004.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2026 00:25:11 -0700
Received: from FMSMSX903.amr.corp.intel.com (10.18.126.92) by
 fmsmsx902.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.2562.37; Mon, 16 Mar 2026 00:25:11 -0700
Received: from fmsedg903.ED.cps.intel.com (10.1.192.145) by
 FMSMSX903.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.2562.37 via Frontend Transport; Mon, 16 Mar 2026 00:25:11 -0700
Received: from CH1PR05CU001.outbound.protection.outlook.com (52.101.193.24) by
 edgegateway.intel.com (192.55.55.83) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.2562.37; Mon, 16 Mar 2026 00:25:10 -0700
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
 b=d/KlbrwrQ3wEwI2tmBRA9ODXM6EMqRxxumeYy497IZsjZmbZSh9sm/wa6P5Qj8AUC5VfFCMZlIvySy0D4PaB8Je9etSdcx7LPvIKkOXR2RqKoGEDkgYtlcR4XLGwn+s/5WnySYdi4P/OdRBNj/QgUk79NmsWRjNnqkWo+SIR+11N+F7GPKTv2swULzVl2abUzgvhDAsz1nLshKUUkau/sOxDxuGt58gUpCZWn3yFopTQpy9Wkd6h97f9ywBe5M5qZDYo3XRVpDELhKOj7h+bsrJBbrx1jiOvWTir9mRrLFgDirDSMNuiKJeavQVK+G3/u0s9VFIuwPVAiwbXSjCdIQ==
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=a5axQFOCGw/9w1Mqu1k64E+sWeY2sntNS+p0XI0z56s=;
 b=FpKLZyyRjSCzU1fQVlyqsPhbxfRzqYq5CQ5s3mZTigLRJFx9j422l8uHYPydgnfUSGRWIizLUwmqoL4xb23xfEtSE6lfCROGimi542b7GSNffPOG4tvboexoTBskEFA1/ukSndgNvHoTmY37RuVL9MRbz9DZwKAeAIgJPCgraEa9I3SJ67ssU2VwY6g/foRgQTuTfe9dpoJTct5WQXcaQj2Y/ickiDt1sy+jhs5JJMXkugtl8Y544u7He/uPvtgc0rTz0RFzBmgKyTk82cj5Pw+Qm1BpnavlXW941V0aSNrRdKgGWnywYvRenAmzbkNcAYkPrG/xzpqYg8CmvKo9VQ==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
 smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com;
 dkim=pass header.d=intel.com; arc=none
Received: from BN9PR11MB5276.namprd11.prod.outlook.com (2603:10b6:408:135::18)
 by PH0PR11MB7447.namprd11.prod.outlook.com (2603:10b6:510:28b::9) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9723.13; Mon, 16 Mar
 2026 07:25:07 +0000
Received: from BN9PR11MB5276.namprd11.prod.outlook.com
 ([fe80::f997:762f:f079:134f]) by BN9PR11MB5276.namprd11.prod.outlook.com
 ([fe80::f997:762f:f079:134f%5]) with mapi id 15.20.9723.016; Mon, 16 Mar 2026
 07:25:07 +0000
From: "Tian, Kevin" <kevin.tian@intel.com>
To: "Williams, Dan J" <dan.j.williams@intel.com>, Jason Gunthorpe
	<jgg@ziepe.ca>, "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>
CC: "iommu@lists.linux.dev" <iommu@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>, Joerg Roedel <joro@8bytes.org>,
	Will Deacon <will@kernel.org>, Bjorn Helgaas <helgaas@kernel.org>, "Jonathan
 Cameron" <Jonathan.Cameron@huawei.com>, Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>, Xu Yilun <yilun.xu@linux.intel.com>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>, Steven Price
	<steven.price@arm.com>
Subject: RE: [PATCH v2 3/3] iommufd/vdevice: add TSM guest request ioctl
Thread-Topic: [PATCH v2 3/3] iommufd/vdevice: add TSM guest request ioctl
Thread-Index: AQHcr7Zg2nUMA9oep0Ot8T7R69iYtLWs1POAgAA6EACAA7n1UA==
Date: Mon, 16 Mar 2026 07:25:07 +0000
Message-ID: <BN9PR11MB52760B1BFB652AE73C7DB2CB8C40A@BN9PR11MB5276.namprd11.prod.outlook.com>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-4-aneesh.kumar@kernel.org>
 <20260313184957.GP1704121@ziepe.ca>
 <69b48d0a374a_b2b6100eb@dwillia2-mobl4.notmuch>
In-Reply-To: <69b48d0a374a_b2b6100eb@dwillia2-mobl4.notmuch>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
authentication-results: dkim=none (message not signed)
 header.d=none;dmarc=none action=none header.from=intel.com;
x-ms-publictraffictype: Email
x-ms-traffictypediagnostic: BN9PR11MB5276:EE_|PH0PR11MB7447:EE_
x-ms-office365-filtering-correlation-id: bf08416b-edad-49f8-e8eb-08de832d269c
x-ms-exchange-senderadcheck: 1
x-ms-exchange-antispam-relay: 0
x-microsoft-antispam: BCL:0;ARA:13230040|366016|1800799024|7416014|376014|38070700021|22082099003|18002099003|56012099003;
x-microsoft-antispam-message-info:  
x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN9PR11MB5276.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(7416014)(376014)(38070700021)(22082099003)(18002099003)(56012099003);DIR:OUT;SFP:1101;
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: =?utf-8?B?VE5SQm85cFl2RzYyRlV3SnViVHJneHBTcncyMGlUNE1tWm00STkzR1pFZjFR?=
 =?utf-8?B?aW9xbklzckRxQUlZcjA0QTlUaHEySzNJaWpPeHBKVjI2ZDF6Q1JWZlA5NXk0?=
 =?utf-8?B?T0lJMkFhNng1eGFrNG1vZEZ4d2NVOTZXQ0l3aVBFK0NnYUQ2QklSWnZCZUpQ?=
 =?utf-8?B?QXZHc0tXY3BmTzdjRVJEZ0g5TDIxL2JuYnBaS05JVitJM0pyMVRWbzJPcEpY?=
 =?utf-8?B?eDMzeTd4NXZ5Y2tWaXhHUld2R0tUTUJpRTdXNU0vdzRmejZuYlBUSlR3N1RP?=
 =?utf-8?B?bGZScGdIVm1vcHk3dTNlZkxvclF5aUhGTHZNZVRucnRsWUd1QjBFZHFFdU54?=
 =?utf-8?B?SUE5dHNZSjFCNWxJMGNyT2VKaTE4ZTFZVk1tQWd6VDVZMnpnT2pEMW9JdXEv?=
 =?utf-8?B?akZDWHhuMkV0ODNuV25HQmRYeUhqNnJidE9kbitxM3ZkOUxvVk5QTlhmd3Jy?=
 =?utf-8?B?L2hWbGFFOE1EdjlnQWxjOGZqOXJNVUpyVWFwMy9lRUltWklUR0dxZDBzY0d2?=
 =?utf-8?B?YkdleVNWa2N1RXZOdStxR2pDTk9iNFNONkxyZlVXMk0zZUo2RUh6SkVyaExl?=
 =?utf-8?B?RXNIZHZrZytSZnA0aHM2TElMdERIQ3pDKy8yb1Z4elBhVXRSZDRoa2NwZEVn?=
 =?utf-8?B?NSs0NityZXhKdFE5SDMzOWlweUlSc0NwZXVickNoSWJ2cW50TjFvN3pNaytL?=
 =?utf-8?B?VmR3bC9oVDVYbTJ6dmNJZ21lUFU1T1pLN3RkOFExODhXNXByWmtrNEVJRUtw?=
 =?utf-8?B?cncrREVBbUN1SVYrUDdpd1pBOUdjQzNSV1VCM1VZN1lPbk9WbVFBYUovaXZZ?=
 =?utf-8?B?RW1zdXUrS3d3R2Z2QzIyeVV4eXhua3picG9IcWt6c0YwLzZVU01qbzF0NU9D?=
 =?utf-8?B?V241WmVIYWVMVldTNVZvOUpmQmVsMDFVRDc2OCs5SlAwVjY0QlN4SnkxVlV3?=
 =?utf-8?B?Mlo3ZmY3SDhOaEJPK2pucTQ0MUlrYmIwUUFTTFd5anlVaEZ6c20rTXJ2TE13?=
 =?utf-8?B?Nysrb0FsMmRUNzUrMlVHR3hveG04dTFIQ2JCTVo5aEtyTFFrN3JuMS9tY0tY?=
 =?utf-8?B?ZFg4KzJRNUpuOG50SmQrVFAxZU1DSWdtbEFGK2Y3L0tQWUZxWDVDZVdYQVJz?=
 =?utf-8?B?MjROWDltdmc4TGh6NW8wNzFpNVc1UDRIUGcwbWR2VGxIUHowbUFzeGhLeXN3?=
 =?utf-8?B?Z1NjVjRjQURkQU03UTdYQnljTEZOQjN5OTFmSzQ2cVRublU0ZzZlTEc1WVp5?=
 =?utf-8?B?d0RQaDN2WUU5WGc4UFpJZXpKZXBKbXVKYVNPc3ozaTRKSEdWQTl2dUV2bkFn?=
 =?utf-8?B?OGRWMFZadVp6Vko1cUdPWjZCNEZyS3ZpSzNNaitIRzVpVldmejQvZ01kb0dC?=
 =?utf-8?B?UVp6Q2NYSDhJUkhPSUQwZTUyLytDcHV3RDhSamFKbmFnaDFwTHpBYzVnNlNU?=
 =?utf-8?B?OHJkVnZuVHlJOUpMTXhHWEFmZG5mR3MxRWZEc21McHZVbXR1RDN0MHlzMGZw?=
 =?utf-8?B?bnNzdW9WbnZaWG5DTGM4MWJZeFdRNHBZUWtTMFl1UWJ2cVU5YmVYVWVseHg1?=
 =?utf-8?B?QkYrR0Q5ZU5FbFdRSlZoQy9UcDlEYVg0cGVGK21PRTc1ZE9od1FPYWxySlBC?=
 =?utf-8?B?bVgrNHVyZlEvY3d4SGJkMjc5bFFCOGQ4M1ErNTBrbDZNN25reWJnbU94YnBv?=
 =?utf-8?B?amhmWVFidkphTk1IQ0VlRXpBaVYxS1VtQUsxSEtPVGZDejh1dFlPMXY5bFZo?=
 =?utf-8?B?TXZGQnFXNlhBY3FjZkI1bHJLYVNRR3F3aEo1NmRWWlNXaVJhcXd1bG5NSElY?=
 =?utf-8?B?K2hXMHhZVkNoMkpyeUEvdzRvdXZmaVdwVzVVeCtpQmNzL2s1bFc0a3Z1QTNv?=
 =?utf-8?B?R2hVL3lUR3ljTVl3UnBmQ1JOM0dFMVJrK200QSttNVNnWEhUVmZpWTJUM29G?=
 =?utf-8?B?SWFlRHhuQS9RY0dBbWIraVVURnNGL1NTTWF1Nk05b1Q1VDlPMlR3eS80UTFy?=
 =?utf-8?B?R1pBTm9ZSFFzM3J1UENuS1lBVnlhMENlWXR0TUJnTHZFL1pWWFp6MDNjcHFy?=
 =?utf-8?B?VUtHdWFsQ3R3TzAxb0djK2NkQmNCNWxyNGdZUzB6akt3NG5PREJGdHV3elg1?=
 =?utf-8?B?UUdNZGUxWGhKUmo0SnAzR0hBNnUxNUhFYlp1YzYyQjlINjhjeG1KaVNveTdu?=
 =?utf-8?B?YU1hQjBBdXVsUElHYzVMWGoyUzAzRVM1V2NNYjUvdVFHZ01DbitOZWRQZHI0?=
 =?utf-8?B?eC9PSEk4U3JFODErSXBBMjB6cjJQSzF4SWlpYk1sVTZHa1c5OVVJZGk5TjFJ?=
 =?utf-8?B?UW4yd1NPN3RKNGlMcVFTVXZ5ODdKbW5JVUw4c3B1Q1RXKzJvajh5QT09?=
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
X-Exchange-RoutingPolicyChecked: JVvRMyZLzIcDKRWpV/iuOOHPyR3unhMvMQLtAteVebxMgjpYSfji3mqrErwAvGQGNzTKSfDzJfwLQXOF3qdVPgtAlqyLB05mq0N8WW0MRkVqaoaFMmbuLDlKhHWplCBUZ4/ZAGIHQ16HNfiE0qvFRA6n1Y4fWVKcfzVmdfoqORyLzcRB52GbGsr6iJOjPBrb4FnD5ZGIO/kV1/Yna1fbZ319Gin83aMCFcw2WAiMZ1/HvjzfK6qXp4wmVcvm1lAnAXeLmh9AGLZOGHJY0GOg77AgtY301yLt/1OSndzgl6Ab73laKWWj0nYMAVyaVOvtM72c/v2c7y6KfAnzCs/f4w==
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: BN9PR11MB5276.namprd11.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: bf08416b-edad-49f8-e8eb-08de832d269c
X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Mar 2026 07:25:07.7308
 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: afuv4yUQjM9w/dzEjKPw2oRLq9dB2j5HF1sp+b+uIYYYu5oLURl+VYGXVOdY8TQgzk7APthJYG1DjNPaSbrhAw==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB7447
X-OriginatorOrg: intel.com

PiBGcm9tOiBXaWxsaWFtcywgRGFuIEogPGRhbi5qLndpbGxpYW1zQGludGVsLmNvbT4NCj4gU2Vu
dDogU2F0dXJkYXksIE1hcmNoIDE0LCAyMDI2IDY6MTggQU0NCj4gDQo+IEphc29uIEd1bnRob3Jw
ZSB3cm90ZToNCj4gPiBPbiBNb24sIE1hciAwOSwgMjAyNiBhdCAwNDo0NzowNFBNICswNTMwLCBB
bmVlc2ggS3VtYXIgSy5WIChBcm0pDQo+IHdyb3RlOg0KPiA+ID4gKy8qKg0KPiA+ID4gKyAqIHN0
cnVjdCBpb21tdV92ZGV2aWNlX3RzbV9ndWVzdF9yZXF1ZXN0IC0NCj4gaW9jdGwoSU9NTVVfVkRF
VklDRV9UU01fR1VFU1RfUkVRVUVTVCkNCj4gPiA+ICsgKiBAc2l6ZTogc2l6ZW9mKHN0cnVjdCBp
b21tdV92ZGV2aWNlX3RzbV9ndWVzdF9yZXF1ZXN0KQ0KPiA+ID4gKyAqIEB2ZGV2aWNlX2lkOiB2
RGV2aWNlIElEIHRoZSBndWVzdCByZXF1ZXN0IGlzIGZvcg0KPiA+ID4gKyAqIEBzY29wZTogc2Nv
cGUgb2YgdHNtIGd1ZXN0IHJlcXVlc3QNCj4gPiA+ICsgKiBAcmVxX2xlbjogdGhlIGJsb2Igc2l6
ZSBmb3IgQHJlcV91cHRyLCBmaWxsZWQgYnkgZ3Vlc3QNCj4gPiA+ICsgKiBAcmVzcF9sZW46IHRo
ZSBibG9iIHNpemUgZm9yIEByZXNwX3VwdHIsIGZpbGxlZCBieSBndWVzdA0KPiA+ID4gKyAqIEBy
ZXFfdXB0cjogcmVxdWVzdCBkYXRhIGJ1ZmZlciBmaWxsZWQgYnkgZ3Vlc3QNCj4gPiA+ICsgKiBA
cmVzcF91cHRyOiByZXNwb25zZSBkYXRhIGJ1ZmZlcg0KPiA+ID4gKyAqLw0KPiA+DQo+ID4gVGhp
cyBuZWVkcyBhIG11Y2ggYmV0dGVyIGtkb2MuDQo+ID4NCj4gPiBSZWZlciB0byBzcGVjcyB0aGF0
IGRlZmluZSB0aGlzLg0KPiA+DQo+ID4gRXhwbGFpbiBXVEYgc2NvcGUgaXMNCj4gDQo+IEkgcHJv
cG9zZWQgQHNjb3BlLCB5ZXMgdGhpcyBuZWVkcyBtb3JlIGRvY3VtZW50YXRpb24sIGJ1dCByZWFs
bHkgaXQNCj4gbmVlZHMgbW9yZSBkaXNjdXNzaW9uIGZpcnN0LiBJdCB3YXMgaW5zcGlyZWQgYnkg
J2VudW0gZndjdGxfcnBjX3Njb3BlJw0KPiANCj4gR3Vlc3RzIHRoYXQgYXJlIG1vdmluZyB0aGUg
ZGV2aWNlIHRocm91Z2ggdGhlIFRESVNQIHNldHVwIHN0YXRlIG1hY2hpbmUNCj4gbmVlZCB0byBh
c2sgZm9yIGhvc3Qgc2VydmljZXMgYmVjYXVzZSBvbmx5IHRoZSBob3N0IHBhc3NlcyBtZXNzYWdl
cyBvdmVyDQo+IFNQRE0gaW4gYWxsIG9mIHRoZXNlIGFyY2hpdGVjdHVyZXMuIFRoYXQgaXMsIG9u
ZSBTUERNIHNlc3Npb24gcGVyDQo+IHBoeXNpY2FsIGRldmljZSwgbm90IHBlciBhc3NpZ25lZCB2
aXJ0dWFsIGZ1bmN0aW9uLiBJbiB0aGUgQU1EIGNhc2UNCj4gdGhlcmUgaXMgbGVzcyBndWVzdCBk
aXJlY3QgYWNjZXNzIHRvIHRoZSBUU00gc28gaXQgbmVlZHMgdG8gcGFzcw0KPiBhZGRpdGlvbmFs
IG1lc3NhZ2VzIHRoYXQgdGhlIENQVSBtb2RlIGJhc2VkIFRTTXMgZG8gbm90Lg0KPiANCj4gVGhv
c2UgcmVxdWVzdHMgYXJlIHZhcnlpbmcgZGVncmVlcyBvZjogaG9zdCBrZXJuZWwgY2FyZXMsIGhv
c3Qga2VybmVsDQo+IGRvZXMgbm90IGNhcmUgYnV0IGNhbiBzZWUgdGhlIGNvbnRlbnRzIG9mIHRo
ZSBtZXNzYWdlLCBhbmQgaG9zdCBrZXJuZWwNCj4gZG9lcyBub3QgY2FyZSBhbmQgY2FuIG5vdCBz
ZWUgdGhlIGNvbnRlbnRzIG9mIHRoZSBtZXNzYWdlIGJleW9uZA0KPiBlbnZlbG9wZS4NCg0KImhv
c3Qga2VybmVsIGNhcmVzIiBtZWFucyB0aGF0IHRoZSBob3N0IGtlcm5lbCBtYXkgY2hlY2sgQ0FQ
X1NZU19SQVdfSU8NCm9yIHRhaW50IGl0c2VsZiB0byBsaW1pdCBjb21tYW5kcyBhY2NvcmRpbmcg
dG8gdGhlIGRlc2NyaXB0aW9uIG9mDQplbnVtIHBjaV90c21fcmVxX3Njb3BlPw0KDQppbnRlcmVz
dGluZ2x5IGNvbW1pdCBjMzE2Yzc1ZDU3ZmIgKCJQQ0kvVFNNOiBBZGQgcGNpX3RzbV9ndWVzdF9y
ZXEoKQ0KZm9yIG1hbmFnaW5nIFRESXMgIikgaGFzIHRoZSBmb2xsb3dpbmcgZGVzY3JpcHRpb246
DQoNCiINCiAgICBUaGlzIHBhdGggaXMgcHVyZWx5IGEgdHJhbnNwb3J0IGZvciBtZXNzYWdlcyBm
cm9tIFRWTSB0byBwbGF0Zm9ybSBUU00uIEJ5DQogICAgZGVzaWduIHRoZSBob3N0IGtlcm5lbCBk
b2VzIG5vdCBhbmQgbXVzdCBub3QgY2FyZSBhYm91dCB0aGUgY29udGVudCBvZg0KICAgIHRoZXNl
IG1lc3NhZ2VzLiBJLmUuIHRoZSBob3N0IGtlcm5lbCBpcyBub3QgaW4gdGhlIFRDQiBvZiB0aGUg
VFZNLg0KIg0KDQpob3cgdG8gYXNzb2NpYXRlICJtdXN0IG5vdCBjYXJlIiB3aXRoIGFib3ZlICJo
b3N0IGtlcm5lbCBjYXJlcyI/DQoNCj4gDQo+IEFzIGZhciBhcyB0aGUgaG9zdCBrZXJuZWwgc2Vj
dXJpdHkgbW9kZWwgaXMgY29uY2VybmVkIHRoaXMgYmVjb21lcyBhDQo+IG9wYXF1ZSBpbXBsZW1l
bnRhdGlvbiBzcGVjaWZpYyBwYXNzdGhyb3VnaC4gU28gdGhlIHJvbGUgb2YgQHNjb3BlIGlzIHRv
DQo+IGhhdmUgdGhlIFRTTSBkcml2ZXJzIGRlY2xhcmUgdGhlIHNlY3VyaXR5IG1vZGVsIGZvciB2
YXJpb3VzIG1lc3NhZ2VzLg0KPiBQdXQgdGhlIGV4cGxpY2l0IG9udXMgb24gdGhlIGltcGxtZW50
YXRpb25zIHRvIGRlY2xhcmUgdGhhdCB0aGUNCj4gZ3Vlc3RfcmVxdWVzdCBvcGVyYXRpb24gYmVp
bmcgZXhlY3V0ZWQgaW4gcmVzcG9uc2UgdG8gYSBLVk0gZXhpdCBpcw0KPiBjb250YWluZWQgd2l0
aGluIGEgZ2l2ZW4gc2VjdXJpdHkgc2NvcGUuIFNlZSAnZW51bSBwY2lfdHNtX3JlcV9zY29wZScu
DQoNCmR1bWIgcXVlc3Rpb24gLSB3aGF0IGFib3V0IGEgbWFsaWNpb3VzIHVzZXJzcGFjZSBzcGVj
aWZpZXMgYSBzY29wZSANCndpdGggYSBzbWFsbGVyIHZhbHVlIHRoYW4gd2hhdCdzIGRlZmluZWQg
Zm9yIGEgcmVxdWVzdD8gV291bGQgKGNvdWxkKSB0aGUNCnRzbSBkcml2ZXIgdmVyaWZ5IHRoYXQg
aXTigJlzIGEgd3JvbmcgdmFsdWUgKGJ1dCBpZiBpdCBjYW4gdGhlbiB3aHkgd2UgbmVlZA0KdGhp
cyBmaWVsZCBhdCBhbGwpPw0K

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id A259134DB7B
	for <iommu@lists.linux.dev>; Mon, 16 Mar 2026 07:28:16 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=198.175.65.17
ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773646097; cv=fail; b=Uu43dM2s3y0nhtkxvePBcRIi3igpIFjYzRPKFKqia1H/zAP30Adsr+J6xAD7tU2cbf4OgSVgpA+aPVd4Yw5Ez9ZqjM/K9TzzQZ4fuxAksWhPa0MgLH5lu9044PgpZOi5SscXQpuetzKTczabylGAUYh/eZ0eWQrOJsxkLtFBm7U=
ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773646097; c=relaxed/simple;
	bh=WvALz34KVP0H0RzfC2niyMWUfsNJeyFSnW73E0ZLc98=;
	h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To:
	 Content-Type:MIME-Version; b=ECAEMyjgWlxNhCJKgnhPtaUzhBI5rpQn/whpKC6oenzRYSBlPf6lpwo9SHqPOkfFhyzDTLZXL/BObIdAqTnAV2j8af7UIGqpex+pXRVkKV63IDkecuL9SdpET2ryQF2MQomVtR2v7bW86tLZ/A6Hgm2PFjxaQ9apedxhvSGUPUc=
ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=kJ4tBu39; arc=fail smtp.client-ip=198.175.65.17
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="kJ4tBu39"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
  t=1773646096; x=1805182096;
  h=from:to:cc:subject:date:message-id:references:
   in-reply-to:content-transfer-encoding:mime-version;
  bh=WvALz34KVP0H0RzfC2niyMWUfsNJeyFSnW73E0ZLc98=;
  b=kJ4tBu39aTgp1gsEK7oTUYfTuxBIBcnx18o+WCZE3jIk/vBFzV2VVkwW
   R5Zv8en+fuxoMOSMl8jlHE2z5IhBdwqJVBNw5VFzdf5a7jK8z9eCm6QOD
   cv8sn1xBvLeH9I12/DLpJEwSdgdUE5ZvA/gyl5d2j5iJ+Rx0DydqX242a
   iPVzU5T3PhRB4KiEwm/YiugcTuIqrhlUde668kfIyRULwEiShEhyw+ay0
   mEMX2R7epBe0U8i7fd2CN5T5lQgVn+B3pgn/iCFLZh3nl2t5yHUjtGmXg
   svV0y9xFtmLbPJa+nURg4S9CTRMuzA8z9osKla7jUShKazh6WaRC0sOZc
   Q==;
X-CSE-ConnectionGUID: ijynejeHQnWSh8AjKX+w0Q==
X-CSE-MsgGUID: IiMGRUfVTCCKXWn8nCfCiQ==
X-IronPort-AV: E=McAfee;i="6800,10657,11730"; a="74629382"
X-IronPort-AV: E=Sophos;i="6.23,123,1770624000"; 
   d="scan'208";a="74629382"
Received: from fmviesa006.fm.intel.com ([10.60.135.146])
  by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2026 00:28:16 -0700
X-CSE-ConnectionGUID: EmArTp5oRvim49SosGhpUw==
X-CSE-MsgGUID: KbIhe1SbR1SBQiavo9t5cw==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="6.23,123,1770624000"; 
   d="scan'208";a="217686126"
Received: from orsmsx902.amr.corp.intel.com ([10.22.229.24])
  by fmviesa006.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2026 00:28:15 -0700
Received: from ORSMSX903.amr.corp.intel.com (10.22.229.25) by
 ORSMSX902.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.2562.37; Mon, 16 Mar 2026 00:28:14 -0700
Received: from ORSEDG903.ED.cps.intel.com (10.7.248.13) by
 ORSMSX903.amr.corp.intel.com (10.22.229.25) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.2562.37 via Frontend Transport; Mon, 16 Mar 2026 00:28:14 -0700
Received: from CY3PR05CU001.outbound.protection.outlook.com (40.93.201.30) by
 edgegateway.intel.com (134.134.137.113) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.2562.37; Mon, 16 Mar 2026 00:28:14 -0700
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
 b=dvT1/HzkV1tvYZj0aHvASteScnMLXVzxU0skW+3SM9aGZ5/tOaNVYSk25Wjull7S1WnrNsBm/JHFr20r8INgIFE2FF07zMEzPx5faASofcRAQ9jU7TLVCxmqyVJKI5Gixwr0VGEtwg92sjxa1Ci+zOOXIL782mIjAwF59lbQWjq7DoJha4bW6ritsOXDpTT1RDV4FcngrbstpLq6cRrVcM2NbKiTZIVSBD9SzJ19PNXL579e/AshiZHJxFwgZn5FI0LIFjFa6x+cXFbDmkN0XdiVgRpwrYS9r+/sDPwiOhxcVE47alTVynir5c4kDx+UQtPo9hX4wFKPn8uvZdoMrA==
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=uGYScoRB3in5nCLEnRPSNgnmsI+y50o6xTRwFnLjueA=;
 b=Ksn4/vb3MX+sj2OLB9oEKDQ22yL5VnNYueD70QwymVLcBZ6Qe5zP/HoK1xa+kiYkVxinw92l3MvCv9u9DbuW+pStY02yFKSIm0T0y92jhe0XRVoZx/t3IgZgO78GipkP3PLARRomyAGo8XZWdlvWXM52/2RydlJSBs5WbRSJhNacF6DY6qqucltfcdEWMpBerts6aUGRyUy9wfJC/Kwq9qEyuUn4ybcQFFboLBB4HqIjxR2mBvAD70g2jfnnx9k12XLRSZjTzZd3e1UnZamH7kShmRl1axIuR5aA1yklflx9z3r0q0192iVuDDYkdR+PYOYslrnZyHwKXRFcmsbW6Q==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
 smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com;
 dkim=pass header.d=intel.com; arc=none
Received: from BN9PR11MB5276.namprd11.prod.outlook.com (2603:10b6:408:135::18)
 by PH0PR11MB7447.namprd11.prod.outlook.com (2603:10b6:510:28b::9) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9723.13; Mon, 16 Mar
 2026 07:28:12 +0000
Received: from BN9PR11MB5276.namprd11.prod.outlook.com
 ([fe80::f997:762f:f079:134f]) by BN9PR11MB5276.namprd11.prod.outlook.com
 ([fe80::f997:762f:f079:134f%5]) with mapi id 15.20.9723.016; Mon, 16 Mar 2026
 07:28:11 +0000
From: "Tian, Kevin" <kevin.tian@intel.com>
To: Aneesh Kumar K.V <aneesh.kumar@kernel.org>, Jason Gunthorpe <jgg@ziepe.ca>
CC: "iommu@lists.linux.dev" <iommu@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>, Joerg Roedel <joro@8bytes.org>,
	Will Deacon <will@kernel.org>, Bjorn Helgaas <helgaas@kernel.org>, "Jonathan
 Cameron" <Jonathan.Cameron@huawei.com>, "Williams, Dan J"
	<dan.j.williams@intel.com>, Alexey Kardashevskiy <aik@amd.com>, Samuel Ortiz
	<sameo@rivosinc.com>, Xu Yilun <yilun.xu@linux.intel.com>, Suzuki K Poulose
	<Suzuki.Poulose@arm.com>, Steven Price <steven.price@arm.com>
Subject: RE: [PATCH v2 3/3] iommufd/vdevice: add TSM guest request ioctl
Thread-Topic: [PATCH v2 3/3] iommufd/vdevice: add TSM guest request ioctl
Thread-Index: AQHcr7Zg2nUMA9oep0Ot8T7R69iYtLWs1POAgAPcaYCAABtVUA==
Date: Mon, 16 Mar 2026 07:28:11 +0000
Message-ID: <BN9PR11MB5276CDFAE7606A066DB25FAD8C40A@BN9PR11MB5276.namprd11.prod.outlook.com>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-4-aneesh.kumar@kernel.org>
 <20260313184957.GP1704121@ziepe.ca> <yq5a4img8gw6.fsf@kernel.org>
In-Reply-To: <yq5a4img8gw6.fsf@kernel.org>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
authentication-results: dkim=none (message not signed)
 header.d=none;dmarc=none action=none header.from=intel.com;
x-ms-publictraffictype: Email
x-ms-traffictypediagnostic: BN9PR11MB5276:EE_|PH0PR11MB7447:EE_
x-ms-office365-filtering-correlation-id: 348c9740-40fe-4401-fd71-08de832d9458
x-ms-exchange-senderadcheck: 1
x-ms-exchange-antispam-relay: 0
x-microsoft-antispam: BCL:0;ARA:13230040|366016|1800799024|7416014|376014|38070700021|22082099003|18002099003|56012099003;
x-microsoft-antispam-message-info:  
x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN9PR11MB5276.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(7416014)(376014)(38070700021)(22082099003)(18002099003)(56012099003);DIR:OUT;SFP:1101;
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?Fqt9Vvzty8IqcFLcik5CJZJ+ZTBipJA9+OeIXiwXGh4PCcaXoCwX/otHwxbb?=
 =?us-ascii?Q?yxeOV5AAmszHyv0mV4P8wEvT5etuDqmUtYYin46nxHEel1g8/5swr+7knpeq?=
 =?us-ascii?Q?fBGcn9Qos/Q+yqTDS5upM65ow738pNi8sus/5DYwTzSKsFvhwRKnJunmyCLO?=
 =?us-ascii?Q?HghFLULkXMz5bXh+wMk/uq7ME0cJqGlvbAeFSe4pZWEIuxCz2tNJBPTewYW5?=
 =?us-ascii?Q?U6PjTB+vzsH9bKGaS8yeAuESUQ2W3SBn/AvQm9JClLRNr43Eplae0WmooKNq?=
 =?us-ascii?Q?LmRIYF+E889mPAKYBxJajVtbzDSkp/sbX+xpVq+w1XhSWIkTCtgstT+lD6PG?=
 =?us-ascii?Q?4cBYAVLS+0Kxv6A9vBJevM1pnkshSgF0iyikghUZ/TadDbZQ+hxJZih8WrqV?=
 =?us-ascii?Q?F/irgHXZZDdlmqSx6wki6K3FcpzWYmz0UlSa1fStYBloMI9QaaCuEytVMgay?=
 =?us-ascii?Q?IAQID6tN8Bjrj6MlkL+sarVtN5HeLq8TA2GeruHRdwNVbq/5Xrz638ufxiAg?=
 =?us-ascii?Q?ijhaLyO+/obW8fcGN9pWmUd7IX6EVCNW4QGE0V7bnHurCtBzPrNYmkqTUacn?=
 =?us-ascii?Q?8yRV8dT0HxCfO5quiJLfSIHEkwAPCylpmuMG/cPz/l420Pm9tG+n10JLGn2R?=
 =?us-ascii?Q?H4Ixp9fKRy/07iAUjOTN661gYLc7m8FCDIkb23ieKiRGTswrmYVDsdk5nnPm?=
 =?us-ascii?Q?wX1BPQd7b179Z3JeDBKJL76jueI3jt/vgR2pXnv1MVT1dNyWFr6s8rRkKOPH?=
 =?us-ascii?Q?qjWtDy7dKqI0VhwOmGumNuDn2ya9sPby2Ch0wyWUD+kjzwGvlh95AW09rSpU?=
 =?us-ascii?Q?MiGydpNjmMaagkk6QE2kQB8MJMaTtShGxCxgeDbUmG+7IVF+Ig9CtRhWJh/a?=
 =?us-ascii?Q?D6soFkhPNhsxhVcBT15ARvYqaSsHMmqsggSNf8S8yyB4fVI2AkP9RWmA4a9G?=
 =?us-ascii?Q?0hoS6d/dzWZyBCEs3RscYw2fX92AGRDGtu6l3k39v9acJr6cPClROwfSkI99?=
 =?us-ascii?Q?6wKItWkaGMEiXd8xAE3uM4rqng71UhklxMLNDDg/Fg3kUTNIYb3kbo2CG7lG?=
 =?us-ascii?Q?SFdrikrOzC4Ft+b1vXJa6I9NOH2qUHSbMDotf41wAgvugdIzc0ibHpynMXDs?=
 =?us-ascii?Q?1oHRYHh4lzHwDQZTm7ukY62Vde6NL0WrbCDCIty10IGM2pJoxKtpsj1pxPy4?=
 =?us-ascii?Q?WBq0p+RqQbSKjX+eYG/NqHkmvVj1SRwPccZFLLvEUokk94wssj8ESZOisfWV?=
 =?us-ascii?Q?y/z1C6NQFE4x1Ia5uFZ+uDYe3BBuPz0t6e03xtsQ+QAOYxc7HVNGv3P8bn+a?=
 =?us-ascii?Q?GNBJTz95EI87moCzKyAVDWdaO5mXcIg8BFV7XiIXlTwyqgJnXfny3PAxkpdz?=
 =?us-ascii?Q?HFq/p4rXtJ1gpJjjOX+krmKYQp1Aqzx+xOjpQee0nBcDJZxIycBbCRgCRNhw?=
 =?us-ascii?Q?xjKnXqUQPeUc8eqGqioqNdKgoKrWuR2TVYsRD3MEg1Iv37nbWQC33ZbRRJ8h?=
 =?us-ascii?Q?jDdWqifNYFiDG650U7ytv2+5AueFNTzkGhop4Dd7P17RN0gSAuPmsK71nFOO?=
 =?us-ascii?Q?wNrr0IB/XzV7iQ1TDPQFQGCt2/Xnp0xdYackDHy92RxBMB6vz8PueNBb8f9h?=
 =?us-ascii?Q?CabbmBqewpWKHXw0x3IHjOCFUsWuJAuecYSr/dD9h+jscMq+jn7OPSr/0vyE?=
 =?us-ascii?Q?GezfdipWNDu2xno2oLjrdlncq/UkAXKKtMMMUkFqxTdJ+3Cn5rPAhTJEejXP?=
 =?us-ascii?Q?LqgzfPly8Q=3D=3D?=
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
X-Exchange-RoutingPolicyChecked: efTkpOKA5Z5tiMriS1g8jdOTeMFu7tqjIfLmSoD4QNNcZyFSUNMRX/mm9oYIdW/oGoqO2F2hHknR4YsFpkpRKWrn8YHn7APkGaFfqz/DQz1BnMPdE92Tigvy13o0nGLjsxMNbbG9cW7vSk9D2rZ5DhKvWGuYfUTDQ/WKJAAq8iwEfTKCJmIOkJp29bclkK18Uz9JXPz68gUnixAaYC/k9e7CmPfEoeXoidJKRhSuPXKLex3yO9t/KqRzQTE0JRHxCXITC/AUta5xnnminb21b7kVGgXQStHyxWMRUvLzTsygiQfA+nxJ9n4rJQqMC8Qc0WoY6FER1ssf2OLkqb0EvQ==
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: BN9PR11MB5276.namprd11.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: 348c9740-40fe-4401-fd71-08de832d9458
X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Mar 2026 07:28:11.8682
 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: jVWxImCIxJfoLPDznHwNNJzFlYeWLH9o63bUDRGA465NQIlfMv6NJJzyzCrkZ3ghr0MxXapAXjM1nX4MFDbYtQ==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB7447
X-OriginatorOrg: intel.com

> From: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
> Sent: Monday, March 16, 2026 1:48 PM
> + * @scope: Scope classification of the guest request, one of enum
> + *         pci_tsm_req_scope values accepted by pci_tsm_guest_req()

from what this patch does the tsm core supports device types other
than PCI (though currently only PCI is supported).

suppose there may be other bus-specific scope values accepted?

if yes here better say that for the meaning of scope values please
refer to bus specific tsm definitions. Then in the following detailed
description take PCI as an example referring to pci_tsm_req_scope.=20

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EC4731E847
	for <iommu@lists.linux.dev>; Mon, 16 Mar 2026 07:31:53 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=198.175.65.19
ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773646314; cv=fail; b=nDnuquAHKhMT6voLSoKXvfrwAM2D+rJPB6jd9jEONDFx8ywmI/RvdugIRbkHSlQ/z2NOJcv9zn9+h05Uyme8NoWJR7b5bAZ+OzyzfYjLHW5rDs++RbWCxsFHXfaSj42PgKndwHeSc8SXkWjapSbh1ew05Vnygxlpg5YzPBVFv+4=
ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773646314; c=relaxed/simple;
	bh=8N4NyrxcWfpiHHimNTTCpMhJgKSf3CInqN6lUZP7KRU=;
	h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To:
	 Content-Type:MIME-Version; b=epvVDxiYhwLTlDOQ2cYJZNBQmS1CunBDsh/1K3IDyU7SONl4X5QbmDyjUL//+qu6t8CI0RicMby/3qtEB4ohs8kXkhcwykX4GYCK8ZrMAPa+Z7j40vAZ2bYyKka3nwwvt+WAw7zXX8zP+uPtOktCDP3ySJRDRC68GT5r308UE6U=
ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=AblaiGuv; arc=fail smtp.client-ip=198.175.65.19
Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com
Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="AblaiGuv"
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
  t=1773646314; x=1805182314;
  h=from:to:cc:subject:date:message-id:references:
   in-reply-to:content-transfer-encoding:mime-version;
  bh=8N4NyrxcWfpiHHimNTTCpMhJgKSf3CInqN6lUZP7KRU=;
  b=AblaiGuv2BNgC4cFq6F3alRold+1B+5VYIxiBg1A/ib4ns9vrV1+j1Nn
   TiMq8noMXuJhpqRv6rVUBgfrZFwy5MRqW5a00axV3lw2fxxHihchcA8gq
   zNiQR/QS3eKOUDUfWJHThISm1IEOpi407LcZsukSMtgn8i7AJisy1NYBn
   0GmeEB4MNYnu6r9AP5W0pPcy+rB7/w0Z7BSweYFRM9DoeLStkgL2ifB4l
   044Jg6Sezs/zghqcsRKDn+NlaDXyPOgHbYNUAgjjWwzRW61V19gTlfozf
   MikGoDKeQSKUNmYkXkk6hNgNZSBUnuLAEkvgWZhjKzxcT5MxIZUAJYT1J
   g==;
X-CSE-ConnectionGUID: gVLuPnmsTrC9eTL3zwIsXw==
X-CSE-MsgGUID: 8mDl/XZuQlOd6uZZkvBH3g==
X-IronPort-AV: E=McAfee;i="6800,10657,11730"; a="74548465"
X-IronPort-AV: E=Sophos;i="6.23,123,1770624000"; 
   d="scan'208";a="74548465"
Received: from fmviesa008.fm.intel.com ([10.60.135.148])
  by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2026 00:31:53 -0700
X-CSE-ConnectionGUID: izE50iUrS5CcisTT+vB+0w==
X-CSE-MsgGUID: KvhH4NRoTwmWYnsKQvSpmA==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="6.23,123,1770624000"; 
   d="scan'208";a="219428764"
Received: from fmsmsx902.amr.corp.intel.com ([10.18.126.91])
  by fmviesa008.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2026 00:31:51 -0700
Received: from FMSMSX902.amr.corp.intel.com (10.18.126.91) by
 fmsmsx902.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.2562.37; Mon, 16 Mar 2026 00:31:50 -0700
Received: from fmsedg902.ED.cps.intel.com (10.1.192.144) by
 FMSMSX902.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.2562.37 via Frontend Transport; Mon, 16 Mar 2026 00:31:50 -0700
Received: from CY3PR05CU001.outbound.protection.outlook.com (40.93.201.39) by
 edgegateway.intel.com (192.55.55.82) with Microsoft SMTP Server
 (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.2.2562.37; Mon, 16 Mar 2026 00:31:49 -0700
ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none;
 b=PDCxh+VL9bKB/r9UpkGcdom9+nIJaXqAUUc6QMhp/2jZxPLKXFSsWowxa3clIWzUEZugJ+rUN1K64xdj/8csf/6Cz0xhgS361GETGIJTwNCBo7DABfJsiHWAw6MwLx/MzgKISd572FpVX8Wd/C5SWYoDFOJWFQhIRpajJXjisqS0U+qFhHsKe51Ku6Vtr++AnVHKfRVhzJdo+Glg0LVm7qL36l0XVFRp8jp6APH4N0FW5eT0GkdxL4QIRqhC/gHy+N3Q6fc7qrlXKHxR6eK18imPTFDkP4hqxOqqaZXLOFPRAqwh34vsfpYMLgjV/uxUMJz5E79TBqBUK3OcJHB9UQ==
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=8N4NyrxcWfpiHHimNTTCpMhJgKSf3CInqN6lUZP7KRU=;
 b=KUJKXYNQMMBAwp81Pxypq8GTgTz1UTJHdNr6Rt68JTg3mMB3vnYDfb+aIeFpVpioNiIQYBmHJK2HITB/QSmhvXph35W7xKMvPiP+JVhWxQXJVcGnGcobiYoZb4BFS/DFTelnZLNSkYf3U4VDUUYr+EAqvVWLzI9mLJb5VS6Vx+AmMC3KWRM3ALTdmfnsfsxMy8yCOXqFYjUZ2YoGygqeOIOfCE+ffc3uMYvF6wz6whdSoWMHlIV02H6rxWZkbH+8fcaQKxkJqRf5R/OEvIVhJldEPUhhynUMXH6c12wiR2vUf9xYG5yIlKyK9n/jQ4T7rZntjdcq60LFy8scHFzpCA==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
 smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com;
 dkim=pass header.d=intel.com; arc=none
Received: from BN9PR11MB5276.namprd11.prod.outlook.com (2603:10b6:408:135::18)
 by PH0PR11MB7447.namprd11.prod.outlook.com (2603:10b6:510:28b::9) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9723.13; Mon, 16 Mar
 2026 07:31:46 +0000
Received: from BN9PR11MB5276.namprd11.prod.outlook.com
 ([fe80::f997:762f:f079:134f]) by BN9PR11MB5276.namprd11.prod.outlook.com
 ([fe80::f997:762f:f079:134f%5]) with mapi id 15.20.9723.016; Mon, 16 Mar 2026
 07:31:46 +0000
From: "Tian, Kevin" <kevin.tian@intel.com>
To: "Aneesh Kumar K.V (Arm)" <aneesh.kumar@kernel.org>,
	"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>
CC: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>, "Bjorn
 Helgaas" <helgaas@kernel.org>, Jonathan Cameron
	<Jonathan.Cameron@huawei.com>, "Williams, Dan J" <dan.j.williams@intel.com>,
	Alexey Kardashevskiy <aik@amd.com>, Samuel Ortiz <sameo@rivosinc.com>, "Xu
 Yilun" <yilun.xu@linux.intel.com>, Jason Gunthorpe <jgg@ziepe.ca>, "Suzuki K
 Poulose" <Suzuki.Poulose@arm.com>, Steven Price <steven.price@arm.com>
Subject: RE: [PATCH v2 3/3] iommufd/vdevice: add TSM guest request ioctl
Thread-Topic: [PATCH v2 3/3] iommufd/vdevice: add TSM guest request ioctl
Thread-Index: AQHcr7Zg2nUMA9oep0Ot8T7R69iYtLWwzX1w
Date: Mon, 16 Mar 2026 07:31:46 +0000
Message-ID: <BN9PR11MB52763E9AF5B0634E75FA082A8C40A@BN9PR11MB5276.namprd11.prod.outlook.com>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-4-aneesh.kumar@kernel.org>
In-Reply-To: <20260309111704.2330479-4-aneesh.kumar@kernel.org>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
authentication-results: dkim=none (message not signed)
 header.d=none;dmarc=none action=none header.from=intel.com;
x-ms-publictraffictype: Email
x-ms-traffictypediagnostic: BN9PR11MB5276:EE_|PH0PR11MB7447:EE_
x-ms-office365-filtering-correlation-id: f5a0fd30-582b-4823-079e-08de832e1443
x-ms-exchange-senderadcheck: 1
x-ms-exchange-antispam-relay: 0
x-microsoft-antispam: BCL:0;ARA:13230040|366016|1800799024|7416014|376014|38070700021|22082099003|18002099003|56012099003;
x-microsoft-antispam-message-info:  
x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN9PR11MB5276.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(7416014)(376014)(38070700021)(22082099003)(18002099003)(56012099003);DIR:OUT;SFP:1101;
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?e6l0IDexROql7uNF6P9c6CRy2V/X4Y3AFAxOJikc7fNddA72wtheYiYrRiKA?=
 =?us-ascii?Q?J5kG7NdKnMM2s2+ObQ8UzJbR90eO5i0IBmZ4vk0mlnWqrMylFiKQ+XxJer/f?=
 =?us-ascii?Q?KXk4aO2abRnpAMzPGE7Fyegp5MmwMqclbsK8PLpZ1jqe79M3ujiSTHFKcSuk?=
 =?us-ascii?Q?DwGL0emHMGTwtR07vvWKLbfsDacklwuoohZVGitW30d/ndCUjhYGJMIMl4QM?=
 =?us-ascii?Q?Qd1C9JHVdTEIpgU+KeEEm5uPWMZ2mIxV3e9S0hmSV2HAs3F2N6SldiaKhE2u?=
 =?us-ascii?Q?0hya6nM0ZgP0IhZr2QIuyJ5NRzP68Zdu6nIbkeJK+jW1OpKDeEMG/ymiCvZH?=
 =?us-ascii?Q?cxCmhhL2un8ZguD3dLvHy1YURUgGMY78dHAP/L0be59ssh8MrTYtgbEyUf2w?=
 =?us-ascii?Q?iIy8ylvV9xOD9kkTQqqJcgsbjngN6H5bzqwTAPPFHmYDUGOWHFGoOoYitjz3?=
 =?us-ascii?Q?jtCdjER/DZ0pryU9mYLKiqyMagIYv8PvlmlgGhIivJqDWEqK858XtObszqYr?=
 =?us-ascii?Q?g1+eguQhQvNBim5xG19DSss3D/0bh5cm8Xk0OtNEaYScDHvlfeEwAQims/MK?=
 =?us-ascii?Q?rP4dwg7zdhcTk9c0OF6bIymYG6yx9AslGwz2/DrV086V48g1Bt/88cKPXthw?=
 =?us-ascii?Q?SpUNUov1PI4RGwK7lY26g5pTBTK3kw0bLsvxQRa/c3TLPnZ4SOXZHSosVNAQ?=
 =?us-ascii?Q?JEn+7j8rpJm5Rr2rKg6WnPHEyyFl9zg0TDRnVTcANvmmbvYlwUbgdp1vcpLh?=
 =?us-ascii?Q?k3VAqGl55KwHaXUsunW61e6F83YXMaWBR9O8ycPomT0O/cUvfdczUfJw2jYp?=
 =?us-ascii?Q?mWJOcvlJwoIGAAuMBvlabumo27Mmifuwh0WeD6es0usaImDV7yW+dt5lFXwS?=
 =?us-ascii?Q?z6ldIarSt6Yj5nm2xDfIXI0x1GXRE+wNaw+KcjxgQG6z2rHNkmNLV7FdSS6n?=
 =?us-ascii?Q?mDFhg7Hm3FDvaRfZg4C/bVUkU+PPuZDS3vqNZZ2R86/U1bRy1JTB14d8M0P4?=
 =?us-ascii?Q?C9R4gL8sxtONky75sgAY3dTa/veJoXvSqsQD1ryvhA9O7LN1TSzmyDImk2d2?=
 =?us-ascii?Q?4ddm9FhjJvOCAmsDGnAox9Myy382QAXWrR+PjV2JB4LdJSnpEi2uWSHkURy5?=
 =?us-ascii?Q?UNqIl11XzbZwgn5XHDoBnwToDB3KneGo49MbZjFQrYgR2AJiRP/Mq0Qqbmpm?=
 =?us-ascii?Q?SVvEH69hlGxqjMiNcpEwCt+rrByq/Jt1lczkLFOULrekK8J6iJOJy9XhVso/?=
 =?us-ascii?Q?zhRKU2n6LYau4HEmTa/lFmrznw+BWBe0rele3bP2nql58c8ta0Q864hv/XX2?=
 =?us-ascii?Q?5KLk5s985GyYIcUcnNVFQBPP4wCiZtq7YgjR21mPYCnrIuJsQKGrfKQS8pOe?=
 =?us-ascii?Q?ah3HJECun5zGIF01hhLBaI4MHEqHVwtcK4xoA43d5roDRQdtMrgRWqBr03Cw?=
 =?us-ascii?Q?lgYktjmapiVyGD6eTmOEvi7uqXvai2A8rHMlciyzR6zeGfC819XLAbf5vL+Q?=
 =?us-ascii?Q?9OcEJKVADqgNIMAlpR224B9RvOS88KbD2YRKEwsSqjKNY8q/1iElaUc4ZrQB?=
 =?us-ascii?Q?M85x/XKmSaKpUI5RLN+JXs2P4gTwh+oo9P6J3gjanHpvWzyQ/uVMvK7riNlh?=
 =?us-ascii?Q?r9kddHDBFM6IX7ZB03UBwnXdVXBevo28NY7W0x6+ghXh9WztaXrcMxQUYJoV?=
 =?us-ascii?Q?2go30xcN8n8s8KpxyHMhZLsyj/e18QtmZ0KO3oesob0Z6w/KBZ39hbhqjDoU?=
 =?us-ascii?Q?wUoSRwqAUw=3D=3D?=
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
X-Exchange-RoutingPolicyChecked: vq6497XKNhhNiVYI2ORvcWEKbwNVUI2H/8m5X3hbONQ185g/uSWwFRaoB9uLLWeEVPwkcH8h6jDQ+VfSesNyY2aXa+ocz6MGq+P6/twytd3qalPj6pKqOotNc3SCjfgcklYjpAyxDw8RvvCPTtWQb5Jvp6IdiMIT5b3+X3sQtoHF4G2WfEafY5iZVuuBEi4C0ehL+dFXuUSDh9Z+Xuz1rBAJwg99FMpd7qWuD+Rv1tqThKg2SX8lh3MZip3YYtr7rQ14vmQyCJSkg2dyxGEyRIBzG/p8lmK4i1TO/kXvJcGia/bMMjHDdfBO0UzxzvBK2v9lp0VuendNzM3iwdtf0g==
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: BN9PR11MB5276.namprd11.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: f5a0fd30-582b-4823-079e-08de832e1443
X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Mar 2026 07:31:46.4336
 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: ubx+JOs1jvj8Y1JhYXzrQ7Xnr3dFK15WaJTJW1LtHYcGBKftBqOv4EGYlHRPP7HvAJlZcuMsnbnHReUcW9NX/A==
X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB7447
X-OriginatorOrg: intel.com

> From: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
> Sent: Monday, March 9, 2026 7:17 PM
>=20
> Add IOMMU_VDEVICE_TSM_GUEST_REQUEST for issuing TSM guest
> request/response
> transactions against an iommufd vdevice.

Does adding '_GUEST_' in the name give any meaningful context?
It's a transparent interface connecting to tsm. why do we care
whether this request actually comes from guest or from the VMM
itself? will there be a TSM_HOST_REQUEST in the future?

I know this has been made this way in many places in this path.
but from uapi p.o.v. let's stick to the minimal required naming.

>=20
> The ioctl takes a vdevice_id plus request/response user buffers and lengt=
h
> fields, and forwards the request through tsm_guest_req() to the PCI TSM
> backend. This provides the host-side passthrough path used by CoCo guests
> for TSM device attestation and acceptance flows after the device has been
> bound to TSM.

tsm cores use "TVM". let's be consistent here (regarding to 'CoCo guests')

From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEBAC32E13B;
	Mon, 16 Mar 2026 08:45:16 +0000 (UTC)
Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201
ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1773650716; cv=none; b=uIpNlCjiBYyxEh9Qb92N6aAIZackJ/IEV2hl/JUunazwG0LgH5OruHrmaNB9r0vKfcK//EQq+5RrGb3wLqarhik6JjOEVnLBAWZwhVMHzV9WPaU0Pzksu7uV216jEopMeRwUaqWXS5ZWWc9Zsa5IFkLDOpRE2oAxT6SjSlzAn6I=
ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1773650716; c=relaxed/simple;
	bh=J3yZAEV7Vvin2RGvd9ZYHV0Kmsob2iw721LP9Geamok=;
	h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:
	 MIME-Version:Content-Type; b=LvyaB6t9SezI5Zom3bNQ3oNI7Hutdr2J9HNsBflUrrSpmz73lGZr5SSX6uPKlSPaIQosC4vTWS6nBqujguGYODCZ1SS8UVyavTI7A8u3lZN4c6eOL/6is+rTIaJUzBigIzAzkn1fE2nCRefFHJBKR5ytwJFnI6Q6PwzcSBGZ1Xw=
ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M/ZnG9uS; arc=none smtp.client-ip=10.30.226.201
Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="M/ZnG9uS"
Received: by smtp.kernel.org (Postfix) with ESMTPSA id 36A5BC19421;
	Mon, 16 Mar 2026 08:45:10 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;
	s=k20201202; t=1773650716;
	bh=J3yZAEV7Vvin2RGvd9ZYHV0Kmsob2iw721LP9Geamok=;
	h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
	b=M/ZnG9uSWZL0KGhRVodzbqi6sbwcNFAwPotrGMq2aFLsJ+ScxCVSZ1Q15dcTOmJeN
	 X/Cn1iCmLTLHiR7tZD8kXz42b8Q6wAhpj9xP6oWZSoGhMsY4CZiy7JhtQ749v7GQtM
	 nznrsk2G/BQPCTxRR1ax4PAlWjBcumEBVJ2l781g0MTEK2KQfxPDW4AllMvtQ1+okt
	 GaZJZRHtksoEozhpcz7IKKVbFNSazmZhfaAt/AM3y0chLRV8ku/vZ4jF8PuQu0EXP8
	 5p/aza/BaKpVCL0+00N0WAdm74+rVKMSyCRljZEsBD8rm7naJu/BAmxMAQU9JXcU1J
	 cA4wwlLClJhGA==
X-Mailer: emacs 30.2 (via feedmail 11-beta-1 I)
From: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
To: "Tian, Kevin" <kevin.tian@intel.com>,
	"iommu@lists.linux.dev" <iommu@lists.linux.dev>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>
Cc: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
	Bjorn Helgaas <helgaas@kernel.org>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>, "Williams,
	Dan J" <dan.j.williams@intel.com>,
	Alexey Kardashevskiy <aik@amd.com>,
	Samuel Ortiz <sameo@rivosinc.com>,
	Xu Yilun <yilun.xu@linux.intel.com>,
	Jason Gunthorpe <jgg@ziepe.ca>,
	Suzuki K Poulose <Suzuki.Poulose@arm.com>,
	Steven Price <steven.price@arm.com>
Subject: RE: [PATCH v2 2/3] iommufd/tsm: add vdevice TSM bind/unbind ioctl
In-Reply-To: <BN9PR11MB5276585EAEC4C80D4D45DD8A8C40A@BN9PR11MB5276.namprd11.prod.outlook.com>
References: <20260309111704.2330479-1-aneesh.kumar@kernel.org>
 <20260309111704.2330479-3-aneesh.kumar@kernel.org>
 <BN9PR11MB5276585EAEC4C80D4D45DD8A8C40A@BN9PR11MB5276.namprd11.prod.outlook.com>
Date: Mon, 16 Mar 2026 14:15:06 +0530
Message-ID: <yq5ay0js6u3x.fsf@kernel.org>
Precedence: bulk
X-Mailing-List: iommu@lists.linux.dev
List-Id: <iommu.lists.linux.dev>
List-Subscribe: <mailto:iommu+subscribe@lists.linux.dev>
List-Unsubscribe: <mailto:iommu+unsubscribe@lists.linux.dev>
MIME-Version: 1.0
Content-Type: text/plain

"Tian, Kevin" <kevin.tian@intel.com> writes:

>> From: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
>> Sent: Monday, March 9, 2026 7:17 PM
>> 
>> Introduce IOMMU_VDEVICE_TSM_OP to allow userspace to issue TSM
>> bind/unbind
>> operations for an iommufd vdevice.
>
> How many ops are planned? If just a few I'd prefer to openly defining
> it:
>
> 	IOMMU_VDEVICE_ALLOC,
> 	IOMMU_VDEVICE_TSM_BIND,
> 	IOMMU_VDEVICE_TSM_UNBIND,
>
> just like how we did for IOAS.
>

Right now only TSM_BIND and TSM_UNBIND. This was done based on earlier
review feedback.

https://lore.kernel.org/all/20250530181842.GU233377@nvidia.com/

>
>> @@ -432,6 +432,7 @@ union ucmd_buffer {
>>  	struct iommu_veventq_alloc veventq;
>>  	struct iommu_vfio_ioas vfio_ioas;
>>  	struct iommu_viommu_alloc viommu;
>> +	struct iommu_vdevice_tsm_op tsm_op;
>
> please follow the alphabetical order
>
>> @@ -493,6 +494,8 @@ static const struct iommufd_ioctl_op
>> iommufd_ioctl_ops[] = {
>>  		 __reserved),
>>  	IOCTL_OP(IOMMU_VIOMMU_ALLOC, iommufd_viommu_alloc_ioctl,
>>  		 struct iommu_viommu_alloc, out_viommu_id),
>> +	IOCTL_OP(IOMMU_VDEVICE_TSM_OP,
>> iommufd_vdevice_tsm_op_ioctl,
>> +		 struct iommu_vdevice_tsm_op, vdevice_id),
>
> ditto
>
>> +int iommufd_vdevice_tsm_op_ioctl(struct iommufd_ucmd *ucmd)
>> +{
>> +	int rc;
>> +	struct kvm *kvm;
>> +	struct iommufd_vdevice *vdev;
>> +	struct iommu_vdevice_tsm_op *cmd = ucmd->cmd;
>> +
>> +	if (cmd->flags)
>> +		return -EOPNOTSUPP;
>> +
>> +	vdev = container_of(iommufd_get_object(ucmd->ictx, cmd-
>> >vdevice_id,
>> +					       IOMMUFD_OBJ_VDEVICE),
>> +			    struct iommufd_vdevice, obj);
>> +	if (IS_ERR(vdev))
>> +		return PTR_ERR(vdev);
>> +
>> +	if (!vdev->viommu->kvm_filp) {
>> +		rc = -ENODEV;
>> +		goto out_put_vdev;
>> +	}
>> +
>> +	kvm = vdev->viommu->kvm_filp->private_data;
>> +	if (!kvm) {
>> +		rc = -ENODEV;
>> +		goto out_put_vdev;
>> +	}
>
> 	if (!vdev->viommu->kvm_filp ||
> 	    !vdev->viommu->kvm_filp->private_data) {
> 		rc = -ENODEV;
> 		goto out_put_vdev;
> 	}
>
> 	kvm = vdev->viommu->kvm_filp->private_data;

-aneesh

