[RFC PATCH 09/42] iommu: Add IOMMU_DOMAIN_KVM

Yan Zhao
2023-12-02T09:48:22Z

Introduce a new domain type to share stage 2 mappings from KVM.

Paging strcture allocation/free of this new domain are managed by KVM.
IOMMU side just gets page table root address from KVM via parsing vendor
specific data passed in from KVM through IOMMUFD and sets it to the IOMMU
hardware.

This new domain can be allocated by domain_alloc_kvm op, and attached to
a device through the existing iommu_attach_device/group() interfaces.

Page mapping/unmapping are managed by KVM too, therefore map/unmap ops are
not implemented.

Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
---
include/linux/iommu.h | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index c79378833c758..9ecee72e2d6c4 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -171,6 +171,8 @@ struct iommu_domain_geometry {
#define __IOMMU_DOMAIN_NESTED (1U << 6) /* User-managed address space nested
on a stage-2 translation */

+#define __IOMMU_DOMAIN_KVM (1U << 7) /* KVM-managed stage-2 translation */
+
#define IOMMU_DOMAIN_ALLOC_FLAGS ~__IOMMU_DOMAIN_DMA_FQ
/*
* This are the possible domain-types
@@ -187,6 +189,7 @@ struct iommu_domain_geometry {
* invalidation.
* IOMMU_DOMAIN_SVA - DMA addresses are shared process addresses
* represented by mm_struct's.
+ * IOMMU_DOMAIN_KVM - DMA mappings on stage 2, managed by KVM.
* IOMMU_DOMAIN_PLATFORM - Legacy domain for drivers that do their own
* dma_api stuff. Do not use in new drivers.
*/
@@ -201,6 +204,7 @@ struct iommu_domain_geometry {
#define IOMMU_DOMAIN_SVA (__IOMMU_DOMAIN_SVA)
#define IOMMU_DOMAIN_PLATFORM (__IOMMU_DOMAIN_PLATFORM)
#define IOMMU_DOMAIN_NESTED (__IOMMU_DOMAIN_NESTED)
+#define IOMMU_DOMAIN_KVM (__IOMMU_DOMAIN_KVM)

struct iommu_domain {
unsigned type;
--
2.17.1