On 7/14/25 5:59 PM, Shameer Kolothum wrote:
> For accelerated SMMUv3, we need nested parent domain creation. Add the
> callback support so that VFIO can create a nested parent.
>
> Since 'accel=on' for SMMUv3 requires the guest SMMUv3 to be configured
> in Stage 1 mode, ensure that the 'stage' property is explicitly set to
> Stage 1.
nit: strictly speaking couldn't we have a stage2 being used at guest
level implemented by a stage1 at physical level?
but it is totally fair to restrict the support.
>
> Signed-off-by: Shameer Kolothum <[email protected]>
> ---
> hw/arm/smmuv3-accel.c | 15 +++++++++++++++
> hw/arm/virt.c | 12 ++++++++++++
> 2 files changed, 27 insertions(+)
>
> diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c
> index 0b0ddb03e2..66cd4f5ece 100644
> --- a/hw/arm/smmuv3-accel.c
> +++ b/hw/arm/smmuv3-accel.c
> @@ -10,6 +10,7 @@
> #include "qemu/error-report.h"
>
> #include "hw/arm/smmuv3.h"
> +#include "hw/iommu.h"
> #include "hw/pci/pci_bridge.h"
> #include "hw/pci-host/gpex.h"
> #include "hw/vfio/pci.h"
> @@ -81,8 +82,22 @@ static AddressSpace *smmuv3_accel_find_add_as(PCIBus *bus,
> void *opaque,
> }
> }
>
> +static uint64_t smmuv3_accel_get_viommu_cap(void *opaque)
> +{
> + /*
> + * Accelerated smmuv3 support only allowes Guest S1
> + * configuration. Hence report VIOMMU_CAP_STAGE1
> + * so that VFIO can create nested parent domain.
> + * The real nested support should be reported from host
the actual nested support at host level will be queried from the host
later on?
> + * SMMUv3 and if it doesn't, the nested parent allocation
> + * will fail anyway.
> + */
> + return VIOMMU_CAP_STAGE1;
> +}
> +
> static const PCIIOMMUOps smmuv3_accel_ops = {
> .get_address_space = smmuv3_accel_find_add_as,
> + .get_viommu_cap = smmuv3_accel_get_viommu_cap,
> };
>
> void smmuv3_accel_init(SMMUv3State *s)
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 22393cf39e..fdb47eda6a 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -3053,6 +3053,18 @@ static void virt_machine_device_plug_cb(HotplugHandler
> *hotplug_dev,
> return;
> }
>
> + if (object_property_get_bool(OBJECT(dev), "accel",
> &error_abort)) {
> + char *stage;
> +
> + stage = object_property_get_str(OBJECT(dev), "stage",
> + &error_fatal);
> + if (*stage && strcmp("1", stage)) {
I am not sure you need to check *stage
> + error_setg(errp, "Only stage1 is supported for SMMUV3
> with "
> + "accel=on");
> + return;
> + }
> + }
> +
> create_smmuv3_dev_dtb(vms, dev, bus);
> }
> }
Thanks
Eric