Skip to contentSkip to conversation

target/arm/hvf: Consolidate

PATCH Superseded Philippe Mathieu-Daudé 4 participants 68 messages Sep 3, 2025 – Oct 7, 2025

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

cover target/arm/hvf: Consolidate

- Fix a pair of memory leak
- Check a pair of return values
- Mention calls which must be run on vCPU thread
- Force MIDR
- Use hv_vcpu_config_create/hv_vcpu_config_get_feature_reg when not running on vCPU thread
- Factor hvf_handle_vmexit() / hvf_handle_exception(() out
- Call hv_vcpu_run() in loop
- Guard hv_vcpu_run() between cpu_exec_start/end()
- Restrict ARM specific in AccelCPUState

Based-on: <[email protected]>

Mohamed Mediouni (2):
target/arm/hvf: Hardcode Apple MIDR
target/arm/hvf: switch hvf_arm_get_host_cpu_features to not create a
vCPU

Philippe Mathieu-Daudé (22):
target/arm/hvf: Release memory allocated by hv_vcpu_config_create() target/arm/hvf: Check hv_vcpus_exit() returned value target/arm/hvf: Check hv_vcpu_set_vtimer_mask() returned value accel/hvf: Rename hvf_vcpu_exec() -> hvf_arch_vcpu_exec() accel/hvf: Rename hvf_put|get_registers -> hvf_arch_put|get_registers target/arm/hvf: Mention flush_cpu_state() must run on vCPU thread accel/hvf: Mention hvf_arch_init_vcpu() must run on vCPU thread target/arm/hvf: Mention hvf_wfi() must run on vCPU thread target/arm/hvf: Mention hvf_sync_vtimer() must run on vCPU thread target/arm/hvf: Mention hvf_arch_set_traps() must run on vCPU thread accel/hvf: Mention hvf_arch_update_guest_debug() must run on vCPU target/arm/hvf: Mention hvf_inject_interrupts() must run on vCPU
thread
accel/hvf: Implement hvf_arch_vcpu_destroy() target/arm/hvf: Factor hvf_handle_exception() out target/arm/hvf: Factor hvf_handle_vmexit() out target/arm/hvf: Keep calling hv_vcpu_run() in loop
cpus: Trace cpu_exec_start() and cpu_exec_end() calls accel/hvf: Guard hv_vcpu_run() between cpu_exec_start/end() calls target/arm: Call aarch64_add_pauth_properties() once in host_initfn() accel/hvf: Restrict ARM specific fields of AccelCPUState target/arm: Rename init_cpreg_list() -> arm_init_cpreg_list() target/arm: Add arm_destroy_cpreg_list() helper

 include/system/hvf_int.h    |  23 ++--
 target/arm/internals.h      |   4 +-
 accel/hvf/hvf-accel-ops.c   |   4 +-
 cpu-common.c                |   3 +
 target/arm/cpu.c            |   2 +-
 target/arm/cpu64.c          |   8 +-
 target/arm/helper.c         |  10 +-
 target/arm/hvf/hvf.c        | 206 ++++++++++++++++++++++--------------
 target/i386/hvf/hvf.c       |   8 +-
 target/i386/hvf/x86hvf.c    |   4 +-
 target/arm/hvf/trace-events |   1 +
 trace-events                |   2 +
 12 files changed, 173 insertions(+), 102 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/24 target/arm/hvf: Release memory allocated by hv_vcpu_config_create()

hv_vcpu_config_create() is documented in <Hypervisor/hv_vcpu_config.h> as:

/*!
@abstract Creates a vcpu configuration object.
@result A new vcpu configuration object. This should be released with os_release when no longer used. */
OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT
hv_vcpu_config_t hv_vcpu_config_create(void);

Release the memory allocated by hv_vcpu_config_create() with os_release().

---
 target/arm/hvf/hvf.c | 2 ++
 1 file changed, 2 insertions(+)
target/arm/hvf/hvf.c +2 -0
index b77db99079e..d67372218de 100644
@@ -150,6 +150,8 @@ void hvf_arm_init_debug(void)
     max_hw_wps = hvf_arm_num_wrps(config);
     hw_watchpoints =
         g_array_sized_new(true, true, sizeof(HWWatchpoint), max_hw_wps);
+
+    os_release(config);
 }
 
 #define HVF_SYSREG(crn, crm, op0, op1, op2) \
Signature · 1 line
2.51.0
Reviewed-by on v1 1/24
#2 lore raw

Re: [PATCH 01/24] target/arm/hvf: Release memory allocated by hv_vcpu_config_create()

Quoted 10 lines · Philippe Mathieu-Daudé

hv_vcpu_config_create() is documented in <Hypervisor/hv_vcpu_config.h> as:

   /*!
    @abstract Creates a vcpu configuration object.
    @result A new vcpu configuration object. This should be released with os_release when no longer used.
    */
   OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT
   hv_vcpu_config_t hv_vcpu_config_create(void);
Quoted 7 lines

Release the memory allocated by hv_vcpu_config_create() with os_release().

---
  target/arm/hvf/hvf.c | 2 ++
  1 file changed, 2 insertions(+)

r~

Reviewed-by on v1 1/24
#3 lore raw

Re: [PATCH 01/24] target/arm/hvf: Release memory allocated by hv_vcpu_config_create()

In reply to Philippe Mathieu-Daudé
Quoted 13 lines · Philippe Mathieu-Daudé

hv_vcpu_config_create() is documented in <Hypervisor/hv_vcpu_config.h> as:

/*!
@abstract Creates a vcpu configuration object.
@result A new vcpu configuration object. This should be released with os_release when no longer used. */
OS_OBJECT_RETURNS_RETAINED OS_WARN_RESULT
hv_vcpu_config_t hv_vcpu_config_create(void);

Quoted 7 lines

Release the memory allocated by hv_vcpu_config_create() with os_release().

---
target/arm/hvf/hvf.c | 2 ++

1 file changed, 2 insertions(+)
#4 lore raw

PATCH 2/24 target/arm/hvf: Check hv_vcpus_exit() returned value

In reply to Philippe Mathieu-Daudé

hv_vcpus_exit() returns a hv_return_t enum type (defined in <Hypervisor/hv_error.h>). Assert we succeeded, as we are not ready to handle any error path.

---
 target/arm/hvf/hvf.c        | 5 ++++-
 target/arm/hvf/trace-events | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)
target/arm/hvf/hvf.c +4 -1
index d67372218de..65ac0bd71aa 100644
@@ -1086,8 +1086,11 @@ int hvf_arch_init_vcpu(CPUState *cpu)
 
 void hvf_kick_vcpu_thread(CPUState *cpu)
 {
+    hv_return_t ret;
+    trace_hvf_kick_vcpu_thread(cpu->cpu_index, cpu->stop);
     cpus_kick_thread(cpu);
-    hv_vcpus_exit(&cpu->accel->fd, 1);
+    ret = hv_vcpus_exit(&cpu->accel->fd, 1);
+    assert_hvf_ok(ret);
 }
 
 static void hvf_raise_exception(CPUState *cpu, uint32_t excp,
target/arm/hvf/trace-events +1 -0
index b29a995f3d3..538af6e0707 100644
@@ -12,3 +12,4 @@ hvf_psci_call(uint64_t x0, uint64_t x1, uint64_t x2, uint64_t x3, uint32_t cpuid
 hvf_vgic_write(const char *name, uint64_t val) "vgic write to %s [val=0x%016"PRIx64"]"
 hvf_vgic_read(const char *name, uint64_t val) "vgic read from %s [val=0x%016"PRIx64"]"
 hvf_illegal_guest_state(void) "HV_ILLEGAL_GUEST_STATE"
+hvf_kick_vcpu_thread(unsigned cpuidx, bool stop) "cpu:%u stop:%u"
Signature · 1 line
2.51.0
#5 lore raw

Re: [PATCH 02/24] target/arm/hvf: Check hv_vcpus_exit() returned value

Quoted 10 lines · Philippe Mathieu-Daudé

hv_vcpus_exit() returns a hv_return_t enum type (defined in <Hypervisor/hv_error.h>). Assert we succeeded, as we are not ready to handle any error path.

---
  target/arm/hvf/hvf.c        | 5 ++++-
  target/arm/hvf/trace-events | 1 +
  2 files changed, 5 insertions(+), 1 deletion(-)

Tracing change not mentioned in commit message.
Split to a separate patch?

r~

Quoted 27 lines
target/arm/hvf/hvf.c +4 -1
index d67372218de..65ac0bd71aa 100644
@@ -1086,8 +1086,11 @@ int hvf_arch_init_vcpu(CPUState *cpu)
 
  void hvf_kick_vcpu_thread(CPUState *cpu)
  {
+    hv_return_t ret;
+    trace_hvf_kick_vcpu_thread(cpu->cpu_index, cpu->stop);
      cpus_kick_thread(cpu);
-    hv_vcpus_exit(&cpu->accel->fd, 1);
+    ret = hv_vcpus_exit(&cpu->accel->fd, 1);
+    assert_hvf_ok(ret);
  }
 
  static void hvf_raise_exception(CPUState *cpu, uint32_t excp,
target/arm/hvf/trace-events +1 -0
index b29a995f3d3..538af6e0707 100644
@@ -12,3 +12,4 @@ hvf_psci_call(uint64_t x0, uint64_t x1, uint64_t x2, uint64_t x3, uint32_t cpuid
  hvf_vgic_write(const char *name, uint64_t val) "vgic write to %s [val=0x%016"PRIx64"]"
  hvf_vgic_read(const char *name, uint64_t val) "vgic read from %s [val=0x%016"PRIx64"]"
  hvf_illegal_guest_state(void) "HV_ILLEGAL_GUEST_STATE"
+hvf_kick_vcpu_thread(unsigned cpuidx, bool stop) "cpu:%u stop:%u"
Reviewed-by on v1 2/24
#6 lore raw

Re: [PATCH 02/24] target/arm/hvf: Check hv_vcpus_exit() returned value

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

hv_vcpus_exit() returns a hv_return_t enum type (defined in <Hypervisor/hv_error.h>). Assert we succeeded, as we are not ready to handle any error path.

Quoted 6 lines

---
target/arm/hvf/hvf.c | 5 ++++-
target/arm/hvf/trace-events | 1 +

2 files changed, 5 insertions(+), 1 deletion(-)
#7 lore raw

PATCH 3/24 target/arm/hvf: Check hv_vcpu_set_vtimer_mask() returned value

In reply to Philippe Mathieu-Daudé

hv_vcpu_set_vtimer_mask() returns a hv_return_t enum type (defined in <Hypervisor/hv_error.h>). Assert we succeeded, as we are not ready to handle any error path.

---
 target/arm/hvf/hvf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
target/arm/hvf/hvf.c +2 -1
index 65ac0bd71aa..1b59cc0eb04 100644
@@ -1906,7 +1906,8 @@ static void hvf_sync_vtimer(CPUState *cpu)
 
     if (!irq_state) {
         /* Timer no longer asserting, we can unmask it */
-        hv_vcpu_set_vtimer_mask(cpu->accel->fd, false);
+        r = hv_vcpu_set_vtimer_mask(cpu->accel->fd, false);
+        assert_hvf_ok(r);
         cpu->accel->vtimer_masked = false;
     }
 }
Signature · 1 line
2.51.0
Reviewed-by on v1 3/24
#8 lore raw

Re: [PATCH 03/24] target/arm/hvf: Check hv_vcpu_set_vtimer_mask() returned value

Quoted 14 lines · Philippe Mathieu-Daudé

hv_vcpu_set_vtimer_mask() returns a hv_return_t enum type (defined in <Hypervisor/hv_error.h>). Assert we succeeded, as we are not ready to handle any error path.

---
  target/arm/hvf/hvf.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
target/arm/hvf/hvf.c +0 -0
index 65ac0bd71aa..1b59cc0eb04 100644

target/arm/hvf/hvf.c static void hvf_sync_vtimer(CPUState *cpu) · line 1913

Quoted 9 lines
target/arm/hvf/hvf.c +2 -1
@@ -1906,7 +1906,8 @@ static void hvf_sync_vtimer(CPUState *cpu)
 
      if (!irq_state) {
          /* Timer no longer asserting, we can unmask it */
-        hv_vcpu_set_vtimer_mask(cpu->accel->fd, false);
+        r = hv_vcpu_set_vtimer_mask(cpu->accel->fd, false);
+        assert_hvf_ok(r);
          cpu->accel->vtimer_masked = false;
      }
  }

r~

Reviewed-by on v1 3/24
#9 lore raw

Re: [PATCH 03/24] target/arm/hvf: Check hv_vcpu_set_vtimer_mask() returned value

In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

hv_vcpu_set_vtimer_mask() returns a hv_return_t enum type (defined in <Hypervisor/hv_error.h>). Assert we succeeded, as we are not ready to handle any error path.

---
target/arm/hvf/hvf.c | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
#10 lore raw

PATCH 4/24 accel/hvf: Rename hvf_vcpu_exec() -> hvf_arch_vcpu_exec()

In reply to Philippe Mathieu-Daudé

hvf_vcpu_exec() is implemented per target, rename it as hvf_arch_vcpu_exec(), following the per target pattern.

Since it calls hv_vcpu_run(), mention it must be called on the vCPU.

---
 include/system/hvf_int.h  | 4 +++-
 accel/hvf/hvf-accel-ops.c | 2 +-
 target/arm/hvf/hvf.c      | 2 +-
 target/i386/hvf/hvf.c     | 2 +-
 4 files changed, 6 insertions(+), 4 deletions(-)
include/system/hvf_int.h +3 -1
index a3b06a3e75b..32b32e1d024 100644
@@ -73,12 +73,14 @@ int hvf_arch_init(void);
 hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range);
 int hvf_arch_init_vcpu(CPUState *cpu);
 void hvf_arch_vcpu_destroy(CPUState *cpu);
-int hvf_vcpu_exec(CPUState *);
 hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
 int hvf_put_registers(CPUState *);
 int hvf_get_registers(CPUState *);
 void hvf_kick_vcpu_thread(CPUState *cpu);
 
+/* Must be called by the owning thread */
+int hvf_arch_vcpu_exec(CPUState *);
+
 struct hvf_sw_breakpoint {
     vaddr pc;
     vaddr saved_insn;
accel/hvf/hvf-accel-ops.c +1 -1
index 4ba3e40831f..c1415b0949a 100644
@@ -194,7 +194,7 @@ static void *hvf_cpu_thread_fn(void *arg)
     do {
         qemu_wait_io_event(cpu);
         if (cpu_can_run(cpu)) {
-            r = hvf_vcpu_exec(cpu);
+            r = hvf_arch_vcpu_exec(cpu);
             if (r == EXCP_DEBUG) {
                 cpu_handle_guest_debug(cpu);
             }
target/arm/hvf/hvf.c +1 -1
index 1b59cc0eb04..7427ac240fb 100644
@@ -1912,7 +1912,7 @@ static void hvf_sync_vtimer(CPUState *cpu)
     }
 }
 
-int hvf_vcpu_exec(CPUState *cpu)
+int hvf_arch_vcpu_exec(CPUState *cpu)
 {
     ARMCPU *arm_cpu = ARM_CPU(cpu);
     CPUARMState *env = &arm_cpu->env;
target/i386/hvf/hvf.c +1 -1
index 8445cadecec..15f79e523e6 100644
@@ -721,7 +721,7 @@ void hvf_simulate_wrmsr(CPUState *cs)
     printf("write msr %llx\n", RCX(cs));*/
 }
 
-int hvf_vcpu_exec(CPUState *cpu)
+int hvf_arch_vcpu_exec(CPUState *cpu)
 {
     X86CPU *x86_cpu = X86_CPU(cpu);
     CPUX86State *env = &x86_cpu->env;
Signature · 1 line
2.51.0
Reviewed-by on v1 4/24
#11 lore raw

Re: [PATCH 04/24] accel/hvf: Rename hvf_vcpu_exec() -> hvf_arch_vcpu_exec()

Quoted 6 lines · Philippe Mathieu-Daudé

hvf_vcpu_exec() is implemented per target, rename it as hvf_arch_vcpu_exec(), following the per target pattern.

Since it calls hv_vcpu_run(), mention it must be called on the vCPU.

Quoted 7 lines
---
  include/system/hvf_int.h  | 4 +++-
  accel/hvf/hvf-accel-ops.c | 2 +-
  target/arm/hvf/hvf.c      | 2 +-
  target/i386/hvf/hvf.c     | 2 +-
  4 files changed, 6 insertions(+), 4 deletions(-)

r~

Reviewed-by on v1 4/24
#12 lore raw

Re: [PATCH 04/24] accel/hvf: Rename hvf_vcpu_exec() -> hvf_arch_vcpu_exec()

In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

hvf_vcpu_exec() is implemented per target, rename it as hvf_arch_vcpu_exec(), following the per target pattern.

Since it calls hv_vcpu_run(), mention it must be called on the vCPU.

Quoted 7 lines

---

include/system/hvf_int.h  | 4 +++-
accel/hvf/hvf-accel-ops.c | 2 +-
target/arm/hvf/hvf.c      | 2 +-
target/i386/hvf/hvf.c     | 2 +-
4 files changed, 6 insertions(+), 4 deletions(-)
#13 lore raw

PATCH 5/24 accel/hvf: Rename hvf_put|get_registers -> hvf_arch_put|get_registers

In reply to Philippe Mathieu-Daudé

hvf_put_registers() and hvf_get_registers() are implemented per target, rename them using the 'hvf_arch_' prefix following the per target pattern.

Since they call hv_vcpu_set_reg() / hv_vcpu_get_reg(), mention they must be called on the vCPU.

---
 include/system/hvf_int.h  | 6 ++++--
 accel/hvf/hvf-accel-ops.c | 2 +-
 target/arm/hvf/hvf.c      | 8 +++++---
 target/i386/hvf/hvf.c     | 2 +-
 target/i386/hvf/x86hvf.c  | 4 ++--
 5 files changed, 13 insertions(+), 9 deletions(-)
include/system/hvf_int.h +4 -2
index 32b32e1d024..8fce627b08c 100644
@@ -74,12 +74,14 @@ hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range);
 int hvf_arch_init_vcpu(CPUState *cpu);
 void hvf_arch_vcpu_destroy(CPUState *cpu);
 hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
-int hvf_put_registers(CPUState *);
-int hvf_get_registers(CPUState *);
 void hvf_kick_vcpu_thread(CPUState *cpu);
 
 /* Must be called by the owning thread */
 int hvf_arch_vcpu_exec(CPUState *);
+/* Must be called by the owning thread */
+int hvf_arch_put_registers(CPUState *);
+/* Must be called by the owning thread */
+int hvf_arch_get_registers(CPUState *);
 
 struct hvf_sw_breakpoint {
     vaddr pc;
accel/hvf/hvf-accel-ops.c +1 -1
index c1415b0949a..b6b7b462144 100644
@@ -81,7 +81,7 @@ hvf_slot *hvf_find_overlap_slot(uint64_t start, uint64_t size)
 static void do_hvf_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg)
 {
     if (!cpu->vcpu_dirty) {
-        hvf_get_registers(cpu);
+        hvf_arch_get_registers(cpu);
         cpu->vcpu_dirty = true;
     }
 }
target/arm/hvf/hvf.c +5 -3
index 7427ac240fb..21002f419f5 100644
@@ -549,7 +549,7 @@ static struct hvf_sreg_match hvf_sreg_match[] = {
     { HV_SYS_REG_SP_EL1, HVF_SYSREG(4, 1, 3, 4, 0) },
 };
 
-int hvf_get_registers(CPUState *cpu)
+int hvf_arch_get_registers(CPUState *cpu)
 {
     ARMCPU *arm_cpu = ARM_CPU(cpu);
     CPUARMState *env = &arm_cpu->env;
@@ -688,7 +688,7 @@ int hvf_get_registers(CPUState *cpu)
     return 0;
 }
 
-int hvf_put_registers(CPUState *cpu)
+int hvf_arch_put_registers(CPUState *cpu)
 {
     ARMCPU *arm_cpu = ARM_CPU(cpu);
     CPUARMState *env = &arm_cpu->env;
@@ -817,11 +817,12 @@ int hvf_put_registers(CPUState *cpu)
 static void flush_cpu_state(CPUState *cpu)
 {
     if (cpu->vcpu_dirty) {
-        hvf_put_registers(cpu);
+        hvf_arch_put_registers(cpu);
         cpu->vcpu_dirty = false;
     }
 }
 
+/* Must be called by the owning thread */
 static void hvf_set_reg(CPUState *cpu, int rt, uint64_t val)
 {
     hv_return_t r;
@@ -834,6 +835,7 @@ static void hvf_set_reg(CPUState *cpu, int rt, uint64_t val)
     }
 }
 
+/* Must be called by the owning thread */
 static uint64_t hvf_get_reg(CPUState *cpu, int rt)
 {
     uint64_t val = 0;
target/i386/hvf/hvf.c +1 -1
index 15f79e523e6..73c50175048 100644
@@ -734,7 +734,7 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
 
     do {
         if (cpu->vcpu_dirty) {
-            hvf_put_registers(cpu);
+            hvf_arch_put_registers(cpu);
             cpu->vcpu_dirty = false;
         }
 
target/i386/hvf/x86hvf.c +2 -2
index a502437c303..afcf737759b 100644
@@ -236,7 +236,7 @@ void hvf_get_msrs(CPUState *cs)
     env->tsc = rdtscp() + rvmcs(cs->accel->fd, VMCS_TSC_OFFSET);
 }
 
-int hvf_put_registers(CPUState *cs)
+int hvf_arch_put_registers(CPUState *cs)
 {
     X86CPU *x86cpu = X86_CPU(cs);
     CPUX86State *env = &x86cpu->env;
@@ -280,7 +280,7 @@ int hvf_put_registers(CPUState *cs)
     return 0;
 }
 
-int hvf_get_registers(CPUState *cs)
+int hvf_arch_get_registers(CPUState *cs)
 {
     X86CPU *x86cpu = X86_CPU(cs);
     CPUX86State *env = &x86cpu->env;
Signature · 1 line
2.51.0
Reviewed-by on v1 5/24
#14 lore raw

Re: [PATCH 05/24] accel/hvf: Rename hvf_put|get_registers -> hvf_arch_put|get_registers

Quoted 7 lines · Philippe Mathieu-Daudé

hvf_put_registers() and hvf_get_registers() are implemented per target, rename them using the 'hvf_arch_' prefix following the per target pattern.

Since they call hv_vcpu_set_reg() / hv_vcpu_get_reg(), mention they must be called on the vCPU.

Quoted 8 lines
---
  include/system/hvf_int.h  | 6 ++++--
  accel/hvf/hvf-accel-ops.c | 2 +-
  target/arm/hvf/hvf.c      | 8 +++++---
  target/i386/hvf/hvf.c     | 2 +-
  target/i386/hvf/x86hvf.c  | 4 ++--
  5 files changed, 13 insertions(+), 9 deletions(-)

r~

Reviewed-by on v1 5/24
#15 lore raw

Re: [PATCH 05/24] accel/hvf: Rename hvf_put|get_registers -> hvf_arch_put|get_registers

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

hvf_put_registers() and hvf_get_registers() are implemented per target, rename them using the 'hvf_arch_' prefix following the per target pattern.

Since they call hv_vcpu_set_reg() / hv_vcpu_get_reg(), mention they must be called on the vCPU.

Quoted 8 lines

---

include/system/hvf_int.h  | 6 ++++--
accel/hvf/hvf-accel-ops.c | 2 +-
target/arm/hvf/hvf.c      | 8 +++++---
target/i386/hvf/hvf.c     | 2 +-
target/i386/hvf/x86hvf.c  | 4 ++--
5 files changed, 13 insertions(+), 9 deletions(-)
#16 lore raw

PATCH 6/24 target/arm/hvf: Mention flush_cpu_state() must run on vCPU thread

In reply to Philippe Mathieu-Daudé

Since flush_cpu_state() calls hvf_arch_put_registers(), which must run on a vCPU, it also must. Mention it.

---
 target/arm/hvf/hvf.c | 1 +
 1 file changed, 1 insertion(+)
target/arm/hvf/hvf.c +1 -0
index 21002f419f5..58934953c4a 100644
@@ -814,6 +814,7 @@ int hvf_arch_put_registers(CPUState *cpu)
     return 0;
 }
 
+/* Must be called by the owning thread */
 static void flush_cpu_state(CPUState *cpu)
 {
     if (cpu->vcpu_dirty) {
Signature · 1 line
2.51.0
Reviewed-by on v1 6/24
#17 lore raw

Re: [PATCH 06/24] target/arm/hvf: Mention flush_cpu_state() must run on vCPU thread

Quoted 13 lines · Philippe Mathieu-Daudé

Since flush_cpu_state() calls hvf_arch_put_registers(), which must run on a vCPU, it also must. Mention it.

---
  target/arm/hvf/hvf.c | 1 +
  1 file changed, 1 insertion(+)
target/arm/hvf/hvf.c +0 -0
index 21002f419f5..58934953c4a 100644

target/arm/hvf/hvf.c int hvf_arch_put_registers(CPUState *cpu) · line 820

Quoted 7 lines
target/arm/hvf/hvf.c +1 -0
@@ -814,6 +814,7 @@ int hvf_arch_put_registers(CPUState *cpu)
      return 0;
  }
 
+/* Must be called by the owning thread */
  static void flush_cpu_state(CPUState *cpu)
  {
      if (cpu->vcpu_dirty) {

r~

Reviewed-by on v1 6/24
#18 lore raw

Re: [PATCH 06/24] target/arm/hvf: Mention flush_cpu_state() must run on vCPU thread

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

Since flush_cpu_state() calls hvf_arch_put_registers(), which must run on a vCPU, it also must. Mention it.

---
target/arm/hvf/hvf.c | 1 +

1 file changed, 1 insertion(+)
#19 lore raw

PATCH 7/24 accel/hvf: Mention hvf_arch_init_vcpu() must run on vCPU thread

In reply to Philippe Mathieu-Daudé

hvf_arch_init_vcpu(), along with hvf_put_guest_debug_registers() and hvf_put_gdbstub_debug_registers(), calls hv_vcpu_set_sys_reg(), which must run on a vCPU. Mention they also must.

---
 include/system/hvf_int.h | 3 ++-
 target/arm/hvf/hvf.c     | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)
include/system/hvf_int.h +2 -1
index 8fce627b08c..0c335facc3b 100644
@@ -71,11 +71,12 @@ void assert_hvf_ok_impl(hv_return_t ret, const char *file, unsigned int line,
 const char *hvf_return_string(hv_return_t ret);
 int hvf_arch_init(void);
 hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range);
-int hvf_arch_init_vcpu(CPUState *cpu);
 void hvf_arch_vcpu_destroy(CPUState *cpu);
 hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
 void hvf_kick_vcpu_thread(CPUState *cpu);
 
+/* Must be called by the owning thread */
+int hvf_arch_init_vcpu(CPUState *cpu);
 /* Must be called by the owning thread */
 int hvf_arch_vcpu_exec(CPUState *);
 /* Must be called by the owning thread */
target/arm/hvf/hvf.c +2 -0
index 58934953c4a..d87a41bcc53 100644
@@ -2244,6 +2244,7 @@ void hvf_arch_remove_all_hw_breakpoints(void)
  * consists of all hardware breakpoints and watchpoints inserted so far while
  * debugging the guest.
  */
+/* Must be called by the owning thread */
 static void hvf_put_gdbstub_debug_registers(CPUState *cpu)
 {
     hv_return_t r = HV_SUCCESS;
@@ -2282,6 +2283,7 @@ static void hvf_put_gdbstub_debug_registers(CPUState *cpu)
  * Update the vCPU with the guest's view of debug registers. This view is kept
  * in the environment at all times.
  */
+/* Must be called by the owning thread */
 static void hvf_put_guest_debug_registers(CPUState *cpu)
 {
     ARMCPU *arm_cpu = ARM_CPU(cpu);
Signature · 1 line
2.51.0
Reviewed-by on v1 7/24
#20 lore raw

Re: [PATCH 07/24] accel/hvf: Mention hvf_arch_init_vcpu() must run on vCPU thread

Quoted 9 lines · Philippe Mathieu-Daudé

hvf_arch_init_vcpu(), along with hvf_put_guest_debug_registers() and hvf_put_gdbstub_debug_registers(), calls hv_vcpu_set_sys_reg(), which must run on a vCPU. Mention they also must.

---
  include/system/hvf_int.h | 3 ++-
  target/arm/hvf/hvf.c     | 2 ++
  2 files changed, 4 insertions(+), 1 deletion(-)

r~

Reviewed-by on v1 7/24
#21 lore raw

Re: [PATCH 07/24] accel/hvf: Mention hvf_arch_init_vcpu() must run on vCPU thread

In reply to Philippe Mathieu-Daudé
Quoted 36 lines · Philippe Mathieu-Daudé

hvf_arch_init_vcpu(), along with hvf_put_guest_debug_registers() and hvf_put_gdbstub_debug_registers(), calls hv_vcpu_set_sys_reg(), which must run on a vCPU. Mention they also must.

---
include/system/hvf_int.h | 3 ++-
target/arm/hvf/hvf.c | 2 ++

2 files changed, 4 insertions(+), 1 deletion(-)
include/system/hvf_int.h +2 -1
index 8fce627b08c..0c335facc3b 100644
@@ -71,11 +71,12 @@ void assert_hvf_ok_impl(hv_return_t ret, const char *file, unsigned int line,
 const char *hvf_return_string(hv_return_t ret);
 int hvf_arch_init(void);
 hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range);
-int hvf_arch_init_vcpu(CPUState *cpu);
 void hvf_arch_vcpu_destroy(CPUState *cpu);
 hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
 void hvf_kick_vcpu_thread(CPUState *cpu);
 
+/* Must be called by the owning thread */
+int hvf_arch_init_vcpu(CPUState *cpu);
 /* Must be called by the owning thread */
 int hvf_arch_vcpu_exec(CPUState *);
 /* Must be called by the owning thread */
target/arm/hvf/hvf.c +0 -0
index 58934953c4a..d87a41bcc53 100644

target/arm/hvf/hvf.c void hvf_arch_remove_all_hw_breakpoints(void) · line 2247

Quoted 4 lines
target/arm/hvf/hvf.c +1 -0
@@ -2244,6 +2244,7 @@ void hvf_arch_remove_all_hw_breakpoints(void)
 * consists of all hardware breakpoints and watchpoints inserted so far while
 * debugging the guest.
 */
+/* Must be called by the owning thread */

Should this be combined with the comment block above it?

target/arm/hvf/hvf.c static void hvf_put_gdbstub_debug_registers(CPUState *cpu) · line 2286

Quoted 8 lines
target/arm/hvf/hvf.c +1 -0
 static void hvf_put_gdbstub_debug_registers(CPUState *cpu)
 {
   hv_return_t r = HV_SUCCESS;
@@ -2282,6 +2283,7 @@ static void hvf_put_gdbstub_debug_registers(CPUState *cpu)
 * Update the vCPU with the guest's view of debug registers. This view is kept
 * in the environment at all times.
 */
+/* Must be called by the owning thread */

Same here.

Quoted 6 lines
target/arm/hvf/hvf.c +0 -0
 static void hvf_put_guest_debug_registers(CPUState *cpu)
 {
   ARMCPU *arm_cpu = ARM_CPU(cpu);
Signature · 1 line
2.51.0

With or without the change:

#22 lore raw

PATCH 8/24 target/arm/hvf: Mention hvf_wfi() must run on vCPU thread

In reply to Philippe Mathieu-Daudé

Since hvf_wfi() calls hv_vcpu_get_sys_reg(), which must run on a vCPU, it also must. Mention it.

---
 target/arm/hvf/hvf.c | 1 +
 1 file changed, 1 insertion(+)
target/arm/hvf/hvf.c +1 -0
index d87a41bcc53..05fc591b523 100644
@@ -1836,6 +1836,7 @@ static void hvf_wait_for_ipi(CPUState *cpu, struct timespec *ts)
     bql_lock();
 }
 
+/* Must be called by the owning thread */
 static void hvf_wfi(CPUState *cpu)
 {
     ARMCPU *arm_cpu = ARM_CPU(cpu);
Signature · 1 line
2.51.0
#23 lore raw

Re: [PATCH 08/24] target/arm/hvf: Mention hvf_wfi() must run on vCPU thread

Quoted 13 lines · Philippe Mathieu-Daudé

Since hvf_wfi() calls hv_vcpu_get_sys_reg(), which must run on a vCPU, it also must. Mention it.

---
  target/arm/hvf/hvf.c | 1 +
  1 file changed, 1 insertion(+)
target/arm/hvf/hvf.c +0 -0
index d87a41bcc53..05fc591b523 100644

target/arm/hvf/hvf.c static void hvf_wait_for_ipi(CPUState *cpu, struct timespec *ts) · line 1842

Quoted 7 lines
target/arm/hvf/hvf.c +1 -0
@@ -1836,6 +1836,7 @@ static void hvf_wait_for_ipi(CPUState *cpu, struct timespec *ts)
      bql_lock();
  }
 
+/* Must be called by the owning thread */
  static void hvf_wfi(CPUState *cpu)
  {
      ARMCPU *arm_cpu = ARM_CPU(cpu);

How can it not? Are all these separate patches and annotations helpful?

r~

#24 lore raw

Re: [PATCH 08/24] target/arm/hvf: Mention hvf_wfi() must run on vCPU thread

Quoted 9 lines · Richard Henderson
Quoted 8 lines · Philippe Mathieu-Daudé

Since hvf_wfi() calls hv_vcpu_get_sys_reg(), which must run on a vCPU, it also must. Mention it.

---
  target/arm/hvf/hvf.c | 1 +

  1 file changed, 1 insertion(+)
Quoted 14 lines

target/arm/hvf/hvf.c static void hvf_wait_for_ipi(CPUState *cpu, · line 1842

Quoted 12 lines
target/arm/hvf/hvf.c +1 -0
index d87a41bcc53..05fc591b523 100644
@@ -1836,6 +1836,7 @@ static void hvf_wait_for_ipi(CPUState *cpu, 
 struct timespec *ts)
       bql_lock();
   }
+/* Must be called by the owning thread */
   static void hvf_wfi(CPUState *cpu)
   {
       ARMCPU *arm_cpu = ARM_CPU(cpu);

How can it not?  Are all these separate patches and annotations helpful?

Well they helped me understand the locking issue in patch 15 in hvf_arm_get_host_cpu_features().

#25 lore raw

Re: [PATCH 08/24] target/arm/hvf: Mention hvf_wfi() must run on vCPU thread

In reply to Richard Henderson
Quoted 24 lines · Richard Henderson
Quoted 11 lines · Philippe Mathieu-Daudé

Since hvf_wfi() calls hv_vcpu_get_sys_reg(), which must run on a vCPU, it also must. Mention it.

---
 target/arm/hvf/hvf.c | 1 +
 1 file changed, 1 insertion(+)
target/arm/hvf/hvf.c +0 -0
index d87a41bcc53..05fc591b523 100644

target/arm/hvf/hvf.c static void hvf_wait_for_ipi(CPUState *cpu, struct timespec *ts) · line 1841

Quoted 6 lines
target/arm/hvf/hvf.c +0 -0
@@ -1836,6 +1836,7 @@ static void hvf_wait_for_ipi(CPUState *cpu, struct timespec *ts)
     bql_lock();
 }
 +/* Must be called by the owning thread */
 static void hvf_wfi(CPUState *cpu)
 {
     ARMCPU *arm_cpu = ARM_CPU(cpu);

How can it not? Are all these separate patches and annotations helpful?

Quoted 1 line

r~

It's just part of Apple's API. It's documented here:
https://developer.apple.com/documentation/hypervisor/hv_vcpu_get_sys_reg(_:_:_:)?language=objc

If they are not called in the right CPU context, they'll return an error. I find it helpful to have it annotated here.

Reviewed-by on v1 8/24
#26 lore raw

Re: [PATCH 08/24] target/arm/hvf: Mention hvf_wfi() must run on vCPU thread

In reply to Philippe Mathieu-Daudé
Quoted 25 lines · Philippe Mathieu-Daudé

Since hvf_wfi() calls hv_vcpu_get_sys_reg(), which must run on a vCPU, it also must. Mention it.

---
target/arm/hvf/hvf.c | 1 +

1 file changed, 1 insertion(+)
target/arm/hvf/hvf.c +1 -0
index d87a41bcc53..05fc591b523 100644
@@ -1836,6 +1836,7 @@ static void hvf_wait_for_ipi(CPUState *cpu, struct timespec *ts)
    bql_lock();
 }
 
+/* Must be called by the owning thread */
 static void hvf_wfi(CPUState *cpu)
 {
    ARMCPU *arm_cpu = ARM_CPU(cpu);
Signature · 1 line
2.51.0
#27 lore raw

PATCH 9/24 target/arm/hvf: Mention hvf_sync_vtimer() must run on vCPU thread

In reply to Philippe Mathieu-Daudé

Since hvf_sync_vtimer() calls hv_vcpu_get_sys_reg(), which must run on a vCPU, it also must. Mention it.

---
 target/arm/hvf/hvf.c | 1 +
 1 file changed, 1 insertion(+)
target/arm/hvf/hvf.c +1 -0
index 05fc591b523..a7e4b869b04 100644
@@ -1889,6 +1889,7 @@ static void hvf_wfi(CPUState *cpu)
     hvf_wait_for_ipi(cpu, &ts);
 }
 
+/* Must be called by the owning thread */
 static void hvf_sync_vtimer(CPUState *cpu)
 {
     ARMCPU *arm_cpu = ARM_CPU(cpu);
Signature · 1 line
2.51.0
#29 lore raw

PATCH 10/24 target/arm/hvf: Mention hvf_arch_set_traps() must run on vCPU thread

In reply to Philippe Mathieu-Daudé

Since hvf_arch_set_traps() calls hv_vcpu_set_trap_debug_exceptions() and hv_vcpu_set_trap_debug_reg_accesses(), which must run on a vCPU, it also must. Mention it.

---
 target/arm/hvf/hvf.c | 1 +
 1 file changed, 1 insertion(+)
target/arm/hvf/hvf.c +1 -0
index a7e4b869b04..a9793060579 100644
@@ -2317,6 +2317,7 @@ static inline bool hvf_arm_hw_debug_active(CPUState *cpu)
     return ((cur_hw_wps > 0) || (cur_hw_bps > 0));
 }
 
+/* Must be called by the owning thread */
 static void hvf_arch_set_traps(CPUState *cpu)
 {
     bool should_enable_traps = false;
Signature · 1 line
2.51.0
Reviewed-by on v1 10/24
#30 lore raw

Re: [PATCH 10/24] target/arm/hvf: Mention hvf_arch_set_traps() must run on vCPU thread

Quoted 11 lines · Philippe Mathieu-Daudé

Since hvf_arch_set_traps() calls hv_vcpu_set_trap_debug_exceptions() and hv_vcpu_set_trap_debug_reg_accesses(), which must run on a vCPU, it also must. Mention it.

---
target/arm/hvf/hvf.c | 1 +

1 file changed, 1 insertion(+)
#31 lore raw

PATCH 11/24 accel/hvf: Mention hvf_arch_update_guest_debug() must run on vCPU

In reply to Philippe Mathieu-Daudé

Since hvf_arch_update_guest_debug() calls hvf_arch_set_traps() and hvf_arch_update_guest_debug(), which must run on a vCPU, it also must. Mention it.

---
 include/system/hvf_int.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/system/hvf_int.h +2 -1
index 0c335facc3b..241c668795e 100644
@@ -83,6 +83,8 @@ int hvf_arch_vcpu_exec(CPUState *);
 int hvf_arch_put_registers(CPUState *);
 /* Must be called by the owning thread */
 int hvf_arch_get_registers(CPUState *);
+/* Must be called by the owning thread */
+void hvf_arch_update_guest_debug(CPUState *cpu);
 
 struct hvf_sw_breakpoint {
     vaddr pc;
@@ -109,7 +111,6 @@ void hvf_arch_remove_all_hw_breakpoints(void);
  * handled by calling down to hvf_arch_update_guest_debug.
  */
 int hvf_update_guest_debug(CPUState *cpu);
-void hvf_arch_update_guest_debug(CPUState *cpu);
 
 /*
  * Return whether the guest supports debugging.
Signature · 1 line
2.51.0
Reviewed-by on v1 11/24
#32 lore raw

Re: [PATCH 11/24] accel/hvf: Mention hvf_arch_update_guest_debug() must run on vCPU

Quoted 11 lines · Philippe Mathieu-Daudé

Since hvf_arch_update_guest_debug() calls hvf_arch_set_traps() and hvf_arch_update_guest_debug(), which must run on a vCPU, it also must. Mention it.

---
include/system/hvf_int.h | 3 ++-

1 file changed, 2 insertions(+), 1 deletion(-)
#33 lore raw

PATCH 12/24 target/arm/hvf: Mention hvf_inject_interrupts() must run on vCPU thread

In reply to Philippe Mathieu-Daudé

Since hvf_inject_interrupts() calls hv_vcpu_set_pending_interrupt(), which must run on a vCPU, it also must. Mention it.

---
 target/arm/hvf/hvf.c | 1 +
 1 file changed, 1 insertion(+)
target/arm/hvf/hvf.c +1 -0
index a9793060579..4a535d65b7e 100644
@@ -1788,6 +1788,7 @@ static int hvf_sysreg_write(CPUState *cpu, uint32_t reg, uint64_t val)
     return 1;
 }
 
+/* Must be called by the owning thread */
 static int hvf_inject_interrupts(CPUState *cpu)
 {
     if (cpu_test_interrupt(cpu, CPU_INTERRUPT_FIQ)) {
Signature · 1 line
2.51.0
Reviewed-by on v1 12/24
#34 lore raw

Re: [PATCH 12/24] target/arm/hvf: Mention hvf_inject_interrupts() must run on vCPU thread

Quoted 10 lines · Philippe Mathieu-Daudé

Since hvf_inject_interrupts() calls hv_vcpu_set_pending_interrupt(), which must run on a vCPU, it also must. Mention it.

---
target/arm/hvf/hvf.c | 1 +

1 file changed, 1 insertion(+)
#35 lore raw

PATCH 13/24 accel/hvf: Implement hvf_arch_vcpu_destroy()

In reply to Philippe Mathieu-Daudé

Call hv_vcpu_destroy() to destroy our vCPU context.

As hv_vcpu_destroy() must be called by the owning thread, document hvf_arch_vcpu_destroy() also does.

---
 include/system/hvf_int.h | 3 ++-
 target/arm/hvf/hvf.c     | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)
include/system/hvf_int.h +2 -1
index 241c668795e..195d64dcf18 100644
@@ -71,13 +71,14 @@ void assert_hvf_ok_impl(hv_return_t ret, const char *file, unsigned int line,
 const char *hvf_return_string(hv_return_t ret);
 int hvf_arch_init(void);
 hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range);
-void hvf_arch_vcpu_destroy(CPUState *cpu);
 hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
 void hvf_kick_vcpu_thread(CPUState *cpu);
 
 /* Must be called by the owning thread */
 int hvf_arch_init_vcpu(CPUState *cpu);
 /* Must be called by the owning thread */
+void hvf_arch_vcpu_destroy(CPUState *cpu);
+/* Must be called by the owning thread */
 int hvf_arch_vcpu_exec(CPUState *);
 /* Must be called by the owning thread */
 int hvf_arch_put_registers(CPUState *);
target/arm/hvf/hvf.c +4 -0
index 4a535d65b7e..5b3c34014a5 100644
@@ -992,6 +992,10 @@ void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu)
 
 void hvf_arch_vcpu_destroy(CPUState *cpu)
 {
+    hv_return_t ret;
+
+    ret = hv_vcpu_destroy(cpu->accel->fd);
+    assert_hvf_ok(ret);
 }
 
 hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range)
Signature · 1 line
2.51.0
Reviewed-by on v1 13/24
#36 lore raw

Re: [PATCH 13/24] accel/hvf: Implement hvf_arch_vcpu_destroy()

Quoted 10 lines · Philippe Mathieu-Daudé

Call hv_vcpu_destroy() to destroy our vCPU context.

As hv_vcpu_destroy() must be called by the owning thread, document hvf_arch_vcpu_destroy() also does.

---
  include/system/hvf_int.h | 3 ++-
  target/arm/hvf/hvf.c     | 4 ++++
  2 files changed, 6 insertions(+), 1 deletion(-)

r~

Reviewed-by on v1 13/24
#37 lore raw

Re: [PATCH 13/24] accel/hvf: Implement hvf_arch_vcpu_destroy()

In reply to Philippe Mathieu-Daudé
Quoted 39 lines · Philippe Mathieu-Daudé

Call hv_vcpu_destroy() to destroy our vCPU context.

As hv_vcpu_destroy() must be called by the owning thread, document hvf_arch_vcpu_destroy() also does.

---
include/system/hvf_int.h | 3 ++-
target/arm/hvf/hvf.c | 4 ++++

2 files changed, 6 insertions(+), 1 deletion(-)
include/system/hvf_int.h +2 -1
index 241c668795e..195d64dcf18 100644
@@ -71,13 +71,14 @@ void assert_hvf_ok_impl(hv_return_t ret, const char *file, unsigned int line,
 const char *hvf_return_string(hv_return_t ret);
 int hvf_arch_init(void);
 hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range);
-void hvf_arch_vcpu_destroy(CPUState *cpu);
 hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
 void hvf_kick_vcpu_thread(CPUState *cpu);
 
 /* Must be called by the owning thread */
 int hvf_arch_init_vcpu(CPUState *cpu);
 /* Must be called by the owning thread */
+void hvf_arch_vcpu_destroy(CPUState *cpu);
+/* Must be called by the owning thread */
 int hvf_arch_vcpu_exec(CPUState *);
 /* Must be called by the owning thread */
 int hvf_arch_put_registers(CPUState *);
target/arm/hvf/hvf.c +0 -0
index 4a535d65b7e..5b3c34014a5 100644

target/arm/hvf/hvf.c void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu) · line 998

Quoted 7 lines
target/arm/hvf/hvf.c +4 -0
@@ -992,6 +992,10 @@ void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu)
 
 void hvf_arch_vcpu_destroy(CPUState *cpu)
 {
+    hv_return_t ret;
+
+    ret = hv_vcpu_destroy(cpu->accel->fd);
+    assert_hvf_ok(ret);

Interesting that this was missing. I can see x86 is missing it too.

Quoted 6 lines
target/arm/hvf/hvf.c +0 -0
 }
 
 hv_return_t hvf_arch_vm_create(MachineState *ms, uint32_t pa_range)
Signature · 1 line
2.51.0
#38 lore raw

PATCH 14/24 target/arm/hvf: Hardcode Apple MIDR

In reply to Philippe Mathieu-Daudé

From: Mohamed Mediouni <[email protected]>

Hardcode MIDR because Apple deliberately doesn't expose a divergent MIDR across systems.

---
 target/arm/hvf/hvf.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
target/arm/hvf/hvf.c +12 -0
index 5b3c34014a5..3039c0987dc 100644
@@ -887,6 +887,7 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
     hv_vcpu_t fd;
     hv_return_t r = HV_SUCCESS;
     hv_vcpu_exit_t *exit;
+    uint64_t t;
     int i;
 
     ahcf->dtb_compatible = "arm,armv8";
@@ -908,6 +909,17 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
     r |= hv_vcpu_get_sys_reg(fd, HV_SYS_REG_MIDR_EL1, &ahcf->midr);
     r |= hv_vcpu_destroy(fd);
 
+    /*
+     * Hardcode MIDR because Apple deliberately doesn't expose a divergent
+     * MIDR across systems.
+     */
+    t = FIELD_DP64(0, MIDR_EL1, IMPLEMENTER, 0x61); /* Apple */
+    t = FIELD_DP64(t, MIDR_EL1, ARCHITECTURE, 0xf); /* v7 or later */
+    t = FIELD_DP64(t, MIDR_EL1, PARTNUM, 0);
+    t = FIELD_DP64(t, MIDR_EL1, VARIANT, 0);
+    t = FIELD_DP64(t, MIDR_EL1, REVISION, 0);
+    ahcf->midr = t;
+
     clamp_id_aa64mmfr0_parange_to_ipa_size(&host_isar);
 
     /*
Signature · 1 line
2.51.0
Reviewed-by on v1 14/24
#39 lore raw

Re: [PATCH 14/24] target/arm/hvf: Hardcode Apple MIDR

Quoted 10 lines · Philippe Mathieu-Daudé

From: Mohamed Mediouni<[email protected]>

Hardcode MIDR because Apple deliberately doesn't expose a divergent MIDR across systems.

---
  target/arm/hvf/hvf.c | 12 ++++++++++++
  1 file changed, 12 insertions(+)

r~

#40 lore raw

Re: [PATCH 14/24] target/arm/hvf: Hardcode Apple MIDR

In reply to Philippe Mathieu-Daudé
Quoted 27 lines · Philippe Mathieu-Daudé

From: Mohamed Mediouni <[email protected]>

Hardcode MIDR because Apple deliberately doesn't expose a divergent MIDR across systems.

---
target/arm/hvf/hvf.c | 12 ++++++++++++

1 file changed, 12 insertions(+)
target/arm/hvf/hvf.c +1 -0
index 5b3c34014a5..3039c0987dc 100644
@@ -887,6 +887,7 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
    hv_vcpu_t fd;
    hv_return_t r = HV_SUCCESS;
    hv_vcpu_exit_t *exit;
+    uint64_t t;
    int i;
 
    ahcf->dtb_compatible = "arm,armv8";

target/arm/hvf/hvf.c static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) · line 909

Quoted 1 line
target/arm/hvf/hvf.c +0 -0
@@ -908,6 +909,17 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
    r |= hv_vcpu_get_sys_reg(fd, HV_SYS_REG_MIDR_EL1, &ahcf->midr);

This line above seems redundant, if we override it in the following.

Quoted 19 lines
target/arm/hvf/hvf.c +11 -0
    r |= hv_vcpu_destroy(fd);
 
+    /*
+     * Hardcode MIDR because Apple deliberately doesn't expose a divergent
+     * MIDR across systems.
+     */
+    t = FIELD_DP64(0, MIDR_EL1, IMPLEMENTER, 0x61); /* Apple */
+    t = FIELD_DP64(t, MIDR_EL1, ARCHITECTURE, 0xf); /* v7 or later */
+    t = FIELD_DP64(t, MIDR_EL1, PARTNUM, 0);
+    t = FIELD_DP64(t, MIDR_EL1, VARIANT, 0);
+    t = FIELD_DP64(t, MIDR_EL1, REVISION, 0);
+    ahcf->midr = t;
+
    clamp_id_aa64mmfr0_parange_to_ipa_size(&host_isar);
 
    /*
Signature · 1 line
2.51.0
#41 lore raw

PATCH 15/24 target/arm/hvf: switch hvf_arm_get_host_cpu_features to not create a vCPU

In reply to Philippe Mathieu-Daudé

From: Mohamed Mediouni <[email protected]>

Creating a vCPU locks out APIs such as hv_gic_create().

As a result, switch to using the hv_vcpu_config_get_feature_reg interface.

Besides, all the following methods must be run on a vCPU thread:

- hv_vcpu_create()
- hv_vcpu_get_sys_reg()
- hv_vcpu_destroy()

Message-ID: <[email protected]>

[PMD: Release config calling os_release()]
---
 target/arm/hvf/hvf.c | 36 +++++++++++++++---------------------
 1 file changed, 15 insertions(+), 21 deletions(-)
target/arm/hvf/hvf.c +15 -21
index 3039c0987dc..fd209d23c1e 100644
@@ -869,24 +869,25 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
 {
     ARMISARegisters host_isar = {};
     const struct isar_regs {
-        int reg;
+        hv_feature_reg_t reg;
         uint64_t *val;
     } regs[] = {
-        { HV_SYS_REG_ID_AA64PFR0_EL1, &host_isar.idregs[ID_AA64PFR0_EL1_IDX] },
-        { HV_SYS_REG_ID_AA64PFR1_EL1, &host_isar.idregs[ID_AA64PFR1_EL1_IDX] },
-        { HV_SYS_REG_ID_AA64DFR0_EL1, &host_isar.idregs[ID_AA64DFR0_EL1_IDX] },
-        { HV_SYS_REG_ID_AA64DFR1_EL1, &host_isar.idregs[ID_AA64DFR1_EL1_IDX] },
-        { HV_SYS_REG_ID_AA64ISAR0_EL1, &host_isar.idregs[ID_AA64ISAR0_EL1_IDX] },
-        { HV_SYS_REG_ID_AA64ISAR1_EL1, &host_isar.idregs[ID_AA64ISAR1_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64PFR0_EL1, &host_isar.idregs[ID_AA64PFR0_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64PFR1_EL1, &host_isar.idregs[ID_AA64PFR1_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64DFR0_EL1, &host_isar.idregs[ID_AA64DFR0_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64DFR1_EL1, &host_isar.idregs[ID_AA64DFR1_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64ISAR0_EL1, &host_isar.idregs[ID_AA64ISAR0_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64ISAR1_EL1, &host_isar.idregs[ID_AA64ISAR1_EL1_IDX] },
         /* Add ID_AA64ISAR2_EL1 here when HVF supports it */
-        { HV_SYS_REG_ID_AA64MMFR0_EL1, &host_isar.idregs[ID_AA64MMFR0_EL1_IDX] },
-        { HV_SYS_REG_ID_AA64MMFR1_EL1, &host_isar.idregs[ID_AA64MMFR1_EL1_IDX] },
-        { HV_SYS_REG_ID_AA64MMFR2_EL1, &host_isar.idregs[ID_AA64MMFR2_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64MMFR0_EL1, &host_isar.idregs[ID_AA64MMFR0_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64MMFR1_EL1, &host_isar.idregs[ID_AA64MMFR1_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64MMFR2_EL1, &host_isar.idregs[ID_AA64MMFR2_EL1_IDX] },
         /* Add ID_AA64MMFR3_EL1 here when HVF supports it */
+        { HV_FEATURE_REG_CTR_EL0, &host_isar.idregs[CTR_EL0_IDX] },
+        { HV_FEATURE_REG_CLIDR_EL1, &host_isar.idregs[CLIDR_EL1_IDX] },
     };
-    hv_vcpu_t fd;
     hv_return_t r = HV_SUCCESS;
-    hv_vcpu_exit_t *exit;
+    hv_vcpu_config_t config = hv_vcpu_config_create();
     uint64_t t;
     int i;
 
@@ -897,17 +898,10 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
                      (1ULL << ARM_FEATURE_PMU) |
                      (1ULL << ARM_FEATURE_GENERIC_TIMER);
 
-    /* We set up a small vcpu to extract host registers */
-
-    if (hv_vcpu_create(&fd, &exit, NULL) != HV_SUCCESS) {
-        return false;
-    }
-
     for (i = 0; i < ARRAY_SIZE(regs); i++) {
-        r |= hv_vcpu_get_sys_reg(fd, regs[i].reg, regs[i].val);
+        r |= hv_vcpu_config_get_feature_reg(config, regs[i].reg, regs[i].val);
     }
-    r |= hv_vcpu_get_sys_reg(fd, HV_SYS_REG_MIDR_EL1, &ahcf->midr);
-    r |= hv_vcpu_destroy(fd);
+    os_release(config);
 
     /*
      * Hardcode MIDR because Apple deliberately doesn't expose a divergent
Signature · 1 line
2.51.0
#42 lore raw

Re: [PATCH 15/24] target/arm/hvf: switch hvf_arm_get_host_cpu_features to not create a vCPU

Quoted 46 lines · Philippe Mathieu-Daudé

From: Mohamed Mediouni <[email protected]>

Creating a vCPU locks out APIs such as hv_gic_create().

As a result, switch to using the hv_vcpu_config_get_feature_reg interface.

Besides, all the following methods must be run on a vCPU thread:

- hv_vcpu_create()
- hv_vcpu_get_sys_reg()
- hv_vcpu_destroy()

Message-ID: <[email protected]>

[PMD: Release config calling os_release()]
---
  target/arm/hvf/hvf.c | 36 +++++++++++++++---------------------
  1 file changed, 15 insertions(+), 21 deletions(-)
target/arm/hvf/hvf.c +7 -7
index 3039c0987dc..fd209d23c1e 100644
@@ -869,24 +869,25 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
  {
      ARMISARegisters host_isar = {};
      const struct isar_regs {
-        int reg;
+        hv_feature_reg_t reg;
          uint64_t *val;
      } regs[] = {
-        { HV_SYS_REG_ID_AA64PFR0_EL1, &host_isar.idregs[ID_AA64PFR0_EL1_IDX] },
-        { HV_SYS_REG_ID_AA64PFR1_EL1, &host_isar.idregs[ID_AA64PFR1_EL1_IDX] },
-        { HV_SYS_REG_ID_AA64DFR0_EL1, &host_isar.idregs[ID_AA64DFR0_EL1_IDX] },
-        { HV_SYS_REG_ID_AA64DFR1_EL1, &host_isar.idregs[ID_AA64DFR1_EL1_IDX] },
-        { HV_SYS_REG_ID_AA64ISAR0_EL1, &host_isar.idregs[ID_AA64ISAR0_EL1_IDX] },
-        { HV_SYS_REG_ID_AA64ISAR1_EL1, &host_isar.idregs[ID_AA64ISAR1_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64PFR0_EL1, &host_isar.idregs[ID_AA64PFR0_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64PFR1_EL1, &host_isar.idregs[ID_AA64PFR1_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64DFR0_EL1, &host_isar.idregs[ID_AA64DFR0_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64DFR1_EL1, &host_isar.idregs[ID_AA64DFR1_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64ISAR0_EL1, &host_isar.idregs[ID_AA64ISAR0_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64ISAR1_EL1, &host_isar.idregs[ID_AA64ISAR1_EL1_IDX] },

target/arm/hvf/hvf.c static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) · line 887

Quoted 10 lines
target/arm/hvf/hvf.c +5 -3
          /* Add ID_AA64ISAR2_EL1 here when HVF supports it */
-        { HV_SYS_REG_ID_AA64MMFR0_EL1, &host_isar.idregs[ID_AA64MMFR0_EL1_IDX] },
-        { HV_SYS_REG_ID_AA64MMFR1_EL1, &host_isar.idregs[ID_AA64MMFR1_EL1_IDX] },
-        { HV_SYS_REG_ID_AA64MMFR2_EL1, &host_isar.idregs[ID_AA64MMFR2_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64MMFR0_EL1, &host_isar.idregs[ID_AA64MMFR0_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64MMFR1_EL1, &host_isar.idregs[ID_AA64MMFR1_EL1_IDX] },
+        { HV_FEATURE_REG_ID_AA64MMFR2_EL1, &host_isar.idregs[ID_AA64MMFR2_EL1_IDX] },
          /* Add ID_AA64MMFR3_EL1 here when HVF supports it */
+        { HV_FEATURE_REG_CTR_EL0, &host_isar.idregs[CTR_EL0_IDX] },
+        { HV_FEATURE_REG_CLIDR_EL1, &host_isar.idregs[CLIDR_EL1_IDX] },

I'd rather add the 2 last ones in a distinct patch, keeping this one as a simple API conversion.

Quoted 28 lines
target/arm/hvf/hvf.c +3 -11
      };
-    hv_vcpu_t fd;
      hv_return_t r = HV_SUCCESS;
-    hv_vcpu_exit_t *exit;
+    hv_vcpu_config_t config = hv_vcpu_config_create();
      uint64_t t;
      int i;
 
@@ -897,17 +898,10 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
                       (1ULL << ARM_FEATURE_PMU) |
                       (1ULL << ARM_FEATURE_GENERIC_TIMER);
 
-    /* We set up a small vcpu to extract host registers */
-
-    if (hv_vcpu_create(&fd, &exit, NULL) != HV_SUCCESS) {
-        return false;
-    }
-
      for (i = 0; i < ARRAY_SIZE(regs); i++) {
-        r |= hv_vcpu_get_sys_reg(fd, regs[i].reg, regs[i].val);
+        r |= hv_vcpu_config_get_feature_reg(config, regs[i].reg, regs[i].val);
      }
-    r |= hv_vcpu_get_sys_reg(fd, HV_SYS_REG_MIDR_EL1, &ahcf->midr);
-    r |= hv_vcpu_destroy(fd);
+    os_release(config);
 
      /*
       * Hardcode MIDR because Apple deliberately doesn't expose a divergent
#43 lore raw

Re: [PATCH 15/24] target/arm/hvf: switch hvf_arm_get_host_cpu_features to not create a vCPU

In reply to Philippe Mathieu-Daudé

target/arm/hvf/hvf.c static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) · line 875

Quoted 13 lines · Philippe Mathieu-Daudé
target/arm/hvf/hvf.c +1 -2
index 3039c0987dc..fd209d23c1e 100644
@@ -869,24 +869,25 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
  {
      ARMISARegisters host_isar = {};
      const struct isar_regs {
-        int reg;
+        hv_feature_reg_t reg;
          uint64_t *val;
      } regs[] = {
-        { HV_SYS_REG_ID_AA64PFR0_EL1, &host_isar.idregs[ID_AA64PFR0_EL1_IDX] },

Versus the original, I suggested that this should be

	{ HV_SYS_REG_ID_AA64PFR0_EL1, ID_AA64PFR0_EL1_IDX },

etc, so that the data structure could be static const.

r~

#44 lore raw

Re: [PATCH 15/24] target/arm/hvf: switch hvf_arm_get_host_cpu_features to not create a vCPU

Quoted 19 lines · Richard Henderson
Quoted 5 lines · Philippe Mathieu-Daudé
target/arm/hvf/hvf.c +0 -0
index 3039c0987dc..fd209d23c1e 100644

target/arm/hvf/hvf.c static bool · line 876

Quoted 10 lines
target/arm/hvf/hvf.c +1 -2
@@ -869,24 +869,25 @@ static bool 
 hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
   {
       ARMISARegisters host_isar = {};
       const struct isar_regs {
-        int reg;
+        hv_feature_reg_t reg;
           uint64_t *val;
       } regs[] = {
-        { HV_SYS_REG_ID_AA64PFR0_EL1, 
 &host_isar.idregs[ID_AA64PFR0_EL1_IDX] },

Versus the original, I suggested that this should be

Quoted 3 lines

    { HV_SYS_REG_ID_AA64PFR0_EL1, ID_AA64PFR0_EL1_IDX },

etc, so that the data structure could be static const.

Sorry I missed the comment. Good idea!

#45 lore raw

PATCH 16/24 target/arm/hvf: Factor hvf_handle_exception() out

In reply to Philippe Mathieu-Daudé

Factor hvf_handle_exception() out of hvf_vcpu_exec().

---
 target/arm/hvf/hvf.c | 120 +++++++++++++++++++++++--------------------
 1 file changed, 64 insertions(+), 56 deletions(-)
target/arm/hvf/hvf.c +64 -56
index fd209d23c1e..3db0a8e288c 100644
@@ -1928,61 +1928,16 @@ static void hvf_sync_vtimer(CPUState *cpu)
     }
 }
 
-int hvf_arch_vcpu_exec(CPUState *cpu)
+/* Must be called by the owning thread */
+static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp)
 {
     ARMCPU *arm_cpu = ARM_CPU(cpu);
     CPUARMState *env = &arm_cpu->env;
-    int ret;
-    hv_vcpu_exit_t *hvf_exit = cpu->accel->exit;
-    hv_return_t r;
-    bool advance_pc = false;
-
-    if (!(cpu->singlestep_enabled & SSTEP_NOIRQ) &&
-        hvf_inject_interrupts(cpu)) {
-        return EXCP_INTERRUPT;
-    }
-
-    if (cpu->halted) {
-        return EXCP_HLT;
-    }
-
-    flush_cpu_state(cpu);
-
-    bql_unlock();
-    r = hv_vcpu_run(cpu->accel->fd);
-    bql_lock();
-    switch (r) {
-    case HV_SUCCESS:
-        break;
-    case HV_ILLEGAL_GUEST_STATE:
-        trace_hvf_illegal_guest_state();
-        /* fall through */
-    default:
-        g_assert_not_reached();
-    }
-
-    /* handle VMEXIT */
-    uint64_t exit_reason = hvf_exit->reason;
-    uint64_t syndrome = hvf_exit->exception.syndrome;
+    uint64_t syndrome = excp->syndrome;
     uint32_t ec = syn_get_ec(syndrome);
-
-    ret = 0;
-    switch (exit_reason) {
-    case HV_EXIT_REASON_EXCEPTION:
-        /* This is the main one, handle below. */
-        break;
-    case HV_EXIT_REASON_VTIMER_ACTIVATED:
-        qemu_set_irq(arm_cpu->gt_timer_outputs[GTIMER_VIRT], 1);
-        cpu->accel->vtimer_masked = true;
-        return 0;
-    case HV_EXIT_REASON_CANCELED:
-        /* we got kicked, no exit to process */
-        return 0;
-    default:
-        g_assert_not_reached();
-    }
-
-    hvf_sync_vtimer(cpu);
+    bool advance_pc = false;
+    hv_return_t r;
+    int ret = 0;
 
     switch (ec) {
     case EC_SOFTWARESTEP: {
@@ -2021,7 +1976,7 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
         cpu_synchronize_state(cpu);
 
         CPUWatchpoint *wp =
-            find_hw_watchpoint(cpu, hvf_exit->exception.virtual_address);
+            find_hw_watchpoint(cpu, excp->virtual_address);
         if (!wp) {
             error_report("EXCP_DEBUG but unknown hw watchpoint");
         }
@@ -2039,8 +1994,8 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
         uint32_t cm = (syndrome >> 8) & 0x1;
         uint64_t val = 0;
 
-        trace_hvf_data_abort(hvf_exit->exception.virtual_address,
-                             hvf_exit->exception.physical_address, isv,
+        trace_hvf_data_abort(excp->virtual_address,
+                             excp->physical_address, isv,
                              iswrite, s1ptw, len, srt);
 
         if (cm) {
@@ -2054,11 +2009,11 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
         if (iswrite) {
             val = hvf_get_reg(cpu, srt);
             address_space_write(&address_space_memory,
-                                hvf_exit->exception.physical_address,
+                                excp->physical_address,
                                 MEMTXATTRS_UNSPECIFIED, &val, len);
         } else {
             address_space_read(&address_space_memory,
-                               hvf_exit->exception.physical_address,
+                               excp->physical_address,
                                MEMTXATTRS_UNSPECIFIED, &val, len);
             if (sse) {
                 val = sextract64(val, 0, len * 8);
@@ -2156,6 +2111,59 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
     return ret;
 }
 
+int hvf_arch_vcpu_exec(CPUState *cpu)
+{
+    ARMCPU *arm_cpu = ARM_CPU(cpu);
+    hv_vcpu_exit_t *hvf_exit = cpu->accel->exit;
+    hv_return_t r;
+
+    if (!(cpu->singlestep_enabled & SSTEP_NOIRQ) &&
+        hvf_inject_interrupts(cpu)) {
+        return EXCP_INTERRUPT;
+    }
+
+    if (cpu->halted) {
+        return EXCP_HLT;
+    }
+
+    flush_cpu_state(cpu);
+
+    bql_unlock();
+    r = hv_vcpu_run(cpu->accel->fd);
+    bql_lock();
+    switch (r) {
+    case HV_SUCCESS:
+        break;
+    case HV_ILLEGAL_GUEST_STATE:
+        trace_hvf_illegal_guest_state();
+        /* fall through */
+    default:
+        g_assert_not_reached();
+    }
+
+    /* handle VMEXIT */
+    uint64_t exit_reason = hvf_exit->reason;
+
+    switch (exit_reason) {
+    case HV_EXIT_REASON_EXCEPTION:
+        /* This is the main one, handle below. */
+        break;
+    case HV_EXIT_REASON_VTIMER_ACTIVATED:
+        qemu_set_irq(arm_cpu->gt_timer_outputs[GTIMER_VIRT], 1);
+        cpu->accel->vtimer_masked = true;
+        return 0;
+    case HV_EXIT_REASON_CANCELED:
+        /* we got kicked, no exit to process */
+        return 0;
+    default:
+        g_assert_not_reached();
+    }
+
+    hvf_sync_vtimer(cpu);
+
+    return hvf_handle_exception(cpu, &hvf_exit->exception);
+}
+
 static const VMStateDescription vmstate_hvf_vtimer = {
     .name = "hvf-vtimer",
     .version_id = 1,
Signature · 1 line
2.51.0
#46 lore raw

Re: [PATCH 16/24] target/arm/hvf: Factor hvf_handle_exception() out

Quoted 1 line · Philippe Mathieu-Daudé

+/* Must be called by the owning thread */

How could it not?

Quoted 3 lines

+static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp)

  {
      ARMCPU *arm_cpu = ARM_CPU(cpu);

...

target/arm/hvf/hvf.c int hvf_arch_vcpu_exec(CPUState *cpu) · line 2116

Quoted 3 lines
target/arm/hvf/hvf.c +3 -0
+int hvf_arch_vcpu_exec(CPUState *cpu)
+{
+    ARMCPU *arm_cpu = ARM_CPU(cpu);

Don't dynamic cast twice.
Pass down the ARMCPU, or use env_archcpu(cpu_env(cpu)).

r~

Reviewed-by on v1 16/24
#47 lore raw

Re: [PATCH 16/24] target/arm/hvf: Factor hvf_handle_exception() out

In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

Factor hvf_handle_exception() out of hvf_vcpu_exec().

---
target/arm/hvf/hvf.c | 120 +++++++++++++++++++++++--------------------

1 file changed, 64 insertions(+), 56 deletions(-)

Good idea.

With Richard's change to not cast twice:

#48 lore raw

PATCH 17/24 target/arm/hvf: Factor hvf_handle_vmexit() out

In reply to Philippe Mathieu-Daudé

Factor hvf_handle_vmexit() out of hvf_vcpu_exec().

---
 target/arm/hvf/hvf.c | 51 ++++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 23 deletions(-)
target/arm/hvf/hvf.c +28 -23
index 3db0a8e288c..0cfe3066c23 100644
@@ -2111,10 +2111,34 @@ static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp)
     return ret;
 }
 
-int hvf_arch_vcpu_exec(CPUState *cpu)
+/* Must be called by the owning thread */
+static int hvf_handle_vmexit(CPUState *cpu, hv_vcpu_exit_t *exit)
 {
     ARMCPU *arm_cpu = ARM_CPU(cpu);
-    hv_vcpu_exit_t *hvf_exit = cpu->accel->exit;
+    int ret = 0;
+
+    switch (exit->reason) {
+    case HV_EXIT_REASON_EXCEPTION:
+        hvf_sync_vtimer(cpu);
+        ret = hvf_handle_exception(cpu, &exit->exception);
+        break;
+    case HV_EXIT_REASON_VTIMER_ACTIVATED:
+        qemu_set_irq(arm_cpu->gt_timer_outputs[GTIMER_VIRT], 1);
+        cpu->accel->vtimer_masked = true;
+        break;
+    case HV_EXIT_REASON_CANCELED:
+        /* we got kicked, no exit to process */
+        break;
+    default:
+        g_assert_not_reached();
+    }
+
+    return ret;
+}
+
+int hvf_arch_vcpu_exec(CPUState *cpu)
+{
+    int ret;
     hv_return_t r;
 
     if (!(cpu->singlestep_enabled & SSTEP_NOIRQ) &&
@@ -2133,6 +2157,7 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
     bql_lock();
     switch (r) {
     case HV_SUCCESS:
+        ret = hvf_handle_vmexit(cpu, cpu->accel->exit);
         break;
     case HV_ILLEGAL_GUEST_STATE:
         trace_hvf_illegal_guest_state();
@@ -2141,27 +2166,7 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
         g_assert_not_reached();
     }
 
-    /* handle VMEXIT */
-    uint64_t exit_reason = hvf_exit->reason;
-
-    switch (exit_reason) {
-    case HV_EXIT_REASON_EXCEPTION:
-        /* This is the main one, handle below. */
-        break;
-    case HV_EXIT_REASON_VTIMER_ACTIVATED:
-        qemu_set_irq(arm_cpu->gt_timer_outputs[GTIMER_VIRT], 1);
-        cpu->accel->vtimer_masked = true;
-        return 0;
-    case HV_EXIT_REASON_CANCELED:
-        /* we got kicked, no exit to process */
-        return 0;
-    default:
-        g_assert_not_reached();
-    }
-
-    hvf_sync_vtimer(cpu);
-
-    return hvf_handle_exception(cpu, &hvf_exit->exception);
+    return ret;
 }
 
 static const VMStateDescription vmstate_hvf_vtimer = {
Signature · 1 line
2.51.0
Reviewed-by on v1 17/24
#49 lore raw

Re: [PATCH 17/24] target/arm/hvf: Factor hvf_handle_vmexit() out

target/arm/hvf/hvf.c static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp) · line 2117

Quoted 4 lines · Philippe Mathieu-Daudé
target/arm/hvf/hvf.c +2 -0
+/* Must be called by the owning thread */
+static int hvf_handle_vmexit(CPUState *cpu, hv_vcpu_exit_t *exit)
  {
      ARMCPU *arm_cpu = ARM_CPU(cpu);

Likewise don't double-cast.

Otherwise,

r~

Reviewed-by on v1 17/24
#50 lore raw

Re: [PATCH 17/24] target/arm/hvf: Factor hvf_handle_vmexit() out

In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

Factor hvf_handle_vmexit() out of hvf_vcpu_exec().

---
target/arm/hvf/hvf.c | 51 ++++++++++++++++++++++++--------------------

1 file changed, 28 insertions(+), 23 deletions(-)

With Richard's change to not cast twice:

#51 lore raw

PATCH 18/24 target/arm/hvf: Keep calling hv_vcpu_run() in loop

In reply to Philippe Mathieu-Daudé
---
 target/arm/hvf/hvf.c | 40 +++++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 19 deletions(-)
target/arm/hvf/hvf.c +21 -19
index 0cfe3066c23..b60efdc1769 100644
@@ -2141,30 +2141,32 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
     int ret;
     hv_return_t r;
 
-    if (!(cpu->singlestep_enabled & SSTEP_NOIRQ) &&
-        hvf_inject_interrupts(cpu)) {
-        return EXCP_INTERRUPT;
-    }
-
     if (cpu->halted) {
         return EXCP_HLT;
     }
 
-    flush_cpu_state(cpu);
+    do {
+        if (!(cpu->singlestep_enabled & SSTEP_NOIRQ) &&
+            hvf_inject_interrupts(cpu)) {
+            return EXCP_INTERRUPT;
+        }
 
-    bql_unlock();
-    r = hv_vcpu_run(cpu->accel->fd);
-    bql_lock();
-    switch (r) {
-    case HV_SUCCESS:
-        ret = hvf_handle_vmexit(cpu, cpu->accel->exit);
-        break;
-    case HV_ILLEGAL_GUEST_STATE:
-        trace_hvf_illegal_guest_state();
-        /* fall through */
-    default:
-        g_assert_not_reached();
-    }
+        flush_cpu_state(cpu);
+
+        bql_unlock();
+        r = hv_vcpu_run(cpu->accel->fd);
+        bql_lock();
+        switch (r) {
+        case HV_SUCCESS:
+            ret = hvf_handle_vmexit(cpu, cpu->accel->exit);
+            break;
+        case HV_ILLEGAL_GUEST_STATE:
+            trace_hvf_illegal_guest_state();
+            /* fall through */
+        default:
+            g_assert_not_reached();
+        }
+    } while (ret == 0);
 
     return ret;
 }
Signature · 1 line
2.51.0
Reviewed-by on v1 18/24
#52 lore raw

Re: [PATCH 18/24] target/arm/hvf: Keep calling hv_vcpu_run() in loop

Quoted 4 lines · Philippe Mathieu-Daudé
---
  target/arm/hvf/hvf.c | 40 +++++++++++++++++++++-------------------
  1 file changed, 21 insertions(+), 19 deletions(-)

r~

Quoted 47 lines
target/arm/hvf/hvf.c +14 -19
index 0cfe3066c23..b60efdc1769 100644
@@ -2141,30 +2141,32 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
      int ret;
      hv_return_t r;
 
-    if (!(cpu->singlestep_enabled & SSTEP_NOIRQ) &&
-        hvf_inject_interrupts(cpu)) {
-        return EXCP_INTERRUPT;
-    }
-
      if (cpu->halted) {
          return EXCP_HLT;
      }
 
-    flush_cpu_state(cpu);
+    do {
+        if (!(cpu->singlestep_enabled & SSTEP_NOIRQ) &&
+            hvf_inject_interrupts(cpu)) {
+            return EXCP_INTERRUPT;
+        }
 
-    bql_unlock();
-    r = hv_vcpu_run(cpu->accel->fd);
-    bql_lock();
-    switch (r) {
-    case HV_SUCCESS:
-        ret = hvf_handle_vmexit(cpu, cpu->accel->exit);
-        break;
-    case HV_ILLEGAL_GUEST_STATE:
-        trace_hvf_illegal_guest_state();
-        /* fall through */
-    default:
-        g_assert_not_reached();
-    }
+        flush_cpu_state(cpu);
+
+        bql_unlock();
+        r = hv_vcpu_run(cpu->accel->fd);
+        bql_lock();
+        switch (r) {
+        case HV_SUCCESS:
+            ret = hvf_handle_vmexit(cpu, cpu->accel->exit);
+            break;

target/arm/hvf/hvf.c int hvf_arch_vcpu_exec(CPUState *cpu) · line 2172

Quoted 10 lines
target/arm/hvf/hvf.c +7 -0
+        case HV_ILLEGAL_GUEST_STATE:
+            trace_hvf_illegal_guest_state();
+            /* fall through */
+        default:
+            g_assert_not_reached();
+        }
+    } while (ret == 0);
 
      return ret;
  }

r~

Reviewed-by on v1 18/24
#53 lore raw

Re: [PATCH 18/24] target/arm/hvf: Keep calling hv_vcpu_run() in loop

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

---
target/arm/hvf/hvf.c | 40 +++++++++++++++++++++-------------------

1 file changed, 21 insertions(+), 19 deletions(-)

It'd be nice with a commit message justifying the need for the change. I assume performance?

Besides that:

#54 lore raw

Re: [PATCH 18/24] target/arm/hvf: Keep calling hv_vcpu_run() in loop

Quoted 10 lines · Mads Ynddal
Quoted 7 lines · Philippe Mathieu-Daudé

---
target/arm/hvf/hvf.c | 40 +++++++++++++++++++++-------------------

1 file changed, 21 insertions(+), 19 deletions(-)

It'd be nice with a commit message justifying the need for the change. I assume performance?

Performance is a super positive side effect. Actually I had issues in the outer vCPU loop because it is only aware of EXCP_* return values, and the code handling unknown '0' retval is dubious. IOW I'd rather have the outer loop assert for unknown values, as a programming error.

Quoted 3 lines

Besides that:

#55 lore raw

Re: [PATCH 18/24] target/arm/hvf: Keep calling hv_vcpu_run() in loop

Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Mads Ynddal
Quoted 7 lines · Philippe Mathieu-Daudé

---
target/arm/hvf/hvf.c | 40 +++++++++++++++++++++-------------------

1 file changed, 21 insertions(+), 19 deletions(-)
Quoted 7 lines
Quoted 2 lines

It'd be nice with a commit message justifying the need for the change. I assume performance?

Performance is a super positive side effect. Actually I had issues in the outer vCPU loop because it is only aware of EXCP_* return values, and the code handling unknown '0' retval is dubious. IOW I'd rather have the outer loop assert for unknown values, as a programming error.

(Also Richard later noted flush_cpu_state() should be called out of the inner loop).

#56 lore raw

PATCH 19/24 cpus: Trace cpu_exec_start() and cpu_exec_end() calls

In reply to Philippe Mathieu-Daudé
---
 cpu-common.c | 3 +++
 trace-events | 2 ++
 2 files changed, 5 insertions(+)
cpu-common.c +3 -0
index 152661df8e9..614391fb9bc 100644
@@ -249,6 +249,8 @@ void end_exclusive(void)
 /* Wait for exclusive ops to finish, and begin cpu execution.  */
 void cpu_exec_start(CPUState *cpu)
 {
+    trace_cpu_exec_start(cpu->cpu_index);
+
     qatomic_set(&cpu->running, true);
 
     /* Write cpu->running before reading pending_cpus.  */
@@ -319,6 +321,7 @@ void cpu_exec_end(CPUState *cpu)
             }
         }
     }
+    trace_cpu_exec_end(cpu->cpu_index);
 }
 
 void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func,
trace-events +2 -0
index 3ec8a6c7202..faeba6242fa 100644
@@ -29,6 +29,8 @@
 breakpoint_insert(int cpu_index, uint64_t pc, int flags) "cpu=%d pc=0x%" PRIx64 " flags=0x%x"
 breakpoint_remove(int cpu_index, uint64_t pc, int flags) "cpu=%d pc=0x%" PRIx64 " flags=0x%x"
 breakpoint_singlestep(int cpu_index, int enabled) "cpu=%d enable=%d"
+cpu_exec_start(int cpu_index) "cpu=%d"
+cpu_exec_end(int cpu_index) "cpu=%d"
 
 # job.c
 job_state_transition(void *job,  int ret, const char *legal, const char *s0, const char *s1) "job %p (ret: %d) attempting %s transition (%s-->%s)"
Signature · 1 line
2.51.0
#58 lore raw

PATCH 20/24 accel/hvf: Guard hv_vcpu_run() between cpu_exec_start/end() calls

In reply to Philippe Mathieu-Daudé
---
 target/arm/hvf/hvf.c  | 2 ++
 target/i386/hvf/hvf.c | 4 ++++
 2 files changed, 6 insertions(+)
target/arm/hvf/hvf.c +2 -0
index b60efdc1769..40ec930d244 100644
@@ -2154,7 +2154,9 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
         flush_cpu_state(cpu);
 
         bql_unlock();
+        cpu_exec_start(cpu);
         r = hv_vcpu_run(cpu->accel->fd);
+        cpu_exec_end(cpu);
         bql_lock();
         switch (r) {
         case HV_SUCCESS:
target/i386/hvf/hvf.c +4 -0
index 73c50175048..cb4af70e91d 100644
@@ -749,9 +749,13 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
             return EXCP_HLT;
         }
 
+        cpu_exec_start(cpu);
+
         hv_return_t r = hv_vcpu_run_until(cpu->accel->fd, HV_DEADLINE_FOREVER);
         assert_hvf_ok(r);
 
+        cpu_exec_end(cpu);
+
         /* handle VMEXIT */
         uint64_t exit_reason = rvmcs(cpu->accel->fd, VMCS_EXIT_REASON);
         uint64_t exit_qual = rvmcs(cpu->accel->fd, VMCS_EXIT_QUALIFICATION);
Signature · 1 line
2.51.0
#59 lore raw

Re: [PATCH 20/24] accel/hvf: Guard hv_vcpu_run() between cpu_exec_start/end() calls

Missing description:

Similarly to 1d78a3c3ab8 for KVM, wrap hv_vcpu_run() with cpu_exec_start/end(), so that the accelerator can perform pending operations while all vCPUs are quiescent. See also explanation in commit c265e976f46 ("cpus-common: lock-free fast path for cpu_exec_start/end").

Quoted 38 lines · Philippe Mathieu-Daudé
---
  target/arm/hvf/hvf.c  | 2 ++
  target/i386/hvf/hvf.c | 4 ++++
  2 files changed, 6 insertions(+)
target/arm/hvf/hvf.c +2 -0
index b60efdc1769..40ec930d244 100644
@@ -2154,7 +2154,9 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
          flush_cpu_state(cpu);
 
          bql_unlock();
+        cpu_exec_start(cpu);
          r = hv_vcpu_run(cpu->accel->fd);
+        cpu_exec_end(cpu);
          bql_lock();
          switch (r) {
          case HV_SUCCESS:
target/i386/hvf/hvf.c +4 -0
index 73c50175048..cb4af70e91d 100644
@@ -749,9 +749,13 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
              return EXCP_HLT;
          }
 
+        cpu_exec_start(cpu);
+
          hv_return_t r = hv_vcpu_run_until(cpu->accel->fd, HV_DEADLINE_FOREVER);
          assert_hvf_ok(r);
 
+        cpu_exec_end(cpu);
+
          /* handle VMEXIT */
          uint64_t exit_reason = rvmcs(cpu->accel->fd, VMCS_EXIT_REASON);
          uint64_t exit_qual = rvmcs(cpu->accel->fd, VMCS_EXIT_QUALIFICATION);
#60 lore raw

PATCH 21/24 target/arm: Call aarch64_add_pauth_properties() once in host_initfn()

In reply to Philippe Mathieu-Daudé
---
 target/arm/cpu64.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
target/arm/cpu64.c +4 -4
index 26cf7e6dfa2..f81cfd0113c 100644
@@ -762,20 +762,20 @@ static void aarch64_a53_initfn(Object *obj)
 
 static void aarch64_host_initfn(Object *obj)
 {
-#if defined(CONFIG_KVM)
     ARMCPU *cpu = ARM_CPU(obj);
+#if defined(CONFIG_KVM)
     kvm_arm_set_cpu_features_from_host(cpu);
     if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
         aarch64_add_sve_properties(obj);
-        aarch64_add_pauth_properties(obj);
     }
 #elif defined(CONFIG_HVF)
-    ARMCPU *cpu = ARM_CPU(obj);
     hvf_arm_set_cpu_features_from_host(cpu);
-    aarch64_add_pauth_properties(obj);
 #else
     g_assert_not_reached();
 #endif
+    if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
+        aarch64_add_pauth_properties(obj);
+    }
 }
 
 static void aarch64_max_initfn(Object *obj)
Signature · 1 line
2.51.0
Reviewed-by on v1 21/24
#61 lore raw

Re: [PATCH 21/24] target/arm: Call aarch64_add_pauth_properties() once in host_initfn()

Quoted 4 lines · Philippe Mathieu-Daudé
---
  target/arm/cpu64.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)

r~

Quoted 30 lines
target/arm/cpu64.c +4 -4
index 26cf7e6dfa2..f81cfd0113c 100644
@@ -762,20 +762,20 @@ static void aarch64_a53_initfn(Object *obj)
 
  static void aarch64_host_initfn(Object *obj)
  {
-#if defined(CONFIG_KVM)
      ARMCPU *cpu = ARM_CPU(obj);
+#if defined(CONFIG_KVM)
      kvm_arm_set_cpu_features_from_host(cpu);
      if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
          aarch64_add_sve_properties(obj);
-        aarch64_add_pauth_properties(obj);
      }
  #elif defined(CONFIG_HVF)
-    ARMCPU *cpu = ARM_CPU(obj);
      hvf_arm_set_cpu_features_from_host(cpu);
-    aarch64_add_pauth_properties(obj);
  #else
      g_assert_not_reached();
  #endif
+    if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
+        aarch64_add_pauth_properties(obj);
+    }
  }
 
  static void aarch64_max_initfn(Object *obj)
#62 lore raw

PATCH 22/24 accel/hvf: Restrict ARM specific fields of AccelCPUState

In reply to Philippe Mathieu-Daudé

Do not expose ARM specific fields to X86 implementation, allowing to use the proper 'hv_vcpu_exit_t' type.

---
 include/system/hvf_int.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/system/hvf_int.h +3 -1
index 195d64dcf18..3d2be4092ef 100644
@@ -59,10 +59,12 @@ extern HVFState *hvf_state;
 
 struct AccelCPUState {
     hvf_vcpuid fd;
-    void *exit;
+#ifdef __aarch64__
+    hv_vcpu_exit_t *exit;
     bool vtimer_masked;
     sigset_t unblock_ipi_mask;
     bool guest_debug_enabled;
+#endif
 };
 
 void assert_hvf_ok_impl(hv_return_t ret, const char *file, unsigned int line,
Signature · 1 line
2.51.0
Reviewed-by on v1 22/24
#63 lore raw

Re: [PATCH 22/24] accel/hvf: Restrict ARM specific fields of AccelCPUState

Quoted 7 lines · Philippe Mathieu-Daudé

Do not expose ARM specific fields to X86 implementation, allowing to use the proper 'hv_vcpu_exit_t' type.

---
  include/system/hvf_int.h | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

r~

Quoted 19 lines
include/system/hvf_int.h +3 -1
index 195d64dcf18..3d2be4092ef 100644
@@ -59,10 +59,12 @@ extern HVFState *hvf_state;
 
  struct AccelCPUState {
      hvf_vcpuid fd;
-    void *exit;
+#ifdef __aarch64__
+    hv_vcpu_exit_t *exit;
      bool vtimer_masked;
      sigset_t unblock_ipi_mask;
      bool guest_debug_enabled;
+#endif
  };
 
  void assert_hvf_ok_impl(hv_return_t ret, const char *file, unsigned int line,
#64 lore raw

PATCH 23/24 target/arm: Rename init_cpreg_list() -> arm_init_cpreg_list()

In reply to Philippe Mathieu-Daudé

Prefix init_cpreg_list() with 'arm_'.

---
 target/arm/internals.h | 2 +-
 target/arm/cpu.c       | 2 +-
 target/arm/helper.c    | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
target/arm/internals.h +1 -1
index f0aa26c5117..400b4d670f6 100644
@@ -374,7 +374,7 @@ static inline int r14_bank_number(int mode)
 void arm_cpu_register(const ARMCPUInfo *info);
 
 void register_cp_regs_for_features(ARMCPU *cpu);
-void init_cpreg_list(ARMCPU *cpu);
+void arm_init_cpreg_list(ARMCPU *cpu);
 
 void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu);
 void arm_translate_init(void);
target/arm/cpu.c +1 -1
index 633ec55a57c..1789890dea3 100644
@@ -2141,7 +2141,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
     arm_cpu_register_gdb_regs_for_features(cpu);
     arm_cpu_register_gdb_commands(cpu);
 
-    init_cpreg_list(cpu);
+    arm_init_cpreg_list(cpu);
 
 #ifndef CONFIG_USER_ONLY
     MachineState *ms = MACHINE(qdev_get_machine());
target/arm/helper.c +1 -1
index fb62742d983..0db3e05571f 100644
@@ -237,7 +237,7 @@ static gint cpreg_key_compare(gconstpointer a, gconstpointer b, gpointer d)
     return 0;
 }
 
-void init_cpreg_list(ARMCPU *cpu)
+void arm_init_cpreg_list(ARMCPU *cpu)
 {
     /*
      * Initialise the cpreg_tuples[] array based on the cp_regs hash.
Signature · 1 line
2.51.0
#66 lore raw

PATCH 24/24 target/arm: Add arm_destroy_cpreg_list() helper

In reply to Philippe Mathieu-Daudé

arm_destroy_cpreg_list() releases ressources allocated by arm_init_cpreg_list().

---
 target/arm/internals.h | 2 ++
 target/arm/helper.c    | 8 ++++++++
 2 files changed, 10 insertions(+)
target/arm/internals.h +2 -0
index 400b4d670f6..5af9b1110e8 100644
@@ -375,6 +375,8 @@ void arm_cpu_register(const ARMCPUInfo *info);
 
 void register_cp_regs_for_features(ARMCPU *cpu);
 void arm_init_cpreg_list(ARMCPU *cpu);
+/* Release ressources allocated by arm_init_cpreg_list() */
+void arm_destroy_cpreg_list(ARMCPU *cpu);
 
 void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu);
 void arm_translate_init(void);
target/arm/helper.c +8 -0
index 0db3e05571f..9b7a2b94bd3 100644
@@ -268,6 +268,14 @@ void arm_init_cpreg_list(ARMCPU *cpu)
     g_list_free(keys);
 }
 
+void arm_destroy_cpreg_list(ARMCPU *cpu)
+{
+    g_free(cpu->cpreg_indexes);
+    g_free(cpu->cpreg_values);
+    g_free(cpu->cpreg_vmstate_indexes);
+    g_free(cpu->cpreg_vmstate_values);
+}
+
 bool arm_pan_enabled(CPUARMState *env)
 {
     if (is_a64(env)) {
Signature · 1 line
2.51.0
#67 lore raw

Re: [PATCH 24/24] target/arm: Add arm_destroy_cpreg_list() helper

Quoted 10 lines · Philippe Mathieu-Daudé

arm_destroy_cpreg_list() releases ressources allocated by arm_init_cpreg_list().

---
  target/arm/internals.h | 2 ++
  target/arm/helper.c    | 8 ++++++++
  2 files changed, 10 insertions(+)

target/arm/helper.c void arm_init_cpreg_list(ARMCPU *cpu) · line 277

Quoted 7 lines
target/arm/helper.c +7 -0
+void arm_destroy_cpreg_list(ARMCPU *cpu)
+{
+    g_free(cpu->cpreg_indexes);
+    g_free(cpu->cpreg_values);
+    g_free(cpu->cpreg_vmstate_indexes);
+    g_free(cpu->cpreg_vmstate_values);
+}

Please ignore this patch, it is part of another series related to arm DeviceUnrealize() implementation.