]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iommu: Drop sw_msi from iommu_domain
authorNicolin Chen <nicolinc@nvidia.com>
Tue, 25 Mar 2025 04:05:17 +0000 (21:05 -0700)
committerJason Gunthorpe <jgg@nvidia.com>
Tue, 25 Mar 2025 13:18:19 +0000 (10:18 -0300)
There are only two sw_msi implementations in the entire system, thus it's
not very necessary to have an sw_msi pointer.

Instead, check domain->cookie_type to call the two sw_msi implementations
directly from the core code.

Link: https://patch.msgid.link/r/7ded87c871afcbaac665b71354de0a335087bf0f.1742871535.git.nicolinc@nvidia.com
Suggested-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/dma-iommu.c
drivers/iommu/dma-iommu.h
drivers/iommu/iommu.c
drivers/iommu/iommufd/hw_pagetable.c
include/linux/iommu.h

index 31a7b4b81656399753f3423ff93ace11f76e40d8..2bd9f80a83fe45955cf39b3210f7199bb76d8ce6 100644 (file)
@@ -94,9 +94,6 @@ static int __init iommu_dma_forcedac_setup(char *str)
 }
 early_param("iommu.forcedac", iommu_dma_forcedac_setup);
 
-static int iommu_dma_sw_msi(struct iommu_domain *domain, struct msi_desc *desc,
-                           phys_addr_t msi_addr);
-
 /* Number of entries per flush queue */
 #define IOVA_DEFAULT_FQ_SIZE   256
 #define IOVA_SINGLE_FQ_SIZE    32768
@@ -377,7 +374,6 @@ int iommu_get_dma_cookie(struct iommu_domain *domain)
 
        mutex_init(&cookie->mutex);
        INIT_LIST_HEAD(&cookie->msi_page_list);
-       iommu_domain_set_sw_msi(domain, iommu_dma_sw_msi);
        domain->cookie_type = IOMMU_COOKIE_DMA_IOVA;
        domain->iova_cookie = cookie;
        return 0;
@@ -411,7 +407,6 @@ int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base)
 
        cookie->msi_iova = base;
        INIT_LIST_HEAD(&cookie->msi_page_list);
-       iommu_domain_set_sw_msi(domain, iommu_dma_sw_msi);
        domain->cookie_type = IOMMU_COOKIE_DMA_MSI;
        domain->msi_cookie = cookie;
        return 0;
@@ -427,11 +422,6 @@ void iommu_put_dma_cookie(struct iommu_domain *domain)
        struct iommu_dma_cookie *cookie = domain->iova_cookie;
        struct iommu_dma_msi_page *msi, *tmp;
 
-#if IS_ENABLED(CONFIG_IRQ_MSI_IOMMU)
-       if (domain->sw_msi != iommu_dma_sw_msi)
-               return;
-#endif
-
        if (cookie->iovad.granule) {
                iommu_dma_free_fq(cookie);
                put_iova_domain(&cookie->iovad);
@@ -1826,8 +1816,8 @@ out_free_page:
        return NULL;
 }
 
-static int iommu_dma_sw_msi(struct iommu_domain *domain, struct msi_desc *desc,
-                           phys_addr_t msi_addr)
+int iommu_dma_sw_msi(struct iommu_domain *domain, struct msi_desc *desc,
+                    phys_addr_t msi_addr)
 {
        struct device *dev = msi_desc_to_dev(desc);
        const struct iommu_dma_msi_page *msi_page;
index 9cca11806e5d097703feaf57849db0986e9f74fa..eca201c1f963940c0abc1fb506b690e35673c423 100644 (file)
@@ -19,6 +19,9 @@ int iommu_dma_init_fq(struct iommu_domain *domain);
 
 void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list);
 
+int iommu_dma_sw_msi(struct iommu_domain *domain, struct msi_desc *desc,
+                    phys_addr_t msi_addr);
+
 extern bool iommu_dma_forcedac;
 
 #else /* CONFIG_IOMMU_DMA */
@@ -49,5 +52,11 @@ static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_he
 {
 }
 
+static inline int iommu_dma_sw_msi(struct iommu_domain *domain,
+                                  struct msi_desc *desc, phys_addr_t msi_addr)
+{
+       return -ENODEV;
+}
+
 #endif /* CONFIG_IOMMU_DMA */
 #endif /* __DMA_IOMMU_H */
index c92e47f333cb2aae26918e01578767a7e907cd3a..d96e6fabb4dae692509ac3f88abc6d98dfe1fb60 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/errno.h>
 #include <linux/host1x_context_bus.h>
 #include <linux/iommu.h>
+#include <linux/iommufd.h>
 #include <linux/idr.h>
 #include <linux/err.h>
 #include <linux/pci.h>
@@ -3650,8 +3651,21 @@ int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr)
                return 0;
 
        mutex_lock(&group->mutex);
-       if (group->domain && group->domain->sw_msi)
-               ret = group->domain->sw_msi(group->domain, desc, msi_addr);
+       /* An IDENTITY domain must pass through */
+       if (group->domain && group->domain->type != IOMMU_DOMAIN_IDENTITY) {
+               switch (group->domain->cookie_type) {
+               case IOMMU_COOKIE_DMA_MSI:
+               case IOMMU_COOKIE_DMA_IOVA:
+                       ret = iommu_dma_sw_msi(group->domain, desc, msi_addr);
+                       break;
+               case IOMMU_COOKIE_IOMMUFD:
+                       ret = iommufd_sw_msi(group->domain, desc, msi_addr);
+                       break;
+               default:
+                       ret = -EOPNOTSUPP;
+                       break;
+               }
+       }
        mutex_unlock(&group->mutex);
        return ret;
 }
index fded3f07bfa7beab28cf6b4f561bcc33470cd1ad..8e87ae71e1284a5a76825999a48f039333c5f53a 100644 (file)
@@ -161,7 +161,6 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
        }
        hwpt->domain->iommufd_hwpt = hwpt;
        hwpt->domain->cookie_type = IOMMU_COOKIE_IOMMUFD;
-       iommu_domain_set_sw_msi(hwpt->domain, iommufd_sw_msi);
 
        /*
         * Set the coherency mode before we do iopt_table_add_domain() as some
@@ -259,7 +258,6 @@ iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx,
        hwpt->domain->owner = ops;
        hwpt->domain->iommufd_hwpt = hwpt;
        hwpt->domain->cookie_type = IOMMU_COOKIE_IOMMUFD;
-       iommu_domain_set_sw_msi(hwpt->domain, iommufd_sw_msi);
 
        if (WARN_ON_ONCE(hwpt->domain->type != IOMMU_DOMAIN_NESTED)) {
                rc = -EINVAL;
@@ -318,7 +316,6 @@ iommufd_viommu_alloc_hwpt_nested(struct iommufd_viommu *viommu, u32 flags,
        hwpt->domain->iommufd_hwpt = hwpt;
        hwpt->domain->owner = viommu->iommu_dev->ops;
        hwpt->domain->cookie_type = IOMMU_COOKIE_IOMMUFD;
-       iommu_domain_set_sw_msi(hwpt->domain, iommufd_sw_msi);
 
        if (WARN_ON_ONCE(hwpt->domain->type != IOMMU_DOMAIN_NESTED)) {
                rc = -EINVAL;
index 06cc14e9993d4f9837a11a4145bc13b708eaf966..e01c855ae8a7aacdb47ad3a4a46a52b8b5dfb803 100644 (file)
@@ -229,11 +229,6 @@ struct iommu_domain {
        struct iommu_domain_geometry geometry;
        int (*iopf_handler)(struct iopf_group *group);
 
-#if IS_ENABLED(CONFIG_IRQ_MSI_IOMMU)
-       int (*sw_msi)(struct iommu_domain *domain, struct msi_desc *desc,
-                     phys_addr_t msi_addr);
-#endif
-
        union { /* cookie */
                struct iommu_dma_cookie *iova_cookie;
                struct iommu_dma_msi_cookie *msi_cookie;
@@ -254,16 +249,6 @@ struct iommu_domain {
        };
 };
 
-static inline void iommu_domain_set_sw_msi(
-       struct iommu_domain *domain,
-       int (*sw_msi)(struct iommu_domain *domain, struct msi_desc *desc,
-                     phys_addr_t msi_addr))
-{
-#if IS_ENABLED(CONFIG_IRQ_MSI_IOMMU)
-       domain->sw_msi = sw_msi;
-#endif
-}
-
 static inline bool iommu_is_dma_domain(struct iommu_domain *domain)
 {
        return domain->type & __IOMMU_DOMAIN_DMA_API;