From: Nicolin Chen <nicolinc@nvidia.com>
To: Jason Gunthorpe <jgg@nvidia.com>, <joro@8bytes.org>,
Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
<rafael@kernel.org>, Danilo Krummrich <dakr@kernel.org>,
Johan Hovold <johan@kernel.org>,
Marek Szyprowski <m.szyprowski@samsung.com>,
<aneesh.kumar@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>,
Pranjal Shrivastava <praan@google.com>,
Mostafa Saleh <smostafa@google.com>,
<linux-kernel@vger.kernel.org>, <iommu@lists.linux.dev>,
<driver-core@lists.linux.dev>, Sonang Patel <sonangp@nvidia.com>,
"Ankit Agrawal" <ankita@nvidia.com>,
<shameerali.kolothum.thodi@huawei.com>
Subject: [PATCH v4 5/6] iommu: Use the blocking domain for a bypassed confidential vIOMMU
Date: Mon, 30 Nov 2026 23:33:57 -0800 [thread overview]
Message-ID: <940a7b791a0dd92686f885e0ade80cc75f9a9a58.1796069375.git.nicolinc@nvidia.com> (raw)
In-Reply-To: <cover.1796069375.git.nicolinc@nvidia.com>
Inside a confidential VM, a device stays associated with its confidential
vIOMMU, even before it is accepted into T=1. Until then, its DMA bypasses
the vIOMMU. The hypervisor translates that DMA through the T=0 stream.
Without core support, such a device gets a translating default domain. The
DMA API then hands out IOVAs that only the vIOMMU knows about, whereas the
DMA of the device goes into the hypervisor. Also, dma-iommu keeps the DMA
buffers in private memory, which the device cannot reach.
Add iommu_cc_viommu_bypassed(). For now, every device behind a cc_private
IOMMU bypasses it. Use the blocking domain as the default domain for such
a device. This keeps the DMA API on dma-direct, which uses shared buffers
and matches the DMA path set up by the hypervisor.
Linux's model requires a device to either use T=0 or T=1. Aside from MSI,
it cannot use T=0 for normal DMA once moved into T=1 mode, since the device
will have IOVA's that are not valid in T=0.
A strict IOMMU_RESV_DIRECT region sets require_direct for the device. One
such region is the MSI doorbell RMR that the VMM creates for an accelerated
vSMMU. The core then refuses the blocking domain for that device, and the
IOMMU fails to register. At release, the core also moves such a device to
an identity domain. Skip both for a device behind a bypassed vIOMMU. This
vIOMMU is not in the DMA path of the device, so it needs no 1:1 mappings.
Keep require_direct as reported by firmware, for a future paging domain.
Reject sysfs domain changes, driver-managed group attachment, and any PASID
attachments that would install a translating domain. The state is uniform
across each group, since all devices on a confidential IOMMU bypass it now.
The MSI of such a device always goes through T=0 and needs no MSI cookie.
Check cc_private directly there, since MSI stays on T=0 even after a device
moves into T=1.
Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
drivers/iommu/iommu-priv.h | 11 +++++++
drivers/iommu/iommu.c | 60 ++++++++++++++++++++++++++++++++++----
2 files changed, 65 insertions(+), 6 deletions(-)
diff --git a/drivers/iommu/iommu-priv.h b/drivers/iommu/iommu-priv.h
index 1f9f886b2c107..1acff957e9f24 100644
--- a/drivers/iommu/iommu-priv.h
+++ b/drivers/iommu/iommu-priv.h
@@ -8,6 +8,17 @@
#include <linux/iommu-debug-pagealloc.h>
#include <linux/msi.h>
+/*
+ * A bypassed confidential vIOMMU does not translate the DMA of the device. The
+ * hypervisor sets up identity translation for the device instead. PCIe ATS on
+ * its own controls the ATS behavior. For now, every device behind a cc_private
+ * IOMMU bypasses it.
+ */
+static inline bool iommu_cc_viommu_bypassed(struct device *dev)
+{
+ return dev->iommu->iommu_dev->cc_private;
+}
+
static inline const struct iommu_ops *dev_iommu_ops(struct device *dev)
{
/*
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 5ddb37236da11..c30eab2eca66a 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -598,10 +598,12 @@ static void iommu_deinit_device(struct device *dev)
/*
* If the device requires direct mappings then it should not
* be parked on a BLOCKED domain during release as that would
- * break the direct mappings.
+ * break the direct mappings. A bypassed confidential vIOMMU is
+ * not in the DMA path of the device. So it stays BLOCKED.
*/
if (dev->iommu->require_direct && ops->identity_domain &&
- release_domain == ops->blocked_domain)
+ release_domain == ops->blocked_domain &&
+ !iommu_cc_viommu_bypassed(dev))
release_domain = ops->identity_domain;
release_domain->ops->attach_dev(release_domain, dev,
@@ -1777,11 +1779,24 @@ __iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
static struct iommu_domain *
iommu_group_alloc_default_domain(struct iommu_group *group, int req_type)
{
- const struct iommu_ops *ops = dev_iommu_ops(iommu_group_first_dev(group));
+ struct device *first = iommu_group_first_dev(group);
+ const struct iommu_ops *ops = dev_iommu_ops(first);
struct iommu_domain *dom;
lockdep_assert_held(&group->mutex);
+ /*
+ * A bypassed confidential vIOMMU is not in the DMA path of the device.
+ * Attach the device to the blocking domain. This keeps the vIOMMU path
+ * closed. Also, it keeps the DMA API on dma-direct, which matches the
+ * DMA path set up by the hypervisor.
+ */
+ if (iommu_cc_viommu_bypassed(first)) {
+ if (!ops->blocked_domain)
+ return ERR_PTR(-EINVAL);
+ return ops->blocked_domain;
+ }
+
/*
* Allow legacy drivers to specify the domain that will be the default
* domain. This should always be either an IDENTITY/BLOCKED/PLATFORM
@@ -2386,6 +2401,10 @@ static int __iommu_attach_group(struct iommu_domain *domain,
!domain_iommu_ops_compatible(dev_iommu_ops(dev), domain))
return -EINVAL;
+ /* No domain attachment while the confidential vIOMMU is bypassed */
+ if (iommu_cc_viommu_bypassed(dev))
+ return -EINVAL;
+
return __iommu_group_set_domain(group, domain);
}
@@ -2427,8 +2446,12 @@ static int __iommu_device_set_domain(struct iommu_group *group,
* required 1:1 mapping. This test effectively excludes the device
* being used with iommu_group_claim_dma_owner() which will block
* vfio and iommufd as well.
+ *
+ * A bypassed confidential vIOMMU is not in the DMA path of the device.
+ * The hypervisor sets up the identity translation on that path. So the
+ * blocking domain cannot break any 1:1 mapping.
*/
- if (dev->iommu->require_direct &&
+ if (dev->iommu->require_direct && !iommu_cc_viommu_bypassed(dev) &&
(new_domain->type == IOMMU_DOMAIN_BLOCKED ||
new_domain == group->blocking_domain)) {
dev_warn(dev,
@@ -3312,6 +3335,12 @@ static ssize_t iommu_group_store_type(struct iommu_group *group,
goto out_unlock;
}
+ /* No default domain change while the confidential vIOMMU is bypassed */
+ if (iommu_cc_viommu_bypassed(iommu_group_first_dev(group))) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
+
ret = iommu_setup_default_domain(group, req_type);
if (ret)
goto out_unlock;
@@ -3677,6 +3706,12 @@ int iommu_attach_device_pasid(struct iommu_domain *domain,
goto out_unlock;
}
+ /* PASID cannot be used while the confidential vIOMMU is bypassed */
+ if (iommu_cc_viommu_bypassed(dev)) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
+
for_each_group_device(group, device) {
/*
* Skip PASID validation for devices without PASID support
@@ -3770,6 +3805,12 @@ int iommu_replace_device_pasid(struct iommu_domain *domain,
goto out_unlock;
}
+ /* PASID cannot be used while the confidential vIOMMU is bypassed */
+ if (iommu_cc_viommu_bypassed(dev)) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
+
entry = iommu_make_pasid_array_entry(domain, handle);
curr = xa_cmpxchg(&group->pasid_array, pasid, NULL,
XA_ZERO_ENTRY, GFP_KERNEL);
@@ -4004,6 +4045,12 @@ int iommu_replace_group_handle(struct iommu_group *group,
return -EINVAL;
mutex_lock(&group->mutex);
+ /* Like attach, no replace while the confidential vIOMMU is bypassed */
+ if (iommu_cc_viommu_bypassed(iommu_group_first_dev(group))) {
+ ret = -EINVAL;
+ goto err_unlock;
+ }
+
entry = iommu_make_pasid_array_entry(new_domain, handle);
ret = xa_reserve(&group->pasid_array, IOMMU_NO_PASID, GFP_KERNEL);
if (ret)
@@ -4268,8 +4315,9 @@ int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr)
return ret;
mutex_lock(&group->mutex);
- /* An IDENTITY domain must pass through */
- if (group->domain && group->domain->type != IOMMU_DOMAIN_IDENTITY) {
+ /* An IDENTITY domain or a confidential vIOMMU passes MSI through */
+ if (group->domain && group->domain->type != IOMMU_DOMAIN_IDENTITY &&
+ !dev->iommu->iommu_dev->cc_private) {
switch (group->domain->cookie_type) {
case IOMMU_COOKIE_DMA_MSI:
case IOMMU_COOKIE_DMA_IOVA:
--
2.43.0
next prev parent reply other threads:[~2026-12-01 7:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 7:33 [PATCH v4 0/6] iommu/arm-smmu-v3: Support guest-level Realm VSMMU (Part-1) Nicolin Chen
2026-12-01 7:33 ` [PATCH v4 1/6] firmware: arm_rmm: Add VSMMU commands and fields Nicolin Chen
2026-12-01 7:33 ` [PATCH v4 2/6] dma-mapping: Let a device declare that it reaches private memory Nicolin Chen
2026-12-01 7:33 ` [PATCH v4 3/6] dma-mapping: Keep DMA memory private for capable devices Nicolin Chen
2026-12-01 7:33 ` [PATCH v4 4/6] iommu: Let a driver mark an IOMMU as confidential Nicolin Chen
2026-12-01 7:33 ` Nicolin Chen [this message]
2026-12-01 7:33 ` [PATCH v4 6/6] iommu/arm-smmu-v3: Probe a guest-level Realm VSMMU via RSI commands 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=940a7b791a0dd92686f885e0ade80cc75f9a9a58.1796069375.git.nicolinc@nvidia.com \
--to=nicolinc@nvidia.com \
--cc=aneesh.kumar@kernel.org \
--cc=ankita@nvidia.com \
--cc=catalin.marinas@arm.com \
--cc=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=johan@kernel.org \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=mark.rutland@arm.com \
--cc=praan@google.com \
--cc=rafael@kernel.org \
--cc=robin.murphy@arm.com \
--cc=shameerali.kolothum.thodi@huawei.com \
--cc=smostafa@google.com \
--cc=sonangp@nvidia.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®