[PATCH v6 12/13] target/arm: hvf: instantiate GIC early

Mohamed Mediouni posted 13 patches 4 months, 1 week ago
Maintainers: Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>, Phil Dennis-Jordan <phil@philjordan.eu>, Mads Ynddal <mads@ynddal.dk>, "Michael S. Tsirkin" <mst@redhat.com>, Igor Mammedov <imammedo@redhat.com>, Ani Sinha <anisinha@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Shannon Zhao <shannon.zhaosl@gmail.com>, Paolo Bonzini <pbonzini@redhat.com>, Alexander Graf <agraf@csgraf.de>
[PATCH v6 12/13] target/arm: hvf: instantiate GIC early
Posted by Mohamed Mediouni 4 months, 1 week ago
While figuring out a better spot for it, put it in hv_arch_vm_create().

After hv_vcpu_create is documented as too late, and deferring
vCPU initialization isn't enough either.

Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>
---
 target/arm/hvf/hvf.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 6da636724b..bb7b84ff35 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1084,6 +1084,21 @@ hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range)
     }
 
     ret = hv_vm_create(config);
+    if (hvf_irqchip_in_kernel()) {
+        /*
+         * Instantiate GIC.
+         * This must be done prior to the creation of any vCPU
+         * but past hv_vm_create()
+         */
+        hv_gic_config_t cfg = hv_gic_config_create();
+        hv_gic_config_set_distributor_base(cfg, 0x08000000);
+        hv_gic_config_set_redistributor_base(cfg, 0x080A0000);
+        hv_return_t err = hv_gic_create(cfg);
+        if (err != HV_SUCCESS) {
+            error_report("error creating platform VGIC");
+            goto cleanup;
+         }
+    }
 
 cleanup:
     os_release(config);
-- 
2.39.5 (Apple Git-154)
Re: [PATCH v6 12/13] target/arm: hvf: instantiate GIC early
Posted by Mads Ynddal 4 months ago
> On 8 Aug 2025, at 09.01, Mohamed Mediouni <mohamed@unpredictable.fr> wrote:
> 
> While figuring out a better spot for it, put it in hv_arch_vm_create().
> 
> After hv_vcpu_create is documented as too late, and deferring
> vCPU initialization isn't enough either.
> 
> Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>
> ---
> target/arm/hvf/hvf.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
> 
> diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
> index 6da636724b..bb7b84ff35 100644
> --- a/target/arm/hvf/hvf.c
> +++ b/target/arm/hvf/hvf.c
> @@ -1084,6 +1084,21 @@ hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range)
>     }
> 
>     ret = hv_vm_create(config);
> +    if (hvf_irqchip_in_kernel()) {
> +        /*
> +         * Instantiate GIC.
> +         * This must be done prior to the creation of any vCPU
> +         * but past hv_vm_create()
> +         */
> +        hv_gic_config_t cfg = hv_gic_config_create();
> +        hv_gic_config_set_distributor_base(cfg, 0x08000000);
> +        hv_gic_config_set_redistributor_base(cfg, 0x080A0000);
> +        hv_return_t err = hv_gic_create(cfg);
> +        if (err != HV_SUCCESS) {
> +            error_report("error creating platform VGIC");
> +            goto cleanup;
> +         }
> +    }
> 
> cleanup:
>     os_release(config);
> -- 
> 2.39.5 (Apple Git-154)
> 

It is difficult to find a place to initialize the GIC config, so I don't
know if it gets better than this.

Should the values 0x08000000 and 0x080A0000 be defined somewhere, or
found through a look up? I see hw/arm/virt.c has them in the
base_memmap.

You can do os_release(cfg) after hv_gic_create.