From: Andrew Jones <andrew.jones@oss.qualcomm.com>
To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org
Cc: jgg@ziepe.ca, kevin.tian@intel.com, robin.murphy@arm.com,
joro@8bytes.org, will@kernel.org
Subject: [RFC PATCH v1 3/8] iommufd: Split software MSI map lookup and allocation
Date: Wed, 26 Aug 2026 16:52:57 +0200 [thread overview]
Message-ID: <20260826145302.449904-4-andrew.jones@oss.qualcomm.com> (raw)
In-Reply-To: <20260826145302.449904-1-andrew.jones@oss.qualcomm.com>
Separate lookup of an existing software MSI mapping from allocation of a
new mapping. This prepares the code for allocating multiple mappings for
an MSI physical address list.
Signed-off-by: Andrew Jones <andrew.jones@oss.qualcomm.com>
---
drivers/iommu/iommufd/driver.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/iommufd/driver.c b/drivers/iommu/iommufd/driver.c
index d0b05b1fda42..3856989f5c4b 100644
--- a/drivers/iommu/iommufd/driver.c
+++ b/drivers/iommu/iommufd/driver.c
@@ -189,6 +189,23 @@ iommufd_sw_msi_get_map(struct iommufd_ctx *ictx, phys_addr_t msi_addr,
phys_addr_t sw_msi_start)
{
struct iommufd_sw_msi_map *cur;
+
+ lockdep_assert_held(&ictx->sw_msi_lock);
+
+ list_for_each_entry(cur, &ictx->sw_msi_list, sw_msi_item) {
+ if (cur->sw_msi_start != sw_msi_start)
+ continue;
+ if (cur->msi_addr == msi_addr)
+ return cur;
+ }
+ return NULL;
+}
+
+static struct iommufd_sw_msi_map *
+iommufd_sw_msi_alloc_map(struct iommufd_ctx *ictx, phys_addr_t msi_addr,
+ phys_addr_t sw_msi_start)
+{
+ struct iommufd_sw_msi_map *cur;
unsigned int max_pgoff = 0;
lockdep_assert_held(&ictx->sw_msi_lock);
@@ -199,8 +216,6 @@ iommufd_sw_msi_get_map(struct iommufd_ctx *ictx, phys_addr_t msi_addr,
if (cur->pgoff == UINT_MAX)
return ERR_PTR(-EOVERFLOW);
max_pgoff = max(max_pgoff, cur->pgoff + 1);
- if (cur->msi_addr == msi_addr)
- return cur;
}
if (ictx->sw_msi_id > IOMMUFD_SW_MSI_MAX_ID ||
@@ -293,6 +308,10 @@ int iommufd_sw_msi(struct iommu_domain *domain, struct msi_desc *desc,
msi_map = iommufd_sw_msi_get_map(handle->idev->ictx,
msi_addr & PAGE_MASK,
handle->idev->igroup->sw_msi_start);
+ if (!msi_map)
+ msi_map = iommufd_sw_msi_alloc_map(handle->idev->ictx,
+ msi_addr & PAGE_MASK,
+ handle->idev->igroup->sw_msi_start);
if (IS_ERR(msi_map))
return PTR_ERR(msi_map);
--
2.43.0
next prev parent reply other threads:[~2026-08-26 14:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-26 14:52 [RFC PATCH v1 0/8] iommu: Add contiguous MSI mapping support Andrew Jones
2026-08-26 14:52 ` [RFC PATCH v1 1/8] iommu/dma: Prepare MSI physical address lists Andrew Jones
2026-08-26 14:52 ` [RFC PATCH v1 2/8] iommufd: Convert struct iommufd_sw_msi_maps to a growable bitmap Andrew Jones
2026-08-26 14:52 ` Andrew Jones [this message]
2026-08-26 14:52 ` [RFC PATCH v1 4/8] iommufd: Bound software MSI mappings to the reserved range Andrew Jones
2026-08-26 14:52 ` [RFC PATCH v1 5/8] iommufd: Prepare software MSI maps for address lists Andrew Jones
2026-08-26 14:53 ` [RFC PATCH v1 6/8] iommufd: Install software MSI map ranges atomically Andrew Jones
2026-08-26 14:53 ` [RFC PATCH v1 7/8] iommufd: Prepare software MSI installation for address lists Andrew Jones
2026-08-26 14:53 ` [RFC PATCH v1 8/8] iommu/dma: Introduce iommu_dma_prepare_msi_list() Andrew Jones
2026-08-27 8:13 ` [RFC PATCH v1 0/8] iommu: Add contiguous MSI mapping support Andrew Jones
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=20260826145302.449904-4-andrew.jones@oss.qualcomm.com \
--to=andrew.jones@oss.qualcomm.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@ziepe.ca \
--cc=joro@8bytes.org \
--cc=kevin.tian@intel.com \
--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®