From: Nicolin Chen <nicolinc@nvidia.com>
To: <will@kernel.org>, <robin.murphy@arm.com>, <jgg@nvidia.com>
Cc: <joro@8bytes.org>, <jpb@kernel.org>, <praan@google.com>,
<miko.lenczewski@arm.com>, <smostafa@google.com>,
<linux-arm-kernel@lists.infradead.org>, <iommu@lists.linux.dev>,
<linux-kernel@vger.kernel.org>, <patches@lists.linux.dev>
Subject: [PATCH v3 10/10] iommu/arm-smmu-v3: Allow sharing domain across SMMUs
Date: Mon, 23 Feb 2026 12:27:46 -0800 [thread overview]
Message-ID: <b7459e6833be0eecc33263723e75853efd43bcc1.1771877893.git.nicolinc@nvidia.com> (raw)
In-Reply-To: <cover.1771877893.git.nicolinc@nvidia.com>
VMM needs a domain holding the mappings between gPA to hPA. It can be an S1
domain or an S2 nesting parent domain, depending on whether the VM is built
with a vSMMU or not.
Given that the IOAS for this gPA mapping is the same across SMMU instances,
this domain can be shared across devices even if they sit behind different
SMMUs, so long as the underlying page table is compatible between the SMMU
instances.
There is no direct information about the page table from the master device,
but a comparison can be done between the page table bits held in the domain
and the SMMU feature bits that are used to decide those page table bits.
Replace the smmu test in arm_smmu_attach_dev() and arm_vsmmu_init() with a
compatibility test for the S1 and S2 cases respectively.
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 27 +++++++++++++++++++
.../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 2 +-
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 3 +--
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
index e0832b191a2a6..2e5981db11cd6 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
@@ -9,6 +9,7 @@
#define _ARM_SMMU_V3_H
#include <linux/bitfield.h>
+#include <linux/io-pgtable.h>
#include <linux/iommu.h>
#include <linux/iommufd.h>
#include <linux/kernel.h>
@@ -987,6 +988,32 @@ struct arm_smmu_nested_domain {
__le64 ste[2];
};
+static inline bool
+arm_smmu_domain_can_share(struct arm_smmu_domain *smmu_domain,
+ struct arm_smmu_device *new_smmu)
+{
+ struct io_pgtable *pgtbl =
+ io_pgtable_ops_to_pgtable(smmu_domain->pgtbl_ops);
+
+ if (pgtbl->fmt == ARM_64_LPAE_S1 &&
+ !(new_smmu->features & ARM_SMMU_FEAT_TRANS_S1))
+ return false;
+ if (pgtbl->fmt == ARM_64_LPAE_S2 &&
+ !(new_smmu->features & ARM_SMMU_FEAT_TRANS_S2))
+ return false;
+ if (pgtbl->cfg.pgsize_bitmap & ~new_smmu->pgsize_bitmap)
+ return false;
+ if (pgtbl->cfg.oas > new_smmu->oas)
+ return false;
+ if (pgtbl->cfg.coherent_walk &&
+ !(new_smmu->features & ARM_SMMU_FEAT_COHERENCY))
+ return false;
+ if ((pgtbl->cfg.quirks & IO_PGTABLE_QUIRK_ARM_S2FWB) &&
+ !(new_smmu->features & ARM_SMMU_FEAT_S2FWB))
+ return false;
+ return true;
+}
+
/* The following are exposed for testing purposes. */
struct arm_smmu_entry_writer_ops;
struct arm_smmu_entry_writer {
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
index dc638c38515e4..fbe5fc4e98ead 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
@@ -471,7 +471,7 @@ int arm_vsmmu_init(struct iommufd_viommu *viommu,
struct arm_smmu_domain *s2_parent = to_smmu_domain(parent_domain);
int id;
- if (s2_parent->smmu != smmu)
+ if (!arm_smmu_domain_can_share(s2_parent, smmu))
return -EINVAL;
mutex_lock(&arm_smmu_asid_lock);
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index a10da6b8f64d5..af99722d3b6fc 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -16,7 +16,6 @@
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/interrupt.h>
-#include <linux/io-pgtable.h>
#include <linux/iopoll.h>
#include <linux/module.h>
#include <linux/msi.h>
@@ -3709,7 +3708,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev,
state.master = master = dev_iommu_priv_get(dev);
smmu = master->smmu;
- if (smmu_domain->smmu != smmu)
+ if (!arm_smmu_domain_can_share(smmu_domain, smmu))
return -EINVAL;
if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) {
--
2.43.0
prev parent reply other threads:[~2026-02-23 20:28 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-23 20:27 [PATCH v3 00/10] iommu/arm-smmu-v3: Share domain across SMMU/vSMMU instances Nicolin Chen
2026-02-23 20:27 ` [PATCH v3 01/10] iommu/arm-smmu-v3: Add a wrapper for arm_smmu_make_sva_cd() Nicolin Chen
2026-02-23 20:27 ` [PATCH v3 02/10] iommu/arm-smmu-v3: Pass in arm_smmu_make_cd_fn to arm_smmu_set_pasid() Nicolin Chen
2026-02-23 20:27 ` [PATCH v3 03/10] iommu/arm-smmu-v3: Store IOTLB cache tags in struct arm_smmu_attach_state Nicolin Chen
2026-02-23 20:27 ` [PATCH v3 04/10] iommu/arm-smmu-v3: Pass in IOTLB cache tag to arm_smmu_master_build_invs() Nicolin Chen
2026-02-23 20:27 ` [PATCH v3 05/10] iommu/arm-smmu-v3: Pass in IOTLB cache tag to CD and STE Nicolin Chen
2026-02-23 20:27 ` [PATCH v3 06/10] iommu/arm-smmu-v3: Introduce INV_TYPE_S2_VMID_VSMMU Nicolin Chen
2026-02-23 20:27 ` [PATCH v3 07/10] iommu/arm-smmu-v3: Allocate IOTLB cache tag if no id to reuse Nicolin Chen
2026-02-23 20:27 ` [PATCH v3 08/10] iommu/arm-smmu-v3: Allocate INV_TYPE_S2_VMID_VSMMU in arm_vsmmu_init Nicolin Chen
2026-03-12 17:11 ` Jonathan Cameron
2026-03-12 19:54 ` Nicolin Chen
2026-02-23 20:27 ` [PATCH v3 09/10] iommu/arm-smmu-v3: Remove ASID/VMID from arm_smmu_domain Nicolin Chen
2026-02-23 20:27 ` Nicolin Chen [this message]
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=b7459e6833be0eecc33263723e75853efd43bcc1.1771877893.git.nicolinc@nvidia.com \
--to=nicolinc@nvidia.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=jpb@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miko.lenczewski@arm.com \
--cc=patches@lists.linux.dev \
--cc=praan@google.com \
--cc=robin.murphy@arm.com \
--cc=smostafa@google.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®