target/arm/hvf: Consolidate
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
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
@@ -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
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()withos_release().Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/arm/hvf/hvf.c | 2 ++ 1 file changed, 2 insertions(+)
r~
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 withos_releasewhen no longer used. */
OS_OBJECT_RETURNS_RETAINEDOS_WARN_RESULT
hv_vcpu_config_thv_vcpu_config_create(void);
Quoted 7 lines
Release the memory allocated by
hv_vcpu_config_create()withos_release().Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/arm/hvf/hvf.c| 2 ++1 file changed, 2 insertions(+)
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
@@ -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
@@ -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
Re: [PATCH 02/24] target/arm/hvf: Check hv_vcpus_exit() returned value
Quoted 10 lines · Philippe Mathieu-Daudé
hv_vcpus_exit()returns ahv_return_tenum type (defined in <Hypervisor/hv_error.h>). Assert we succeeded, as we are not ready to handle any error path.Suggested-by Alex Bennée <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- 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@@ -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@@ -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"
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 ahv_return_tenum type (defined in <Hypervisor/hv_error.h>). Assert we succeeded, as we are not ready to handle any error path.
Quoted 6 lines
Suggested-by Alex Bennée <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/arm/hvf/hvf.c| 5 ++++-
target/arm/hvf/trace-events | 1 +2 files changed, 5 insertions(+), 1 deletion(-)
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
@@ -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
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 ahv_return_tenum type (defined in <Hypervisor/hv_error.h>). Assert we succeeded, as we are not ready to handle any error path.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/arm/hvf/hvf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)target/arm/hvf/hvf.c +0
-0
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~
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 ahv_return_tenum type (defined in <Hypervisor/hv_error.h>). Assert we succeeded, as we are not ready to handle any error path.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/arm/hvf/hvf.c| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)
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
@@ -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
@@ -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
@@ -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
@@ -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
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 ashvf_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
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- 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~
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 ashvf_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
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
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(-)
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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()andhvf_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
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- 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~
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()andhvf_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
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
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(-)
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
@@ -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
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()callshvf_arch_put_registers(), which must run on a vCPU, it also must. Mention it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/arm/hvf/hvf.c | 1 + 1 file changed, 1 insertion(+)target/arm/hvf/hvf.c +0
-0
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~
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()callshvf_arch_put_registers(), which must run on a vCPU, it also must. Mention it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/arm/hvf/hvf.c| 1 +1 file changed, 1 insertion(+)
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
@@ -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
@@ -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
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 withhvf_put_guest_debug_registers()andhvf_put_gdbstub_debug_registers(), callshv_vcpu_set_sys_reg(), which must run on a vCPU. Mention they also must.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/system/hvf_int.h | 3 ++- target/arm/hvf/hvf.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-)
r~
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 withhvf_put_guest_debug_registers()andhvf_put_gdbstub_debug_registers(), callshv_vcpu_set_sys_reg(), which must run on a vCPU. Mention they also must.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
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@@ -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
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
-0static 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
-0static 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:
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
@@ -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
Re: [PATCH 08/24] target/arm/hvf: Mention hvf_wfi() must run on vCPU thread
Quoted 13 lines · Philippe Mathieu-Daudé
Since
hvf_wfi()callshv_vcpu_get_sys_reg(), which must run on a vCPU, it also must. Mention it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/arm/hvf/hvf.c | 1 + 1 file changed, 1 insertion(+)target/arm/hvf/hvf.c +0
-0
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~
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()callshv_vcpu_get_sys_reg(), which must run on a vCPU, it also must. Mention it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
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@@ -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().
Re: [PATCH 08/24] target/arm/hvf: Mention hvf_wfi() must run on vCPU thread
In reply to Richard HendersonQuoted 24 lines · Richard Henderson
Quoted 11 lines · Philippe Mathieu-Daudé
Since
hvf_wfi()callshv_vcpu_get_sys_reg(), which must run on a vCPU, it also must. Mention it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/arm/hvf/hvf.c | 1 + 1 file changed, 1 insertion(+)target/arm/hvf/hvf.c +0
-0target/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.
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()callshv_vcpu_get_sys_reg(), which must run on a vCPU, it also must. Mention it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/arm/hvf/hvf.c| 1 +1 file changed, 1 insertion(+)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);Signature · 1 line
2.51.0
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
@@ -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
Re: [PATCH 09/24] target/arm/hvf: Mention hvf_sync_vtimer() must run on vCPU thread
Quoted 10 lines · Philippe Mathieu-Daudé
Since
hvf_sync_vtimer()callshv_vcpu_get_sys_reg(), which must run on a vCPU, it also must. Mention it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/arm/hvf/hvf.c| 1 +1 file changed, 1 insertion(+)
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
@@ -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
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()callshv_vcpu_set_trap_debug_exceptions()andhv_vcpu_set_trap_debug_reg_accesses(), which must run on a vCPU, it also must. Mention it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/arm/hvf/hvf.c| 1 +1 file changed, 1 insertion(+)
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
@@ -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
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()callshvf_arch_set_traps()andhvf_arch_update_guest_debug(), which must run on a vCPU, it also must. Mention it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
include/system/hvf_int.h| 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)
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
@@ -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
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()callshv_vcpu_set_pending_interrupt(), which must run on a vCPU, it also must. Mention it.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/arm/hvf/hvf.c| 1 +1 file changed, 1 insertion(+)
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
@@ -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
@@ -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
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, documenthvf_arch_vcpu_destroy()also does.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/system/hvf_int.h | 3 ++- target/arm/hvf/hvf.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-)
r~
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, documenthvf_arch_vcpu_destroy()also does.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
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@@ -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
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
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
@@ -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
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.
Signed-off-by Mohamed Mediouni<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/arm/hvf/hvf.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
r~
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.
Signed-off-by Mohamed Mediouni <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/arm/hvf/hvf.c| 12 ++++++++++++1 file changed, 12 insertions(+)target/arm/hvf/hvf.c +1
-0@@ -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
-0r |=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
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]>
--- target/arm/hvf/hvf.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-)
target/arm/hvf/hvf.c +15 -21
@@ -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
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_reginterface.Besides, all the following methods must be run on a vCPU thread:
-
hv_vcpu_create()
-hv_vcpu_get_sys_reg()
-hv_vcpu_destroy()Signed-off-by Mohamed Mediouni <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Message-ID: <[email protected]>
[PMD: Release config calling os_release()]Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/arm/hvf/hvf.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-)target/arm/hvf/hvf.c +7
-7@@ -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
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@@ -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~
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
-0target/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!
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
@@ -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
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~
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 ofhvf_vcpu_exec().Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/arm/hvf/hvf.c| 120 +++++++++++++++++++++++--------------------1 file changed, 64 insertions(+), 56 deletions(-)
Good idea.
With Richard's change to not cast twice:
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
@@ -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
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~
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 ofhvf_vcpu_exec().Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
target/arm/hvf/hvf.c| 51 ++++++++++++++++++++++++--------------------1 file changed, 28 insertions(+), 23 deletions(-)
With Richard's change to not cast twice:
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
@@ -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
Re: [PATCH 18/24] target/arm/hvf: Keep calling hv_vcpu_run() in loop
Quoted 4 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/arm/hvf/hvf.c | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-)
r~
Quoted 47 lines
target/arm/hvf/hvf.c +14
-19@@ -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~
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é
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
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:
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é
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
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:
Reviewed-by Mads Ynddal <[email protected]>
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é
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
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).
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
@@ -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
@@ -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
Re: [PATCH 19/24] cpus: Trace cpu_exec_start() and cpu_exec_end() calls
Quoted 5 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- cpu-common.c | 3 +++ trace-events | 2 ++ 2 files changed, 5 insertions(+)
r~
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
@@ -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
@@ -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
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é
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/arm/hvf/hvf.c | 2 ++ target/i386/hvf/hvf.c | 4 ++++ 2 files changed, 6 insertions(+)target/arm/hvf/hvf.c +2
-0@@ -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@@ -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 );
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
@@ -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
Re: [PATCH 21/24] target/arm: Call aarch64_add_pauth_properties() once in host_initfn()
Quoted 4 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/arm/cpu64.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
r~
Quoted 30 lines
target/arm/cpu64.c +4
-4@@ -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)
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
@@ -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
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.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/system/hvf_int.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
r~
Quoted 19 lines
include/system/hvf_int.h +3
-1@@ -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,
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
@@ -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
@@ -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
@@ -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
Re: [PATCH 23/24] target/arm: Rename init_cpreg_list() -> arm_init_cpreg_list()
Quoted 4 lines · Philippe Mathieu-Daudé
Prefix
init_cpreg_list()with 'arm_'.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
thanks
-- PMM
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
@@ -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
@@ -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
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 byarm_init_cpreg_list().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- 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.