Subject: linux-next: manual merge of the iommufd tree with the iommu tree

From: Stephen Rothwell <[email-masked]>
Date: Fri, 21 Mar 2025 19:09:12 +1100

Hi all,

Today's linux-next merge of the iommufd tree got a conflict in:

  drivers/iommu/dma-iommu.c

between commit:

  032d7e435cbd ("iommu/dma: Remove redundant locking")

from the iommu tree and commits:

  f3f47b821931 ("iommu: Sort out domain user data")
  e009e088d88e ("iommu: Drop sw_msi from iommu_domain")

from the iommufd tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc drivers/iommu/dma-iommu.c
index 0832998eca38,2bd9f80a83fe..000000000000
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@@ -59,34 -54,31 +54,30 @@@ struct iommu_dma_options 
  };
  
  struct iommu_dma_cookie {
- 	enum iommu_dma_cookie_type	type;
+ 	struct iova_domain iovad;
+ 	struct list_head msi_page_list;
+ 	/* Flush queue */
  	union {
- 		/* Full allocator for IOMMU_DMA_IOVA_COOKIE */
- 		struct {
- 			struct iova_domain	iovad;
- 			/* Flush queue */
- 			union {
- 				struct iova_fq	*single_fq;
- 				struct iova_fq	__percpu *percpu_fq;
- 			};
- 			/* Number of TLB flushes that have been started */
- 			atomic64_t		fq_flush_start_cnt;
- 			/* Number of TLB flushes that have been finished */
- 			atomic64_t		fq_flush_finish_cnt;
- 			/* Timer to regularily empty the flush queues */
- 			struct timer_list	fq_timer;
- 			/* 1 when timer is active, 0 when not */
- 			atomic_t		fq_timer_on;
- 		};
- 		/* Trivial linear page allocator for IOMMU_DMA_MSI_COOKIE */
- 		dma_addr_t		msi_iova;
+ 		struct iova_fq *single_fq;
+ 		struct iova_fq __percpu *percpu_fq;
  	};
- 	struct list_head		msi_page_list;
- 
+ 	/* Number of TLB flushes that have been started */
+ 	atomic64_t fq_flush_start_cnt;
+ 	/* Number of TLB flushes that have been finished */
+ 	atomic64_t fq_flush_finish_cnt;
+ 	/* Timer to regularily empty the flush queues */
+ 	struct timer_list fq_timer;
+ 	/* 1 when timer is active, 0 when not */
+ 	atomic_t fq_timer_on;
  	/* Domain for flush queue callback; NULL if flush queue not in use */
- 	struct iommu_domain		*fq_domain;
+ 	struct iommu_domain *fq_domain;
  	/* Options for dma-iommu use */
- 	struct iommu_dma_options	options;
+ 	struct iommu_dma_options options;
 -	struct mutex mutex;
+ };
+ 
+ struct iommu_dma_msi_cookie {
+ 	dma_addr_t msi_iova;
+ 	struct list_head msi_page_list;
  };
  
  static DEFINE_STATIC_KEY_FALSE(iommu_deferred_attach_enabled);
@@@ -393,14 -363,19 +362,18 @@@ int iommu_dma_init_fq(struct iommu_doma
   */
  int iommu_get_dma_cookie(struct iommu_domain *domain)
  {
- 	if (domain->iova_cookie)
+ 	struct iommu_dma_cookie *cookie;
+ 
+ 	if (domain->cookie_type != IOMMU_COOKIE_NONE)
  		return -EEXIST;
  
- 	domain->iova_cookie = cookie_alloc(IOMMU_DMA_IOVA_COOKIE);
- 	if (!domain->iova_cookie)
+ 	cookie = kzalloc(sizeof(*cookie), GFP_KERNEL);
+ 	if (!cookie)
  		return -ENOMEM;
  
- 	iommu_domain_set_sw_msi(domain, iommu_dma_sw_msi);
 -	mutex_init(&cookie->mutex);
+ 	INIT_LIST_HEAD(&cookie->msi_page_list);
+ 	domain->cookie_type = IOMMU_COOKIE_DMA_IOVA;
+ 	domain->iova_cookie = cookie;
  	return 0;
  }