Re: [PATCH v8 11/25] iommu/arm-smmu-v3-kvm: Add the kernel driver

From: Nicolin Chen

Date: Tue Sep 22 2026 - 20:22:56 EST


On Tue, Sep 22, 2026 at 01:12:44PM +0000, Mostafa Saleh wrote:
> When KVM runs in protected mode, and CONFIG_ARM_SMMU_V3_PKVM
> is enabled, it will manage the SMMUv3 HW using trap and emulate
> and present emulated SMMUs to the host kernel.
>
> In that case, those SMMUs will be on the aux bus, so make it
> possible to the driver to probe those devices.
>
> Otherwise, everything else is the same, as the KVM emulation
> complies with the architecture,so the driver doesn't need

Missing space before "so".

> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-kvm.c
> @@ -0,0 +1,187 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * pKVM host driver for the Arm SMMUv3

I am a bit confused by pkvm/arm-smmu-v3.c and arm-smmu-v3-kvm.c

It would be nicer to have a design doc or diagram here and the
other place to show their relationships (with host and KVM too).

Naming-wise, could it be arm-smmu-v3-pkvm? I also wonder if we
could move it into the pkvm folder:
pkvm/arm-smmu-v3-hyp.c
pkvm/arm-smmu-v3.c

> + *
> + * Copyright (C) 2022 Linaro Ltd.
> + */
> +#include <asm/kvm_mmu.h>
> +#include <asm/kvm_pkvm.h>
> +
> +#include <linux/auxiliary_bus.h>
> +#include <linux/of_address.h>
> +#include <linux/of_platform.h>
> +#include <linux/platform_device.h>
> +
> +#include "arm-smmu-v3.h"
> +#include "pkvm/arm-smmu-v3-hyp.h"
> +
> +extern struct pkvm_iommu_ops kvm_nvhe_sym(smmu_ops);
> +
> +static size_t kvm_arm_smmu_count;
> +static struct hyp_arm_smmu_v3_device *kvm_arm_smmu_array;
> +static size_t kvm_arm_smmu_cur;

That spaces/tabs in those two lines look a bit odd..

> +static unsigned int smmu_hyp_pgt_pages(void)
> +{
> + struct device_node *np = of_find_compatible_node(NULL, NULL, "arm,smmu-v3");
> +
> + /*
> + * SMMUv3 uses the same format as the CPU stage-2 and hence have the same memory
> + * requirements, we add extra 500 pages for L2 STEs.
> + * Only one set of memory is allocated as the page table is shared between all
> + * the SMMUs.

Mind briefly elaborate the 500 pages in this notes? Why pick 500?

Also, there is no hard requirement, but the main driver still wraps
inline comments at 80 cols. So, it would be nicer for this driver to
follow that.

> + */
> + if (np) {
> + of_node_put(np);
> + return host_s2_pgtable_pages() + 500;
> + }
> +
> + return 0;
> +}
> +
> +static struct platform_driver smmuv3_nesting_driver;
> +static int smmuv3_nesting_probe(struct platform_device *pdev)
> +{
> + struct hyp_arm_smmu_v3_device *smmu = &kvm_arm_smmu_array[kvm_arm_smmu_cur];
> + struct device *dev = &pdev->dev;
> + struct resource *res;
> +
> + /* Only device tree, ACPI not supported. */
> + if (!dev->of_node)
> + return -EINVAL;

Sashiko reported a critical finding, which sounds plausible to me:
"
Can an adversary bypass pKVM stage-2 memory protections here?
If an SMMU fails to bind to the hypervisor due to early returns in this
probe function (like missing a device tree node or hitting the cavium
erratum below), it is excluded from kvm_arm_smmu_array and the hypervisor
does not trap its MMIO.
When the native host arm_smmu_driver registers at device_initcall, it can
successfully bind to this unbound SMMU. Does this allow an adversary host
kernel at EL1 to natively program this untrapped SMMU to perform arbitrary
DMA into hypervisor or guest memory?
"

Would you please justify?

> + if (kvm_arm_smmu_cur >= kvm_arm_smmu_count)
> + return -ENOSPC;

Both counts and probe() are coming from Device Tree. So, it doesn't
seem possible unless a kernel bug. Should it WARN_ON?

> + smmu->mmio_addr = res->start;
> + smmu->mmio_size = resource_size(res);
> + if (smmu->mmio_size < SZ_128K) {
> + dev_err(dev, "MMIO region too small(%pr)\n", res);
> + return -EINVAL;
> + }

Should it reject !PAGE_ALIGNED(addr|size) like the other driver?

> +static int __init kvm_arm_smmu_v3_register(void)
> +{
[...]
> +out_err:
> + kvm_arm_smmu_count = 0;
> + kvm_arm_smmu_array = NULL;
> + return ret;
> +};

No ';' after '}'.

> +static int kvm_arm_smmu_v3_post_init(void)

__init?

> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -5203,6 +5204,72 @@ static struct platform_driver arm_smmu_driver = {
> module_driver(arm_smmu_driver, platform_driver_register,
> arm_smmu_driver_unregister);
>
> +#ifdef CONFIG_ARM_SMMU_V3_PKVM
> +/*
> + * Now we have 2 devices, the aux device bound to this driver, and pdev
> + * which is the physical platform device bound to the KVM driver but not used.
> + * However, this driver keeps using the platform device for 2 reasons:
> + * 1) Simplicity: Avoiding changing big parts of the code assuming
> + * the underlying device is a platform device.
> + * 2) Dealing with DMA-API, irqs(MSIs), RPM... requires the physical device.
> + *
> + * That means arm_smmu_device_probe() allocates its devm resources on the
> + * platform device, where they are not freed when the aux device unbinds.
> + * The devres group bounds them to the lifetime of this binding instead.

There is an "unbinds", so I assume it should be:

s/bounds/binds

?

Nicolin