Accelerators patches for 2025-07-04
The following changes since commit c77283dd5d79149f4e7e9edd00f65416c648ee59:
Merge tag 'pull-request-2025-07-02' of https://gitlab.com/thuth/qemu into staging (2025-07-03 06:01:41 -0400)
are available in the Git repository at:
https://github.com/philmd/qemu.git tags/accel-20250704
for you to fetch changes up to 569efc2cd64fd7a1f9112e200f2ada20ba1af087:
MAINTAINERS: Add me as reviewer of overall accelerators section (2025-07-04 15:22:04 +0200)
----------------------------------------------------------------
Accelerators patches
- Generic API consolidation, cleanups (dead code removal, documentation added)
- Remove monitor TCG 'info opcount' and @x-query-opcount
- Have HVF / NVMM / WHPX use generic CPUState::vcpu_dirty field
- Expose nvmm_enabled() and whpx_enabled() to common code
- Report missing com.apple.security.hypervisor entitlement
- Have hmp_info_registers() dump vector registers
----------------------------------------------------------------
Daniel Henrique Barboza (1):
monitor/hmp-cmds-target: add CPU_DUMP_VPU in hmp_info_registers()
Philippe Mathieu-Daudé (35):
system/cpus: Assert interrupt handling is done with BQL locked accel/kvm: Remove kvm_init_cpu_signals() stub
accel/kvm: Reduce kvm_create_vcpu() declaration scope accel/tcg: Remove 'info opcount' and @x-query-opcount accel/tcg: Remove profiler leftover
accel/tcg: Factor tcg_dump_flush_info() out
accel/tcg: Factor tcg_dump_stats() out for re-use accel/tcg: Clear exit_request once in tcg_cpu_exec() accel/tcg: Unregister the RCU before exiting RR thread accel/hvf: Restrict internal declarations
accel/hvf: Move per-cpu method declarations to hvf-accel-ops.c accel/hvf: Move generic method declarations to hvf-all.c accel/hvf: Report missing com.apple.security.hypervisor entitlement
cpus: Document CPUState::vcpu_dirty field
accel/hvf: Replace @dirty field by generic CPUState::vcpu_dirty field accel/nvmm: Replace @dirty field by generic CPUState::vcpu_dirty field accel/whpx: Replace @dirty field by generic CPUState::vcpu_dirty field accel/kvm: Remove kvm_cpu_synchronize_state() stub accel/system: Document cpu_synchronize_state() accel/system: Document cpu_synchronize_state_post_init/reset() accel/nvmm: Expose nvmm_enabled() to common code accel/whpx: Expose whpx_enabled() to common code accel/dummy: Extract 'dummy-cpus.h' header from 'system/cpus.h'
accel: Expose and register generic_handle_interrupt()
accel: Keep reference to AccelOpsClass in AccelClass
accel: Propagate AccelState to AccelClass::init_machine() accel/hvf: Re-use QOM allocated state
accel/tcg: Prefer local AccelState over global current_accel() accel/kvm: Prefer local AccelState over global MachineState::accel accel/kvm: Directly pass KVMState argument to do_kvm_create_vm()
accel: Directly pass AccelState argument to AccelClass::has_memory()
accel: Remove unused MachineState argument of AccelClass::setup_post()
accel: Pass AccelState argument to gdbstub_supported_sstep_flags() accel/system: Convert pre_resume() from AccelOpsClass to AccelClass
MAINTAINERS: Add me as reviewer of overall accelerators section
MAINTAINERS | 4 + qapi/machine.json | 18 -- accel/dummy-cpus.h | 14 ++ accel/tcg/internal-common.h | 2 + include/hw/core/cpu.h | 3 +- include/qemu/accel.h | 14 +- include/system/accel-ops.h | 23 ++- include/system/cpus.h | 5 - include/system/hvf.h | 38 ---- include/system/hvf_int.h | 35 +++- include/system/hw_accel.h | 21 +- include/system/kvm.h | 8 - include/system/nvmm.h | 23 +-- include/system/whpx.h | 27 +-- target/i386/whpx/whpx-accel-ops.h | 1 - accel/accel-common.c | 2 +- accel/accel-system.c | 16 +- accel/dummy-cpus.c | 1 + accel/hvf/hvf-accel-ops.c | 314 ++++-------------------------- accel/hvf/hvf-all.c | 280 ++++++++++++++++++++++++-- accel/kvm/kvm-accel-ops.c | 1 + accel/kvm/kvm-all.c | 27 +-- accel/qtest/qtest.c | 4 +- accel/stubs/kvm-stub.c | 9 - accel/stubs/nvmm-stub.c | 12 ++ accel/stubs/whpx-stub.c | 12 ++ accel/tcg/monitor.c | 57 ++---- accel/tcg/tcg-accel-ops-mttcg.c | 1 - accel/tcg/tcg-accel-ops-rr.c | 2 + accel/tcg/tcg-accel-ops.c | 9 +- accel/tcg/tcg-all.c | 6 +- accel/xen/xen-all.c | 6 +- bsd-user/main.c | 2 +- linux-user/main.c | 2 +- monitor/hmp-cmds-target.c | 4 +- system/cpus.c | 16 +- system/memory.c | 2 +- target/arm/hvf/hvf.c | 4 +- target/i386/hvf/hvf.c | 4 +- target/i386/hvf/x86hvf.c | 2 +- target/i386/nvmm/nvmm-accel-ops.c | 1 + target/i386/nvmm/nvmm-all.c | 31 ++- target/i386/whpx/whpx-accel-ops.c | 2 +- target/i386/whpx/whpx-all.c | 35 ++-- tests/qtest/qmp-cmd-test.c | 1 - accel/stubs/meson.build | 2 + hmp-commands-info.hx | 14 -- 47 files changed, 574 insertions(+), 543 deletions(-) create mode 100644 accel/dummy-cpus.h create mode 100644 accel/stubs/nvmm-stub.c create mode 100644 accel/stubs/whpx-stub.c
Signature · 1 line
2.49.0
[PULL v2 34/36] accel/system: Convert pre_resume() from AccelOpsClass to AccelClass
Accelerators call pre_resume() once. Since it isn't a method to call for each vCPU, move it from AccelOpsClass to AccelClass. Adapt WHPX.
Message-Id: <[email protected]>
--- include/qemu/accel.h | 3 +++ include/system/accel-ops.h | 1 - target/i386/whpx/whpx-accel-ops.h | 1 - accel/accel-system.c | 9 +++++++++ system/cpus.c | 4 +--- target/i386/whpx/whpx-accel-ops.c | 1 - target/i386/whpx/whpx-all.c | 3 ++- 7 files changed, 15 insertions(+), 7 deletions(-)
include/qemu/accel.h +3 -0
@@ -51,6 +51,7 @@ typedef struct AccelClass {/* gdbstub related hooks */ int (*gdbstub_supported_sstep_flags)(AccelState *as); +void (*pre_resume_vm)(AccelState *as,bool step_pending);bool *allowed;/*
@@ -86,6 +87,8 @@ int accel_init_machine(AccelState *accel, MachineState *ms);/* Called just before os_setup_post (ie just before drop OS privs) */ void accel_setup_post (MachineState *ms); +void accel_pre_resume (MachineState *ms,bool step_pending); +/** * accel_cpu_instance_init: * @cpu: The CPU that needs to do accel-specific object initializations.
include/system/accel-ops.h +0 -1
@@ -61,7 +61,6 @@ struct AccelOpsClass {*/ void (*synchronize_state)(CPUState *cpu);void (*synchronize_pre_loadvm)(CPUState *cpu); -void (*synchronize_pre_resume)(bool step_pending);/* handle_interrupt is mandatory. */ void (*handle_interrupt)(CPUState *cpu,int mask);
target/i386/whpx/whpx-accel-ops.h +0 -1
@@ -21,7 +21,6 @@ void whpx_cpu_synchronize_state(CPUState *cpu);void whpx_cpu_synchronize_post_reset (CPUState *cpu);void whpx_cpu_synchronize_post_init (CPUState *cpu);void whpx_cpu_synchronize_pre_loadvm (CPUState *cpu); -void whpx_cpu_synchronize_pre_resume (bool step_pending);/* state subset only touched by the VCPU itself during runtime */ #define WHPX_SET_RUNTIME_STATE 1
accel/accel-system.c +9 -0
@@ -62,6 +62,15 @@ void accel_setup_post(MachineState *ms) } } +void accel_pre_resume (MachineState *ms,bool step_pending) +{ +AccelState *accel = ms->accelerator; +AccelClass *acc =ACCEL_GET_CLASS (accel); +if (acc->pre_resume_vm) { + acc->pre_resume_vm (accel, step_pending); + } +} +/* initialize the arch-independent accel operation interfaces */ void accel_init_ops_interfaces (AccelClass *ac) {
system/cpus.c +1 -3
@@ -768,9 +768,7 @@ int vm_prepare_start(bool step_pending)* WHPX accelerator needs to know whether we are going to step * any CPUs, before starting the first one. */ -if (cpus_accel->synchronize_pre_resume) { - cpus_accel->synchronize_pre_resume (step_pending); - } +accel_pre_resume (MACHINE (qdev_get_machine ()), step_pending);/* We are sending this now, but the CPUs will be resumed shortly later */ qapi_event_send_resume ();
target/i386/whpx/whpx-accel-ops.c +0 -1
@@ -96,7 +96,6 @@ static void whpx_accel_ops_class_init(ObjectClass *oc, const void *data) ops->synchronize_post_init = whpx_cpu_synchronize_post_init; ops->synchronize_state = whpx_cpu_synchronize_state; ops->synchronize_pre_loadvm = whpx_cpu_synchronize_pre_loadvm; - ops->synchronize_pre_resume = whpx_cpu_synchronize_pre_resume; }static const TypeInfo whpx_accel_ops_type = {
target/i386/whpx/whpx-all.c +2 -1
@@ -2105,7 +2105,7 @@ void whpx_cpu_synchronize_pre_loadvm(CPUState *cpu)run_on_cpu (cpu, do_whpx_cpu_synchronize_pre_loadvm,RUN_ON_CPU_NULL ); } -void whpx_cpu_synchronize_pre_resume (bool step_pending) +static void whpx_pre_resume_vm (AccelState *as,bool step_pending) { whpx_global.step_pending = step_pending; }
@@ -2697,6 +2697,7 @@ static void whpx_accel_class_init(ObjectClass *oc, const void *data)AccelClass *ac =ACCEL_CLASS (oc); ac->name ="WHPX" ; ac->init_machine = whpx_accel_init; + ac->pre_resume_vm = whpx_pre_resume_vm; ac->allowed = &whpx_allowed; object_class_property_add(oc, "kernel-irqchip", "on|off|split",
Signature · 1 line
2.49.0
[PULL v2 08/36] accel/tcg: Clear exit_request once in tcg_cpu_exec()
In reply to Philippe Mathieu-DaudéMessage-Id: <[email protected]>
--- accel/tcg/tcg-accel-ops-mttcg.c | 1 - accel/tcg/tcg-accel-ops.c | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-)
accel/tcg/tcg-accel-ops-mttcg.c +0 -1
@@ -113,7 +113,6 @@ static void *mttcg_cpu_thread_fn(void *arg) } } -qatomic_set_mb (&cpu->exit_request,0 );qemu_wait_io_event (cpu); }while (!cpu->unplug ||cpu_can_run (cpu));
accel/tcg/tcg-accel-ops.c +3 -0
@@ -80,6 +80,9 @@ int tcg_cpu_exec(CPUState *cpu)cpu_exec_start (cpu); ret =cpu_exec (cpu);cpu_exec_end (cpu); + +qatomic_set_mb (&cpu->exit_request,0 ); +return ret; }
Signature · 1 line
2.49.0
[PULL v2 09/36] accel/tcg: Unregister the RCU before exiting RR thread
In reply to Philippe Mathieu-DaudéAlthough unreachable, still unregister the RCU before exiting the thread, as documented in "qemu/rcu.h":
/*
* Important !
*
* Each thread containing read-side critical sections must be registered
* with rcu_register_thread() before calling rcu_read_lock().
* rcu_unregister_thread() should be called before the thread exits. */
Unregister the RCU to be on par with what is done for other accelerators.
Message-Id: <[email protected]>
--- accel/tcg/tcg-accel-ops-rr.c | 2 ++ 1 file changed, 2 insertions(+)
accel/tcg/tcg-accel-ops-rr.c +2 -0
@@ -302,6 +302,8 @@ static void *rr_cpu_thread_fn(void *arg)rr_deal_with_unplugged_cpus (); } +rcu_unregister_thread (); +g_assert_not_reached (); }
Signature · 1 line
2.49.0
Re: [PULL v2 09/36] accel/tcg: Unregister the RCU before exiting RR thread
Quoted 29 lines · Philippe Mathieu-Daudé
Although unreachable, still unregister the RCU before exiting the thread, as documented in "
qemu/rcu.h":/*
* Important !
*
* Each thread containing read-side critical sections must be registered
* withrcu_register_thread()before callingrcu_read_lock().
*rcu_unregister_thread()should be called before the thread exits. */Unregister the RCU to be on par with what is done for other accelerators.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Pierrick Bouvier <[email protected]>Reviewed-by Zhao Liu <[email protected]>Message-Id: <[email protected]>
--- accel/tcg/tcg-accel-ops-rr.c | 2 ++ 1 file changed, 2 insertions(+)accel/tcg/tcg-accel-ops-rr.c +0
-0
accel/tcg/tcg-accel-ops-rr.c static void *rr_cpu_thread_fn(void *arg) · line 308
Quoted 7 lines
accel/tcg/tcg-accel-ops-rr.c +2
-0@@ -302,6 +302,8 @@ static void *rr_cpu_thread_fn(void *arg)rr_deal_with_unplugged_cpus (); } +rcu_unregister_thread (); +g_assert_not_reached (); }
This has reintroduced CID 1547782 (unreachable code).
We can't get to this point, so why are we trying to call a function here ? This is not a place where the thread can exit.
thanks
-- PMM
Re: [PULL v2 09/36] accel/tcg: Unregister the RCU before exiting RR thread
Quoted 40 lines · Peter Maydell
Quoted 29 lines · Philippe Mathieu-Daudé
Although unreachable, still unregister the RCU before exiting the thread, as documented in "
qemu/rcu.h":/*
* Important !
*
* Each thread containing read-side critical sections must be registered
* withrcu_register_thread()before callingrcu_read_lock().
*rcu_unregister_thread()should be called before the thread exits. */Unregister the RCU to be on par with what is done for other accelerators.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Pierrick Bouvier <[email protected]>Reviewed-by Zhao Liu <[email protected]>Message-Id: <[email protected]>
--- accel/tcg/tcg-accel-ops-rr.c | 2 ++ 1 file changed, 2 insertions(+)accel/tcg/tcg-accel-ops-rr.c +0
-0accel/tcg/tcg-accel-ops-rr.c static void *rr_cpu_thread_fn(void *arg) · line 308
Quoted 7 lines
accel/tcg/tcg-accel-ops-rr.c +2
-0@@ -302,6 +302,8 @@ static void *rr_cpu_thread_fn(void *arg)rr_deal_with_unplugged_cpus (); } +rcu_unregister_thread (); +g_assert_not_reached (); }This has reintroduced CID 1547782 (unreachable code).
Quoted 2 lines
We can't get to this point, so why are we trying to call a function here ? This is not a place where the thread can exit.
The goal is to unify accelerators vcpu thread logic and eventually remove AccelOpsClass::create_vcpu_thread(), superseded by AccelOpsClass::cpu_thread_routine(). I couldn't finish RR for 10.1 but squeezed this patch in. Let's revert it, and I'll re-commit it later.
Re: [PULL v2 09/36] accel/tcg: Unregister the RCU before exiting RR thread
Quoted 4 lines · Philippe Mathieu-Daudé
Quoted 2 lines · Peter Maydell
This has reintroduced CID 1547782 (unreachable code).
Quoted 8 lines
Quoted 2 lines
We can't get to this point, so why are we trying to call a function here ? This is not a place where the thread can exit.
The goal is to unify accelerators vcpu thread logic and eventually remove
AccelOpsClass::create_vcpu_thread(), superseded byAccelOpsClass::cpu_thread_routine(). I couldn't finish RR for 10.1 but squeezed this patch in. Let's revert it, and I'll re-commit it later.
When you do have a need for it, note that rcu_unregister_thread() is probably not the only call you need here -- see commit da7510b720591. We used to also have an equally unreachable rcu_remove_force_rcu_notifier() call.
thanks
-- PMM
[PULL v2 13/36] accel/hvf: Report missing com.apple.security.hypervisor entitlement
In reply to Philippe Mathieu-DaudéWe need the QEMU binary signed to be able to use HVF. Improve the following:
$ ./qemu-system-aarch64-unsigned -M virt -accel hvf qemu-system-aarch64-unsigned: -accel hvf: Error: ret = HV_DENIED (0xfae94007, at ../../accel/hvf/hvf-accel-ops.c:339) Abort trap: 6
to:
$ ./qemu-system-aarch64-unsigned -M virt -accel hvf qemu-system-aarch64-unsigned: -accel hvf: Could not access HVF. Is the executable signed with com.apple.security.hypervisor entitlement?
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2800
Message-Id: <[email protected]>
--- accel/hvf/hvf-all.c | 5 +++++ 1 file changed, 5 insertions(+)
accel/hvf/hvf-all.c +5 -0
@@ -263,6 +263,11 @@ static int hvf_accel_init(MachineState *ms) } ret =hvf_arch_vm_create (ms, (uint32_t )pa_range); +if (ret ==HV_DENIED ) { +error_report ("Could not access HVF. Is the executable signed" +" with com.apple.security.hypervisor entitlement?" ); +exit (1 ); + }assert_hvf_ok (ret); s =g_new0 (HVFState,1 );
Signature · 1 line
2.49.0
[PULL v2 26/36] accel: Propagate AccelState to AccelClass::init_machine()
In reply to Philippe Mathieu-DaudéIn order to avoid init_machine() to call current_accel(), pass AccelState along.
Message-Id: <[email protected]>
--- include/qemu/accel.h | 2 +- accel/accel-system.c | 2 +- accel/hvf/hvf-all.c | 2 +- accel/kvm/kvm-all.c | 2 +- accel/qtest/qtest.c | 2 +- accel/tcg/tcg-all.c | 2 +- accel/xen/xen-all.c | 2 +- bsd-user/main.c | 2 +- linux-user/main.c | 2 +- target/i386/nvmm/nvmm-all.c | 2 +- target/i386/whpx/whpx-all.c | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-)
include/qemu/accel.h +1 -1
@@ -40,7 +40,7 @@ typedef struct AccelClass {/* Cached by accel_init_ops_interfaces() when created */ AccelOpsClass *ops; -int (*init_machine)(MachineState *ms); +int (*init_machine)(AccelState *as,MachineState *ms);bool (*cpu_common_realize)(CPUState *cpu,Error **errp);void (*cpu_common_unrealize)(CPUState *cpu);
accel/accel-system.c +1 -1
@@ -37,7 +37,7 @@ int accel_init_machine(AccelState *accel, MachineState *ms)int ret; ms->accelerator = accel; *(acc->allowed) = true; - ret = acc->init_machine (ms); + ret = acc->init_machine (accel, ms);if (ret <0 ) { ms->accelerator =NULL ; *(acc->allowed) = false;
accel/hvf/hvf-all.c +1 -1
@@ -247,7 +247,7 @@ static MemoryListener hvf_memory_listener = { .log_sync = hvf_log_sync, }; -static int hvf_accel_init (MachineState *ms) +static int hvf_accel_init (AccelState *as,MachineState *ms) {int x;hv_return_t ret;
accel/kvm/kvm-all.c +1 -1
@@ -2573,7 +2573,7 @@ static int kvm_setup_dirty_ring(KVMState *s)return 0 ; } -static int kvm_init (MachineState *ms) +static int kvm_init (AccelState *as,MachineState *ms) {MachineClass *mc =MACHINE_GET_CLASS (ms); static const char upgrade_note[] =
accel/qtest/qtest.c +1 -1
@@ -38,7 +38,7 @@ static void qtest_set_virtual_clock(int64_t count)qatomic_set_i64 (&qtest_clock_counter, count); } -static int qtest_init_accel (MachineState *ms) +static int qtest_init_accel (AccelState *as,MachineState *ms) {return 0 ; }
accel/tcg/tcg-all.c +1 -1
@@ -80,7 +80,7 @@ static void tcg_accel_instance_init(Object *obj)bool one_insn_per_tb; -static int tcg_init_machine (MachineState *ms) +static int tcg_init_machine (AccelState *as,MachineState *ms) {TCGState *s =TCG_STATE (current_accel ());unsigned max_threads =1 ;
accel/xen/xen-all.c +1 -1
@@ -77,7 +77,7 @@ static void xen_setup_post(MachineState *ms, AccelState *accel) } } -static int xen_init (MachineState *ms) +static int xen_init (AccelState *as,MachineState *ms) {MachineClass *mc =MACHINE_GET_CLASS (ms);
bsd-user/main.c +1 -1
@@ -474,7 +474,7 @@ int main(int argc, char **argv) opt_one_insn_per_tb, &error_abort);object_property_set_int (OBJECT (accel),"tb-size" , opt_tb_size, &error_abort); - ac->init_machine (NULL ); + ac->init_machine (accel,NULL ); }/*
linux-user/main.c +1 -1
@@ -820,7 +820,7 @@ int main(int argc, char **argv, char **envp) opt_one_insn_per_tb, &error_abort);object_property_set_int (OBJECT (accel),"tb-size" , opt_tb_size, &error_abort); - ac->init_machine (NULL ); + ac->init_machine (accel,NULL ); }/*
target/i386/nvmm/nvmm-all.c +1 -1
@@ -1152,7 +1152,7 @@ static struct RAMBlockNotifier nvmm_ram_notifier = {/* -------------------------------------------------------------------------- */ static int -nvmm_accel_init (MachineState *ms) +nvmm_accel_init (AccelState *as,MachineState *ms) {int ret, err;
target/i386/whpx/whpx-all.c +1 -1
@@ -2504,7 +2504,7 @@ static void whpx_set_kernel_irqchip(Object *obj, Visitor *v,* Partition support */ -static int whpx_accel_init (MachineState *ms) +static int whpx_accel_init (AccelState *as,MachineState *ms) {struct whpx_state *whpx;int ret;
Signature · 1 line
2.49.0
[PULL v2 27/36] accel/hvf: Re-use QOM allocated state
In reply to Philippe Mathieu-DaudéMessage-Id: <[email protected]>
--- accel/hvf/hvf-all.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
accel/hvf/hvf-all.c +1 -3
@@ -251,7 +251,7 @@ static int hvf_accel_init(AccelState *as, MachineState *ms) {int x;hv_return_t ret; -HVFState *s; +HVFState *s =HVF_STATE (as);int pa_range =36 ;MachineClass *mc =MACHINE_GET_CLASS (ms);
@@ -270,8 +270,6 @@ static int hvf_accel_init(AccelState *as, MachineState *ms) }assert_hvf_ok (ret); - s =g_new0 (HVFState,1 ); - s->num_slots =ARRAY_SIZE (s->slots);for (x =0 ; x < s->num_slots; ++x) { s->slots[x].size =0 ;
Signature · 1 line
2.49.0
Stefan Hajnoczi
AppliedApplied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/10.1 for any user-visible changes.