Re: [PATCH v4 14/32] iommu: introduce iommu_domain_alloc_type and the KVM type

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2022-03-14 19:44, Matthew Rosato wrote:
s390x will introduce an additional domain type that is used for
managing IOMMU owned by KVM.  Define the type here and add an
interface for allocating a specified type vs the default type.

I'm also not a huge fan of adding a new domain_alloc interface like this, however if it is justifiable, then please make it take struct device rather than struct bus_type as an argument.

It also sounds like there may be a degree of conceptual overlap here with what Jean-Philippe is working on for sharing pagetables between KVM and SMMU for Android pKVM, so it's probably worth some thought over whether there's any scope for common interfaces in terms of actual implementation.

Thanks,
Robin.

Signed-off-by: Matthew Rosato <mjrosato@xxxxxxxxxxxxx>
---
  drivers/iommu/iommu.c |  7 +++++++
  include/linux/iommu.h | 12 ++++++++++++
  2 files changed, 19 insertions(+)

diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index f2c45b85b9fc..8bb57e0e3945 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1976,6 +1976,13 @@ void iommu_domain_free(struct iommu_domain *domain)
  }
  EXPORT_SYMBOL_GPL(iommu_domain_free);
+struct iommu_domain *iommu_domain_alloc_type(struct bus_type *bus,
+					     unsigned int t)
+{
+	return __iommu_domain_alloc(bus, t);
+}
+EXPORT_SYMBOL_GPL(iommu_domain_alloc_type);
+
  static int __iommu_attach_device(struct iommu_domain *domain,
  				 struct device *dev)
  {
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 9208eca4b0d1..b427bbb9f387 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -63,6 +63,7 @@ struct iommu_domain_geometry {
  					      implementation              */
  #define __IOMMU_DOMAIN_PT	(1U << 2)  /* Domain is identity mapped   */
  #define __IOMMU_DOMAIN_DMA_FQ	(1U << 3)  /* DMA-API uses flush queue    */
+#define __IOMMU_DOMAIN_KVM	(1U << 4)  /* Domain is controlled by KVM */
/*
   * This are the possible domain-types
@@ -77,6 +78,7 @@ struct iommu_domain_geometry {
   *				  certain optimizations for these domains
   *	IOMMU_DOMAIN_DMA_FQ	- As above, but definitely using batched TLB
   *				  invalidation.
+ *	IOMMU_DOMAIN_KVM	- DMA mappings managed by KVM, used for VMs
   */
  #define IOMMU_DOMAIN_BLOCKED	(0U)
  #define IOMMU_DOMAIN_IDENTITY	(__IOMMU_DOMAIN_PT)
@@ -86,6 +88,8 @@ struct iommu_domain_geometry {
  #define IOMMU_DOMAIN_DMA_FQ	(__IOMMU_DOMAIN_PAGING |	\
  				 __IOMMU_DOMAIN_DMA_API |	\
  				 __IOMMU_DOMAIN_DMA_FQ)
+#define IOMMU_DOMAIN_KVM	(__IOMMU_DOMAIN_PAGING |	\
+				 __IOMMU_DOMAIN_KVM)
struct iommu_domain {
  	unsigned type;
@@ -421,6 +425,8 @@ extern bool iommu_capable(struct bus_type *bus, enum iommu_cap cap);
  extern struct iommu_domain *iommu_domain_alloc(struct bus_type *bus);
  extern struct iommu_group *iommu_group_get_by_id(int id);
  extern void iommu_domain_free(struct iommu_domain *domain);
+extern struct iommu_domain *iommu_domain_alloc_type(struct bus_type *bus,
+						    unsigned int t);
  extern int iommu_attach_device(struct iommu_domain *domain,
  			       struct device *dev);
  extern void iommu_detach_device(struct iommu_domain *domain,
@@ -708,6 +714,12 @@ static inline void iommu_domain_free(struct iommu_domain *domain)
  {
  }
+static inline struct iommu_domain *iommu_domain_alloc_type(struct bus_type *bus,
+							   unsigned int t)
+{
+	return NULL;
+}
+
  static inline int iommu_attach_device(struct iommu_domain *domain,
  				      struct device *dev)
  {



[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux