[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251117184815.1027271-14-smostafa@google.com>
Date: Mon, 17 Nov 2025 18:48:00 +0000
From: Mostafa Saleh <smostafa@...gle.com>
To: linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
kvmarm@...ts.linux.dev, iommu@...ts.linux.dev
Cc: catalin.marinas@....com, will@...nel.org, maz@...nel.org,
oliver.upton@...ux.dev, joey.gouly@....com, suzuki.poulose@....com,
yuzenghui@...wei.com, joro@...tes.org, jean-philippe@...aro.org, jgg@...pe.ca,
praan@...gle.com, danielmentz@...gle.com, mark.rutland@....com,
qperret@...gle.com, tabba@...gle.com, Mostafa Saleh <smostafa@...gle.com>
Subject: [PATCH v5 13/27] iommu/arm-smmu-v3-kvm: Add the kernel driver
A platform driver is created to probe the SMMUs, which then creates
aux devices for the emulated SMMUs.
Then the driver registers with KVM.
Next, the SMMUv3 driver will probed the aux devices.
Signed-off-by: Mostafa Saleh <smostafa@...gle.com>
---
drivers/iommu/arm/arm-smmu-v3/Makefile | 1 +
.../iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c | 91 +++++++++++++++++++
2 files changed, 92 insertions(+)
create mode 100644 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c
diff --git a/drivers/iommu/arm/arm-smmu-v3/Makefile b/drivers/iommu/arm/arm-smmu-v3/Makefile
index c9ce392e6d31..c3fc5c4a4a1e 100644
--- a/drivers/iommu/arm/arm-smmu-v3/Makefile
+++ b/drivers/iommu/arm/arm-smmu-v3/Makefile
@@ -4,5 +4,6 @@ arm_smmu_v3-y := arm-smmu-v3.o arm-smmu-v3-common-lib.o
arm_smmu_v3-$(CONFIG_ARM_SMMU_V3_IOMMUFD) += arm-smmu-v3-iommufd.o
arm_smmu_v3-$(CONFIG_ARM_SMMU_V3_SVA) += arm-smmu-v3-sva.o
arm_smmu_v3-$(CONFIG_TEGRA241_CMDQV) += tegra241-cmdqv.o
+arm_smmu_v3-$(CONFIG_ARM_SMMU_V3_PKVM) += arm-smmu-v3-kvm.o
obj-$(CONFIG_ARM_SMMU_V3_KUNIT_TEST) += arm-smmu-v3-test.o
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c
new file mode 100644
index 000000000000..ca12560639c5
--- /dev/null
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c
@@ -0,0 +1,91 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * pKVM host driver for the Arm SMMUv3
+ *
+ * Copyright (C) 2022 Linaro Ltd.
+ */
+#include <asm/kvm_mmu.h>
+#include <asm/kvm_pkvm.h>
+
+#include <linux/auxiliary_bus.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+
+#include "arm-smmu-v3.h"
+#include "pkvm/arm_smmu_v3.h"
+
+extern struct kvm_iommu_ops kvm_nvhe_sym(smmu_ops);
+
+static size_t smmu_hyp_pgt_pages(void)
+{
+ /*
+ * SMMUv3 uses the same format as stage-2 and hence have the same memory
+ * requirements, we add extra 500 pages for L2 ste.
+ */
+ if (of_find_compatible_node(NULL, NULL, "arm,smmu-v3"))
+ return host_s2_pgtable_pages() + 500;
+ return 0;
+}
+
+static struct platform_driver smmuv3_nesting_driver;
+static int smmuv3_nesting_probe(struct platform_device *pdev)
+{
+ return 0;
+}
+
+static int kvm_arm_smmu_v3_register(void)
+{
+ size_t nr_pages = smmu_hyp_pgt_pages();
+ int ret;
+
+ if (!is_protected_kvm_enabled() || !nr_pages)
+ return 0;
+
+ ret = platform_driver_probe(&smmuv3_nesting_driver, smmuv3_nesting_probe);
+ if (ret)
+ return ret;
+
+ return kvm_iommu_register_driver(kern_hyp_va(lm_alias(&kvm_nvhe_sym(smmu_ops))),
+ nr_pages);
+};
+
+static int smmu_create_aux_device(struct device *dev, void *data)
+{
+ static int dev_id;
+ struct auxiliary_device *auxdev;
+
+ auxdev = __devm_auxiliary_device_create(dev, "protected_kvm",
+ "smmu_v3_emu", NULL, dev_id++);
+ if (!auxdev)
+ return -ENODEV;
+
+ auxdev->dev.parent = dev;
+
+ return 0;
+}
+
+static struct platform_driver smmuv3_nesting_driver;
+static int kvm_arm_smmu_v3_post_init(void)
+{
+ if (!is_protected_kvm_enabled())
+ return 0;
+
+ WARN_ON(driver_for_each_device(&smmuv3_nesting_driver.driver, NULL,
+ NULL, smmu_create_aux_device));
+
+ return 0;
+}
+
+static const struct of_device_id smmuv3_nested_of_match[] = {
+ { .compatible = "arm,smmu-v3", },
+ { },
+};
+
+static struct platform_driver smmuv3_nesting_driver = {
+ .driver = {
+ .name = "smmuv3-nesting",
+ .of_match_table = smmuv3_nested_of_match,
+ },
+};
+late_initcall(kvm_arm_smmu_v3_post_init);
+subsys_initcall(kvm_arm_smmu_v3_register);
--
2.52.0.rc1.455.g30608eb744-goog
Powered by blists - more mailing lists