[PATCH v4 6/6] iommu/arm-smmu-v3: Probe a guest-level Realm VSMMU via RSI commands
From: Nicolin Chen
Date: Tue Dec 01 2026 - 02:34:52 EST
In CCA, the ACPI/etc doesn't tell the OS whether the SMMU is a confidential
T=1 instance or a normal T=0 one. Instead, it has to be learned by issuing
a trusted RSI. Before the kernel can operate the trusted T=1 IOMMU, it also
has to validate all the information that it gets from ACPI against the true
information that it gets from the RSI call, to ensure the ACPI is correct
and prevent substitution attacks.
Use RSI_VSMMU_GET_INFO during probe and require the returned register range
to match firmware. Then use RSI_ARCH_DEV_ACTIVATE before mapping registers.
Currently the driver doesn't support a T=0 SMMU inside a realm. For example
it doesn't make the page table allocations into shared memory. If we are in
a realm reject any SMMU that is not T=1.
Once the SMMU is activated, its DMA will follow the DEV_FLAG_DMA_CC_PRIVATE
rules. It must set that flag to ensure its coherent allocations for its own
structures are allocated from private memory, not the SWIOTLB shared pool.
Also skip the Tegra241 CMDQV in the realm world. The CMDQV hardware can be
used in realms. But neither the RMM spec nor the RMM firmware supports the
CMDQV yet. From a guest perspective, there is no way to verify the NVDA200C
ACPI device with the RMM yet. Thus, its MMIO space cannot be used for now.
Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
Signed-off-by: Nicolin Chen <nicolinc@xxxxxxxxxx>
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 78 ++++++++++++++++++++-
1 file changed, 77 insertions(+), 1 deletion(-)
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 6d4520c473086..f71982d72cae7 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -11,9 +11,11 @@
#include <linux/acpi.h>
#include <linux/acpi_iort.h>
+#include <linux/arm-rsi-cmds.h>
#include <linux/bitops.h>
#include <linux/crash_dump.h>
#include <linux/delay.h>
+#include <linux/dma-mapping.h>
#include <linux/err.h>
#include <linux/interrupt.h>
#include <linux/io-pgtable.h>
@@ -5545,6 +5547,15 @@ static void tegra_cmdqv_dt_probe(struct device_node *smmu_node,
struct platform_device *pdev;
struct device_node *np;
+ /*
+ * A realm can have a CMDQV. But neither the RMM spec nor the firmware
+ * supports the CMDQV yet. So, a realm guest has no way to verify it via
+ * the RMM yet. Thus, its MMIO space cannot be used. Realms only get the
+ * standard SMMU for now.
+ */
+ if (is_realm_world())
+ return;
+
np = of_parse_phandle(smmu_node, "nvidia,cmdqv", 0);
if (!np)
return;
@@ -5572,8 +5583,19 @@ static void tegra_cmdqv_dt_probe(struct device_node *smmu_node,
static void acpi_smmu_dsdt_probe_tegra241_cmdqv(struct acpi_iort_node *node,
struct arm_smmu_device *smmu)
{
- const char *uid = kasprintf(GFP_KERNEL, "%u", node->identifier);
struct acpi_device *adev;
+ const char *uid;
+
+ /*
+ * A realm can have a CMDQV. But neither the RMM spec nor the firmware
+ * supports the CMDQV yet. So, a realm guest has no way to verify it via
+ * the RMM yet. Thus, its MMIO space cannot be used. Realms only get the
+ * standard SMMU for now.
+ */
+ if (is_realm_world())
+ return;
+
+ uid = kasprintf(GFP_KERNEL, "%u", node->identifier);
/* Look for an NVDA200C node whose _UID matches the SMMU node ID */
adev = acpi_dev_get_first_match_dev("NVDA200C", uid, -1);
@@ -5779,6 +5801,56 @@ static struct arm_smmu_device *arm_smmu_impl_probe(struct arm_smmu_device *smmu)
return ERR_PTR(ret);
}
+static void arm_smmu_clear_realm_private(void *dev)
+{
+ dma_set_cc_private(dev, false);
+}
+
+static int arm_smmu_probe_realm_vsmmu(struct arm_smmu_device *smmu,
+ const struct resource *res)
+{
+ struct device *dev = smmu->dev;
+ unsigned long rsi_ret;
+ phys_addr_t top;
+
+ if (!is_realm_world())
+ return 0;
+
+ /*
+ * Currently the driver does not support a T=0 SMMU inside a realm. For
+ * instance it does not make the page table allocations into shared
+ * memory. If we are in a realm reject any SMMU that is not T=1.
+ */
+ rsi_ret = rsi_vsmmu_get_info(res->start, &top);
+ if (rsi_ret != RSI_SUCCESS) {
+ dev_err(dev, "RSI_VSMMU_GET_INFO failed for %pr: %lu\n", res,
+ rsi_ret);
+ return -ENODEV;
+ }
+
+ if (top != res->end + 1) {
+ dev_err(dev, "VSMMU range %pr ends at %pa\n", res, &top);
+ return -EINVAL;
+ }
+
+ rsi_ret = rsi_arch_dev_activate(res->start, RSI_ARCH_DEV_SMMUV3);
+ if (rsi_ret != RSI_SUCCESS) {
+ dev_err(dev, "RSI_ARCH_DEV_ACTIVATE failed for %pr: %lu\n", res,
+ rsi_ret);
+ return -EIO;
+ }
+
+ /*
+ * Once activated, the SMMU DMA follows DEV_FLAG_DMA_CC_PRIVATE so its
+ * queues and tables are allocated from private memory, not the SWIOTLB
+ * shared pool. It only translates for a device we've requested the RMM
+ * to put into T=1.
+ */
+ iommu_device_set_cc_private(&smmu->iommu, dev);
+
+ return devm_add_action_or_reset(dev, arm_smmu_clear_realm_private, dev);
+}
+
static int arm_smmu_device_probe(struct platform_device *pdev)
{
int irq, ret;
@@ -5814,6 +5886,10 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
}
ioaddr = res->start;
+ ret = arm_smmu_probe_realm_vsmmu(smmu, res);
+ if (ret)
+ return ret;
+
/*
* Don't map the IMPLEMENTATION DEFINED regions, since they may contain
* the PMCG registers which are reserved by the PMU driver.
--
2.43.0