From: Nicolin Chen <nicolinc@nvidia.com>
To: <robin.murphy@arm.com>, <joro@8bytes.org>, <will@kernel.org>,
<alex.williamson@redhat.com>
Cc: <jgg@nvidia.com>, <iommu@lists.linux.dev>,
<linux-kernel@vger.kernel.org>, <kvm@vger.kernel.org>
Subject: [PATCH v1 1/4] iommu: Define iommu_get/put_msi_cookie() under CONFIG_IRQ_MSI_IOMMU
Date: Wed, 26 Feb 2025 12:16:04 -0800 [thread overview]
Message-ID: <b5ec70595b63017598a256db71af8feff28c6733.1740600272.git.nicolinc@nvidia.com> (raw)
In-Reply-To: <cover.1740600272.git.nicolinc@nvidia.com>
Not all domain owners call iommu_get_dma/msi_cookie(), e.g. iommufd has
its sw_msi implementation without using the domain->iova_cookie but the
domain->iommufd_hwpt.
To isolate the unused iova_cookie from the iommufd, iommu_domain_free()
will no longer call iommu_put_dma_cookie().
Add iommu_put_msi_cookie() to pair with iommu_put_dma_cookie() for VFIO
that is the only caller to explicitly put the MSI cookie.
Move iommufd_get/put_msi_cookie() inside "ifdef CONFIG_IRQ_MSI_IOMMU".
Note that the iommufd_get_msi_cookie now returns a 0 for NOP in case of:
*) !CONFIG_IOMMU_DMA - the caller in VFIO would have returned prior to
reaching to this function.
*) !CONFIG_IRQ_MSI_IOMMU - in a system without an irqchip driver, vfio
or iommufd shouldn't fail if an IOMMU driver
still reports SW_MSI reserved regions.
Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
include/linux/iommu.h | 10 +++++++---
drivers/iommu/dma-iommu.c | 12 ++++++++++++
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index e93d2e918599..6f66980e0c86 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -1534,12 +1534,16 @@ void iommu_debugfs_setup(void);
static inline void iommu_debugfs_setup(void) {}
#endif
-#ifdef CONFIG_IOMMU_DMA
+#if defined(CONFIG_IOMMU_DMA) && IS_ENABLED(CONFIG_IRQ_MSI_IOMMU)
int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base);
-#else /* CONFIG_IOMMU_DMA */
+void iommu_put_msi_cookie(struct iommu_domain *domain);
+#else /* CONFIG_IOMMU_DMA && CONFIG_IRQ_MSI_IOMMU */
static inline int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base)
{
- return -ENODEV;
+ return 0;
+}
+static inline void iommu_put_msi_cookie(struct iommu_domain *domain)
+{
}
#endif /* CONFIG_IOMMU_DMA */
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 94263ed2c564..228524c81b72 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -418,6 +418,7 @@ int iommu_get_dma_cookie(struct iommu_domain *domain)
* number of PAGE_SIZE mappings necessary to cover every MSI doorbell address
* used by the devices attached to @domain.
*/
+#if IS_ENABLED(CONFIG_IRQ_MSI_IOMMU)
int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base)
{
struct iommu_dma_cookie *cookie;
@@ -439,6 +440,17 @@ int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base)
}
EXPORT_SYMBOL(iommu_get_msi_cookie);
+/**
+ * iommu_put_msi_cookie - Release a domain's MSI remapping resources
+ * @domain: IOMMU domain previously prepared by iommu_get_msi_cookie()
+ */
+void iommu_put_msi_cookie(struct iommu_domain *domain)
+{
+ iommu_put_dma_cookie(domain);
+}
+EXPORT_SYMBOL_GPL(iommu_put_msi_cookie);
+#endif
+
/**
* iommu_put_dma_cookie - Release a domain's DMA mapping resources
* @domain: IOMMU domain previously prepared by iommu_get_dma_cookie() or
--
2.43.0
next prev parent reply other threads:[~2025-02-26 20:16 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-26 20:16 [PATCH v1 0/4] iommu: Isolate iova_cookie to actual owners Nicolin Chen
2025-02-26 20:16 ` Nicolin Chen [this message]
2025-02-26 20:16 ` [PATCH v1 2/4] iommu: Add iommu_default_domain_free helper Nicolin Chen
2025-02-27 19:50 ` Jason Gunthorpe
2025-02-27 20:59 ` Nicolin Chen
2025-02-27 21:03 ` Jason Gunthorpe
2025-02-27 23:32 ` Nicolin Chen
2025-02-28 11:20 ` Robin Murphy
2025-02-26 20:16 ` [PATCH v1 3/4] iommu: Request iova_cookie owner to put cookie explicitly Nicolin Chen
2025-02-26 20:16 ` [PATCH v1 4/4] iommu: Turn iova_cookie to dma-iommu private pointer Nicolin Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b5ec70595b63017598a256db71af8feff28c6733.1740600272.git.nicolinc@nvidia.com \
--to=nicolinc@nvidia.com \
--cc=alex.williamson@redhat.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®