qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 00/59] target/arm/hvf: Consolidate
@ 2025-10-28  5:41 Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 01/59] target/arm/hvf: Release memory allocated by hv_vcpu_config_create() Philippe Mathieu-Daudé
                   ` (59 more replies)
  0 siblings, 60 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Missing review: 15, 18, 26, 32, 33, 38 (up to #41 could be merged)
                42, 43 (up to #49 could be merged)
                50+

Since v2:
- Improve host page size/mask uses (rth)
- Remove cpu_test_interrupt in hvf_wfi (rth)

Since v1:
- Addressed Mads & Richard comments
- Fixed migration by reworking memory listeners
  (unfortunately the current broken code has been
   used as base for WHPX)
- Sync CNTV_CTL/CVAL_EL0
- Remove WFI racy signal implementation
- Simplify PSCI Suspend (I expect the same can be
  done for the other hvf_psci_cpu_off() calls).
- Emulate more missing registers (PMU & Monitor Dbg)

From v1:
- 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: <20250829152909.1589668-14-pbonzini@redhat.com>

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é (48):
  target/arm/hvf: Release memory allocated by hv_vcpu_config_create()
  target/arm/hvf: Trace vCPU KICK events
  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_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: Simplify hvf_arm_get_host_cpu_features()
  target/arm/hvf: Factor hvf_handle_exception() out
  target/i386/hvf: Factor hvf_handle_vmexit() 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/hvf: Rename 'vgic' -> 'emu_reginfo' in trace events
  target/arm: Re-use arm_is_psci_call() in HVF
  target/arm: Share ARM_PSCI_CALL trace event between TCG and HVF
  target/arm/hvf/hvf: Document $pc adjustment in HVF & SMC
  accel/hvf: Trace prefetch abort
  accel/hvf: Enforce host alignment in hv_vm_protect()
  target/i386/hvf: Use host page alignment in ept_emulation_fault()
  accel/hvf: Skip WFI if CPU has work to do
  accel/hvf: Implement WFI without using pselect()
  accel/hvf: Have PSCI CPU_SUSPEND halt the vCPU
  accel: Introduce AccelOpsClass::cpu_target_realize() hook
  accel/hvf: Add hvf_arch_cpu_realize() stubs
  target/arm: Create GTimers *after* features finalized / accel realized
  target/arm/hvf: Really set Generic Timer counter frequency
  target/arm: Only allow disabling NEON when using TCG
  target/arm/hvf: Do not abort in hvf_arm_get_*_ipa_bit_size()
  hw/arm/virt: Warn when HVF doesn't report IPA bit length
  accel/hvf: Introduce hvf_arch_cpu_synchronize_[pre/post]exec() hooks
  target/i386/hvf: Flush vCPU registers once before vcpu_exec() loop
  target/arm/hvf: Flush vCPU registers once before vcpu_exec() loop
  accel/hvf: Sync CNTV_CTL_EL0 & CNTV_CVAL_EL0
  target/arm: Better describe PMU depends on TCG or HVF
  target/arm/hvf: Emulate PMU registers
  target/arm/hvf: Emulate Monitor Debug registers
  target/arm/hvf: Emulate PhysTimer registers

Richard Henderson (9):
  accel/hvf: Create hvf_protect_clean_range, hvf_unprotect_dirty_range
  target/i386/hvf: Use hvf_unprotect_page
  target/i386/hvf: Use address_space_translate in ept_emulation_fault
  accel/hvf: Simplify hvf_log_*
  accel/hvf: Move hvf_log_sync to hvf_log_clear
  accel/hvf: Simplify hvf_set_phys_mem
  accel/hvf: Drop hvf_slot and hvf_find_overlap_slot
  accel/hvf: Remove mac_slots
  target/arm/hvf: Implement dirty page tracking

 include/accel/accel-cpu-ops.h |   1 +
 include/system/hvf_int.h      |  49 ++--
 target/arm/hvf_arm.h          |  11 +
 target/arm/internals.h        |   2 +-
 accel/accel-common.c          |   5 +
 accel/hvf/hvf-accel-ops.c     |  28 +-
 accel/hvf/hvf-all.c           | 185 ++++--------
 cpu-common.c                  |   3 +
 hw/arm/virt.c                 |   8 +-
 target/arm/cpu.c              |  71 ++---
 target/arm/cpu64.c            |   8 +-
 target/arm/helper.c           |   2 +-
 target/arm/hvf/hvf.c          | 498 +++++++++++++++++++------------
 target/arm/machine.c          |  10 +-
 target/arm/tcg/psci.c         |   3 +
 target/i386/hvf/hvf.c         | 537 ++++++++++++++++++----------------
 target/i386/hvf/x86hvf.c      |   4 +-
 accel/hvf/trace-events        |   1 +
 target/arm/hvf/trace-events   |   6 +-
 target/arm/trace-events       |   3 +
 trace-events                  |   2 +
 21 files changed, 762 insertions(+), 675 deletions(-)

-- 
2.51.0



^ permalink raw reply	[flat|nested] 83+ messages in thread

* [PATCH v3 01/59] target/arm/hvf: Release memory allocated by hv_vcpu_config_create()
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 02/59] target/arm/hvf: Trace vCPU KICK events Philippe Mathieu-Daudé
                   ` (58 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, 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);

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
---
 target/arm/hvf/hvf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 0658a99a2d1..83db1088384 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -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 SYSREG_OP0_SHIFT      20
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 02/59] target/arm/hvf: Trace vCPU KICK events
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 01/59] target/arm/hvf: Release memory allocated by hv_vcpu_config_create() Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 03/59] target/arm/hvf: Check hv_vcpus_exit() returned value Philippe Mathieu-Daudé
                   ` (57 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/hvf/hvf.c        | 1 +
 target/arm/hvf/trace-events | 1 +
 2 files changed, 2 insertions(+)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 83db1088384..91bbd3a6aae 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -963,6 +963,7 @@ int hvf_arch_init_vcpu(CPUState *cpu)
 
 void hvf_kick_vcpu_thread(CPUState *cpu)
 {
+    trace_hvf_kick_vcpu_thread(cpu->cpu_index, cpu->stop);
     cpus_kick_thread(cpu);
     hv_vcpus_exit(&cpu->accel->fd, 1);
 }
diff --git a/target/arm/hvf/trace-events b/target/arm/hvf/trace-events
index b29a995f3d3..538af6e0707 100644
--- a/target/arm/hvf/trace-events
+++ b/target/arm/hvf/trace-events
@@ -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"
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 03/59] target/arm/hvf: Check hv_vcpus_exit() returned value
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 01/59] target/arm/hvf: Release memory allocated by hv_vcpu_config_create() Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 02/59] target/arm/hvf: Trace vCPU KICK events Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 04/59] target/arm/hvf: Check hv_vcpu_set_vtimer_mask() " Philippe Mathieu-Daudé
                   ` (56 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé, Alex Bennée

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.

Suggested-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/hvf/hvf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 91bbd3a6aae..4c98faebbed 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -963,9 +963,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,
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 04/59] target/arm/hvf: Check hv_vcpu_set_vtimer_mask() returned value
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 03/59] target/arm/hvf: Check hv_vcpus_exit() returned value Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 05/59] accel/hvf: Rename hvf_vcpu_exec() -> hvf_arch_vcpu_exec() Philippe Mathieu-Daudé
                   ` (55 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, 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.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
---
 target/arm/hvf/hvf.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 4c98faebbed..bbe0b24b821 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1782,7 +1782,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;
     }
 }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 05/59] accel/hvf: Rename hvf_vcpu_exec() -> hvf_arch_vcpu_exec()
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 04/59] target/arm/hvf: Check hv_vcpu_set_vtimer_mask() " Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 06/59] accel/hvf: Rename hvf_put|get_registers -> hvf_arch_put|get_registers Philippe Mathieu-Daudé
                   ` (54 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, 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.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
---
 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(-)

diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h
index a3b06a3e75b..32b32e1d024 100644
--- a/include/system/hvf_int.h
+++ b/include/system/hvf_int.h
@@ -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;
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index 8b794c2d418..005e2bd891a 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -194,7 +194,7 @@ static void *hvf_cpu_thread_fn(void *arg)
     do {
         qemu_process_cpu_events(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);
             }
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index bbe0b24b821..9111c1d717b 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1788,7 +1788,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;
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 33f723a76a7..b2bf59cb483 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -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;
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 06/59] accel/hvf: Rename hvf_put|get_registers -> hvf_arch_put|get_registers
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (4 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 05/59] accel/hvf: Rename hvf_vcpu_exec() -> hvf_arch_vcpu_exec() Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 07/59] target/arm/hvf: Mention flush_cpu_state() must run on vCPU thread Philippe Mathieu-Daudé
                   ` (53 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, 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.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
---
 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(-)

diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h
index 32b32e1d024..8fce627b08c 100644
--- a/include/system/hvf_int.h
+++ b/include/system/hvf_int.h
@@ -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;
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index 005e2bd891a..3e5feecd8a7 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -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;
     }
 }
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 9111c1d717b..f0a0e5d1a75 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -424,7 +424,7 @@ static const hv_sys_reg_t hvf_sreg_list[] = {
 
 #undef DEF_SYSREG
 
-int hvf_get_registers(CPUState *cpu)
+int hvf_arch_get_registers(CPUState *cpu)
 {
     ARMCPU *arm_cpu = ARM_CPU(cpu);
     CPUARMState *env = &arm_cpu->env;
@@ -564,7 +564,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;
@@ -692,11 +692,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;
@@ -709,6 +710,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;
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index b2bf59cb483..76a58cb0350 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -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;
         }
 
diff --git a/target/i386/hvf/x86hvf.c b/target/i386/hvf/x86hvf.c
index a502437c303..afcf737759b 100644
--- a/target/i386/hvf/x86hvf.c
+++ b/target/i386/hvf/x86hvf.c
@@ -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;
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 07/59] target/arm/hvf: Mention flush_cpu_state() must run on vCPU thread
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (5 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 06/59] accel/hvf: Rename hvf_put|get_registers -> hvf_arch_put|get_registers Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 08/59] accel/hvf: Mention hvf_arch_init_vcpu() " Philippe Mathieu-Daudé
                   ` (52 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
---
 target/arm/hvf/hvf.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index f0a0e5d1a75..fdf8df09d4b 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -689,6 +689,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) {
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 08/59] accel/hvf: Mention hvf_arch_init_vcpu() must run on vCPU thread
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (6 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 07/59] target/arm/hvf: Mention flush_cpu_state() must run on vCPU thread Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 09/59] target/arm/hvf: Mention hvf_sync_vtimer() " Philippe Mathieu-Daudé
                   ` (51 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, 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.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
---
 include/system/hvf_int.h | 3 ++-
 target/arm/hvf/hvf.c     | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h
index 8fce627b08c..0c335facc3b 100644
--- a/include/system/hvf_int.h
+++ b/include/system/hvf_int.h
@@ -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 */
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index fdf8df09d4b..8095cb0805a 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -2119,6 +2119,7 @@ void hvf_arch_remove_all_hw_breakpoints(void)
  * Update the vCPU with the gdbstub's view of debug registers. This view
  * 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)
 {
@@ -2157,6 +2158,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)
 {
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 09/59] target/arm/hvf: Mention hvf_sync_vtimer() must run on vCPU thread
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (7 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 08/59] accel/hvf: Mention hvf_arch_init_vcpu() " Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 10/59] target/arm/hvf: Mention hvf_arch_set_traps() " Philippe Mathieu-Daudé
                   ` (50 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
---
 target/arm/hvf/hvf.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 8095cb0805a..bfccf5e9a2a 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1764,6 +1764,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);
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 10/59] target/arm/hvf: Mention hvf_arch_set_traps() must run on vCPU thread
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (8 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 09/59] target/arm/hvf: Mention hvf_sync_vtimer() " Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 11/59] accel/hvf: Mention hvf_arch_update_guest_debug() must run on vCPU Philippe Mathieu-Daudé
                   ` (49 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, 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.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
---
 target/arm/hvf/hvf.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index bfccf5e9a2a..ee04943b0f8 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -2192,6 +2192,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;
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 11/59] accel/hvf: Mention hvf_arch_update_guest_debug() must run on vCPU
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (9 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 10/59] target/arm/hvf: Mention hvf_arch_set_traps() " Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 12/59] target/arm/hvf: Mention hvf_inject_interrupts() must run on vCPU thread Philippe Mathieu-Daudé
                   ` (48 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, 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.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
---
 include/system/hvf_int.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h
index 0c335facc3b..241c668795e 100644
--- a/include/system/hvf_int.h
+++ b/include/system/hvf_int.h
@@ -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.
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 12/59] target/arm/hvf: Mention hvf_inject_interrupts() must run on vCPU thread
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (10 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 11/59] accel/hvf: Mention hvf_arch_update_guest_debug() must run on vCPU Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 13/59] accel/hvf: Implement hvf_arch_vcpu_destroy() Philippe Mathieu-Daudé
                   ` (47 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

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

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
---
 target/arm/hvf/hvf.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index ee04943b0f8..0d8ff49ae15 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1664,6 +1664,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)) {
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 13/59] accel/hvf: Implement hvf_arch_vcpu_destroy()
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (11 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 12/59] target/arm/hvf: Mention hvf_inject_interrupts() must run on vCPU thread Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 14/59] target/arm/hvf: Hardcode Apple MIDR Philippe Mathieu-Daudé
                   ` (46 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, 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.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
---
 include/system/hvf_int.h | 3 ++-
 target/arm/hvf/hvf.c     | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h
index 241c668795e..195d64dcf18 100644
--- a/include/system/hvf_int.h
+++ b/include/system/hvf_int.h
@@ -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 *);
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 0d8ff49ae15..d13ccf5508c 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -868,6 +868,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)
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 14/59] target/arm/hvf: Hardcode Apple MIDR
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (12 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 13/59] accel/hvf: Implement hvf_arch_vcpu_destroy() Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 15/59] target/arm/hvf: Simplify hvf_arm_get_host_cpu_features() Philippe Mathieu-Daudé
                   ` (45 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

From: Mohamed Mediouni <mohamed@unpredictable.fr>

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

Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/hvf/hvf.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index d13ccf5508c..890e9266f93 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -763,6 +763,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";
@@ -781,9 +782,19 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
     for (i = 0; i < ARRAY_SIZE(regs); i++) {
         r |= hv_vcpu_get_sys_reg(fd, 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);
 
+    /*
+     * 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);
 
     /*
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 15/59] target/arm/hvf: Simplify hvf_arm_get_host_cpu_features()
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (13 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 14/59] target/arm/hvf: Hardcode Apple MIDR Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28 11:16   ` Peter Maydell
  2025-10-28 11:33   ` Richard Henderson
  2025-10-28  5:41 ` [PATCH v3 16/59] target/arm/hvf: switch hvf_arm_get_host_cpu_features to not create a vCPU Philippe Mathieu-Daudé
                   ` (44 subsequent siblings)
  59 siblings, 2 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Use index in the structure, dereference &host_isar.idregs[] once.

Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/hvf/hvf.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 890e9266f93..dea1cb37d1f 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -743,21 +743,21 @@ static void clamp_id_aa64mmfr0_parange_to_ipa_size(ARMISARegisters *isar)
 static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
 {
     ARMISARegisters host_isar = {};
-    const struct isar_regs {
+    static const struct isar_regs {
         int reg;
-        uint64_t *val;
+        ARMIDRegisterIdx index;
     } 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_AA64PFR0_EL1, ID_AA64PFR0_EL1_IDX },
+        { HV_SYS_REG_ID_AA64PFR1_EL1, ID_AA64PFR1_EL1_IDX },
         /* Add ID_AA64PFR2_EL1 here when HVF supports it */
-        { 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_SYS_REG_ID_AA64DFR0_EL1, ID_AA64DFR0_EL1_IDX },
+        { HV_SYS_REG_ID_AA64DFR1_EL1, ID_AA64DFR1_EL1_IDX },
+        { HV_SYS_REG_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_IDX },
+        { HV_SYS_REG_ID_AA64ISAR1_EL1, 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_SYS_REG_ID_AA64MMFR0_EL1, ID_AA64MMFR0_EL1_IDX },
+        { HV_SYS_REG_ID_AA64MMFR1_EL1, ID_AA64MMFR1_EL1_IDX },
+        { HV_SYS_REG_ID_AA64MMFR2_EL1, ID_AA64MMFR2_EL1_IDX },
         /* Add ID_AA64MMFR3_EL1 here when HVF supports it */
     };
     hv_vcpu_t fd;
@@ -780,7 +780,8 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
     }
 
     for (i = 0; i < ARRAY_SIZE(regs); i++) {
-        r |= hv_vcpu_get_sys_reg(fd, regs[i].reg, regs[i].val);
+        r |= hv_vcpu_get_sys_reg(fd, regs[i].reg,
+                                 &host_isar.idregs[regs[i].index]);
     }
     r |= hv_vcpu_destroy(fd);
 
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 16/59] target/arm/hvf: switch hvf_arm_get_host_cpu_features to not create a vCPU
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (14 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 15/59] target/arm/hvf: Simplify hvf_arm_get_host_cpu_features() Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 17/59] target/arm/hvf: Factor hvf_handle_exception() out Philippe Mathieu-Daudé
                   ` (43 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

From: Mohamed Mediouni <mohamed@unpredictable.fr>

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()

Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
Message-ID: <20250808070137.48716-3-mohamed@unpredictable.fr>
[PMD: Release config calling os_release()]
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/hvf/hvf.c | 35 ++++++++++++++---------------------
 1 file changed, 14 insertions(+), 21 deletions(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index dea1cb37d1f..fcb6950692b 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -744,25 +744,24 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)
 {
     ARMISARegisters host_isar = {};
     static const struct isar_regs {
-        int reg;
+        hv_feature_reg_t reg;
         ARMIDRegisterIdx index;
     } regs[] = {
-        { HV_SYS_REG_ID_AA64PFR0_EL1, ID_AA64PFR0_EL1_IDX },
-        { HV_SYS_REG_ID_AA64PFR1_EL1, ID_AA64PFR1_EL1_IDX },
+        { HV_FEATURE_REG_ID_AA64PFR0_EL1, ID_AA64PFR0_EL1_IDX },
+        { HV_FEATURE_REG_ID_AA64PFR1_EL1, ID_AA64PFR1_EL1_IDX },
         /* Add ID_AA64PFR2_EL1 here when HVF supports it */
-        { HV_SYS_REG_ID_AA64DFR0_EL1, ID_AA64DFR0_EL1_IDX },
-        { HV_SYS_REG_ID_AA64DFR1_EL1, ID_AA64DFR1_EL1_IDX },
-        { HV_SYS_REG_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_IDX },
-        { HV_SYS_REG_ID_AA64ISAR1_EL1, ID_AA64ISAR1_EL1_IDX },
+        { HV_FEATURE_REG_ID_AA64DFR0_EL1, ID_AA64DFR0_EL1_IDX },
+        { HV_FEATURE_REG_ID_AA64DFR1_EL1, ID_AA64DFR1_EL1_IDX },
+        { HV_FEATURE_REG_ID_AA64ISAR0_EL1, ID_AA64ISAR0_EL1_IDX },
+        { HV_FEATURE_REG_ID_AA64ISAR1_EL1, ID_AA64ISAR1_EL1_IDX },
         /* Add ID_AA64ISAR2_EL1 here when HVF supports it */
-        { HV_SYS_REG_ID_AA64MMFR0_EL1, ID_AA64MMFR0_EL1_IDX },
-        { HV_SYS_REG_ID_AA64MMFR1_EL1, ID_AA64MMFR1_EL1_IDX },
-        { HV_SYS_REG_ID_AA64MMFR2_EL1, ID_AA64MMFR2_EL1_IDX },
+        { HV_FEATURE_REG_ID_AA64MMFR0_EL1, ID_AA64MMFR0_EL1_IDX },
+        { HV_FEATURE_REG_ID_AA64MMFR1_EL1, ID_AA64MMFR1_EL1_IDX },
+        { HV_FEATURE_REG_ID_AA64MMFR2_EL1, ID_AA64MMFR2_EL1_IDX },
         /* Add ID_AA64MMFR3_EL1 here when HVF supports it */
     };
-    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;
 
@@ -773,17 +772,11 @@ 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,
-                                 &host_isar.idregs[regs[i].index]);
+        r |= hv_vcpu_config_get_feature_reg(config, regs[i].reg,
+                                            &host_isar.idregs[regs[i].index]);
     }
-    r |= hv_vcpu_destroy(fd);
+    os_release(config);
 
     /*
      * Hardcode MIDR because Apple deliberately doesn't expose a divergent
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 17/59] target/arm/hvf: Factor hvf_handle_exception() out
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (15 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 16/59] target/arm/hvf: switch hvf_arm_get_host_cpu_features to not create a vCPU Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 18/59] target/i386/hvf: Factor hvf_handle_vmexit() out Philippe Mathieu-Daudé
                   ` (42 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Factor hvf_handle_exception() out of hvf_vcpu_exec().

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
---
 target/arm/hvf/hvf.c | 123 +++++++++++++++++++++++--------------------
 1 file changed, 65 insertions(+), 58 deletions(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index fcb6950692b..8553ce6adc2 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1802,61 +1802,15 @@ static void hvf_sync_vtimer(CPUState *cpu)
     }
 }
 
-int hvf_arch_vcpu_exec(CPUState *cpu)
+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;
+    CPUARMState *env = cpu_env(cpu);
+    ARMCPU *arm_cpu = env_archcpu(env);
+    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: {
@@ -1895,7 +1849,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");
         }
@@ -1913,8 +1867,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) {
@@ -1928,11 +1882,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);
@@ -2030,6 +1984,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,
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 18/59] target/i386/hvf: Factor hvf_handle_vmexit() out
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (16 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 17/59] target/arm/hvf: Factor hvf_handle_exception() out Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28 11:18   ` Peter Maydell
  2025-10-28  5:41 ` [PATCH v3 19/59] target/arm/hvf: " Philippe Mathieu-Daudé
                   ` (41 subsequent siblings)
  59 siblings, 1 reply; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Factor hvf_handle_vmexit() out of hvf_arch_vcpu_exec().

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/i386/hvf/hvf.c | 478 +++++++++++++++++++++---------------------
 1 file changed, 244 insertions(+), 234 deletions(-)

diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 76a58cb0350..28d98659ec2 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -721,6 +721,249 @@ void hvf_simulate_wrmsr(CPUState *cs)
     printf("write msr %llx\n", RCX(cs));*/
 }
 
+static int hvf_handle_vmexit(CPUState *cpu)
+{
+    X86CPU *x86_cpu = env_archcpu(cpu_env(cpu));
+    uint64_t exit_reason = rvmcs(cpu->accel->fd, VMCS_EXIT_REASON);
+    uint64_t exit_qual = rvmcs(cpu->accel->fd, VMCS_EXIT_QUALIFICATION);
+    uint32_t ins_len = (uint32_t)rvmcs(cpu->accel->fd,
+                                       VMCS_EXIT_INSTRUCTION_LENGTH);
+
+    uint64_t idtvec_info = rvmcs(cpu->accel->fd, VMCS_IDT_VECTORING_INFO);
+    int ret = 0;
+
+    hvf_store_events(cpu, ins_len, idtvec_info);
+    rip = rreg(cpu->accel->fd, HV_X86_RIP);
+    env->eflags = rreg(cpu->accel->fd, HV_X86_RFLAGS);
+
+    bql_lock();
+
+    update_apic_tpr(cpu);
+    current_cpu = cpu;
+
+    switch (exit_reason) {
+    case EXIT_REASON_HLT: {
+        macvm_set_rip(cpu, rip + ins_len);
+        if (!(cpu_test_interrupt(cpu, CPU_INTERRUPT_HARD)
+              && (env->eflags & IF_MASK))
+            && !cpu_test_interrupt(cpu, CPU_INTERRUPT_NMI)
+            && !(idtvec_info & VMCS_IDT_VEC_VALID)) {
+            cpu->halted = 1;
+            ret = EXCP_HLT;
+            break;
+        }
+        ret = EXCP_INTERRUPT;
+        break;
+    }
+    case EXIT_REASON_MWAIT: {
+        ret = EXCP_INTERRUPT;
+        break;
+    }
+    /* Need to check if MMIO or unmapped fault */
+    case EXIT_REASON_EPT_FAULT:
+    {
+        hvf_slot *slot;
+        uint64_t gpa = rvmcs(cpu->accel->fd, VMCS_GUEST_PHYSICAL_ADDRESS);
+
+        if (((idtvec_info & VMCS_IDT_VEC_VALID) == 0) &&
+            ((exit_qual & EXIT_QUAL_NMIUDTI) != 0)) {
+            vmx_set_nmi_blocking(cpu);
+        }
+
+        slot = hvf_find_overlap_slot(gpa, 1);
+        /* mmio */
+        if (ept_emulation_fault(slot, gpa, exit_qual)) {
+            struct x86_decode decode;
+
+            hvf_load_regs(cpu);
+            decode_instruction(env, &decode);
+            exec_instruction(env, &decode);
+            hvf_store_regs(cpu);
+            break;
+        }
+        break;
+    }
+    case EXIT_REASON_INOUT:
+    {
+        uint32_t in = (exit_qual & 8) != 0;
+        uint32_t size =  (exit_qual & 7) + 1;
+        uint32_t string =  (exit_qual & 16) != 0;
+        uint32_t port =  exit_qual >> 16;
+        /*uint32_t rep = (exit_qual & 0x20) != 0;*/
+        struct x86_decode decode;
+
+        if (!string && in) {
+            uint64_t val = 0;
+
+            hvf_load_regs(cpu);
+            hvf_handle_io(env_cpu(env), port, &val, 0, size, 1);
+            if (size == 1) {
+                AL(env) = val;
+            } else if (size == 2) {
+                AX(env) = val;
+            } else if (size == 4) {
+                RAX(env) = (uint32_t)val;
+            } else {
+                RAX(env) = (uint64_t)val;
+            }
+            env->eip += ins_len;
+            hvf_store_regs(cpu);
+            break;
+        } else if (!string && !in) {
+            RAX(env) = rreg(cpu->accel->fd, HV_X86_RAX);
+            hvf_handle_io(env_cpu(env), port, &RAX(env), 1, size, 1);
+            macvm_set_rip(cpu, rip + ins_len);
+            break;
+        }
+
+        hvf_load_regs(cpu);
+        decode_instruction(env, &decode);
+        assert(ins_len == decode.len);
+        exec_instruction(env, &decode);
+        hvf_store_regs(cpu);
+
+        break;
+    }
+    case EXIT_REASON_CPUID: {
+        uint32_t rax = (uint32_t)rreg(cpu->accel->fd, HV_X86_RAX);
+        uint32_t rbx = (uint32_t)rreg(cpu->accel->fd, HV_X86_RBX);
+        uint32_t rcx = (uint32_t)rreg(cpu->accel->fd, HV_X86_RCX);
+        uint32_t rdx = (uint32_t)rreg(cpu->accel->fd, HV_X86_RDX);
+
+        if (rax == 1) {
+            /* CPUID1.ecx.OSXSAVE needs to know CR4 */
+            env->cr[4] = rvmcs(cpu->accel->fd, VMCS_GUEST_CR4);
+        }
+        hvf_cpu_x86_cpuid(env, rax, rcx, &rax, &rbx, &rcx, &rdx);
+
+        wreg(cpu->accel->fd, HV_X86_RAX, rax);
+        wreg(cpu->accel->fd, HV_X86_RBX, rbx);
+        wreg(cpu->accel->fd, HV_X86_RCX, rcx);
+        wreg(cpu->accel->fd, HV_X86_RDX, rdx);
+
+        macvm_set_rip(cpu, rip + ins_len);
+        break;
+    }
+    case EXIT_REASON_XSETBV: {
+        uint32_t eax = (uint32_t)rreg(cpu->accel->fd, HV_X86_RAX);
+        uint32_t ecx = (uint32_t)rreg(cpu->accel->fd, HV_X86_RCX);
+        uint32_t edx = (uint32_t)rreg(cpu->accel->fd, HV_X86_RDX);
+
+        if (ecx) {
+            macvm_set_rip(cpu, rip + ins_len);
+            break;
+        }
+        env->xcr0 = ((uint64_t)edx << 32) | eax;
+        wreg(cpu->accel->fd, HV_X86_XCR0, env->xcr0 | 1);
+        macvm_set_rip(cpu, rip + ins_len);
+        break;
+    }
+    case EXIT_REASON_INTR_WINDOW:
+        vmx_clear_int_window_exiting(cpu);
+        ret = EXCP_INTERRUPT;
+        break;
+    case EXIT_REASON_NMI_WINDOW:
+        vmx_clear_nmi_window_exiting(cpu);
+        ret = EXCP_INTERRUPT;
+        break;
+    case EXIT_REASON_EXT_INTR:
+        /* force exit and allow io handling */
+        ret = EXCP_INTERRUPT;
+        break;
+    case EXIT_REASON_RDMSR:
+    case EXIT_REASON_WRMSR:
+    {
+        hvf_load_regs(cpu);
+        if (exit_reason == EXIT_REASON_RDMSR) {
+            hvf_simulate_rdmsr(cpu);
+        } else {
+            hvf_simulate_wrmsr(cpu);
+        }
+        env->eip += ins_len;
+        hvf_store_regs(cpu);
+        break;
+    }
+    case EXIT_REASON_CR_ACCESS: {
+        int cr;
+        int reg;
+
+        hvf_load_regs(cpu);
+        cr = exit_qual & 15;
+        reg = (exit_qual >> 8) & 15;
+
+        switch (cr) {
+        case 0x0: {
+            macvm_set_cr0(cpu->accel->fd, RRX(env, reg));
+            break;
+        }
+        case 4: {
+            macvm_set_cr4(cpu->accel->fd, RRX(env, reg));
+            break;
+        }
+        case 8: {
+            if (exit_qual & 0x10) {
+                RRX(env, reg) = cpu_get_apic_tpr(x86_cpu->apic_state);
+            } else {
+                int tpr = RRX(env, reg);
+                cpu_set_apic_tpr(x86_cpu->apic_state, tpr);
+                ret = EXCP_INTERRUPT;
+            }
+            break;
+        }
+        default:
+            error_report("Unrecognized CR %d", cr);
+            abort();
+        }
+        env->eip += ins_len;
+        hvf_store_regs(cpu);
+        break;
+    }
+    case EXIT_REASON_APIC_ACCESS: { /* TODO */
+        struct x86_decode decode;
+
+        hvf_load_regs(cpu);
+        decode_instruction(env, &decode);
+        exec_instruction(env, &decode);
+        hvf_store_regs(cpu);
+        break;
+    }
+    case EXIT_REASON_TPR: {
+        ret = 1;
+        break;
+    }
+    case EXIT_REASON_TASK_SWITCH: {
+        uint64_t vinfo = rvmcs(cpu->accel->fd, VMCS_IDT_VECTORING_INFO);
+        x86_segment_selector sel = {.sel = exit_qual & 0xffff};
+
+        vmx_handle_task_switch(cpu, sel, (exit_qual >> 30) & 0x3,
+                               vinfo & VMCS_INTR_VALID,
+                               vinfo & VECTORING_INFO_VECTOR_MASK,
+                               vinfo & VMCS_INTR_T_MASK);
+        break;
+    }
+    case EXIT_REASON_TRIPLE_FAULT: {
+        qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
+        ret = EXCP_INTERRUPT;
+        break;
+    }
+    case EXIT_REASON_RDPMC:
+        wreg(cpu->accel->fd, HV_X86_RAX, 0);
+        wreg(cpu->accel->fd, HV_X86_RDX, 0);
+        macvm_set_rip(cpu, rip + ins_len);
+        break;
+    case VMX_REASON_VMCALL:
+        env->exception_nr = EXCP0D_GPF;
+        env->exception_injected = 1;
+        env->has_error_code = true;
+        env->error_code = 0;
+        break;
+    default:
+        error_report("%llx: unhandled exit %llx", rip, exit_reason);
+    }
+
+    return ret;
+}
+
 int hvf_arch_vcpu_exec(CPUState *cpu)
 {
     X86CPU *x86_cpu = X86_CPU(cpu);
@@ -752,240 +995,7 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
         hv_return_t r = hv_vcpu_run_until(cpu->accel->fd, HV_DEADLINE_FOREVER);
         assert_hvf_ok(r);
 
-        /* handle VMEXIT */
-        uint64_t exit_reason = rvmcs(cpu->accel->fd, VMCS_EXIT_REASON);
-        uint64_t exit_qual = rvmcs(cpu->accel->fd, VMCS_EXIT_QUALIFICATION);
-        uint32_t ins_len = (uint32_t)rvmcs(cpu->accel->fd,
-                                           VMCS_EXIT_INSTRUCTION_LENGTH);
-
-        uint64_t idtvec_info = rvmcs(cpu->accel->fd, VMCS_IDT_VECTORING_INFO);
-
-        hvf_store_events(cpu, ins_len, idtvec_info);
-        rip = rreg(cpu->accel->fd, HV_X86_RIP);
-        env->eflags = rreg(cpu->accel->fd, HV_X86_RFLAGS);
-
-        bql_lock();
-
-        update_apic_tpr(cpu);
-        current_cpu = cpu;
-
-        ret = 0;
-        switch (exit_reason) {
-        case EXIT_REASON_HLT: {
-            macvm_set_rip(cpu, rip + ins_len);
-            if (!(cpu_test_interrupt(cpu, CPU_INTERRUPT_HARD) &&
-                (env->eflags & IF_MASK))
-                && !cpu_test_interrupt(cpu, CPU_INTERRUPT_NMI) &&
-                !(idtvec_info & VMCS_IDT_VEC_VALID)) {
-                cpu->halted = 1;
-                ret = EXCP_HLT;
-                break;
-            }
-            ret = EXCP_INTERRUPT;
-            break;
-        }
-        case EXIT_REASON_MWAIT: {
-            ret = EXCP_INTERRUPT;
-            break;
-        }
-        /* Need to check if MMIO or unmapped fault */
-        case EXIT_REASON_EPT_FAULT:
-        {
-            hvf_slot *slot;
-            uint64_t gpa = rvmcs(cpu->accel->fd, VMCS_GUEST_PHYSICAL_ADDRESS);
-
-            if (((idtvec_info & VMCS_IDT_VEC_VALID) == 0) &&
-                ((exit_qual & EXIT_QUAL_NMIUDTI) != 0)) {
-                vmx_set_nmi_blocking(cpu);
-            }
-
-            slot = hvf_find_overlap_slot(gpa, 1);
-            /* mmio */
-            if (ept_emulation_fault(slot, gpa, exit_qual)) {
-                struct x86_decode decode;
-
-                hvf_load_regs(cpu);
-                decode_instruction(env, &decode);
-                exec_instruction(env, &decode);
-                hvf_store_regs(cpu);
-                break;
-            }
-            break;
-        }
-        case EXIT_REASON_INOUT:
-        {
-            uint32_t in = (exit_qual & 8) != 0;
-            uint32_t size =  (exit_qual & 7) + 1;
-            uint32_t string =  (exit_qual & 16) != 0;
-            uint32_t port =  exit_qual >> 16;
-            /*uint32_t rep = (exit_qual & 0x20) != 0;*/
-
-            if (!string && in) {
-                uint64_t val = 0;
-                hvf_load_regs(cpu);
-                hvf_handle_io(env_cpu(env), port, &val, 0, size, 1);
-                if (size == 1) {
-                    AL(env) = val;
-                } else if (size == 2) {
-                    AX(env) = val;
-                } else if (size == 4) {
-                    RAX(env) = (uint32_t)val;
-                } else {
-                    RAX(env) = (uint64_t)val;
-                }
-                env->eip += ins_len;
-                hvf_store_regs(cpu);
-                break;
-            } else if (!string && !in) {
-                RAX(env) = rreg(cpu->accel->fd, HV_X86_RAX);
-                hvf_handle_io(env_cpu(env), port, &RAX(env), 1, size, 1);
-                macvm_set_rip(cpu, rip + ins_len);
-                break;
-            }
-            struct x86_decode decode;
-
-            hvf_load_regs(cpu);
-            decode_instruction(env, &decode);
-            assert(ins_len == decode.len);
-            exec_instruction(env, &decode);
-            hvf_store_regs(cpu);
-
-            break;
-        }
-        case EXIT_REASON_CPUID: {
-            uint32_t rax = (uint32_t)rreg(cpu->accel->fd, HV_X86_RAX);
-            uint32_t rbx = (uint32_t)rreg(cpu->accel->fd, HV_X86_RBX);
-            uint32_t rcx = (uint32_t)rreg(cpu->accel->fd, HV_X86_RCX);
-            uint32_t rdx = (uint32_t)rreg(cpu->accel->fd, HV_X86_RDX);
-
-            if (rax == 1) {
-                /* CPUID1.ecx.OSXSAVE needs to know CR4 */
-                env->cr[4] = rvmcs(cpu->accel->fd, VMCS_GUEST_CR4);
-            }
-            hvf_cpu_x86_cpuid(env, rax, rcx, &rax, &rbx, &rcx, &rdx);
-
-            wreg(cpu->accel->fd, HV_X86_RAX, rax);
-            wreg(cpu->accel->fd, HV_X86_RBX, rbx);
-            wreg(cpu->accel->fd, HV_X86_RCX, rcx);
-            wreg(cpu->accel->fd, HV_X86_RDX, rdx);
-
-            macvm_set_rip(cpu, rip + ins_len);
-            break;
-        }
-        case EXIT_REASON_XSETBV: {
-            uint32_t eax = (uint32_t)rreg(cpu->accel->fd, HV_X86_RAX);
-            uint32_t ecx = (uint32_t)rreg(cpu->accel->fd, HV_X86_RCX);
-            uint32_t edx = (uint32_t)rreg(cpu->accel->fd, HV_X86_RDX);
-
-            if (ecx) {
-                macvm_set_rip(cpu, rip + ins_len);
-                break;
-            }
-            env->xcr0 = ((uint64_t)edx << 32) | eax;
-            wreg(cpu->accel->fd, HV_X86_XCR0, env->xcr0 | 1);
-            macvm_set_rip(cpu, rip + ins_len);
-            break;
-        }
-        case EXIT_REASON_INTR_WINDOW:
-            vmx_clear_int_window_exiting(cpu);
-            ret = EXCP_INTERRUPT;
-            break;
-        case EXIT_REASON_NMI_WINDOW:
-            vmx_clear_nmi_window_exiting(cpu);
-            ret = EXCP_INTERRUPT;
-            break;
-        case EXIT_REASON_EXT_INTR:
-            /* force exit and allow io handling */
-            ret = EXCP_INTERRUPT;
-            break;
-        case EXIT_REASON_RDMSR:
-        case EXIT_REASON_WRMSR:
-        {
-            hvf_load_regs(cpu);
-            if (exit_reason == EXIT_REASON_RDMSR) {
-                hvf_simulate_rdmsr(cpu);
-            } else {
-                hvf_simulate_wrmsr(cpu);
-            }
-            env->eip += ins_len;
-            hvf_store_regs(cpu);
-            break;
-        }
-        case EXIT_REASON_CR_ACCESS: {
-            int cr;
-            int reg;
-
-            hvf_load_regs(cpu);
-            cr = exit_qual & 15;
-            reg = (exit_qual >> 8) & 15;
-
-            switch (cr) {
-            case 0x0: {
-                macvm_set_cr0(cpu->accel->fd, RRX(env, reg));
-                break;
-            }
-            case 4: {
-                macvm_set_cr4(cpu->accel->fd, RRX(env, reg));
-                break;
-            }
-            case 8: {
-                if (exit_qual & 0x10) {
-                    RRX(env, reg) = cpu_get_apic_tpr(x86_cpu->apic_state);
-                } else {
-                    int tpr = RRX(env, reg);
-                    cpu_set_apic_tpr(x86_cpu->apic_state, tpr);
-                    ret = EXCP_INTERRUPT;
-                }
-                break;
-            }
-            default:
-                error_report("Unrecognized CR %d", cr);
-                abort();
-            }
-            env->eip += ins_len;
-            hvf_store_regs(cpu);
-            break;
-        }
-        case EXIT_REASON_APIC_ACCESS: { /* TODO */
-            struct x86_decode decode;
-
-            hvf_load_regs(cpu);
-            decode_instruction(env, &decode);
-            exec_instruction(env, &decode);
-            hvf_store_regs(cpu);
-            break;
-        }
-        case EXIT_REASON_TPR: {
-            ret = 1;
-            break;
-        }
-        case EXIT_REASON_TASK_SWITCH: {
-            uint64_t vinfo = rvmcs(cpu->accel->fd, VMCS_IDT_VECTORING_INFO);
-            x86_segment_selector sel = {.sel = exit_qual & 0xffff};
-            vmx_handle_task_switch(cpu, sel, (exit_qual >> 30) & 0x3,
-             vinfo & VMCS_INTR_VALID, vinfo & VECTORING_INFO_VECTOR_MASK, vinfo
-             & VMCS_INTR_T_MASK);
-            break;
-        }
-        case EXIT_REASON_TRIPLE_FAULT: {
-            qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
-            ret = EXCP_INTERRUPT;
-            break;
-        }
-        case EXIT_REASON_RDPMC:
-            wreg(cpu->accel->fd, HV_X86_RAX, 0);
-            wreg(cpu->accel->fd, HV_X86_RDX, 0);
-            macvm_set_rip(cpu, rip + ins_len);
-            break;
-        case VMX_REASON_VMCALL:
-            env->exception_nr = EXCP0D_GPF;
-            env->exception_injected = 1;
-            env->has_error_code = true;
-            env->error_code = 0;
-            break;
-        default:
-            error_report("%llx: unhandled exit %llx", rip, exit_reason);
-        }
+        ret = hvf_handle_vmexit(cpu);
     } while (ret == 0);
 
     return ret;
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 19/59] target/arm/hvf: Factor hvf_handle_vmexit() out
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (17 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 18/59] target/i386/hvf: Factor hvf_handle_vmexit() out Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 20/59] target/arm/hvf: Keep calling hv_vcpu_run() in loop Philippe Mathieu-Daudé
                   ` (40 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Factor hvf_handle_vmexit() out of hvf_vcpu_exec().

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
---
 target/arm/hvf/hvf.c | 50 ++++++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 23 deletions(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 8553ce6adc2..27c600148f9 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1984,10 +1984,33 @@ static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp)
     return ret;
 }
 
+static int hvf_handle_vmexit(CPUState *cpu, hv_vcpu_exit_t *exit)
+{
+    ARMCPU *arm_cpu = env_archcpu(cpu_env(cpu));
+    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)
 {
-    ARMCPU *arm_cpu = ARM_CPU(cpu);
-    hv_vcpu_exit_t *hvf_exit = cpu->accel->exit;
+    int ret;
     hv_return_t r;
 
     if (!(cpu->singlestep_enabled & SSTEP_NOIRQ) &&
@@ -2006,6 +2029,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();
@@ -2014,27 +2038,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 = {
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 20/59] target/arm/hvf: Keep calling hv_vcpu_run() in loop
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (18 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 19/59] target/arm/hvf: " Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 21/59] cpus: Trace cpu_exec_start() and cpu_exec_end() calls Philippe Mathieu-Daudé
                   ` (39 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Mads Ynddal <mads@ynddal.dk>
---
 target/arm/hvf/hvf.c | 38 ++++++++++++++++++++------------------
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 27c600148f9..79861dcacf9 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -2013,30 +2013,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);
 
-    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();
-    }
+    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();
+        }
+    } while (ret == 0);
 
     return ret;
 }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 21/59] cpus: Trace cpu_exec_start() and cpu_exec_end() calls
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (19 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 20/59] target/arm/hvf: Keep calling hv_vcpu_run() in loop Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 22/59] accel/hvf: Guard hv_vcpu_run() between cpu_exec_start/end() calls Philippe Mathieu-Daudé
                   ` (38 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé, Paolo Bonzini,
	Stefan Hajnoczi

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 cpu-common.c | 3 +++
 trace-events | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/cpu-common.c b/cpu-common.c
index 0eb5c7b8f24..988d057d844 100644
--- a/cpu-common.c
+++ b/cpu-common.c
@@ -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,
diff --git a/trace-events b/trace-events
index 3ec8a6c7202..faeba6242fa 100644
--- a/trace-events
+++ b/trace-events
@@ -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)"
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 22/59] accel/hvf: Guard hv_vcpu_run() between cpu_exec_start/end() calls
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (20 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 21/59] cpus: Trace cpu_exec_start() and cpu_exec_end() calls Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:41 ` [PATCH v3 23/59] target/arm: Call aarch64_add_pauth_properties() once in host_initfn() Philippe Mathieu-Daudé
                   ` (37 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

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").

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/hvf/hvf.c  | 2 ++
 target/i386/hvf/hvf.c | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 79861dcacf9..c882f4c89cf 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -2026,7 +2026,9 @@ int hvf_arch_vcpu_exec(CPUState *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:
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 28d98659ec2..16febbac48f 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -992,9 +992,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);
+
         ret = hvf_handle_vmexit(cpu);
     } while (ret == 0);
 
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 23/59] target/arm: Call aarch64_add_pauth_properties() once in host_initfn()
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (21 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 22/59] accel/hvf: Guard hv_vcpu_run() between cpu_exec_start/end() calls Philippe Mathieu-Daudé
@ 2025-10-28  5:41 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 24/59] accel/hvf: Restrict ARM specific fields of AccelCPUState Philippe Mathieu-Daudé
                   ` (36 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/cpu64.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
index 26cf7e6dfa2..f81cfd0113c 100644
--- a/target/arm/cpu64.c
+++ b/target/arm/cpu64.c
@@ -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)
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 24/59] accel/hvf: Restrict ARM specific fields of AccelCPUState
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (22 preceding siblings ...)
  2025-10-28  5:41 ` [PATCH v3 23/59] target/arm: Call aarch64_add_pauth_properties() once in host_initfn() Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 25/59] target/arm: Rename init_cpreg_list() -> arm_init_cpreg_list() Philippe Mathieu-Daudé
                   ` (35 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, 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é <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/system/hvf_int.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h
index 195d64dcf18..3d2be4092ef 100644
--- a/include/system/hvf_int.h
+++ b/include/system/hvf_int.h
@@ -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,
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 25/59] target/arm: Rename init_cpreg_list() -> arm_init_cpreg_list()
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (23 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 24/59] accel/hvf: Restrict ARM specific fields of AccelCPUState Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 26/59] target/arm/hvf: Rename 'vgic' -> 'emu_reginfo' in trace events Philippe Mathieu-Daudé
                   ` (34 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Prefix init_cpreg_list() with 'arm_'.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/arm/internals.h | 2 +-
 target/arm/cpu.c       | 2 +-
 target/arm/helper.c    | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/target/arm/internals.h b/target/arm/internals.h
index f86f421a3db..773c08d4f7c 100644
--- a/target/arm/internals.h
+++ b/target/arm/internals.h
@@ -376,7 +376,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);
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index d2fc17eab63..39292fb9bc1 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -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());
diff --git a/target/arm/helper.c b/target/arm/helper.c
index 2ef9c178147..31bb3ce5172 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -252,7 +252,7 @@ static void count_cpreg(gpointer key, gpointer value, gpointer opaque)
     }
 }
 
-void init_cpreg_list(ARMCPU *cpu)
+void arm_init_cpreg_list(ARMCPU *cpu)
 {
     /*
      * Initialise the cpreg_tuples[] array based on the cp_regs hash.
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 26/59] target/arm/hvf: Rename 'vgic' -> 'emu_reginfo' in trace events
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (24 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 25/59] target/arm: Rename init_cpreg_list() -> arm_init_cpreg_list() Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28 11:23   ` Peter Maydell
  2025-10-28  5:42 ` [PATCH v3 27/59] target/arm: Re-use arm_is_psci_call() in HVF Philippe Mathieu-Daudé
                   ` (33 subsequent siblings)
  59 siblings, 1 reply; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

In order to extend the trace events to other registers,
rename and pass the register group as argument.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/hvf/hvf.c        | 14 ++++++++------
 target/arm/hvf/trace-events |  4 ++--
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index c882f4c89cf..26bafee259e 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1149,7 +1149,8 @@ static uint32_t hvf_reg2cp_reg(uint32_t reg)
                               (reg >> SYSREG_OP2_SHIFT) & SYSREG_OP2_MASK);
 }
 
-static bool hvf_sysreg_read_cp(CPUState *cpu, uint32_t reg, uint64_t *val)
+static bool hvf_sysreg_read_cp(CPUState *cpu, const char *cpname,
+                               uint32_t reg, uint64_t *val)
 {
     ARMCPU *arm_cpu = ARM_CPU(cpu);
     CPUARMState *env = &arm_cpu->env;
@@ -1172,7 +1173,7 @@ static bool hvf_sysreg_read_cp(CPUState *cpu, uint32_t reg, uint64_t *val)
         } else {
             *val = raw_read(env, ri);
         }
-        trace_hvf_vgic_read(ri->name, *val);
+        trace_hvf_emu_reginfo_read(cpname, ri->name, *val);
         return true;
     }
 
@@ -1261,7 +1262,7 @@ static int hvf_sysreg_read(CPUState *cpu, uint32_t reg, uint64_t *val)
     case SYSREG_ICC_SRE_EL1:
     case SYSREG_ICC_CTLR_EL1:
         /* Call the TCG sysreg handler. This is only safe for GICv3 regs. */
-        if (hvf_sysreg_read_cp(cpu, reg, val)) {
+        if (hvf_sysreg_read_cp(cpu, "GICv3", reg, val)) {
             return 0;
         }
         break;
@@ -1432,7 +1433,8 @@ static void pmswinc_write(CPUARMState *env, uint64_t value)
     }
 }
 
-static bool hvf_sysreg_write_cp(CPUState *cpu, uint32_t reg, uint64_t val)
+static bool hvf_sysreg_write_cp(CPUState *cpu, const char *cpname,
+                                uint32_t reg, uint64_t val)
 {
     ARMCPU *arm_cpu = ARM_CPU(cpu);
     CPUARMState *env = &arm_cpu->env;
@@ -1455,7 +1457,7 @@ static bool hvf_sysreg_write_cp(CPUState *cpu, uint32_t reg, uint64_t val)
             raw_write(env, ri, val);
         }
 
-        trace_hvf_vgic_write(ri->name, val);
+        trace_hvf_emu_reginfo_write(cpname, ri->name, val);
         return true;
     }
 
@@ -1581,7 +1583,7 @@ static int hvf_sysreg_write(CPUState *cpu, uint32_t reg, uint64_t val)
     case SYSREG_ICC_SGI1R_EL1:
     case SYSREG_ICC_SRE_EL1:
         /* Call the TCG sysreg handler. This is only safe for GICv3 regs. */
-        if (hvf_sysreg_write_cp(cpu, reg, val)) {
+        if (hvf_sysreg_write_cp(cpu, "GICv3", reg, val)) {
             return 0;
         }
         break;
diff --git a/target/arm/hvf/trace-events b/target/arm/hvf/trace-events
index 538af6e0707..29387780e3f 100644
--- a/target/arm/hvf/trace-events
+++ b/target/arm/hvf/trace-events
@@ -9,7 +9,7 @@ hvf_unknown_hvc(uint64_t pc, uint64_t x0) "pc=0x%"PRIx64" unknown HVC! 0x%016"PR
 hvf_unknown_smc(uint64_t x0) "unknown SMC! 0x%016"PRIx64
 hvf_exit(uint64_t syndrome, uint32_t ec, uint64_t pc) "exit: 0x%"PRIx64" [ec=0x%x pc=0x%"PRIx64"]"
 hvf_psci_call(uint64_t x0, uint64_t x1, uint64_t x2, uint64_t x3, uint32_t cpuid) "PSCI Call x0=0x%016"PRIx64" x1=0x%016"PRIx64" x2=0x%016"PRIx64" x3=0x%016"PRIx64" cpuid=0x%x"
-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_emu_reginfo_write(const char *cpname, const char *regname, uint64_t val) "[%s] write to %s [val=0x%016"PRIx64"]"
+hvf_emu_reginfo_read(const char *cpname, const char *regname, uint64_t val) "[%s] 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"
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 27/59] target/arm: Re-use arm_is_psci_call() in HVF
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (25 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 26/59] target/arm/hvf: Rename 'vgic' -> 'emu_reginfo' in trace events Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 28/59] target/arm: Share ARM_PSCI_CALL trace event between TCG and HVF Philippe Mathieu-Daudé
                   ` (32 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Re-use arm_is_psci_call() instead of open-coding it.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/hvf/hvf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 26bafee259e..a3bb71e63b9 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1934,7 +1934,7 @@ static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp)
         break;
     case EC_AA64_HVC:
         cpu_synchronize_state(cpu);
-        if (arm_cpu->psci_conduit == QEMU_PSCI_CONDUIT_HVC) {
+        if (arm_is_psci_call(arm_cpu, EXCP_HVC)) {
             if (!hvf_handle_psci_call(cpu)) {
                 trace_hvf_unknown_hvc(env->pc, env->xregs[0]);
                 /* SMCCC 1.3 section 5.2 says every unknown SMCCC call returns -1 */
@@ -1947,7 +1947,7 @@ static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp)
         break;
     case EC_AA64_SMC:
         cpu_synchronize_state(cpu);
-        if (arm_cpu->psci_conduit == QEMU_PSCI_CONDUIT_SMC) {
+        if (arm_is_psci_call(arm_cpu, EXCP_SMC)) {
             advance_pc = true;
 
             if (!hvf_handle_psci_call(cpu)) {
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 28/59] target/arm: Share ARM_PSCI_CALL trace event between TCG and HVF
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (26 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 27/59] target/arm: Re-use arm_is_psci_call() in HVF Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 29/59] target/arm/hvf/hvf: Document $pc adjustment in HVF & SMC Philippe Mathieu-Daudé
                   ` (31 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

It is useful to compare PSCI calls of the same guest running
under TCG or HVF.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/hvf/hvf.c    | 3 ++-
 target/arm/tcg/psci.c   | 3 +++
 target/arm/trace-events | 3 +++
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index a3bb71e63b9..f31b6e54ee7 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -34,6 +34,7 @@
 #include "target/arm/internals.h"
 #include "target/arm/multiprocessing.h"
 #include "target/arm/gtimer.h"
+#include "target/arm/trace.h"
 #include "trace.h"
 #include "migration/vmstate.h"
 
@@ -1025,7 +1026,7 @@ static bool hvf_handle_psci_call(CPUState *cpu)
     int target_el = 1;
     int32_t ret = 0;
 
-    trace_hvf_psci_call(param[0], param[1], param[2], param[3],
+    trace_arm_psci_call(param[0], param[1], param[2], param[3],
                         arm_cpu_mp_affinity(arm_cpu));
 
     switch (param[0]) {
diff --git a/target/arm/tcg/psci.c b/target/arm/tcg/psci.c
index cabed43e8a8..2d409301578 100644
--- a/target/arm/tcg/psci.c
+++ b/target/arm/tcg/psci.c
@@ -25,6 +25,7 @@
 #include "internals.h"
 #include "arm-powerctl.h"
 #include "target/arm/multiprocessing.h"
+#include "target/arm/trace.h"
 
 bool arm_is_psci_call(ARMCPU *cpu, int excp_type)
 {
@@ -79,6 +80,8 @@ void arm_handle_psci_call(ARMCPU *cpu)
          */
         param[i] = is_a64(env) ? env->xregs[i] : env->regs[i];
     }
+    trace_arm_psci_call(param[0], param[1], param[2], param[3],
+                        arm_cpu_mp_affinity(cpu));
 
     if ((param[0] & QEMU_PSCI_0_2_64BIT) && !is_a64(env)) {
         ret = QEMU_PSCI_RET_NOT_SUPPORTED;
diff --git a/target/arm/trace-events b/target/arm/trace-events
index 72a2c7d0969..676d29fe516 100644
--- a/target/arm/trace-events
+++ b/target/arm/trace-events
@@ -23,3 +23,6 @@ arm_powerctl_set_cpu_on(uint64_t mp_aff, unsigned target_el, const char *mode, u
 arm_powerctl_set_cpu_on_and_reset(uint64_t mp_aff) "cpu %" PRIu64
 arm_powerctl_set_cpu_off(uint64_t mp_aff) "cpu %" PRIu64
 arm_powerctl_reset_cpu(uint64_t mp_aff) "cpu %" PRIu64
+
+# tcg/psci.c and hvf/hvf.c
+arm_psci_call(uint64_t x0, uint64_t x1, uint64_t x2, uint64_t x3, uint32_t cpuid) "PSCI Call x0=0x%016"PRIx64" x1=0x%016"PRIx64" x2=0x%016"PRIx64" x3=0x%016"PRIx64" cpuid=0x%x"
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 29/59] target/arm/hvf/hvf: Document $pc adjustment in HVF & SMC
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (27 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 28/59] target/arm: Share ARM_PSCI_CALL trace event between TCG and HVF Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 30/59] accel/hvf: Trace prefetch abort Philippe Mathieu-Daudé
                   ` (30 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/hvf/hvf.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index f31b6e54ee7..805fe75e6b1 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1936,6 +1936,7 @@ static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp)
     case EC_AA64_HVC:
         cpu_synchronize_state(cpu);
         if (arm_is_psci_call(arm_cpu, EXCP_HVC)) {
+            /* Do NOT advance $pc for HVC */
             if (!hvf_handle_psci_call(cpu)) {
                 trace_hvf_unknown_hvc(env->pc, env->xregs[0]);
                 /* SMCCC 1.3 section 5.2 says every unknown SMCCC call returns -1 */
@@ -1949,6 +1950,7 @@ static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp)
     case EC_AA64_SMC:
         cpu_synchronize_state(cpu);
         if (arm_is_psci_call(arm_cpu, EXCP_SMC)) {
+            /* Secure Monitor Call exception, we need to advance $pc */
             advance_pc = true;
 
             if (!hvf_handle_psci_call(cpu)) {
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 30/59] accel/hvf: Trace prefetch abort
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (28 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 29/59] target/arm/hvf/hvf: Document $pc adjustment in HVF & SMC Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 31/59] accel/hvf: Create hvf_protect_clean_range, hvf_unprotect_dirty_range Philippe Mathieu-Daudé
                   ` (29 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/hvf/hvf.c        | 11 +++++++++++
 target/arm/hvf/trace-events |  1 +
 2 files changed, 12 insertions(+)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 805fe75e6b1..de1e8fb8a05 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1963,6 +1963,17 @@ static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp)
             hvf_raise_exception(cpu, EXCP_UDEF, syn_uncategorized(), 1);
         }
         break;
+    case EC_INSNABORT: {
+        uint32_t set = (syndrome >> 12) & 3;
+        bool fnv = (syndrome >> 10) & 1;
+        bool ea = (syndrome >> 9) & 1;
+        bool s1ptw = (syndrome >> 7) & 1;
+        uint32_t ifsc = (syndrome >> 0) & 0x3f;
+
+        trace_hvf_insn_abort(env->pc, set, fnv, ea, s1ptw, ifsc);
+
+        /* fall through */
+    }
     default:
         cpu_synchronize_state(cpu);
         trace_hvf_exit(syndrome, ec, env->pc);
diff --git a/target/arm/hvf/trace-events b/target/arm/hvf/trace-events
index 29387780e3f..b0d3d7bd322 100644
--- a/target/arm/hvf/trace-events
+++ b/target/arm/hvf/trace-events
@@ -3,6 +3,7 @@ hvf_unhandled_sysreg_write(uint64_t pc, uint32_t reg, uint32_t op0, uint32_t op1
 hvf_inject_fiq(void) "injecting FIQ"
 hvf_inject_irq(void) "injecting IRQ"
 hvf_data_abort(uint64_t va, uint64_t pa, bool isv, bool iswrite, bool s1ptw, uint32_t len, uint32_t srt) "data abort: [va=0x%016"PRIx64" pa=0x%016"PRIx64" isv=%d iswrite=%d s1ptw=%d len=%d srt=%d]"
+hvf_insn_abort(uint64_t pc, uint32_t set, bool fnv, bool ea, bool s1ptw, uint32_t ifsc) "insn abort: [pc=0x%"PRIx64" set=%d fnv=%d ea=%d s1ptw=%d ifsc=%d]"
 hvf_sysreg_read(uint32_t reg, uint32_t op0, uint32_t op1, uint32_t crn, uint32_t crm, uint32_t op2, uint64_t val) "sysreg read 0x%08x (op0=%d op1=%d crn=%d crm=%d op2=%d) = 0x%016"PRIx64
 hvf_sysreg_write(uint32_t reg, uint32_t op0, uint32_t op1, uint32_t crn, uint32_t crm, uint32_t op2, uint64_t val) "sysreg write 0x%08x (op0=%d op1=%d crn=%d crm=%d op2=%d, val=0x%016"PRIx64")"
 hvf_unknown_hvc(uint64_t pc, uint64_t x0) "pc=0x%"PRIx64" unknown HVC! 0x%016"PRIx64
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 31/59] accel/hvf: Create hvf_protect_clean_range, hvf_unprotect_dirty_range
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (29 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 30/59] accel/hvf: Trace prefetch abort Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 32/59] accel/hvf: Enforce host alignment in hv_vm_protect() Philippe Mathieu-Daudé
                   ` (28 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

From: Richard Henderson <richard.henderson@linaro.org>

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/system/hvf_int.h |  3 +++
 accel/hvf/hvf-all.c      | 25 +++++++++++++++++++++++++
 accel/hvf/trace-events   |  1 +
 3 files changed, 29 insertions(+)

diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h
index 3d2be4092ef..5a57691885f 100644
--- a/include/system/hvf_int.h
+++ b/include/system/hvf_int.h
@@ -89,6 +89,9 @@ int hvf_arch_get_registers(CPUState *);
 /* Must be called by the owning thread */
 void hvf_arch_update_guest_debug(CPUState *cpu);
 
+void hvf_protect_clean_range(hwaddr addr, size_t size);
+void hvf_unprotect_dirty_range(hwaddr addr, size_t size);
+
 struct hvf_sw_breakpoint {
     vaddr pc;
     vaddr saved_insn;
diff --git a/accel/hvf/hvf-all.c b/accel/hvf/hvf-all.c
index 0a4b498e836..e13abddbd9c 100644
--- a/accel/hvf/hvf-all.c
+++ b/accel/hvf/hvf-all.c
@@ -58,6 +58,31 @@ void assert_hvf_ok_impl(hv_return_t ret, const char *file, unsigned int line,
     abort();
 }
 
+static void do_hv_vm_protect(hwaddr start, size_t size,
+                             hv_memory_flags_t flags)
+{
+    hv_return_t ret;
+
+    trace_hvf_vm_protect(start, size, flags,
+                         flags & HV_MEMORY_READ  ? 'R' : '-',
+                         flags & HV_MEMORY_WRITE ? 'W' : '-',
+                         flags & HV_MEMORY_EXEC  ? 'X' : '-');
+
+    ret = hv_vm_protect(start, size, flags);
+    assert_hvf_ok(ret);
+}
+
+void hvf_protect_clean_range(hwaddr addr, size_t size)
+{
+    do_hv_vm_protect(addr, size, HV_MEMORY_READ | HV_MEMORY_EXEC);
+}
+
+void hvf_unprotect_dirty_range(hwaddr addr, size_t size)
+{
+    do_hv_vm_protect(addr, size,
+                     HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
+}
+
 static int do_hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags)
 {
     struct mac_slot *macslot;
diff --git a/accel/hvf/trace-events b/accel/hvf/trace-events
index 2fd3e127c74..f989da59492 100644
--- a/accel/hvf/trace-events
+++ b/accel/hvf/trace-events
@@ -5,3 +5,4 @@
 # hvf-accel-ops.c
 hvf_vm_map(uint64_t paddr, uint64_t size, void *vaddr, uint8_t flags, const char r, const char w, const char e) "paddr:0x%016"PRIx64" size:0x%08"PRIx64" vaddr:%p flags:0x%02x/%c%c%c"
 hvf_vm_unmap(uint64_t paddr, uint64_t size) "paddr:0x%016"PRIx64" size:0x%08"PRIx64
+hvf_vm_protect(uint64_t paddr, size_t size, uint8_t flags, const char r, const char w, const char e) "paddr:0x%016"PRIx64" size:0x%08zx flags:0x%02x/%c%c%c"
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 32/59] accel/hvf: Enforce host alignment in hv_vm_protect()
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (30 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 31/59] accel/hvf: Create hvf_protect_clean_range, hvf_unprotect_dirty_range Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28 11:26   ` Peter Maydell
  2025-10-28 11:44   ` Richard Henderson
  2025-10-28  5:42 ` [PATCH v3 33/59] target/i386/hvf: Use host page alignment in ept_emulation_fault() Philippe Mathieu-Daudé
                   ` (27 subsequent siblings)
  59 siblings, 2 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

hv_vm_protect() arguments must be aligned to host page.

Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 accel/hvf/hvf-all.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/accel/hvf/hvf-all.c b/accel/hvf/hvf-all.c
index e13abddbd9c..2efecdc9f40 100644
--- a/accel/hvf/hvf-all.c
+++ b/accel/hvf/hvf-all.c
@@ -11,6 +11,7 @@
 #include "qemu/osdep.h"
 #include "qemu/error-report.h"
 #include "accel/accel-ops.h"
+#include "exec/cpu-common.h"
 #include "system/address-spaces.h"
 #include "system/memory.h"
 #include "system/hvf.h"
@@ -67,6 +68,8 @@ static void do_hv_vm_protect(hwaddr start, size_t size,
                          flags & HV_MEMORY_READ  ? 'R' : '-',
                          flags & HV_MEMORY_WRITE ? 'W' : '-',
                          flags & HV_MEMORY_EXEC  ? 'X' : '-');
+    g_assert(!((uintptr_t)start & ~qemu_real_host_page_mask()));
+    g_assert(!(size & ~qemu_real_host_page_mask()));
 
     ret = hv_vm_protect(start, size, flags);
     assert_hvf_ok(ret);
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 33/59] target/i386/hvf: Use host page alignment in ept_emulation_fault()
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (31 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 32/59] accel/hvf: Enforce host alignment in hv_vm_protect() Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28 11:28   ` Peter Maydell
  2025-10-28 11:47   ` Richard Henderson
  2025-10-28  5:42 ` [PATCH v3 34/59] target/i386/hvf: Use hvf_unprotect_page Philippe Mathieu-Daudé
                   ` (26 subsequent siblings)
  59 siblings, 2 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/i386/hvf/hvf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 16febbac48f..c0b2352b988 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -76,7 +76,7 @@
 #include "qemu/main-loop.h"
 #include "qemu/accel.h"
 #include "target/i386/cpu.h"
-#include "exec/target_page.h"
+#include "exec/cpu-common.h"
 
 static Error *invtsc_mig_blocker;
 
@@ -137,9 +137,9 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)
 
     if (write && slot) {
         if (slot->flags & HVF_SLOT_LOG) {
-            uint64_t dirty_page_start = gpa & ~(TARGET_PAGE_SIZE - 1u);
+            uint64_t dirty_page_start = gpa & qemu_real_host_page_mask();
             memory_region_set_dirty(slot->region, gpa - slot->start, 1);
-            hv_vm_protect(dirty_page_start, TARGET_PAGE_SIZE,
+            hv_vm_protect(dirty_page_start, qemu_real_host_page_size(),
                           HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
         }
     }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 34/59] target/i386/hvf: Use hvf_unprotect_page
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (32 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 33/59] target/i386/hvf: Use host page alignment in ept_emulation_fault() Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28 11:29   ` Peter Maydell
  2025-10-28  5:42 ` [PATCH v3 35/59] target/i386/hvf: Use address_space_translate in ept_emulation_fault Philippe Mathieu-Daudé
                   ` (25 subsequent siblings)
  59 siblings, 1 reply; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

From: Richard Henderson <richard.henderson@linaro.org>

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/i386/hvf/hvf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index c0b2352b988..1e92e9b707b 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -139,8 +139,8 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)
         if (slot->flags & HVF_SLOT_LOG) {
             uint64_t dirty_page_start = gpa & qemu_real_host_page_mask();
             memory_region_set_dirty(slot->region, gpa - slot->start, 1);
-            hv_vm_protect(dirty_page_start, qemu_real_host_page_size(),
-                          HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
+            hvf_unprotect_dirty_range(dirty_page_start,
+                                      qemu_real_host_page_size());
         }
     }
 
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 35/59] target/i386/hvf: Use address_space_translate in ept_emulation_fault
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (33 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 34/59] target/i386/hvf: Use hvf_unprotect_page Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 36/59] accel/hvf: Simplify hvf_log_* Philippe Mathieu-Daudé
                   ` (24 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

From: Richard Henderson <richard.henderson@linaro.org>

The hvf_slot structure is a poor replacement for properly
looking up a memory region in the address space.
Use memory_region_get_dirty_log_mask instead of HVF_SLOT_LOG.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/i386/hvf/hvf.c | 37 +++++++++++++++++++------------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 1e92e9b707b..b0c3fb97864 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -119,9 +119,12 @@ void hvf_handle_io(CPUState *env, uint16_t port, void *buffer,
     }
 }
 
-static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)
+static bool ept_emulation_fault(CPUState *cs, uint64_t gpa, uint64_t ept_qual)
 {
-    int read, write;
+    bool read, write;
+    MemoryRegion *mr;
+    hwaddr gpa_page = gpa & qemu_real_host_page_mask();
+    hwaddr xlat;
 
     /* EPT fault on an instruction fetch doesn't make sense here */
     if (ept_qual & EPT_VIOLATION_INST_FETCH) {
@@ -129,19 +132,22 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)
     }
 
     /* EPT fault must be a read fault or a write fault */
-    read = ept_qual & EPT_VIOLATION_DATA_READ ? 1 : 0;
-    write = ept_qual & EPT_VIOLATION_DATA_WRITE ? 1 : 0;
-    if ((read | write) == 0) {
+    read = ept_qual & EPT_VIOLATION_DATA_READ;
+    write = ept_qual & EPT_VIOLATION_DATA_WRITE;
+    if (!read && !write) {
         return false;
     }
 
-    if (write && slot) {
-        if (slot->flags & HVF_SLOT_LOG) {
-            uint64_t dirty_page_start = gpa & qemu_real_host_page_mask();
-            memory_region_set_dirty(slot->region, gpa - slot->start, 1);
-            hvf_unprotect_dirty_range(dirty_page_start,
-                                      qemu_real_host_page_size());
-        }
+    mr = address_space_translate(cpu_get_address_space(cs, X86ASIdx_MEM),
+                                 gpa_page, &xlat, NULL, write,
+                                 MEMTXATTRS_UNSPECIFIED);
+
+    /* Handle dirty page logging for ram. */
+    if (write && memory_region_get_dirty_log_mask(mr)) {
+        size_t page_size = qemu_real_host_page_size();
+
+        memory_region_set_dirty(mr, gpa_page + xlat, page_size);
+        hvf_unprotect_dirty_range(gpa_page, page_size);
     }
 
     /*
@@ -154,9 +160,6 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)
         return false;
     }
 
-    if (!slot) {
-        return true;
-    }
     if (!memory_region_is_ram(slot->region) &&
         !(read && memory_region_is_romd(slot->region))) {
         return true;
@@ -762,7 +765,6 @@ static int hvf_handle_vmexit(CPUState *cpu)
     /* Need to check if MMIO or unmapped fault */
     case EXIT_REASON_EPT_FAULT:
     {
-        hvf_slot *slot;
         uint64_t gpa = rvmcs(cpu->accel->fd, VMCS_GUEST_PHYSICAL_ADDRESS);
 
         if (((idtvec_info & VMCS_IDT_VEC_VALID) == 0) &&
@@ -770,9 +772,8 @@ static int hvf_handle_vmexit(CPUState *cpu)
             vmx_set_nmi_blocking(cpu);
         }
 
-        slot = hvf_find_overlap_slot(gpa, 1);
         /* mmio */
-        if (ept_emulation_fault(slot, gpa, exit_qual)) {
+        if (ept_emulation_fault(cpu, gpa, exit_qual)) {
             struct x86_decode decode;
 
             hvf_load_regs(cpu);
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 36/59] accel/hvf: Simplify hvf_log_*
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (34 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 35/59] target/i386/hvf: Use address_space_translate in ept_emulation_fault Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 37/59] accel/hvf: Move hvf_log_sync to hvf_log_clear Philippe Mathieu-Daudé
                   ` (23 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

From: Richard Henderson <richard.henderson@linaro.org>

Rely on the AddressSpace and MemoryRegion structures
rather than hvf_slot.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/system/hvf_int.h |  3 ---
 accel/hvf/hvf-all.c      | 40 ++++++++++------------------------------
 2 files changed, 10 insertions(+), 33 deletions(-)

diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h
index 5a57691885f..ee7ab689f45 100644
--- a/include/system/hvf_int.h
+++ b/include/system/hvf_int.h
@@ -24,9 +24,6 @@ typedef hv_vcpu_t hvf_vcpuid;
 typedef hv_vcpuid_t hvf_vcpuid;
 #endif
 
-/* hvf_slot flags */
-#define HVF_SLOT_LOG (1 << 0)
-
 typedef struct hvf_slot {
     uint64_t start;
     uint64_t size;
diff --git a/accel/hvf/hvf-all.c b/accel/hvf/hvf-all.c
index 2efecdc9f40..361d658a186 100644
--- a/accel/hvf/hvf-all.c
+++ b/accel/hvf/hvf-all.c
@@ -203,45 +203,24 @@ static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
     }
 }
 
-static void hvf_set_dirty_tracking(MemoryRegionSection *section, bool on)
-{
-    hvf_slot *slot;
-
-    slot = hvf_find_overlap_slot(
-            section->offset_within_address_space,
-            int128_get64(section->size));
-
-    /* protect region against writes; begin tracking it */
-    if (on) {
-        slot->flags |= HVF_SLOT_LOG;
-        hv_vm_protect((uintptr_t)slot->start, (size_t)slot->size,
-                      HV_MEMORY_READ | HV_MEMORY_EXEC);
-    /* stop tracking region*/
-    } else {
-        slot->flags &= ~HVF_SLOT_LOG;
-        hv_vm_protect((uintptr_t)slot->start, (size_t)slot->size,
-                      HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
-    }
-}
-
 static void hvf_log_start(MemoryListener *listener,
                           MemoryRegionSection *section, int old, int new)
 {
-    if (old != 0) {
-        return;
+    assert(new != 0);
+    if (old == 0) {
+        hvf_protect_clean_range(section->offset_within_address_space,
+                                int128_get64(section->size));
     }
-
-    hvf_set_dirty_tracking(section, 1);
 }
 
 static void hvf_log_stop(MemoryListener *listener,
                          MemoryRegionSection *section, int old, int new)
 {
-    if (new != 0) {
-        return;
+    assert(old != 0);
+    if (new == 0) {
+        hvf_unprotect_dirty_range(section->offset_within_address_space,
+                                  int128_get64(section->size));
     }
-
-    hvf_set_dirty_tracking(section, 0);
 }
 
 static void hvf_log_sync(MemoryListener *listener,
@@ -251,7 +230,8 @@ static void hvf_log_sync(MemoryListener *listener,
      * sync of dirty pages is handled elsewhere; just make sure we keep
      * tracking the region.
      */
-    hvf_set_dirty_tracking(section, 1);
+    hvf_protect_clean_range(section->offset_within_address_space,
+                            int128_get64(section->size));
 }
 
 static void hvf_region_add(MemoryListener *listener,
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 37/59] accel/hvf: Move hvf_log_sync to hvf_log_clear
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (35 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 36/59] accel/hvf: Simplify hvf_log_* Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 38/59] accel/hvf: Simplify hvf_set_phys_mem Philippe Mathieu-Daudé
                   ` (22 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

From: Richard Henderson <richard.henderson@linaro.org>

Right idea, wrong hook.  log_sync is called before using
dirty bit data (which for hvf is already up-to-date),
whereas log_clear is called before cleaning the range.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 accel/hvf/hvf-all.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/accel/hvf/hvf-all.c b/accel/hvf/hvf-all.c
index 361d658a186..4b0a1af9fdc 100644
--- a/accel/hvf/hvf-all.c
+++ b/accel/hvf/hvf-all.c
@@ -223,12 +223,13 @@ static void hvf_log_stop(MemoryListener *listener,
     }
 }
 
-static void hvf_log_sync(MemoryListener *listener,
-                         MemoryRegionSection *section)
+static void hvf_log_clear(MemoryListener *listener,
+                          MemoryRegionSection *section)
 {
     /*
-     * sync of dirty pages is handled elsewhere; just make sure we keep
-     * tracking the region.
+     * The dirty page bits within section are being cleared.
+     * Some number of those pages may have been dirtied and
+     * the write permission enabled.  Reset the range read-only.
      */
     hvf_protect_clean_range(section->offset_within_address_space,
                             int128_get64(section->size));
@@ -253,7 +254,7 @@ static MemoryListener hvf_memory_listener = {
     .region_del = hvf_region_del,
     .log_start = hvf_log_start,
     .log_stop = hvf_log_stop,
-    .log_sync = hvf_log_sync,
+    .log_clear = hvf_log_clear,
 };
 
 static int hvf_accel_init(AccelState *as, MachineState *ms)
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 38/59] accel/hvf: Simplify hvf_set_phys_mem
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (36 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 37/59] accel/hvf: Move hvf_log_sync to hvf_log_clear Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 39/59] accel/hvf: Drop hvf_slot and hvf_find_overlap_slot Philippe Mathieu-Daudé
                   ` (21 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

From: Richard Henderson <richard.henderson@linaro.org>

All of the complicated parts of updating the address space
are handled by address_space_update_topology_pass.
Do not create or use hvf_slot structures.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 accel/hvf/hvf-all.c | 111 +++++++-------------------------------------
 1 file changed, 17 insertions(+), 94 deletions(-)

diff --git a/accel/hvf/hvf-all.c b/accel/hvf/hvf-all.c
index 4b0a1af9fdc..97b367bd788 100644
--- a/accel/hvf/hvf-all.c
+++ b/accel/hvf/hvf-all.c
@@ -86,45 +86,16 @@ void hvf_unprotect_dirty_range(hwaddr addr, size_t size)
                      HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
 }
 
-static int do_hvf_set_memory(hvf_slot *slot, hv_memory_flags_t flags)
-{
-    struct mac_slot *macslot;
-    hv_return_t ret;
-
-    macslot = &mac_slots[slot->slot_id];
-
-    if (macslot->present) {
-        if (macslot->size != slot->size) {
-            macslot->present = 0;
-            trace_hvf_vm_unmap(macslot->gpa_start, macslot->size);
-            ret = hv_vm_unmap(macslot->gpa_start, macslot->size);
-            assert_hvf_ok(ret);
-        }
-    }
-
-    if (!slot->size) {
-        return 0;
-    }
-
-    macslot->present = 1;
-    macslot->gpa_start = slot->start;
-    macslot->size = slot->size;
-    trace_hvf_vm_map(slot->start, slot->size, slot->mem, flags,
-                     flags & HV_MEMORY_READ ?  'R' : '-',
-                     flags & HV_MEMORY_WRITE ? 'W' : '-',
-                     flags & HV_MEMORY_EXEC ?  'X' : '-');
-    ret = hv_vm_map(slot->mem, slot->start, slot->size, flags);
-    assert_hvf_ok(ret);
-    return 0;
-}
-
 static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
 {
-    hvf_slot *mem;
     MemoryRegion *area = section->mr;
     bool writable = !area->readonly && !area->rom_device;
     hv_memory_flags_t flags;
     uint64_t page_size = qemu_real_host_page_size();
+    uint64_t gva = section->offset_within_address_space;
+    uint64_t size = int128_get64(section->size);
+    hv_return_t ret;
+    void *mem;
 
     if (!memory_region_is_ram(area)) {
         if (writable) {
@@ -138,69 +109,28 @@ static void hvf_set_phys_mem(MemoryRegionSection *section, bool add)
         }
     }
 
-    if (!QEMU_IS_ALIGNED(int128_get64(section->size), page_size) ||
-        !QEMU_IS_ALIGNED(section->offset_within_address_space, page_size)) {
+    if (!QEMU_IS_ALIGNED(size, page_size) ||
+        !QEMU_IS_ALIGNED(gva, page_size)) {
         /* Not page aligned, so we can not map as RAM */
         add = false;
     }
 
-    mem = hvf_find_overlap_slot(
-            section->offset_within_address_space,
-            int128_get64(section->size));
-
-    if (mem && add) {
-        if (mem->size == int128_get64(section->size) &&
-            mem->start == section->offset_within_address_space &&
-            mem->mem == (memory_region_get_ram_ptr(area) +
-            section->offset_within_region)) {
-            return; /* Same region was attempted to register, go away. */
-        }
-    }
-
-    /* Region needs to be reset. set the size to 0 and remap it. */
-    if (mem) {
-        mem->size = 0;
-        if (do_hvf_set_memory(mem, 0)) {
-            error_report("Failed to reset overlapping slot");
-            abort();
-        }
-    }
-
     if (!add) {
+        trace_hvf_vm_unmap(gva, size);
+        ret = hv_vm_unmap(gva, size);
+        assert_hvf_ok(ret);
         return;
     }
 
-    if (area->readonly ||
-        (!memory_region_is_ram(area) && memory_region_is_romd(area))) {
-        flags = HV_MEMORY_READ | HV_MEMORY_EXEC;
-    } else {
-        flags = HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC;
-    }
+    flags = HV_MEMORY_READ | HV_MEMORY_EXEC | (writable ? HV_MEMORY_WRITE : 0);
+    mem = memory_region_get_ram_ptr(area) + section->offset_within_region;
 
-    /* Now make a new slot. */
-    int x;
-
-    for (x = 0; x < hvf_state->num_slots; ++x) {
-        mem = &hvf_state->slots[x];
-        if (!mem->size) {
-            break;
-        }
-    }
-
-    if (x == hvf_state->num_slots) {
-        error_report("No free slots");
-        abort();
-    }
-
-    mem->size = int128_get64(section->size);
-    mem->mem = memory_region_get_ram_ptr(area) + section->offset_within_region;
-    mem->start = section->offset_within_address_space;
-    mem->region = area;
-
-    if (do_hvf_set_memory(mem, flags)) {
-        error_report("Error registering new memory slot");
-        abort();
-    }
+    trace_hvf_vm_map(gva, size, mem, flags,
+                     flags & HV_MEMORY_READ ?  'R' : '-',
+                     flags & HV_MEMORY_WRITE ? 'W' : '-',
+                     flags & HV_MEMORY_EXEC ?  'X' : '-');
+    ret = hv_vm_map(mem, gva, size, flags);
+    assert_hvf_ok(ret);
 }
 
 static void hvf_log_start(MemoryListener *listener,
@@ -259,7 +189,6 @@ static MemoryListener hvf_memory_listener = {
 
 static int hvf_accel_init(AccelState *as, MachineState *ms)
 {
-    int x;
     hv_return_t ret;
     HVFState *s = HVF_STATE(as);
     int pa_range = 36;
@@ -280,12 +209,6 @@ static int hvf_accel_init(AccelState *as, MachineState *ms)
     }
     assert_hvf_ok(ret);
 
-    s->num_slots = ARRAY_SIZE(s->slots);
-    for (x = 0; x < s->num_slots; ++x) {
-        s->slots[x].size = 0;
-        s->slots[x].slot_id = x;
-    }
-
     QTAILQ_INIT(&s->hvf_sw_breakpoints);
 
     hvf_state = s;
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 39/59] accel/hvf: Drop hvf_slot and hvf_find_overlap_slot
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (37 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 38/59] accel/hvf: Simplify hvf_set_phys_mem Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 40/59] accel/hvf: Remove mac_slots Philippe Mathieu-Daudé
                   ` (20 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

From: Richard Henderson <richard.henderson@linaro.org>

These are now unused.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/system/hvf_int.h  | 13 -------------
 accel/hvf/hvf-accel-ops.c | 14 --------------
 2 files changed, 27 deletions(-)

diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h
index ee7ab689f45..d842d4b2b99 100644
--- a/include/system/hvf_int.h
+++ b/include/system/hvf_int.h
@@ -24,15 +24,6 @@ typedef hv_vcpu_t hvf_vcpuid;
 typedef hv_vcpuid_t hvf_vcpuid;
 #endif
 
-typedef struct hvf_slot {
-    uint64_t start;
-    uint64_t size;
-    uint8_t *mem;
-    int slot_id;
-    uint32_t flags;
-    MemoryRegion *region;
-} hvf_slot;
-
 typedef struct hvf_vcpu_caps {
     uint64_t vmx_cap_pinbased;
     uint64_t vmx_cap_procbased;
@@ -45,9 +36,6 @@ typedef struct hvf_vcpu_caps {
 struct HVFState {
     AccelState parent_obj;
 
-    hvf_slot slots[32];
-    int num_slots;
-
     hvf_vcpu_caps *hvf_caps;
     uint64_t vtimer_offset;
     QTAILQ_HEAD(, hvf_sw_breakpoint) hvf_sw_breakpoints;
@@ -70,7 +58,6 @@ 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);
-hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t);
 void hvf_kick_vcpu_thread(CPUState *cpu);
 
 /* Must be called by the owning thread */
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index 3e5feecd8a7..bbb0b385fe9 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -64,20 +64,6 @@ HVFState *hvf_state;
 
 /* Memory slots */
 
-hvf_slot *hvf_find_overlap_slot(uint64_t start, uint64_t size)
-{
-    hvf_slot *slot;
-    int x;
-    for (x = 0; x < hvf_state->num_slots; ++x) {
-        slot = &hvf_state->slots[x];
-        if (slot->size && start < (slot->start + slot->size) &&
-            (start + size) > slot->start) {
-            return slot;
-        }
-    }
-    return NULL;
-}
-
 static void do_hvf_cpu_synchronize_state(CPUState *cpu, run_on_cpu_data arg)
 {
     if (!cpu->vcpu_dirty) {
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 40/59] accel/hvf: Remove mac_slots
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (38 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 39/59] accel/hvf: Drop hvf_slot and hvf_find_overlap_slot Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 41/59] target/arm/hvf: Implement dirty page tracking Philippe Mathieu-Daudé
                   ` (19 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

From: Richard Henderson <richard.henderson@linaro.org>

This data structure is no longer used.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 accel/hvf/hvf-all.c | 9 ---------
 1 file changed, 9 deletions(-)

diff --git a/accel/hvf/hvf-all.c b/accel/hvf/hvf-all.c
index 97b367bd788..53efd54b97a 100644
--- a/accel/hvf/hvf-all.c
+++ b/accel/hvf/hvf-all.c
@@ -22,15 +22,6 @@
 
 bool hvf_allowed;
 
-struct mac_slot {
-    int present;
-    uint64_t size;
-    uint64_t gpa_start;
-    uint64_t gva;
-};
-
-struct mac_slot mac_slots[32];
-
 const char *hvf_return_string(hv_return_t ret)
 {
     switch (ret) {
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 41/59] target/arm/hvf: Implement dirty page tracking
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (39 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 40/59] accel/hvf: Remove mac_slots Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28 11:58   ` Richard Henderson
  2025-10-28  5:42 ` [PATCH v3 42/59] accel/hvf: Skip WFI if CPU has work to do Philippe Mathieu-Daudé
                   ` (18 subsequent siblings)
  59 siblings, 1 reply; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

From: Richard Henderson <richard.henderson@linaro.org>

Notice writes to pages which are being monitored.  Mark the page dirty,
re-enable writes, and retry the instruction without emulation.

Assert the fault is not from a stage1 page table walk.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
v3: TARGET_PAGE_SIZE/MASK -> host page size/mask (rth)
---
 target/arm/hvf/hvf.c | 52 ++++++++++++++++++++++++++++++++++++--------
 1 file changed, 43 insertions(+), 9 deletions(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index de1e8fb8a05..da2f4cf2e9c 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1869,9 +1869,10 @@ static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp)
         uint32_t srt = (syndrome >> 16) & 0x1f;
         uint32_t cm = (syndrome >> 8) & 0x1;
         uint64_t val = 0;
+        uint64_t ipa = excp->physical_address;
+        AddressSpace *as = cpu_get_address_space(cpu, ARMASIdx_NS);
 
-        trace_hvf_data_abort(excp->virtual_address,
-                             excp->physical_address, isv,
+        trace_hvf_data_abort(excp->virtual_address, ipa, isv,
                              iswrite, s1ptw, len, srt);
 
         if (cm) {
@@ -1880,23 +1881,56 @@ static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp)
             break;
         }
 
+        /* Handle dirty page logging for ram. */
+        if (iswrite) {
+            hwaddr xlat;
+            MemoryRegion *mr = address_space_translate(as, ipa, &xlat,
+                                                       NULL, true,
+                                                       MEMTXATTRS_UNSPECIFIED);
+            if (memory_region_is_ram(mr)) {
+                uint64_t ipa_page = ipa & qemu_real_host_page_mask();
+
+                /* TODO: Inject exception to the guest. */
+                assert(!mr->readonly);
+
+                if (memory_region_get_dirty_log_mask(mr)) {
+                    size_t page_size = qemu_real_host_page_size();
+
+                    memory_region_set_dirty(mr, ipa_page + xlat, page_size);
+                    hvf_unprotect_dirty_range(ipa_page, page_size);
+                }
+
+                /* Retry with page writes enabled. */
+                break;
+            }
+        }
+
+        /*
+         * TODO: If s1ptw, this is an error in the guest os page tables.
+         * Inject the exception into the guest.
+         */
+        assert(!s1ptw);
+
+        /*
+         * TODO: ISV will be 0 for SIMD or SVE accesses.
+         * Inject the exception into the guest.
+         */
         assert(isv);
 
+        /*
+         * Emulate MMIO.
+         * TODO: Inject faults for errors.
+         */
         if (iswrite) {
             val = hvf_get_reg(cpu, srt);
-            address_space_write(&address_space_memory,
-                                excp->physical_address,
-                                MEMTXATTRS_UNSPECIFIED, &val, len);
+            address_space_write(as, ipa, MEMTXATTRS_UNSPECIFIED, &val, len);
         } else {
-            address_space_read(&address_space_memory,
-                               excp->physical_address,
-                               MEMTXATTRS_UNSPECIFIED, &val, len);
+            address_space_read(as, ipa, MEMTXATTRS_UNSPECIFIED, &val, len);
             if (sse) {
                 val = sextract64(val, 0, len * 8);
             }
             hvf_set_reg(cpu, srt, val);
         }
-
         advance_pc = true;
         break;
     }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 42/59] accel/hvf: Skip WFI if CPU has work to do
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (40 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 41/59] target/arm/hvf: Implement dirty page tracking Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28 11:51   ` Alex Bennée
  2025-10-28 11:59   ` Richard Henderson
  2025-10-28  5:42 ` [PATCH v3 43/59] accel/hvf: Implement WFI without using pselect() Philippe Mathieu-Daudé
                   ` (17 subsequent siblings)
  59 siblings, 2 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Avoid sleeping vCPU thread for any pending work, not just IRQs.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/hvf/hvf.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index da2f4cf2e9c..1abb4a7d7a9 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1737,8 +1737,11 @@ static void hvf_wfi(CPUState *cpu)
     uint64_t nanos;
     uint32_t cntfrq;
 
-    if (cpu_test_interrupt(cpu, CPU_INTERRUPT_HARD | CPU_INTERRUPT_FIQ)) {
-        /* Interrupt pending, no need to wait */
+    if (cpu_has_work(cpu)) {
+        /*
+         * Don't bother to go into our "low power state" if
+         * we would just wake up immediately.
+         */
         return;
     }
 
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 43/59] accel/hvf: Implement WFI without using pselect()
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (41 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 42/59] accel/hvf: Skip WFI if CPU has work to do Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28 12:01   ` Richard Henderson
  2025-10-28  5:42 ` [PATCH v3 44/59] accel/hvf: Have PSCI CPU_SUSPEND halt the vCPU Philippe Mathieu-Daudé
                   ` (16 subsequent siblings)
  59 siblings, 1 reply; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Return to the main loop where we'll be waken again.
This avoid a tricky race with signals introduced in
commit 219c101fa7f ("Add HVF WFI handler").

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/system/hvf_int.h  |  1 -
 accel/hvf/hvf-accel-ops.c |  5 +--
 target/arm/hvf/hvf.c      | 74 +++------------------------------------
 3 files changed, 8 insertions(+), 72 deletions(-)

diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h
index d842d4b2b99..c8e407a1463 100644
--- a/include/system/hvf_int.h
+++ b/include/system/hvf_int.h
@@ -47,7 +47,6 @@ struct AccelCPUState {
 #ifdef __aarch64__
     hv_vcpu_exit_t *exit;
     bool vtimer_masked;
-    sigset_t unblock_ipi_mask;
     bool guest_debug_enabled;
 #endif
 };
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index bbb0b385fe9..e9dd2d24745 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -128,14 +128,15 @@ static int hvf_init_vcpu(CPUState *cpu)
     cpu->accel = g_new0(AccelCPUState, 1);
 
     /* init cpu signals */
+    sigset_t unblock_ipi_mask;
     struct sigaction sigact;
 
     memset(&sigact, 0, sizeof(sigact));
     sigact.sa_handler = dummy_signal;
     sigaction(SIG_IPI, &sigact, NULL);
 
-    pthread_sigmask(SIG_BLOCK, NULL, &cpu->accel->unblock_ipi_mask);
-    sigdelset(&cpu->accel->unblock_ipi_mask, SIG_IPI);
+    pthread_sigmask(SIG_BLOCK, NULL, &unblock_ipi_mask);
+    sigdelset(&unblock_ipi_mask, SIG_IPI);
 
 #ifdef __aarch64__
     r = hv_vcpu_create(&cpu->accel->fd,
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 1abb4a7d7a9..5fc9b217a11 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -301,7 +301,7 @@ void hvf_arm_init_debug(void)
 #define TMR_CTL_IMASK   (1 << 1)
 #define TMR_CTL_ISTATUS (1 << 2)
 
-static void hvf_wfi(CPUState *cpu);
+static int hvf_wfi(CPUState *cpu);
 
 static uint32_t chosen_ipa_bit_size;
 
@@ -1703,81 +1703,17 @@ static uint64_t hvf_vtimer_val_raw(void)
     return mach_absolute_time() - hvf_state->vtimer_offset;
 }
 
-static uint64_t hvf_vtimer_val(void)
+static int hvf_wfi(CPUState *cpu)
 {
-    if (!runstate_is_running()) {
-        /* VM is paused, the vtimer value is in vtimer.vtimer_val */
-        return vtimer.vtimer_val;
-    }
-
-    return hvf_vtimer_val_raw();
-}
-
-static void hvf_wait_for_ipi(CPUState *cpu, struct timespec *ts)
-{
-    /*
-     * Use pselect to sleep so that other threads can IPI us while we're
-     * sleeping.
-     */
-    qatomic_set_mb(&cpu->thread_kicked, false);
-    bql_unlock();
-    pselect(0, 0, 0, 0, ts, &cpu->accel->unblock_ipi_mask);
-    bql_lock();
-}
-
-static void hvf_wfi(CPUState *cpu)
-{
-    ARMCPU *arm_cpu = ARM_CPU(cpu);
-    struct timespec ts;
-    hv_return_t r;
-    uint64_t ctl;
-    uint64_t cval;
-    int64_t ticks_to_sleep;
-    uint64_t seconds;
-    uint64_t nanos;
-    uint32_t cntfrq;
-
     if (cpu_has_work(cpu)) {
         /*
          * Don't bother to go into our "low power state" if
          * we would just wake up immediately.
          */
-        return;
+        return 0;
     }
 
-    r = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, &ctl);
-    assert_hvf_ok(r);
-
-    if (!(ctl & 1) || (ctl & 2)) {
-        /* Timer disabled or masked, just wait for an IPI. */
-        hvf_wait_for_ipi(cpu, NULL);
-        return;
-    }
-
-    r = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CVAL_EL0, &cval);
-    assert_hvf_ok(r);
-
-    ticks_to_sleep = cval - hvf_vtimer_val();
-    if (ticks_to_sleep < 0) {
-        return;
-    }
-
-    cntfrq = gt_cntfrq_period_ns(arm_cpu);
-    seconds = muldiv64(ticks_to_sleep, cntfrq, NANOSECONDS_PER_SECOND);
-    ticks_to_sleep -= muldiv64(seconds, NANOSECONDS_PER_SECOND, cntfrq);
-    nanos = ticks_to_sleep * cntfrq;
-
-    /*
-     * Don't sleep for less than the time a context switch would take,
-     * so that we can satisfy fast timer requests on the same CPU.
-     * Measurements on M1 show the sweet spot to be ~2ms.
-     */
-    if (!seconds && nanos < (2 * SCALE_MS)) {
-        return;
-    }
-
-    ts = (struct timespec) { seconds, nanos };
-    hvf_wait_for_ipi(cpu, &ts);
+    return EXCP_HLT;
 }
 
 /* Must be called by the owning thread */
@@ -1967,7 +1903,7 @@ static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp)
     case EC_WFX_TRAP:
         advance_pc = true;
         if (!(syndrome & WFX_IS_WFE)) {
-            hvf_wfi(cpu);
+            ret = hvf_wfi(cpu);
         }
         break;
     case EC_AA64_HVC:
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 44/59] accel/hvf: Have PSCI CPU_SUSPEND halt the vCPU
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (42 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 43/59] accel/hvf: Implement WFI without using pselect() Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 45/59] accel: Introduce AccelOpsClass::cpu_target_realize() hook Philippe Mathieu-Daudé
                   ` (15 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Return EXCP_HLT to the main loop.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/hvf/hvf.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 5fc9b217a11..f9d983fa123 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -301,8 +301,6 @@ void hvf_arm_init_debug(void)
 #define TMR_CTL_IMASK   (1 << 1)
 #define TMR_CTL_ISTATUS (1 << 2)
 
-static int hvf_wfi(CPUState *cpu);
-
 static uint32_t chosen_ipa_bit_size;
 
 typedef struct HVFVTimer {
@@ -1008,7 +1006,7 @@ static void hvf_psci_cpu_off(ARMCPU *arm_cpu)
  * Returns 0 on success
  *         -1 when the PSCI call is unknown,
  */
-static bool hvf_handle_psci_call(CPUState *cpu)
+static bool hvf_handle_psci_call(CPUState *cpu, int *excp_ret)
 {
     ARMCPU *arm_cpu = ARM_CPU(cpu);
     CPUARMState *env = &arm_cpu->env;
@@ -1091,9 +1089,8 @@ static bool hvf_handle_psci_call(CPUState *cpu)
             ret = QEMU_PSCI_RET_INVALID_PARAMS;
             break;
         }
-        /* Powerdown is not supported, we always go into WFI */
         env->xregs[0] = 0;
-        hvf_wfi(cpu);
+        *excp_ret = EXCP_HLT;
         break;
     case QEMU_PSCI_0_1_FN_MIGRATE:
     case QEMU_PSCI_0_2_FN_MIGRATE:
@@ -1910,7 +1907,7 @@ static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp)
         cpu_synchronize_state(cpu);
         if (arm_is_psci_call(arm_cpu, EXCP_HVC)) {
             /* Do NOT advance $pc for HVC */
-            if (!hvf_handle_psci_call(cpu)) {
+            if (!hvf_handle_psci_call(cpu, &ret)) {
                 trace_hvf_unknown_hvc(env->pc, env->xregs[0]);
                 /* SMCCC 1.3 section 5.2 says every unknown SMCCC call returns -1 */
                 env->xregs[0] = -1;
@@ -1926,7 +1923,7 @@ static int hvf_handle_exception(CPUState *cpu, hv_vcpu_exit_exception_t *excp)
             /* Secure Monitor Call exception, we need to advance $pc */
             advance_pc = true;
 
-            if (!hvf_handle_psci_call(cpu)) {
+            if (!hvf_handle_psci_call(cpu, &ret)) {
                 trace_hvf_unknown_smc(env->xregs[0]);
                 /* SMCCC 1.3 section 5.2 says every unknown SMCCC call returns -1 */
                 env->xregs[0] = -1;
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 45/59] accel: Introduce AccelOpsClass::cpu_target_realize() hook
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (43 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 44/59] accel/hvf: Have PSCI CPU_SUSPEND halt the vCPU Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 46/59] accel/hvf: Add hvf_arch_cpu_realize() stubs Philippe Mathieu-Daudé
                   ` (14 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé, Paolo Bonzini

Allow accelerators to set vCPU properties before its realization.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/accel/accel-cpu-ops.h | 1 +
 accel/accel-common.c          | 5 +++++
 2 files changed, 6 insertions(+)

diff --git a/include/accel/accel-cpu-ops.h b/include/accel/accel-cpu-ops.h
index 0674764914f..9c07a903ea0 100644
--- a/include/accel/accel-cpu-ops.h
+++ b/include/accel/accel-cpu-ops.h
@@ -34,6 +34,7 @@ struct AccelOpsClass {
     /* initialization function called when accel is chosen */
     void (*ops_init)(AccelClass *ac);
 
+    bool (*cpu_target_realize)(CPUState *cpu, Error **errp);
     bool (*cpus_are_resettable)(void);
     void (*cpu_reset_hold)(CPUState *cpu);
 
diff --git a/accel/accel-common.c b/accel/accel-common.c
index 850c5ab4b8e..eecb2a292af 100644
--- a/accel/accel-common.c
+++ b/accel/accel-common.c
@@ -106,6 +106,11 @@ bool accel_cpu_common_realize(CPUState *cpu, Error **errp)
     if (acc->cpu_common_realize && !acc->cpu_common_realize(cpu, errp)) {
         return false;
     }
+    if (acc->ops
+        && acc->ops->cpu_target_realize
+        && !acc->ops->cpu_target_realize(cpu, errp)) {
+        return false;
+    }
 
     return true;
 }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 46/59] accel/hvf: Add hvf_arch_cpu_realize() stubs
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (44 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 45/59] accel: Introduce AccelOpsClass::cpu_target_realize() hook Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 47/59] target/arm: Create GTimers *after* features finalized / accel realized Philippe Mathieu-Daudé
                   ` (13 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Implement HVF AccelOpsClass::cpu_target_realize() hook as
empty stubs. Target implementations will come separately.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
 include/system/hvf_int.h  | 2 ++
 accel/hvf/hvf-accel-ops.c | 2 ++
 target/arm/hvf/hvf.c      | 5 +++++
 target/i386/hvf/hvf.c     | 5 +++++
 4 files changed, 14 insertions(+)

diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h
index c8e407a1463..96790b49386 100644
--- a/include/system/hvf_int.h
+++ b/include/system/hvf_int.h
@@ -106,4 +106,6 @@ int hvf_update_guest_debug(CPUState *cpu);
  */
 bool hvf_arch_supports_guest_debug(void);
 
+bool hvf_arch_cpu_realize(CPUState *cpu, Error **errp);
+
 #endif
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index e9dd2d24745..28d50e23017 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -360,6 +360,8 @@ static void hvf_accel_ops_class_init(ObjectClass *oc, const void *data)
 {
     AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
 
+    ops->cpu_target_realize = hvf_arch_cpu_realize;
+
     ops->create_vcpu_thread = hvf_start_vcpu_thread;
     ops->kick_vcpu_thread = hvf_kick_vcpu_thread;
     ops->handle_interrupt = generic_handle_interrupt;
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index f9d983fa123..b053bdd7cf2 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -972,6 +972,11 @@ int hvf_arch_init_vcpu(CPUState *cpu)
     return 0;
 }
 
+bool hvf_arch_cpu_realize(CPUState *cs, Error **errp)
+{
+    return true;
+}
+
 void hvf_kick_vcpu_thread(CPUState *cpu)
 {
     hv_return_t ret;
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index b0c3fb97864..49f26169632 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -370,6 +370,11 @@ int hvf_arch_init_vcpu(CPUState *cpu)
     return 0;
 }
 
+bool hvf_arch_cpu_realize(CPUState *cs, Error **errp)
+{
+    return true;
+}
+
 static void hvf_store_events(CPUState *cpu, uint32_t ins_len, uint64_t idtvec_info)
 {
     X86CPU *x86_cpu = X86_CPU(cpu);
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 47/59] target/arm: Create GTimers *after* features finalized / accel realized
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (45 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 46/59] accel/hvf: Add hvf_arch_cpu_realize() stubs Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 48/59] target/arm/hvf: Really set Generic Timer counter frequency Philippe Mathieu-Daudé
                   ` (12 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Call generic (including accelerator) cpu_realize() handlers
*before* setting @gt_cntfrq_hz default

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/arm/cpu.c | 65 ++++++++++++++++++++++++------------------------
 1 file changed, 33 insertions(+), 32 deletions(-)

diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 39292fb9bc1..b392374df98 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1636,26 +1636,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
         return;
     }
 
-    if (!cpu->gt_cntfrq_hz) {
-        /*
-         * 0 means "the board didn't set a value, use the default". (We also
-         * get here for the CONFIG_USER_ONLY case.)
-         * ARMv8.6 and later CPUs architecturally must use a 1GHz timer; before
-         * that it was an IMPDEF choice, and QEMU initially picked 62.5MHz,
-         * which gives a 16ns tick period.
-         *
-         * We will use the back-compat value:
-         *  - for QEMU CPU types added before we standardized on 1GHz
-         *  - for versioned machine types with a version of 9.0 or earlier
-         */
-        if (arm_feature(env, ARM_FEATURE_BACKCOMPAT_CNTFRQ) ||
-            cpu->backcompat_cntfrq) {
-            cpu->gt_cntfrq_hz = GTIMER_BACKCOMPAT_HZ;
-        } else {
-            cpu->gt_cntfrq_hz = GTIMER_DEFAULT_HZ;
-        }
-    }
-
 #ifndef CONFIG_USER_ONLY
     /* The NVIC and M-profile CPU are two halves of a single piece of
      * hardware; trying to use one without the other is a command line
@@ -1702,7 +1682,40 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
             return;
         }
     }
+#endif
 
+    cpu_exec_realizefn(cs, &local_err);
+    if (local_err != NULL) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    arm_cpu_finalize_features(cpu, &local_err);
+    if (local_err != NULL) {
+        error_propagate(errp, local_err);
+        return;
+    }
+
+    if (!cpu->gt_cntfrq_hz) {
+        /*
+         * 0 means "the board didn't set a value, use the default". (We also
+         * get here for the CONFIG_USER_ONLY case.)
+         * ARMv8.6 and later CPUs architecturally must use a 1GHz timer; before
+         * that it was an IMPDEF choice, and QEMU initially picked 62.5MHz,
+         * which gives a 16ns tick period.
+         *
+         * We will use the back-compat value:
+         *  - for QEMU CPU types added before we standardized on 1GHz
+         *  - for versioned machine types with a version of 9.0 or earlier
+         */
+        if (arm_feature(env, ARM_FEATURE_BACKCOMPAT_CNTFRQ) ||
+            cpu->backcompat_cntfrq) {
+            cpu->gt_cntfrq_hz = GTIMER_BACKCOMPAT_HZ;
+        } else {
+            cpu->gt_cntfrq_hz = GTIMER_DEFAULT_HZ;
+        }
+    }
+#ifndef CONFIG_USER_ONLY
     {
         uint64_t scale = gt_cntfrq_period_ns(cpu);
 
@@ -1723,18 +1736,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
     }
 #endif
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
-        return;
-    }
-
-    arm_cpu_finalize_features(cpu, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
-        return;
-    }
-
 #ifdef CONFIG_USER_ONLY
     /*
      * User mode relies on IC IVAU instructions to catch modification of
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 48/59] target/arm/hvf: Really set Generic Timer counter frequency
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (46 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 47/59] target/arm: Create GTimers *after* features finalized / accel realized Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 49/59] target/arm: Only allow disabling NEON when using TCG Philippe Mathieu-Daudé
                   ` (11 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Setting ARMCPU::gt_cntfrq_hz in hvf_arch_init_vcpu() is
not correct because the timers have already be initialized
with the default frequency.

Set it earlier in the AccelOpsClass::cpu_target_realize()
handler instead, and assert the value is correct when
reaching hvf_arch_init_vcpu().

Fixes: a1477da3dde ("hvf: Add Apple Silicon support")
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/hvf/hvf.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index b053bdd7cf2..0788b20cc05 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -897,6 +897,13 @@ cleanup:
     return ret;
 }
 
+static uint64_t get_cntfrq_el0(void)
+{
+    uint64_t freq_hz = 0;
+    asm volatile("mrs %0, cntfrq_el0" : "=r"(freq_hz));
+    return freq_hz;
+}
+
 int hvf_arch_init_vcpu(CPUState *cpu)
 {
     ARMCPU *arm_cpu = ARM_CPU(cpu);
@@ -908,7 +915,9 @@ int hvf_arch_init_vcpu(CPUState *cpu)
     int i;
 
     env->aarch64 = true;
-    asm volatile("mrs %0, cntfrq_el0" : "=r"(arm_cpu->gt_cntfrq_hz));
+
+    /* system count frequency sanity check */
+    assert(arm_cpu->gt_cntfrq_hz == get_cntfrq_el0());
 
     /* Allocate enough space for our sysreg sync */
     arm_cpu->cpreg_indexes = g_renew(uint64_t, arm_cpu->cpreg_indexes,
@@ -974,6 +983,15 @@ int hvf_arch_init_vcpu(CPUState *cpu)
 
 bool hvf_arch_cpu_realize(CPUState *cs, Error **errp)
 {
+    ARMCPU *cpu = ARM_CPU(cs);
+
+    /*
+     * We must set the counter frequency HVF will be using
+     * early, before arm_cpu_realizefn initializes the timers
+     * with it.
+     */
+    cpu->gt_cntfrq_hz = get_cntfrq_el0();
+
     return true;
 }
 
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 49/59] target/arm: Only allow disabling NEON when using TCG
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (47 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 48/59] target/arm/hvf: Really set Generic Timer counter frequency Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 50/59] target/arm/hvf: Do not abort in hvf_arm_get_*_ipa_bit_size() Philippe Mathieu-Daudé
                   ` (10 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Only allow disabling NEON when using TCG.

This avoids confusing user experience:

  $ qemu-system-aarch64 -M virt -accel hvf \
                        -cpu host,neon=off,vfp=off,vfp-d32=off
  qemu-system-aarch64: AArch64 CPUs must have both VFP and Neon or neither

  $ qemu-system-aarch64 -M virt -accel hvf \
                        -cpu host,neon=off,vfp=off,vfp-d32=off
  qemu-system-aarch64: ARM CPUs must have both VFP-D32 and Neon or neither

  $ qemu-system-aarch64 -M virt -accel hvf \
                        -cpu host,neon=off,vfp=off,vfp-d32=off
  qemu-system-aarch64: can't apply global host-arm-cpu.vfp-d32=off: Property 'host-arm-cpu.vfp-d32' not found

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/arm/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index b392374df98..eaf76532eca 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1460,7 +1460,7 @@ static void arm_cpu_post_init(Object *obj)
 
     if (arm_feature(&cpu->env, ARM_FEATURE_NEON)) {
         cpu->has_neon = true;
-        if (!kvm_enabled()) {
+        if (tcg_enabled() || qtest_enabled()) {
             qdev_property_add_static(DEVICE(obj), &arm_cpu_has_neon_property);
         }
     }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 50/59] target/arm/hvf: Do not abort in hvf_arm_get_*_ipa_bit_size()
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (48 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 49/59] target/arm: Only allow disabling NEON when using TCG Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28 12:06   ` Richard Henderson
  2025-10-28  5:42 ` [PATCH v3 51/59] hw/arm/virt: Warn when HVF doesn't report IPA bit length Philippe Mathieu-Daudé
                   ` (9 subsequent siblings)
  59 siblings, 1 reply; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Do not abort in hvf_arm_get_default_ipa_bit_size()
and hvf_arm_get_max_ipa_bit_size() when the IPA can
not be fetched. Return 0 (and document it).

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/hvf_arm.h | 11 +++++++++++
 target/arm/hvf/hvf.c |  8 ++------
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/target/arm/hvf_arm.h b/target/arm/hvf_arm.h
index ea82f2691df..21a69e7d105 100644
--- a/target/arm/hvf_arm.h
+++ b/target/arm/hvf_arm.h
@@ -22,7 +22,18 @@ void hvf_arm_init_debug(void);
 
 void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu);
 
+/**
+ * hvf_arm_get_default_ipa_bit_size:
+ *
+ * Returns the default intermediate physical address bit length or 0 on error.
+ */
 uint32_t hvf_arm_get_default_ipa_bit_size(void);
+
+/**
+ * hvf_arm_get_max_ipa_bit_size:
+ *
+ * Returns the maximum intermediate physical address bit length or 0 on error.
+ */
 uint32_t hvf_arm_get_max_ipa_bit_size(void);
 
 #endif
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 0788b20cc05..5b077744720 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -829,24 +829,20 @@ uint32_t hvf_arm_get_default_ipa_bit_size(void)
 {
     uint32_t default_ipa_size;
     hv_return_t ret = hv_vm_config_get_default_ipa_size(&default_ipa_size);
-    assert_hvf_ok(ret);
-
-    return default_ipa_size;
+    return ret == HV_SUCCESS ? default_ipa_size : 0;
 }
 
 uint32_t hvf_arm_get_max_ipa_bit_size(void)
 {
     uint32_t max_ipa_size;
     hv_return_t ret = hv_vm_config_get_max_ipa_size(&max_ipa_size);
-    assert_hvf_ok(ret);
-
     /*
      * We clamp any IPA size we want to back the VM with to a valid PARange
      * value so the guest doesn't try and map memory outside of the valid range.
      * This logic just clamps the passed in IPA bit size to the first valid
      * PARange value <= to it.
      */
-    return round_down_to_parange_bit_size(max_ipa_size);
+    return ret == HV_SUCCESS ? round_down_to_parange_bit_size(max_ipa_size) : 0;
 }
 
 void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu)
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 51/59] hw/arm/virt: Warn when HVF doesn't report IPA bit length
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (49 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 50/59] target/arm/hvf: Do not abort in hvf_arm_get_*_ipa_bit_size() Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28 12:07   ` Richard Henderson
  2025-10-28  5:42 ` [PATCH v3 52/59] accel/hvf: Introduce hvf_arch_cpu_synchronize_[pre/post]exec() hooks Philippe Mathieu-Daudé
                   ` (8 subsequent siblings)
  59 siblings, 1 reply; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Emit a warning when HVF doesn't return the IPA bit length
and return -1 as "this accelerator is not usable", allowing
QEMU to try with the next one (when using '-accel hvf:tcg').

Reported-by: Ivan Krasilnikov
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2981
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/arm/virt.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 175023897a7..1d65fa471dc 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -3225,8 +3225,12 @@ static int virt_hvf_get_physical_address_range(MachineState *ms)
 {
     VirtMachineState *vms = VIRT_MACHINE(ms);
 
-    int default_ipa_size = hvf_arm_get_default_ipa_bit_size();
-    int max_ipa_size = hvf_arm_get_max_ipa_bit_size();
+    uint32_t default_ipa_size = hvf_arm_get_default_ipa_bit_size();
+    uint32_t max_ipa_size = hvf_arm_get_max_ipa_bit_size();
+    if (!default_ipa_size || !max_ipa_size) {
+        warn_report("HVF didn't report IPA bit length");
+        return -1;
+    }
 
     /* We freeze the memory map to compute the highest gpa */
     virt_set_memmap(vms, max_ipa_size);
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 52/59] accel/hvf: Introduce hvf_arch_cpu_synchronize_[pre/post]exec() hooks
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (50 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 51/59] hw/arm/virt: Warn when HVF doesn't report IPA bit length Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28 12:08   ` Richard Henderson
  2025-10-28  5:42 ` [PATCH v3 53/59] target/i386/hvf: Flush vCPU registers once before vcpu_exec() loop Philippe Mathieu-Daudé
                   ` (7 subsequent siblings)
  59 siblings, 1 reply; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/system/hvf_int.h  | 4 ++++
 accel/hvf/hvf-accel-ops.c | 3 +++
 target/arm/hvf/hvf.c      | 8 ++++++++
 target/i386/hvf/hvf.c     | 8 ++++++++
 4 files changed, 23 insertions(+)

diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h
index 96790b49386..3120a4593a4 100644
--- a/include/system/hvf_int.h
+++ b/include/system/hvf_int.h
@@ -71,6 +71,10 @@ int hvf_arch_put_registers(CPUState *);
 int hvf_arch_get_registers(CPUState *);
 /* Must be called by the owning thread */
 void hvf_arch_update_guest_debug(CPUState *cpu);
+/* Must be called by the owning thread */
+void hvf_arch_cpu_synchronize_pre_exec(CPUState *cpu);
+/* Must be called by the owning thread */
+void hvf_arch_cpu_synchronize_post_exec(CPUState *cpu);
 
 void hvf_protect_clean_range(hwaddr addr, size_t size);
 void hvf_unprotect_dirty_range(hwaddr addr, size_t size);
diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
index 28d50e23017..6fb1fda424c 100644
--- a/accel/hvf/hvf-accel-ops.c
+++ b/accel/hvf/hvf-accel-ops.c
@@ -181,10 +181,13 @@ static void *hvf_cpu_thread_fn(void *arg)
     do {
         qemu_process_cpu_events(cpu);
         if (cpu_can_run(cpu)) {
+
+            hvf_arch_cpu_synchronize_pre_exec(cpu);
             r = hvf_arch_vcpu_exec(cpu);
             if (r == EXCP_DEBUG) {
                 cpu_handle_guest_debug(cpu);
             }
+            hvf_arch_cpu_synchronize_post_exec(cpu);
         }
     } while (!cpu->unplug || cpu_can_run(cpu));
 
diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 5b077744720..f5bab7e7213 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -2013,6 +2013,14 @@ static int hvf_handle_vmexit(CPUState *cpu, hv_vcpu_exit_t *exit)
     return ret;
 }
 
+void hvf_arch_cpu_synchronize_pre_exec(CPUState *cpu)
+{
+}
+
+void hvf_arch_cpu_synchronize_post_exec(CPUState *cpu)
+{
+}
+
 int hvf_arch_vcpu_exec(CPUState *cpu)
 {
     int ret;
diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 49f26169632..5711ed6f1d3 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -729,6 +729,14 @@ void hvf_simulate_wrmsr(CPUState *cs)
     printf("write msr %llx\n", RCX(cs));*/
 }
 
+void hvf_arch_cpu_synchronize_pre_exec(CPUState *cpu)
+{
+}
+
+void hvf_arch_cpu_synchronize_post_exec(CPUState *cpu)
+{
+}
+
 static int hvf_handle_vmexit(CPUState *cpu)
 {
     X86CPU *x86_cpu = env_archcpu(cpu_env(cpu));
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 53/59] target/i386/hvf: Flush vCPU registers once before vcpu_exec() loop
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (51 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 52/59] accel/hvf: Introduce hvf_arch_cpu_synchronize_[pre/post]exec() hooks Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28 12:09   ` Richard Henderson
  2025-10-28  5:42 ` [PATCH v3 54/59] target/arm/hvf: " Philippe Mathieu-Daudé
                   ` (6 subsequent siblings)
  59 siblings, 1 reply; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/i386/hvf/hvf.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
index 5711ed6f1d3..8df1196a55e 100644
--- a/target/i386/hvf/hvf.c
+++ b/target/i386/hvf/hvf.c
@@ -731,6 +731,10 @@ void hvf_simulate_wrmsr(CPUState *cs)
 
 void hvf_arch_cpu_synchronize_pre_exec(CPUState *cpu)
 {
+    if (cpu->vcpu_dirty) {
+        hvf_arch_put_registers(cpu);
+        cpu->vcpu_dirty = false;
+    }
 }
 
 void hvf_arch_cpu_synchronize_post_exec(CPUState *cpu)
@@ -990,11 +994,6 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
     }
 
     do {
-        if (cpu->vcpu_dirty) {
-            hvf_arch_put_registers(cpu);
-            cpu->vcpu_dirty = false;
-        }
-
         if (hvf_inject_interrupts(cpu)) {
             return EXCP_INTERRUPT;
         }
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 54/59] target/arm/hvf: Flush vCPU registers once before vcpu_exec() loop
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (52 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 53/59] target/i386/hvf: Flush vCPU registers once before vcpu_exec() loop Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 55/59] accel/hvf: Sync CNTV_CTL_EL0 & CNTV_CVAL_EL0 Philippe Mathieu-Daudé
                   ` (5 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/hvf/hvf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index f5bab7e7213..cc02df2e907 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -2015,6 +2015,7 @@ static int hvf_handle_vmexit(CPUState *cpu, hv_vcpu_exit_t *exit)
 
 void hvf_arch_cpu_synchronize_pre_exec(CPUState *cpu)
 {
+    flush_cpu_state(cpu);
 }
 
 void hvf_arch_cpu_synchronize_post_exec(CPUState *cpu)
@@ -2030,8 +2031,6 @@ int hvf_arch_vcpu_exec(CPUState *cpu)
         return EXCP_HLT;
     }
 
-    flush_cpu_state(cpu);
-
     do {
         if (!(cpu->singlestep_enabled & SSTEP_NOIRQ) &&
             hvf_inject_interrupts(cpu)) {
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 55/59] accel/hvf: Sync CNTV_CTL_EL0 & CNTV_CVAL_EL0
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (53 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 54/59] target/arm/hvf: " Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 56/59] target/arm: Better describe PMU depends on TCG or HVF Philippe Mathieu-Daudé
                   ` (4 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/hvf/hvf.c | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index cc02df2e907..22b7e34db0e 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -200,6 +200,9 @@ void hvf_arm_init_debug(void)
 #define SYSREG_PMCEID0_EL0    SYSREG(3, 3, 9, 12, 6)
 #define SYSREG_PMCEID1_EL0    SYSREG(3, 3, 9, 12, 7)
 #define SYSREG_PMCCNTR_EL0    SYSREG(3, 3, 9, 13, 0)
+
+#define SYSREG_CNTV_CTL_EL0   SYSREG(3, 3, 14, 3, 1)
+#define SYSREG_CNTV_CVAL_EL0  SYSREG(3, 3, 14, 3, 2)
 #define SYSREG_PMCCFILTR_EL0  SYSREG(3, 3, 14, 15, 7)
 
 #define SYSREG_ICC_AP0R0_EL1     SYSREG(3, 0, 12, 8, 4)
@@ -2013,13 +2016,49 @@ static int hvf_handle_vmexit(CPUState *cpu, hv_vcpu_exit_t *exit)
     return ret;
 }
 
+static void hvf_sync_vtimer_pre_exec(CPUState *cpu)
+{
+    hv_return_t r;
+    uint64_t val;
+    bool b;
+
+    b = hvf_sysreg_read_cp(cpu, "VTimer", SYSREG_CNTV_CVAL_EL0, &val);
+    assert(b);
+    r = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CVAL_EL0, val);
+    assert_hvf_ok(r);
+
+    b = hvf_sysreg_read_cp(cpu, "VTimer", SYSREG_CNTV_CTL_EL0, &val);
+    assert(b);
+    r = hv_vcpu_set_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, val);
+    assert_hvf_ok(r);
+}
+
+static void hvf_sync_vtimer_post_exec(CPUState *cpu)
+{
+    hv_return_t r;
+    uint64_t val;
+    bool b;
+
+    r = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CVAL_EL0, &val);
+    assert_hvf_ok(r);
+    b = hvf_sysreg_write_cp(cpu, "VTimer", SYSREG_CNTV_CVAL_EL0, val);
+    assert(b);
+
+    r = hv_vcpu_get_sys_reg(cpu->accel->fd, HV_SYS_REG_CNTV_CTL_EL0, &val);
+    assert_hvf_ok(r);
+    b = hvf_sysreg_write_cp(cpu, "VTimer", SYSREG_CNTV_CTL_EL0, val);
+    assert(b);
+}
+
 void hvf_arch_cpu_synchronize_pre_exec(CPUState *cpu)
 {
+    hvf_sync_vtimer_pre_exec(cpu);
     flush_cpu_state(cpu);
 }
 
 void hvf_arch_cpu_synchronize_post_exec(CPUState *cpu)
 {
+    hvf_sync_vtimer_post_exec(cpu);
 }
 
 int hvf_arch_vcpu_exec(CPUState *cpu)
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 56/59] target/arm: Better describe PMU depends on TCG or HVF
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (54 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 55/59] accel/hvf: Sync CNTV_CTL_EL0 & CNTV_CVAL_EL0 Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28 12:29   ` Richard Henderson
  2025-10-28  5:42 ` [PATCH v3 57/59] target/arm/hvf: Emulate PMU registers Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  59 siblings, 1 reply; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Simplify PMU logic by rewriting '!KVM' as 'TCG || HVF'
(ignoring QTest, because vCPUs are not available there).

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/cpu.c     |  2 +-
 target/arm/machine.c | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index eaf76532eca..5a5a9994af0 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1979,7 +1979,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
     if (arm_feature(env, ARM_FEATURE_PMU)) {
         pmu_init(cpu);
 
-        if (!kvm_enabled()) {
+        if (tcg_enabled() || hvf_enabled()) {
             arm_register_pre_el_change_hook(cpu, &pmu_pre_el_change, 0);
             arm_register_el_change_hook(cpu, &pmu_post_el_change, 0);
         }
diff --git a/target/arm/machine.c b/target/arm/machine.c
index 44a0cf844b0..80aa2e34b4b 100644
--- a/target/arm/machine.c
+++ b/target/arm/machine.c
@@ -1,7 +1,7 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "qemu/error-report.h"
-#include "system/kvm.h"
+#include "system/hvf.h"
 #include "system/tcg.h"
 #include "kvm_arm.h"
 #include "internals.h"
@@ -943,7 +943,7 @@ static int cpu_pre_save(void *opaque)
 {
     ARMCPU *cpu = opaque;
 
-    if (!kvm_enabled()) {
+    if (tcg_enabled() || hvf_enabled()) {
         pmu_op_start(&cpu->env);
     }
 
@@ -978,7 +978,7 @@ static int cpu_post_save(void *opaque)
 {
     ARMCPU *cpu = opaque;
 
-    if (!kvm_enabled()) {
+    if (tcg_enabled() || hvf_enabled()) {
         pmu_op_finish(&cpu->env);
     }
 
@@ -1011,7 +1011,7 @@ static int cpu_pre_load(void *opaque)
      */
     env->irq_line_state = UINT32_MAX;
 
-    if (!kvm_enabled()) {
+    if (tcg_enabled() || hvf_enabled()) {
         pmu_op_start(env);
     }
 
@@ -1103,7 +1103,7 @@ static int cpu_post_load(void *opaque, int version_id)
         }
     }
 
-    if (!kvm_enabled()) {
+    if (tcg_enabled() || hvf_enabled()) {
         pmu_op_finish(env);
     }
 
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 57/59] target/arm/hvf: Emulate PMU registers
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (55 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 56/59] target/arm: Better describe PMU depends on TCG or HVF Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 58/59] target/arm/hvf: Emulate Monitor Debug registers Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
TODO: audit it is safe
---
 target/arm/hvf/hvf.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 22b7e34db0e..639eef3b800 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1234,6 +1234,10 @@ static int hvf_sysreg_read(CPUState *cpu, uint32_t reg, uint64_t *val)
             *val = env->cp15.c9_pmcnten;
             return 0;
         case SYSREG_PMUSERENR_EL0:
+            /* Call the TCG sysreg handler. This is only safe for PMU regs. */
+            if (hvf_sysreg_read_cp(cpu, "PMU", reg, val)) {
+                return 0;
+            }
             *val = env->cp15.c9_pmuserenr;
             return 0;
         case SYSREG_PMCEID0_EL0:
@@ -1525,6 +1529,10 @@ static int hvf_sysreg_write(CPUState *cpu, uint32_t reg, uint64_t val)
             pmu_op_finish(env);
             return 0;
         case SYSREG_PMUSERENR_EL0:
+            /* Call the TCG sysreg handler. This is only safe for PMU regs. */
+            if (hvf_sysreg_write_cp(cpu, "PMU", reg, val)) {
+                return 0;
+            }
             env->cp15.c9_pmuserenr = val & 0xf;
             return 0;
         case SYSREG_PMCNTENSET_EL0:
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 58/59] target/arm/hvf: Emulate Monitor Debug registers
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (56 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 57/59] target/arm/hvf: Emulate PMU registers Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28  5:42 ` [PATCH v3 59/59] target/arm/hvf: Emulate PhysTimer registers Philippe Mathieu-Daudé
  2025-10-28 13:10 ` [PATCH v3 00/59] target/arm/hvf: Consolidate Peter Maydell
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
TODO: audit it is safe
---
 target/arm/hvf/hvf.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 639eef3b800..113f1415011 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -1616,6 +1616,9 @@ static int hvf_sysreg_write(CPUState *cpu, uint32_t reg, uint64_t val)
         }
         break;
     case SYSREG_MDSCR_EL1:
+        if (hvf_sysreg_write_cp(cpu, "Monitor Debug", reg, val)) {
+            return 0;
+        }
         env->cp15.mdscr_el1 = val;
         return 0;
     case SYSREG_DBGBVR0_EL1:
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* [PATCH v3 59/59] target/arm/hvf: Emulate PhysTimer registers
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (57 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 58/59] target/arm/hvf: Emulate Monitor Debug registers Philippe Mathieu-Daudé
@ 2025-10-28  5:42 ` Philippe Mathieu-Daudé
  2025-10-28 13:10 ` [PATCH v3 00/59] target/arm/hvf: Consolidate Peter Maydell
  59 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28  5:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf,
	Richard Henderson, Philippe Mathieu-Daudé

Emulate PhysTimer dispatching to TCG, like we do with GIC registers.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
TODO: audit it is safe
---
 target/arm/hvf/hvf.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
index 113f1415011..a7b5e4711b0 100644
--- a/target/arm/hvf/hvf.c
+++ b/target/arm/hvf/hvf.c
@@ -189,6 +189,7 @@ void hvf_arm_init_debug(void)
 #define SYSREG_LORC_EL1       SYSREG(3, 0, 10, 4, 3)
 #define SYSREG_CNTPCT_EL0     SYSREG(3, 3, 14, 0, 1)
 #define SYSREG_CNTP_CTL_EL0   SYSREG(3, 3, 14, 2, 1)
+#define SYSREG_CNTP_CVAL_EL0  SYSREG(3, 3, 14, 2, 2)
 #define SYSREG_PMCR_EL0       SYSREG(3, 3, 9, 12, 0)
 #define SYSREG_PMUSERENR_EL0  SYSREG(3, 3, 9, 14, 0)
 #define SYSREG_PMCNTENSET_EL0 SYSREG(3, 3, 9, 12, 1)
@@ -201,6 +202,8 @@ void hvf_arm_init_debug(void)
 #define SYSREG_PMCEID1_EL0    SYSREG(3, 3, 9, 12, 7)
 #define SYSREG_PMCCNTR_EL0    SYSREG(3, 3, 9, 13, 0)
 
+#define SYSREG_CNTP_TVAL_EL0  SYSREG(3, 3, 14, 2, 0)
+#define SYSREG_CNTP_CVAL_EL0  SYSREG(3, 3, 14, 2, 2)
 #define SYSREG_CNTV_CTL_EL0   SYSREG(3, 3, 14, 3, 1)
 #define SYSREG_CNTV_CVAL_EL0  SYSREG(3, 3, 14, 3, 2)
 #define SYSREG_PMCCFILTR_EL0  SYSREG(3, 3, 14, 15, 7)
@@ -1249,16 +1252,20 @@ static int hvf_sysreg_read(CPUState *cpu, uint32_t reg, uint64_t *val)
     }
 
     switch (reg) {
-    case SYSREG_CNTPCT_EL0:
-        *val = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) /
-              gt_cntfrq_period_ns(arm_cpu);
-        return 0;
     case SYSREG_OSLSR_EL1:
         *val = env->cp15.oslsr_el1;
         return 0;
     case SYSREG_OSDLR_EL1:
         /* Dummy register */
         return 0;
+    case SYSREG_CNTP_CTL_EL0:
+    case SYSREG_CNTP_TVAL_EL0:
+    case SYSREG_CNTPCT_EL0:
+        /* Call the TCG sysreg handler. This is only safe for VTimer regs. */
+        if (hvf_sysreg_read_cp(cpu, "VTimer", reg, val)) {
+            return 0;
+        }
+        break;
     case SYSREG_ICC_AP0R0_EL1:
     case SYSREG_ICC_AP0R1_EL1:
     case SYSREG_ICC_AP0R2_EL1:
@@ -1571,19 +1578,20 @@ static int hvf_sysreg_write(CPUState *cpu, uint32_t reg, uint64_t val)
     case SYSREG_OSLAR_EL1:
         env->cp15.oslsr_el1 = val & 1;
         return 0;
-    case SYSREG_CNTP_CTL_EL0:
-        /*
-         * Guests should not rely on the physical counter, but macOS emits
-         * disable writes to it. Let it do so, but ignore the requests.
-         */
-        qemu_log_mask(LOG_UNIMP, "Unsupported write to CNTP_CTL_EL0\n");
-        return 0;
     case SYSREG_OSDLR_EL1:
         /* Dummy register */
         return 0;
     case SYSREG_LORC_EL1:
         /* Dummy register */
         return 0;
+    case SYSREG_CNTP_CTL_EL0:
+    case SYSREG_CNTP_CVAL_EL0:
+    case SYSREG_CNTP_TVAL_EL0:
+        /* Call the TCG sysreg handler. This is only safe for VTimer regs. */
+        if (hvf_sysreg_write_cp(cpu, "VTimer", reg, val)) {
+            return 0;
+        }
+        break;
     case SYSREG_ICC_AP0R0_EL1:
     case SYSREG_ICC_AP0R1_EL1:
     case SYSREG_ICC_AP0R2_EL1:
-- 
2.51.0



^ permalink raw reply related	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 15/59] target/arm/hvf: Simplify hvf_arm_get_host_cpu_features()
  2025-10-28  5:41 ` [PATCH v3 15/59] target/arm/hvf: Simplify hvf_arm_get_host_cpu_features() Philippe Mathieu-Daudé
@ 2025-10-28 11:16   ` Peter Maydell
  2025-10-28 11:33   ` Richard Henderson
  1 sibling, 0 replies; 83+ messages in thread
From: Peter Maydell @ 2025-10-28 11:16 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Mads Ynddal, Cameron Esfahani, qemu-arm,
	Roman Bolshakov, Akihiko Odaki, Phil Dennis-Jordan,
	Mohamed Mediouni, Peter Collingbourne, Alexander Graf,
	Richard Henderson

On Tue, 28 Oct 2025 at 05:53, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> Use index in the structure, dereference &host_isar.idregs[] once.
>
> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>


Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 18/59] target/i386/hvf: Factor hvf_handle_vmexit() out
  2025-10-28  5:41 ` [PATCH v3 18/59] target/i386/hvf: Factor hvf_handle_vmexit() out Philippe Mathieu-Daudé
@ 2025-10-28 11:18   ` Peter Maydell
  0 siblings, 0 replies; 83+ messages in thread
From: Peter Maydell @ 2025-10-28 11:18 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Mads Ynddal, Cameron Esfahani, qemu-arm,
	Roman Bolshakov, Akihiko Odaki, Phil Dennis-Jordan,
	Mohamed Mediouni, Peter Collingbourne, Alexander Graf,
	Richard Henderson

On Tue, 28 Oct 2025 at 05:55, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> Factor hvf_handle_vmexit() out of hvf_arch_vcpu_exec().
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  target/i386/hvf/hvf.c | 478 +++++++++++++++++++++---------------------
>  1 file changed, 244 insertions(+), 234 deletions(-)

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 26/59] target/arm/hvf: Rename 'vgic' -> 'emu_reginfo' in trace events
  2025-10-28  5:42 ` [PATCH v3 26/59] target/arm/hvf: Rename 'vgic' -> 'emu_reginfo' in trace events Philippe Mathieu-Daudé
@ 2025-10-28 11:23   ` Peter Maydell
  0 siblings, 0 replies; 83+ messages in thread
From: Peter Maydell @ 2025-10-28 11:23 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Mads Ynddal, Cameron Esfahani, qemu-arm,
	Roman Bolshakov, Akihiko Odaki, Phil Dennis-Jordan,
	Mohamed Mediouni, Peter Collingbourne, Alexander Graf,
	Richard Henderson

On Tue, 28 Oct 2025 at 06:01, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> In order to extend the trace events to other registers,
> rename and pass the register group as argument.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 32/59] accel/hvf: Enforce host alignment in hv_vm_protect()
  2025-10-28  5:42 ` [PATCH v3 32/59] accel/hvf: Enforce host alignment in hv_vm_protect() Philippe Mathieu-Daudé
@ 2025-10-28 11:26   ` Peter Maydell
  2025-10-28 11:44   ` Richard Henderson
  1 sibling, 0 replies; 83+ messages in thread
From: Peter Maydell @ 2025-10-28 11:26 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Mads Ynddal, Cameron Esfahani, qemu-arm,
	Roman Bolshakov, Akihiko Odaki, Phil Dennis-Jordan,
	Mohamed Mediouni, Peter Collingbourne, Alexander Graf,
	Richard Henderson

On Tue, 28 Oct 2025 at 06:05, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> hv_vm_protect() arguments must be aligned to host page.
>
> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  accel/hvf/hvf-all.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/accel/hvf/hvf-all.c b/accel/hvf/hvf-all.c
> index e13abddbd9c..2efecdc9f40 100644
> --- a/accel/hvf/hvf-all.c
> +++ b/accel/hvf/hvf-all.c
> @@ -11,6 +11,7 @@
>  #include "qemu/osdep.h"
>  #include "qemu/error-report.h"
>  #include "accel/accel-ops.h"
> +#include "exec/cpu-common.h"
>  #include "system/address-spaces.h"
>  #include "system/memory.h"
>  #include "system/hvf.h"
> @@ -67,6 +68,8 @@ static void do_hv_vm_protect(hwaddr start, size_t size,
>                           flags & HV_MEMORY_READ  ? 'R' : '-',
>                           flags & HV_MEMORY_WRITE ? 'W' : '-',
>                           flags & HV_MEMORY_EXEC  ? 'X' : '-');
> +    g_assert(!((uintptr_t)start & ~qemu_real_host_page_mask()));
> +    g_assert(!(size & ~qemu_real_host_page_mask()));

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 33/59] target/i386/hvf: Use host page alignment in ept_emulation_fault()
  2025-10-28  5:42 ` [PATCH v3 33/59] target/i386/hvf: Use host page alignment in ept_emulation_fault() Philippe Mathieu-Daudé
@ 2025-10-28 11:28   ` Peter Maydell
  2025-11-03 10:00     ` Philippe Mathieu-Daudé
  2025-10-28 11:47   ` Richard Henderson
  1 sibling, 1 reply; 83+ messages in thread
From: Peter Maydell @ 2025-10-28 11:28 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Mads Ynddal, Cameron Esfahani, qemu-arm,
	Roman Bolshakov, Akihiko Odaki, Phil Dennis-Jordan,
	Mohamed Mediouni, Peter Collingbourne, Alexander Graf,
	Richard Henderson

On Tue, 28 Oct 2025 at 06:06, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  target/i386/hvf/hvf.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
> index 16febbac48f..c0b2352b988 100644
> --- a/target/i386/hvf/hvf.c
> +++ b/target/i386/hvf/hvf.c
> @@ -76,7 +76,7 @@
>  #include "qemu/main-loop.h"
>  #include "qemu/accel.h"
>  #include "target/i386/cpu.h"
> -#include "exec/target_page.h"
> +#include "exec/cpu-common.h"
>
>  static Error *invtsc_mig_blocker;
>
> @@ -137,9 +137,9 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)
>
>      if (write && slot) {
>          if (slot->flags & HVF_SLOT_LOG) {
> -            uint64_t dirty_page_start = gpa & ~(TARGET_PAGE_SIZE - 1u);
> +            uint64_t dirty_page_start = gpa & qemu_real_host_page_mask();
>              memory_region_set_dirty(slot->region, gpa - slot->start, 1);
> -            hv_vm_protect(dirty_page_start, TARGET_PAGE_SIZE,
> +            hv_vm_protect(dirty_page_start, qemu_real_host_page_size(),
>                            HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
>          }
>      }

I guess we're guaranteed that the host page and TARGET_PAGE_SIZE
are the same thing here (so it doesn't matter that we put
the assert in first and then fix this) ?

On that assumption
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 34/59] target/i386/hvf: Use hvf_unprotect_page
  2025-10-28  5:42 ` [PATCH v3 34/59] target/i386/hvf: Use hvf_unprotect_page Philippe Mathieu-Daudé
@ 2025-10-28 11:29   ` Peter Maydell
  0 siblings, 0 replies; 83+ messages in thread
From: Peter Maydell @ 2025-10-28 11:29 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Mads Ynddal, Cameron Esfahani, qemu-arm,
	Roman Bolshakov, Akihiko Odaki, Phil Dennis-Jordan,
	Mohamed Mediouni, Peter Collingbourne, Alexander Graf,
	Richard Henderson

On Tue, 28 Oct 2025 at 06:06, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> From: Richard Henderson <richard.henderson@linaro.org>
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  target/i386/hvf/hvf.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
> index c0b2352b988..1e92e9b707b 100644
> --- a/target/i386/hvf/hvf.c
> +++ b/target/i386/hvf/hvf.c
> @@ -139,8 +139,8 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)
>          if (slot->flags & HVF_SLOT_LOG) {
>              uint64_t dirty_page_start = gpa & qemu_real_host_page_mask();
>              memory_region_set_dirty(slot->region, gpa - slot->start, 1);
> -            hv_vm_protect(dirty_page_start, qemu_real_host_page_size(),
> -                          HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
> +            hvf_unprotect_dirty_range(dirty_page_start,
> +                                      qemu_real_host_page_size());
>          }
>      }

Subject says hvf_unprotect_page, code uses hvf_unprotect_dirty_range.

I assume we can just fix the Subject.

-- PMM


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 15/59] target/arm/hvf: Simplify hvf_arm_get_host_cpu_features()
  2025-10-28  5:41 ` [PATCH v3 15/59] target/arm/hvf: Simplify hvf_arm_get_host_cpu_features() Philippe Mathieu-Daudé
  2025-10-28 11:16   ` Peter Maydell
@ 2025-10-28 11:33   ` Richard Henderson
  1 sibling, 0 replies; 83+ messages in thread
From: Richard Henderson @ 2025-10-28 11:33 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf

On 10/28/25 06:41, Philippe Mathieu-Daudé wrote:
> Use index in the structure, dereference &host_isar.idregs[] once.
> 
> Suggested-by: Richard Henderson<richard.henderson@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   target/arm/hvf/hvf.c | 25 +++++++++++++------------
>   1 file changed, 13 insertions(+), 12 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 32/59] accel/hvf: Enforce host alignment in hv_vm_protect()
  2025-10-28  5:42 ` [PATCH v3 32/59] accel/hvf: Enforce host alignment in hv_vm_protect() Philippe Mathieu-Daudé
  2025-10-28 11:26   ` Peter Maydell
@ 2025-10-28 11:44   ` Richard Henderson
  1 sibling, 0 replies; 83+ messages in thread
From: Richard Henderson @ 2025-10-28 11:44 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf

On 10/28/25 06:42, Philippe Mathieu-Daudé wrote:
> hv_vm_protect() arguments must be aligned to host page.
> 
> Suggested-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   accel/hvf/hvf-all.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/accel/hvf/hvf-all.c b/accel/hvf/hvf-all.c
> index e13abddbd9c..2efecdc9f40 100644
> --- a/accel/hvf/hvf-all.c
> +++ b/accel/hvf/hvf-all.c
> @@ -11,6 +11,7 @@
>   #include "qemu/osdep.h"
>   #include "qemu/error-report.h"
>   #include "accel/accel-ops.h"
> +#include "exec/cpu-common.h"
>   #include "system/address-spaces.h"
>   #include "system/memory.h"
>   #include "system/hvf.h"
> @@ -67,6 +68,8 @@ static void do_hv_vm_protect(hwaddr start, size_t size,
>                            flags & HV_MEMORY_READ  ? 'R' : '-',
>                            flags & HV_MEMORY_WRITE ? 'W' : '-',
>                            flags & HV_MEMORY_EXEC  ? 'X' : '-');
> +    g_assert(!((uintptr_t)start & ~qemu_real_host_page_mask()));
> +    g_assert(!(size & ~qemu_real_host_page_mask()));
>   
>       ret = hv_vm_protect(start, size, flags);
>       assert_hvf_ok(ret);

You should call qemu_real_host_page_mask only once.
Otherwise,

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 33/59] target/i386/hvf: Use host page alignment in ept_emulation_fault()
  2025-10-28  5:42 ` [PATCH v3 33/59] target/i386/hvf: Use host page alignment in ept_emulation_fault() Philippe Mathieu-Daudé
  2025-10-28 11:28   ` Peter Maydell
@ 2025-10-28 11:47   ` Richard Henderson
  1 sibling, 0 replies; 83+ messages in thread
From: Richard Henderson @ 2025-10-28 11:47 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf

On 10/28/25 06:42, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   target/i386/hvf/hvf.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
> index 16febbac48f..c0b2352b988 100644
> --- a/target/i386/hvf/hvf.c
> +++ b/target/i386/hvf/hvf.c
> @@ -76,7 +76,7 @@
>   #include "qemu/main-loop.h"
>   #include "qemu/accel.h"
>   #include "target/i386/cpu.h"
> -#include "exec/target_page.h"
> +#include "exec/cpu-common.h"
>   
>   static Error *invtsc_mig_blocker;
>   
> @@ -137,9 +137,9 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)
>   
>       if (write && slot) {
>           if (slot->flags & HVF_SLOT_LOG) {
> -            uint64_t dirty_page_start = gpa & ~(TARGET_PAGE_SIZE - 1u);
> +            uint64_t dirty_page_start = gpa & qemu_real_host_page_mask();
>               memory_region_set_dirty(slot->region, gpa - slot->start, 1);
> -            hv_vm_protect(dirty_page_start, TARGET_PAGE_SIZE,
> +            hv_vm_protect(dirty_page_start, qemu_real_host_page_size(),
>                             HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
>           }
>       }

Call qemu_real_host_page_size once -- page_mask is -size.

We could get away with TARGET_PAGE_SIZE here, due to x86 and it's fixed 4k page size.  But 
it's better for consistency.


Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 42/59] accel/hvf: Skip WFI if CPU has work to do
  2025-10-28  5:42 ` [PATCH v3 42/59] accel/hvf: Skip WFI if CPU has work to do Philippe Mathieu-Daudé
@ 2025-10-28 11:51   ` Alex Bennée
  2025-10-28 11:59   ` Richard Henderson
  1 sibling, 0 replies; 83+ messages in thread
From: Alex Bennée @ 2025-10-28 11:51 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Mads Ynddal, Cameron Esfahani, qemu-arm,
	Roman Bolshakov, Akihiko Odaki, Phil Dennis-Jordan,
	Mohamed Mediouni, Peter Collingbourne, Peter Maydell,
	Alexander Graf, Richard Henderson

Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> Avoid sleeping vCPU thread for any pending work, not just IRQs.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Reviewed-by: Alex Bennée <alex.bennee@linaro.org>

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 41/59] target/arm/hvf: Implement dirty page tracking
  2025-10-28  5:42 ` [PATCH v3 41/59] target/arm/hvf: Implement dirty page tracking Philippe Mathieu-Daudé
@ 2025-10-28 11:58   ` Richard Henderson
  0 siblings, 0 replies; 83+ messages in thread
From: Richard Henderson @ 2025-10-28 11:58 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf

On 10/28/25 06:42, Philippe Mathieu-Daudé wrote:
> +            if (memory_region_is_ram(mr)) {
> +                uint64_t ipa_page = ipa & qemu_real_host_page_mask();
> +
> +                /* TODO: Inject exception to the guest. */
> +                assert(!mr->readonly);
> +
> +                if (memory_region_get_dirty_log_mask(mr)) {
> +                    size_t page_size = qemu_real_host_page_size();
> +

Call qemu_real_host_page_size once; mask = -size.


r~


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 42/59] accel/hvf: Skip WFI if CPU has work to do
  2025-10-28  5:42 ` [PATCH v3 42/59] accel/hvf: Skip WFI if CPU has work to do Philippe Mathieu-Daudé
  2025-10-28 11:51   ` Alex Bennée
@ 2025-10-28 11:59   ` Richard Henderson
  1 sibling, 0 replies; 83+ messages in thread
From: Richard Henderson @ 2025-10-28 11:59 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf

On 10/28/25 06:42, Philippe Mathieu-Daudé wrote:
> Avoid sleeping vCPU thread for any pending work, not just IRQs.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   target/arm/hvf/hvf.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 43/59] accel/hvf: Implement WFI without using pselect()
  2025-10-28  5:42 ` [PATCH v3 43/59] accel/hvf: Implement WFI without using pselect() Philippe Mathieu-Daudé
@ 2025-10-28 12:01   ` Richard Henderson
  2025-11-03 10:01     ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 83+ messages in thread
From: Richard Henderson @ 2025-10-28 12:01 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf

On 10/28/25 06:42, Philippe Mathieu-Daudé wrote:
> --- a/accel/hvf/hvf-accel-ops.c
> +++ b/accel/hvf/hvf-accel-ops.c
> @@ -128,14 +128,15 @@ static int hvf_init_vcpu(CPUState *cpu)
>       cpu->accel = g_new0(AccelCPUState, 1);
>   
>       /* init cpu signals */
> +    sigset_t unblock_ipi_mask;

Why introduce this?  Surely it's unused...

>       struct sigaction sigact;
>   
>       memset(&sigact, 0, sizeof(sigact));
>       sigact.sa_handler = dummy_signal;
>       sigaction(SIG_IPI, &sigact, NULL);
>   
> -    pthread_sigmask(SIG_BLOCK, NULL, &cpu->accel->unblock_ipi_mask);
> -    sigdelset(&cpu->accel->unblock_ipi_mask, SIG_IPI);
> +    pthread_sigmask(SIG_BLOCK, NULL, &unblock_ipi_mask);
> +    sigdelset(&unblock_ipi_mask, SIG_IPI);

... apart from mere initialization.


r~


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 50/59] target/arm/hvf: Do not abort in hvf_arm_get_*_ipa_bit_size()
  2025-10-28  5:42 ` [PATCH v3 50/59] target/arm/hvf: Do not abort in hvf_arm_get_*_ipa_bit_size() Philippe Mathieu-Daudé
@ 2025-10-28 12:06   ` Richard Henderson
  0 siblings, 0 replies; 83+ messages in thread
From: Richard Henderson @ 2025-10-28 12:06 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf

On 10/28/25 06:42, Philippe Mathieu-Daudé wrote:
> Do not abort in hvf_arm_get_default_ipa_bit_size()
> and hvf_arm_get_max_ipa_bit_size() when the IPA can
> not be fetched. Return 0 (and document it).
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   target/arm/hvf_arm.h | 11 +++++++++++
>   target/arm/hvf/hvf.c |  8 ++------
>   2 files changed, 13 insertions(+), 6 deletions(-)

Doesn't this just lead to a nonsensical error_report, e.g.

-m and ,maxmem option values require an IPA range (XX bits) larger than the one supported 
by the host (0 bits)

?

Is there a reasonable way to populate an Error return?
I guess this only happens with older versions of Darwin, because surely we can always 
probe the supported IPA size...


r~


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 51/59] hw/arm/virt: Warn when HVF doesn't report IPA bit length
  2025-10-28  5:42 ` [PATCH v3 51/59] hw/arm/virt: Warn when HVF doesn't report IPA bit length Philippe Mathieu-Daudé
@ 2025-10-28 12:07   ` Richard Henderson
  0 siblings, 0 replies; 83+ messages in thread
From: Richard Henderson @ 2025-10-28 12:07 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf

On 10/28/25 06:42, Philippe Mathieu-Daudé wrote:
> Emit a warning when HVF doesn't return the IPA bit length
> and return -1 as "this accelerator is not usable", allowing
> QEMU to try with the next one (when using '-accel hvf:tcg').
> 
> Reported-by: Ivan Krasilnikov
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2981
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/arm/virt.c | 8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/arm/virt.c b/hw/arm/virt.c
> index 175023897a7..1d65fa471dc 100644
> --- a/hw/arm/virt.c
> +++ b/hw/arm/virt.c
> @@ -3225,8 +3225,12 @@ static int virt_hvf_get_physical_address_range(MachineState *ms)
>   {
>       VirtMachineState *vms = VIRT_MACHINE(ms);
>   
> -    int default_ipa_size = hvf_arm_get_default_ipa_bit_size();
> -    int max_ipa_size = hvf_arm_get_max_ipa_bit_size();
> +    uint32_t default_ipa_size = hvf_arm_get_default_ipa_bit_size();
> +    uint32_t max_ipa_size = hvf_arm_get_max_ipa_bit_size();
> +    if (!default_ipa_size || !max_ipa_size) {
> +        warn_report("HVF didn't report IPA bit length");
> +        return -1;
> +    }

I suppose this goes back to the previous patch.
It might have been slightly less confusing to merge them, but the underlying questions 
about when and how this can fail remain.


r~


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 52/59] accel/hvf: Introduce hvf_arch_cpu_synchronize_[pre/post]exec() hooks
  2025-10-28  5:42 ` [PATCH v3 52/59] accel/hvf: Introduce hvf_arch_cpu_synchronize_[pre/post]exec() hooks Philippe Mathieu-Daudé
@ 2025-10-28 12:08   ` Richard Henderson
  0 siblings, 0 replies; 83+ messages in thread
From: Richard Henderson @ 2025-10-28 12:08 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf

On 10/28/25 06:42, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   include/system/hvf_int.h  | 4 ++++
>   accel/hvf/hvf-accel-ops.c | 3 +++
>   target/arm/hvf/hvf.c      | 8 ++++++++
>   target/i386/hvf/hvf.c     | 8 ++++++++
>   4 files changed, 23 insertions(+)
> 
> diff --git a/include/system/hvf_int.h b/include/system/hvf_int.h
> index 96790b49386..3120a4593a4 100644
> --- a/include/system/hvf_int.h
> +++ b/include/system/hvf_int.h
> @@ -71,6 +71,10 @@ int hvf_arch_put_registers(CPUState *);
>   int hvf_arch_get_registers(CPUState *);
>   /* Must be called by the owning thread */
>   void hvf_arch_update_guest_debug(CPUState *cpu);
> +/* Must be called by the owning thread */
> +void hvf_arch_cpu_synchronize_pre_exec(CPUState *cpu);
> +/* Must be called by the owning thread */
> +void hvf_arch_cpu_synchronize_post_exec(CPUState *cpu);
>   
>   void hvf_protect_clean_range(hwaddr addr, size_t size);
>   void hvf_unprotect_dirty_range(hwaddr addr, size_t size);
> diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c
> index 28d50e23017..6fb1fda424c 100644
> --- a/accel/hvf/hvf-accel-ops.c
> +++ b/accel/hvf/hvf-accel-ops.c
> @@ -181,10 +181,13 @@ static void *hvf_cpu_thread_fn(void *arg)
>       do {
>           qemu_process_cpu_events(cpu);
>           if (cpu_can_run(cpu)) {
> +
> +            hvf_arch_cpu_synchronize_pre_exec(cpu);

Funny extra line.  Otherwise,

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 53/59] target/i386/hvf: Flush vCPU registers once before vcpu_exec() loop
  2025-10-28  5:42 ` [PATCH v3 53/59] target/i386/hvf: Flush vCPU registers once before vcpu_exec() loop Philippe Mathieu-Daudé
@ 2025-10-28 12:09   ` Richard Henderson
  0 siblings, 0 replies; 83+ messages in thread
From: Richard Henderson @ 2025-10-28 12:09 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf

On 10/28/25 06:42, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   target/i386/hvf/hvf.c | 9 ++++-----
>   1 file changed, 4 insertions(+), 5 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 56/59] target/arm: Better describe PMU depends on TCG or HVF
  2025-10-28  5:42 ` [PATCH v3 56/59] target/arm: Better describe PMU depends on TCG or HVF Philippe Mathieu-Daudé
@ 2025-10-28 12:29   ` Richard Henderson
  0 siblings, 0 replies; 83+ messages in thread
From: Richard Henderson @ 2025-10-28 12:29 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf

On 10/28/25 06:42, Philippe Mathieu-Daudé wrote:
> Simplify PMU logic by rewriting '!KVM' as 'TCG || HVF'
> (ignoring QTest, because vCPUs are not available there).
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   target/arm/cpu.c     |  2 +-
>   target/arm/machine.c | 10 +++++-----
>   2 files changed, 6 insertions(+), 6 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 00/59] target/arm/hvf: Consolidate
  2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
                   ` (58 preceding siblings ...)
  2025-10-28  5:42 ` [PATCH v3 59/59] target/arm/hvf: Emulate PhysTimer registers Philippe Mathieu-Daudé
@ 2025-10-28 13:10 ` Peter Maydell
  2025-10-28 15:41   ` Philippe Mathieu-Daudé
  59 siblings, 1 reply; 83+ messages in thread
From: Peter Maydell @ 2025-10-28 13:10 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Mads Ynddal, Cameron Esfahani, qemu-arm,
	Roman Bolshakov, Akihiko Odaki, Phil Dennis-Jordan,
	Mohamed Mediouni, Peter Collingbourne, Alexander Graf,
	Richard Henderson

On Tue, 28 Oct 2025 at 05:42, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> Missing review: 15, 18, 26, 32, 33, 38 (up to #41 could be merged)
>                 42, 43 (up to #49 could be merged)
>                 50+
>
> Since v2:
> - Improve host page size/mask uses (rth)
> - Remove cpu_test_interrupt in hvf_wfi (rth)

Richard found an issue with patch 32, so I'm going to
take patches 1-30 into target-arm.next (patch 31 is
reviewed, but conceptually part of the next few patches
in the set which use the new functions it defines).

thanks
-- PMM


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 00/59] target/arm/hvf: Consolidate
  2025-10-28 13:10 ` [PATCH v3 00/59] target/arm/hvf: Consolidate Peter Maydell
@ 2025-10-28 15:41   ` Philippe Mathieu-Daudé
  2025-10-28 15:45     ` Peter Maydell
  0 siblings, 1 reply; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-10-28 15:41 UTC (permalink / raw)
  To: Peter Maydell
  Cc: qemu-devel, Mads Ynddal, Cameron Esfahani, qemu-arm,
	Roman Bolshakov, Akihiko Odaki, Phil Dennis-Jordan,
	Mohamed Mediouni, Peter Collingbourne, Alexander Graf,
	Richard Henderson

On 28/10/25 14:10, Peter Maydell wrote:
> On Tue, 28 Oct 2025 at 05:42, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>>
>> Missing review: 15, 18, 26, 32, 33, 38 (up to #41 could be merged)
>>                  42, 43 (up to #49 could be merged)
>>                  50+
>>
>> Since v2:
>> - Improve host page size/mask uses (rth)
>> - Remove cpu_test_interrupt in hvf_wfi (rth)
> 
> Richard found an issue with patch 32, so I'm going to

IIUC this is not an issue, just a worry about performance,
whether getpagesize() implementation calls a syscall.
Anyway I'll cache the value locally -- or better, maybe
have qemu_real_host_page_size() doing that --.

> take patches 1-30 into target-arm.next (patch 31 is
> reviewed, but conceptually part of the next few patches
> in the set which use the new functions it defines).

Thanks, this is really helpful!

Phil.


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 00/59] target/arm/hvf: Consolidate
  2025-10-28 15:41   ` Philippe Mathieu-Daudé
@ 2025-10-28 15:45     ` Peter Maydell
  0 siblings, 0 replies; 83+ messages in thread
From: Peter Maydell @ 2025-10-28 15:45 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, Mads Ynddal, Cameron Esfahani, qemu-arm,
	Roman Bolshakov, Akihiko Odaki, Phil Dennis-Jordan,
	Mohamed Mediouni, Peter Collingbourne, Alexander Graf,
	Richard Henderson

On Tue, 28 Oct 2025 at 15:41, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>
> On 28/10/25 14:10, Peter Maydell wrote:
> > On Tue, 28 Oct 2025 at 05:42, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
> >>
> >> Missing review: 15, 18, 26, 32, 33, 38 (up to #41 could be merged)
> >>                  42, 43 (up to #49 could be merged)
> >>                  50+
> >>
> >> Since v2:
> >> - Improve host page size/mask uses (rth)
> >> - Remove cpu_test_interrupt in hvf_wfi (rth)
> >
> > Richard found an issue with patch 32, so I'm going to
>
> IIUC this is not an issue, just a worry about performance,
> whether getpagesize() implementation calls a syscall.
> Anyway I'll cache the value locally -- or better, maybe
> have qemu_real_host_page_size() doing that --.

I just meant to note "the patch needs some change before
it can be applied"; I agree that the changes are minor.

-- PMM


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 33/59] target/i386/hvf: Use host page alignment in ept_emulation_fault()
  2025-10-28 11:28   ` Peter Maydell
@ 2025-11-03 10:00     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-11-03 10:00 UTC (permalink / raw)
  To: Peter Maydell
  Cc: qemu-devel, Mads Ynddal, Cameron Esfahani, qemu-arm,
	Roman Bolshakov, Akihiko Odaki, Phil Dennis-Jordan,
	Mohamed Mediouni, Peter Collingbourne, Alexander Graf,
	Richard Henderson

On 28/10/25 12:28, Peter Maydell wrote:
> On Tue, 28 Oct 2025 at 06:06, Philippe Mathieu-Daudé <philmd@linaro.org> wrote:
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   target/i386/hvf/hvf.c | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c
>> index 16febbac48f..c0b2352b988 100644
>> --- a/target/i386/hvf/hvf.c
>> +++ b/target/i386/hvf/hvf.c
>> @@ -76,7 +76,7 @@
>>   #include "qemu/main-loop.h"
>>   #include "qemu/accel.h"
>>   #include "target/i386/cpu.h"
>> -#include "exec/target_page.h"
>> +#include "exec/cpu-common.h"
>>
>>   static Error *invtsc_mig_blocker;
>>
>> @@ -137,9 +137,9 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)
>>
>>       if (write && slot) {
>>           if (slot->flags & HVF_SLOT_LOG) {
>> -            uint64_t dirty_page_start = gpa & ~(TARGET_PAGE_SIZE - 1u);
>> +            uint64_t dirty_page_start = gpa & qemu_real_host_page_mask();
>>               memory_region_set_dirty(slot->region, gpa - slot->start, 1);
>> -            hv_vm_protect(dirty_page_start, TARGET_PAGE_SIZE,
>> +            hv_vm_protect(dirty_page_start, qemu_real_host_page_size(),
>>                             HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC);
>>           }
>>       }
> 
> I guess we're guaranteed that the host page and TARGET_PAGE_SIZE
> are the same thing here (so it doesn't matter that we put
> the assert in first and then fix this) ?

Yes, but clearer to re-order before previous patch to avoid
any doubt.

> 
> On that assumption
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

Thanks!


^ permalink raw reply	[flat|nested] 83+ messages in thread

* Re: [PATCH v3 43/59] accel/hvf: Implement WFI without using pselect()
  2025-10-28 12:01   ` Richard Henderson
@ 2025-11-03 10:01     ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 83+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-11-03 10:01 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel
  Cc: Mads Ynddal, Cameron Esfahani, qemu-arm, Roman Bolshakov,
	Akihiko Odaki, Phil Dennis-Jordan, Mohamed Mediouni,
	Peter Collingbourne, Peter Maydell, Alexander Graf

On 28/10/25 13:01, Richard Henderson wrote:
> On 10/28/25 06:42, Philippe Mathieu-Daudé wrote:
>> --- a/accel/hvf/hvf-accel-ops.c
>> +++ b/accel/hvf/hvf-accel-ops.c
>> @@ -128,14 +128,15 @@ static int hvf_init_vcpu(CPUState *cpu)
>>       cpu->accel = g_new0(AccelCPUState, 1);
>>       /* init cpu signals */
>> +    sigset_t unblock_ipi_mask;
> 
> Why introduce this?  Surely it's unused...
> 
>>       struct sigaction sigact;
>>       memset(&sigact, 0, sizeof(sigact));
>>       sigact.sa_handler = dummy_signal;
>>       sigaction(SIG_IPI, &sigact, NULL);
>> -    pthread_sigmask(SIG_BLOCK, NULL, &cpu->accel->unblock_ipi_mask);
>> -    sigdelset(&cpu->accel->unblock_ipi_mask, SIG_IPI);
>> +    pthread_sigmask(SIG_BLOCK, NULL, &unblock_ipi_mask);
>> +    sigdelset(&unblock_ipi_mask, SIG_IPI);
> 
> ... apart from mere initialization.

Leftover (now removed).


^ permalink raw reply	[flat|nested] 83+ messages in thread

end of thread, other threads:[~2025-11-03 10:02 UTC | newest]

Thread overview: 83+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-28  5:41 [PATCH v3 00/59] target/arm/hvf: Consolidate Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 01/59] target/arm/hvf: Release memory allocated by hv_vcpu_config_create() Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 02/59] target/arm/hvf: Trace vCPU KICK events Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 03/59] target/arm/hvf: Check hv_vcpus_exit() returned value Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 04/59] target/arm/hvf: Check hv_vcpu_set_vtimer_mask() " Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 05/59] accel/hvf: Rename hvf_vcpu_exec() -> hvf_arch_vcpu_exec() Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 06/59] accel/hvf: Rename hvf_put|get_registers -> hvf_arch_put|get_registers Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 07/59] target/arm/hvf: Mention flush_cpu_state() must run on vCPU thread Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 08/59] accel/hvf: Mention hvf_arch_init_vcpu() " Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 09/59] target/arm/hvf: Mention hvf_sync_vtimer() " Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 10/59] target/arm/hvf: Mention hvf_arch_set_traps() " Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 11/59] accel/hvf: Mention hvf_arch_update_guest_debug() must run on vCPU Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 12/59] target/arm/hvf: Mention hvf_inject_interrupts() must run on vCPU thread Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 13/59] accel/hvf: Implement hvf_arch_vcpu_destroy() Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 14/59] target/arm/hvf: Hardcode Apple MIDR Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 15/59] target/arm/hvf: Simplify hvf_arm_get_host_cpu_features() Philippe Mathieu-Daudé
2025-10-28 11:16   ` Peter Maydell
2025-10-28 11:33   ` Richard Henderson
2025-10-28  5:41 ` [PATCH v3 16/59] target/arm/hvf: switch hvf_arm_get_host_cpu_features to not create a vCPU Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 17/59] target/arm/hvf: Factor hvf_handle_exception() out Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 18/59] target/i386/hvf: Factor hvf_handle_vmexit() out Philippe Mathieu-Daudé
2025-10-28 11:18   ` Peter Maydell
2025-10-28  5:41 ` [PATCH v3 19/59] target/arm/hvf: " Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 20/59] target/arm/hvf: Keep calling hv_vcpu_run() in loop Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 21/59] cpus: Trace cpu_exec_start() and cpu_exec_end() calls Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 22/59] accel/hvf: Guard hv_vcpu_run() between cpu_exec_start/end() calls Philippe Mathieu-Daudé
2025-10-28  5:41 ` [PATCH v3 23/59] target/arm: Call aarch64_add_pauth_properties() once in host_initfn() Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 24/59] accel/hvf: Restrict ARM specific fields of AccelCPUState Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 25/59] target/arm: Rename init_cpreg_list() -> arm_init_cpreg_list() Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 26/59] target/arm/hvf: Rename 'vgic' -> 'emu_reginfo' in trace events Philippe Mathieu-Daudé
2025-10-28 11:23   ` Peter Maydell
2025-10-28  5:42 ` [PATCH v3 27/59] target/arm: Re-use arm_is_psci_call() in HVF Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 28/59] target/arm: Share ARM_PSCI_CALL trace event between TCG and HVF Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 29/59] target/arm/hvf/hvf: Document $pc adjustment in HVF & SMC Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 30/59] accel/hvf: Trace prefetch abort Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 31/59] accel/hvf: Create hvf_protect_clean_range, hvf_unprotect_dirty_range Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 32/59] accel/hvf: Enforce host alignment in hv_vm_protect() Philippe Mathieu-Daudé
2025-10-28 11:26   ` Peter Maydell
2025-10-28 11:44   ` Richard Henderson
2025-10-28  5:42 ` [PATCH v3 33/59] target/i386/hvf: Use host page alignment in ept_emulation_fault() Philippe Mathieu-Daudé
2025-10-28 11:28   ` Peter Maydell
2025-11-03 10:00     ` Philippe Mathieu-Daudé
2025-10-28 11:47   ` Richard Henderson
2025-10-28  5:42 ` [PATCH v3 34/59] target/i386/hvf: Use hvf_unprotect_page Philippe Mathieu-Daudé
2025-10-28 11:29   ` Peter Maydell
2025-10-28  5:42 ` [PATCH v3 35/59] target/i386/hvf: Use address_space_translate in ept_emulation_fault Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 36/59] accel/hvf: Simplify hvf_log_* Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 37/59] accel/hvf: Move hvf_log_sync to hvf_log_clear Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 38/59] accel/hvf: Simplify hvf_set_phys_mem Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 39/59] accel/hvf: Drop hvf_slot and hvf_find_overlap_slot Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 40/59] accel/hvf: Remove mac_slots Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 41/59] target/arm/hvf: Implement dirty page tracking Philippe Mathieu-Daudé
2025-10-28 11:58   ` Richard Henderson
2025-10-28  5:42 ` [PATCH v3 42/59] accel/hvf: Skip WFI if CPU has work to do Philippe Mathieu-Daudé
2025-10-28 11:51   ` Alex Bennée
2025-10-28 11:59   ` Richard Henderson
2025-10-28  5:42 ` [PATCH v3 43/59] accel/hvf: Implement WFI without using pselect() Philippe Mathieu-Daudé
2025-10-28 12:01   ` Richard Henderson
2025-11-03 10:01     ` Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 44/59] accel/hvf: Have PSCI CPU_SUSPEND halt the vCPU Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 45/59] accel: Introduce AccelOpsClass::cpu_target_realize() hook Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 46/59] accel/hvf: Add hvf_arch_cpu_realize() stubs Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 47/59] target/arm: Create GTimers *after* features finalized / accel realized Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 48/59] target/arm/hvf: Really set Generic Timer counter frequency Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 49/59] target/arm: Only allow disabling NEON when using TCG Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 50/59] target/arm/hvf: Do not abort in hvf_arm_get_*_ipa_bit_size() Philippe Mathieu-Daudé
2025-10-28 12:06   ` Richard Henderson
2025-10-28  5:42 ` [PATCH v3 51/59] hw/arm/virt: Warn when HVF doesn't report IPA bit length Philippe Mathieu-Daudé
2025-10-28 12:07   ` Richard Henderson
2025-10-28  5:42 ` [PATCH v3 52/59] accel/hvf: Introduce hvf_arch_cpu_synchronize_[pre/post]exec() hooks Philippe Mathieu-Daudé
2025-10-28 12:08   ` Richard Henderson
2025-10-28  5:42 ` [PATCH v3 53/59] target/i386/hvf: Flush vCPU registers once before vcpu_exec() loop Philippe Mathieu-Daudé
2025-10-28 12:09   ` Richard Henderson
2025-10-28  5:42 ` [PATCH v3 54/59] target/arm/hvf: " Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 55/59] accel/hvf: Sync CNTV_CTL_EL0 & CNTV_CVAL_EL0 Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 56/59] target/arm: Better describe PMU depends on TCG or HVF Philippe Mathieu-Daudé
2025-10-28 12:29   ` Richard Henderson
2025-10-28  5:42 ` [PATCH v3 57/59] target/arm/hvf: Emulate PMU registers Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 58/59] target/arm/hvf: Emulate Monitor Debug registers Philippe Mathieu-Daudé
2025-10-28  5:42 ` [PATCH v3 59/59] target/arm/hvf: Emulate PhysTimer registers Philippe Mathieu-Daudé
2025-10-28 13:10 ` [PATCH v3 00/59] target/arm/hvf: Consolidate Peter Maydell
2025-10-28 15:41   ` Philippe Mathieu-Daudé
2025-10-28 15:45     ` Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).