accel: Expose and register generic_handle_interrupt()

In order to dispatch over AccelOpsClass::handle_interrupt(),
we need it always defined, not calling a hidden handler under
the hood. Make AccelOpsClass::handle_interrupt() mandatory.
Expose generic_handle_interrupt() prototype and register it
for each accelerator.

Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Message-Id: <20250703173248.44995-29-philmd@linaro.org>
This commit is contained in:
Philippe Mathieu-Daudé 2025-06-12 14:45:19 +02:00
parent e8388158e6
commit b9b8ce0384
8 changed files with 13 additions and 6 deletions

View file

@ -353,6 +353,7 @@ static void hvf_accel_ops_class_init(ObjectClass *oc, const void *data)
ops->create_vcpu_thread = hvf_start_vcpu_thread; ops->create_vcpu_thread = hvf_start_vcpu_thread;
ops->kick_vcpu_thread = hvf_kick_vcpu_thread; ops->kick_vcpu_thread = hvf_kick_vcpu_thread;
ops->handle_interrupt = generic_handle_interrupt;
ops->synchronize_post_reset = hvf_cpu_synchronize_post_reset; ops->synchronize_post_reset = hvf_cpu_synchronize_post_reset;
ops->synchronize_post_init = hvf_cpu_synchronize_post_init; ops->synchronize_post_init = hvf_cpu_synchronize_post_init;

View file

@ -101,6 +101,7 @@ static void kvm_accel_ops_class_init(ObjectClass *oc, const void *data)
ops->synchronize_post_init = kvm_cpu_synchronize_post_init; ops->synchronize_post_init = kvm_cpu_synchronize_post_init;
ops->synchronize_state = kvm_cpu_synchronize_state; ops->synchronize_state = kvm_cpu_synchronize_state;
ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm; ops->synchronize_pre_loadvm = kvm_cpu_synchronize_pre_loadvm;
ops->handle_interrupt = generic_handle_interrupt;
#ifdef TARGET_KVM_HAVE_GUEST_DEBUG #ifdef TARGET_KVM_HAVE_GUEST_DEBUG
ops->update_guest_debug = kvm_update_guest_debug_ops; ops->update_guest_debug = kvm_update_guest_debug_ops;

View file

@ -67,6 +67,7 @@ static void qtest_accel_ops_class_init(ObjectClass *oc, const void *data)
ops->create_vcpu_thread = dummy_start_vcpu_thread; ops->create_vcpu_thread = dummy_start_vcpu_thread;
ops->get_virtual_clock = qtest_get_virtual_clock; ops->get_virtual_clock = qtest_get_virtual_clock;
ops->set_virtual_clock = qtest_set_virtual_clock; ops->set_virtual_clock = qtest_set_virtual_clock;
ops->handle_interrupt = generic_handle_interrupt;
}; };
static const TypeInfo qtest_accel_ops_type = { static const TypeInfo qtest_accel_ops_type = {

View file

@ -153,6 +153,7 @@ static void xen_accel_ops_class_init(ObjectClass *oc, const void *data)
AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
ops->create_vcpu_thread = dummy_start_vcpu_thread; ops->create_vcpu_thread = dummy_start_vcpu_thread;
ops->handle_interrupt = generic_handle_interrupt;
} }
static const TypeInfo xen_accel_ops_type = { static const TypeInfo xen_accel_ops_type = {

View file

@ -62,6 +62,7 @@ struct AccelOpsClass {
void (*synchronize_pre_loadvm)(CPUState *cpu); void (*synchronize_pre_loadvm)(CPUState *cpu);
void (*synchronize_pre_resume)(bool step_pending); void (*synchronize_pre_resume)(bool step_pending);
/* handle_interrupt is mandatory. */
void (*handle_interrupt)(CPUState *cpu, int mask); void (*handle_interrupt)(CPUState *cpu, int mask);
/** /**
@ -86,4 +87,6 @@ struct AccelOpsClass {
void (*remove_all_breakpoints)(CPUState *cpu); void (*remove_all_breakpoints)(CPUState *cpu);
}; };
void generic_handle_interrupt(CPUState *cpu, int mask);
#endif /* ACCEL_OPS_H */ #endif /* ACCEL_OPS_H */

View file

@ -254,7 +254,7 @@ int64_t cpus_get_elapsed_ticks(void)
return cpu_get_ticks(); return cpu_get_ticks();
} }
static void generic_handle_interrupt(CPUState *cpu, int mask) void generic_handle_interrupt(CPUState *cpu, int mask)
{ {
cpu->interrupt_request |= mask; cpu->interrupt_request |= mask;
@ -267,11 +267,7 @@ void cpu_interrupt(CPUState *cpu, int mask)
{ {
g_assert(bql_locked()); g_assert(bql_locked());
if (cpus_accel->handle_interrupt) { cpus_accel->handle_interrupt(cpu, mask);
cpus_accel->handle_interrupt(cpu, mask);
} else {
generic_handle_interrupt(cpu, mask);
}
} }
/* /*
@ -680,6 +676,8 @@ void cpus_register_accel(const AccelOpsClass *ops)
{ {
assert(ops != NULL); assert(ops != NULL);
assert(ops->create_vcpu_thread != NULL); /* mandatory */ assert(ops->create_vcpu_thread != NULL); /* mandatory */
assert(ops->handle_interrupt);
cpus_accel = ops; cpus_accel = ops;
} }

View file

@ -87,6 +87,7 @@ static void nvmm_accel_ops_class_init(ObjectClass *oc, const void *data)
ops->create_vcpu_thread = nvmm_start_vcpu_thread; ops->create_vcpu_thread = nvmm_start_vcpu_thread;
ops->kick_vcpu_thread = nvmm_kick_vcpu_thread; ops->kick_vcpu_thread = nvmm_kick_vcpu_thread;
ops->handle_interrupt = generic_handle_interrupt;
ops->synchronize_post_reset = nvmm_cpu_synchronize_post_reset; ops->synchronize_post_reset = nvmm_cpu_synchronize_post_reset;
ops->synchronize_post_init = nvmm_cpu_synchronize_post_init; ops->synchronize_post_init = nvmm_cpu_synchronize_post_init;

View file

@ -90,6 +90,7 @@ static void whpx_accel_ops_class_init(ObjectClass *oc, const void *data)
ops->create_vcpu_thread = whpx_start_vcpu_thread; ops->create_vcpu_thread = whpx_start_vcpu_thread;
ops->kick_vcpu_thread = whpx_kick_vcpu_thread; ops->kick_vcpu_thread = whpx_kick_vcpu_thread;
ops->cpu_thread_is_idle = whpx_vcpu_thread_is_idle; ops->cpu_thread_is_idle = whpx_vcpu_thread_is_idle;
ops->handle_interrupt = generic_handle_interrupt;
ops->synchronize_post_reset = whpx_cpu_synchronize_post_reset; ops->synchronize_post_reset = whpx_cpu_synchronize_post_reset;
ops->synchronize_post_init = whpx_cpu_synchronize_post_init; ops->synchronize_post_init = whpx_cpu_synchronize_post_init;