* [PATCH 1/8] hw/cpu: Correct CPU_GET_CLASS() comment
2026-08-11 18:34 [PATCH 0/8] hw/cpu: Slightly sanitize CPU API Philippe Mathieu-Daudé
@ 2026-08-11 18:34 ` Philippe Mathieu-Daudé
2026-08-11 18:34 ` [PATCH 2/8] hw/cpu: Include missing 'qemu/accel.h' header Philippe Mathieu-Daudé
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-11 18:34 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
qemu-s390x, kvm, qemu-riscv
commit 0e86d7a71e8 ("cpus: Cache CPUClass early in instance_init()
handler") renamed cpu_exec_realizefn() -> cpu_common_initfn();
update the comment.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
include/hw/core/cpu.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index b54035fb13b..c5064a5449b 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -60,7 +60,7 @@ typedef int (*WriteCoreDumpFunction)(const void *buf, size_t size,
* expensive given the eventual call to
* object_class_dynamic_cast_assert(). Because of this the CPUState
* has a cached value for the class in cs->cc which is set up in
- * cpu_exec_realizefn() for use in hot code paths.
+ * cpu_common_initfn() for use in hot code paths.
*/
typedef struct CPUClass CPUClass;
DECLARE_CLASS_CHECKERS(CPUClass, CPU,
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 2/8] hw/cpu: Include missing 'qemu/accel.h' header
2026-08-11 18:34 [PATCH 0/8] hw/cpu: Slightly sanitize CPU API Philippe Mathieu-Daudé
2026-08-11 18:34 ` [PATCH 1/8] hw/cpu: Correct CPU_GET_CLASS() comment Philippe Mathieu-Daudé
@ 2026-08-11 18:34 ` Philippe Mathieu-Daudé
2026-08-11 18:34 ` [PATCH 3/8] hw/cpu: Move internal declarations to new 'cpu-internal.h' header Philippe Mathieu-Daudé
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-11 18:34 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
qemu-s390x, kvm, qemu-riscv
From: Philippe Mathieu-Daudé <philmd@linaro.org>
cpu_common_realize() calls accel_cpu_common_realize(),
itself declared in "qemu/accel.h". Include the latter,
otherwise we get when refactoring unrelated headers:
hw/core/cpu-common.c:233:10: error: implicit declaration of function ‘accel_cpu_common_realize’
233 | if (!accel_cpu_common_realize(cpu, errp)) {
| ^~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
hw/core/cpu-common.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index e314f916f84..8c9ff25e04a 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -23,6 +23,7 @@
#include "qapi/error.h"
#include "hw/core/cpu.h"
#include "system/hw_accel.h"
+#include "qemu/accel.h"
#include "qemu/log.h"
#include "qemu/main-loop.h"
#include "qemu/lockcnt.h"
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 3/8] hw/cpu: Move internal declarations to new 'cpu-internal.h' header
2026-08-11 18:34 [PATCH 0/8] hw/cpu: Slightly sanitize CPU API Philippe Mathieu-Daudé
2026-08-11 18:34 ` [PATCH 1/8] hw/cpu: Correct CPU_GET_CLASS() comment Philippe Mathieu-Daudé
2026-08-11 18:34 ` [PATCH 2/8] hw/cpu: Include missing 'qemu/accel.h' header Philippe Mathieu-Daudé
@ 2026-08-11 18:34 ` Philippe Mathieu-Daudé
2026-08-11 18:34 ` [PATCH 4/8] hw/cpu: Rename cpu_common_realizefn() -> cpu_exec_realize() Philippe Mathieu-Daudé
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-11 18:34 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
qemu-s390x, kvm, qemu-riscv
Some declarations are only used within hw/core/, in particular
by the 3 cpu-{common,user,system}.c. Restrict the declarations
scope by moving them to a new "cpu-internal.h" local header.
Rename cpu_exec_initfn() -> cpu_exec_init() because we usually
have the 'fn' suffix for handler, not API entry point methods.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
hw/core/cpu-internal.h | 22 ++++++++++++++++++++++
include/hw/core/cpu.h | 6 ------
hw/core/cpu-common.c | 3 ++-
hw/core/cpu-system.c | 3 ++-
hw/core/cpu-user.c | 3 ++-
5 files changed, 28 insertions(+), 9 deletions(-)
create mode 100644 hw/core/cpu-internal.h
diff --git a/hw/core/cpu-internal.h b/hw/core/cpu-internal.h
new file mode 100644
index 00000000000..ae6a31bca2d
--- /dev/null
+++ b/hw/core/cpu-internal.h
@@ -0,0 +1,22 @@
+/*
+ * QEMU private CPU interface between user / system modes)
+ *
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef HW_CORE_CPU_INTERNAL_H
+#define HW_CORE_CPU_INTERNAL_H
+
+#include "hw/core/qdev.h"
+#include "hw/core/cpu.h"
+
+void cpu_class_init_props(DeviceClass *dc);
+void cpu_exec_class_post_init(CPUClass *cc);
+
+void cpu_exec_init(CPUState *cpu);
+
+void cpu_vmstate_register(CPUState *cpu);
+void cpu_vmstate_unregister(CPUState *cpu);
+
+#endif
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index c5064a5449b..6490fb070f2 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -1178,12 +1178,6 @@ G_NORETURN void cpu_abort(CPUState *cpu, const char *fmt, ...)
*/
void qemu_process_cpu_events(CPUState *cpu);
-/* $(top_srcdir)/cpu.c */
-void cpu_class_init_props(DeviceClass *dc);
-void cpu_exec_class_post_init(CPUClass *cc);
-void cpu_exec_initfn(CPUState *cpu);
-void cpu_vmstate_register(CPUState *cpu);
-void cpu_vmstate_unregister(CPUState *cpu);
bool cpu_exec_realizefn(CPUState *cpu, Error **errp);
void cpu_exec_unrealizefn(CPUState *cpu);
void cpu_exec_reset_hold(CPUState *cpu);
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 8c9ff25e04a..17d76580930 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -39,6 +39,7 @@
#ifdef CONFIG_PLUGIN
#include "qemu/plugin.h"
#endif
+#include "cpu-internal.h"
CPUState *cpu_by_arch_id(int64_t id)
{
@@ -326,7 +327,7 @@ static void cpu_common_initfn(Object *obj)
QTAILQ_INIT(&cpu->breakpoints);
QTAILQ_INIT(&cpu->watchpoints);
- cpu_exec_initfn(cpu);
+ cpu_exec_init(cpu);
/*
* Plugin initialization must wait until the cpu start executing
diff --git a/hw/core/cpu-system.c b/hw/core/cpu-system.c
index 14eb4ed87f8..8a9f2fcea84 100644
--- a/hw/core/cpu-system.c
+++ b/hw/core/cpu-system.c
@@ -30,6 +30,7 @@
#include "hw/core/sysemu-cpu-ops.h"
#include "migration/vmstate.h"
#include "system/tcg.h"
+#include "cpu-internal.h"
bool cpu_has_work(CPUState *cpu)
{
@@ -188,7 +189,7 @@ void cpu_exec_class_post_init(CPUClass *cc)
g_assert(cc->sysemu_ops->has_work);
}
-void cpu_exec_initfn(CPUState *cpu)
+void cpu_exec_init(CPUState *cpu)
{
cpu->memory = get_system_memory();
object_ref(OBJECT(cpu->memory));
diff --git a/hw/core/cpu-user.c b/hw/core/cpu-user.c
index 25aa25ad240..c2cb00a85d3 100644
--- a/hw/core/cpu-user.c
+++ b/hw/core/cpu-user.c
@@ -11,6 +11,7 @@
#include "hw/core/qdev-properties.h"
#include "hw/core/cpu.h"
#include "migration/vmstate.h"
+#include "cpu-internal.h"
static const Property cpu_user_props[] = {
/*
@@ -32,7 +33,7 @@ void cpu_exec_class_post_init(CPUClass *cc)
/* nothing to do */
}
-void cpu_exec_initfn(CPUState *cpu)
+void cpu_exec_init(CPUState *cpu)
{
/* nothing to do */
}
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 4/8] hw/cpu: Rename cpu_common_realizefn() -> cpu_exec_realize()
2026-08-11 18:34 [PATCH 0/8] hw/cpu: Slightly sanitize CPU API Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2026-08-11 18:34 ` [PATCH 3/8] hw/cpu: Move internal declarations to new 'cpu-internal.h' header Philippe Mathieu-Daudé
@ 2026-08-11 18:34 ` Philippe Mathieu-Daudé
2026-08-11 18:34 ` [PATCH 5/8] hw/cpu: Rename cpu_exec_realizefn() -> cpu_common_realize() Philippe Mathieu-Daudé
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-11 18:34 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
qemu-s390x, kvm, qemu-riscv
Keep cpu_common_*() pattern for publicly exposed common methods
used by target code. Use cpu_exec_*() pattern for internal ones,
mostly to distinct between system / user mode.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
hw/core/cpu-common.c | 4 ++--
target/i386/kvm/kvm-cpu.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 17d76580930..33e349d4402 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -246,7 +246,7 @@ bool cpu_exec_realizefn(CPUState *cpu, Error **errp)
return true;
}
-static void cpu_common_realizefn(DeviceState *dev, Error **errp)
+static void cpu_exec_realize(DeviceState *dev, Error **errp)
{
CPUState *cpu = CPU(dev);
Object *machine = qdev_get_machine();
@@ -379,7 +379,7 @@ static void cpu_common_class_init(ObjectClass *klass, const void *data)
k->gdb_read_register = cpu_common_gdb_read_register;
k->gdb_write_register = cpu_common_gdb_write_register;
set_bit(DEVICE_CATEGORY_CPU, dc->categories);
- dc->realize = cpu_common_realizefn;
+ dc->realize = cpu_exec_realize;
dc->unrealize = cpu_common_unrealizefn;
rc->phases.hold = cpu_common_reset_hold;
rc->phases.exit = cpu_common_reset_exit;
diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c
index c34d9f15c7e..e164cef2036 100644
--- a/target/i386/kvm/kvm-cpu.c
+++ b/target/i386/kvm/kvm-cpu.c
@@ -63,7 +63,7 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp)
* host_cpu_realizefn()
* kvm_set_guest_phys_bits()
* check/update ucode_rev, phys_bits, guest_phys_bits, mwait
- * cpu_common_realizefn() (via xcc->parent_realize)
+ * cpu_exec_realize() (via xcc->parent_realize)
*/
if (xcc->max_features) {
if (enable_cpu_pm) {
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 5/8] hw/cpu: Rename cpu_exec_realizefn() -> cpu_common_realize()
2026-08-11 18:34 [PATCH 0/8] hw/cpu: Slightly sanitize CPU API Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2026-08-11 18:34 ` [PATCH 4/8] hw/cpu: Rename cpu_common_realizefn() -> cpu_exec_realize() Philippe Mathieu-Daudé
@ 2026-08-11 18:34 ` Philippe Mathieu-Daudé
2026-08-11 18:34 ` [PATCH 6/8] hw/cpu: Rename cpu_exec_unrealizefn() -> cpu_common_unrealize() Philippe Mathieu-Daudé
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-11 18:34 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
qemu-s390x, kvm, qemu-riscv
From: Philippe Mathieu-Daudé <philmd@linaro.org>
Keep cpu_common_*() pattern for publicly exposed common methods
used by target code. Use cpu_exec_*() pattern for internal ones,
mostly to distinct between system / user mode.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
include/hw/core/cpu.h | 3 ++-
hw/core/cpu-common.c | 2 +-
target/alpha/cpu.c | 2 +-
target/arm/cpu.c | 2 +-
target/avr/cpu.c | 2 +-
target/hexagon/cpu.c | 2 +-
target/hppa/cpu.c | 2 +-
target/i386/cpu.c | 10 +++++-----
target/i386/kvm/kvm-cpu.c | 2 +-
target/loongarch/cpu.c | 2 +-
target/m68k/cpu.c | 2 +-
target/microblaze/cpu.c | 2 +-
target/mips/cpu.c | 2 +-
target/or1k/cpu.c | 2 +-
target/ppc/cpu_init.c | 2 +-
target/riscv/cpu.c | 2 +-
target/riscv/kvm/kvm-cpu.c | 2 +-
target/riscv/tcg/tcg-cpu.c | 2 +-
target/rx/cpu.c | 2 +-
target/s390x/cpu.c | 2 +-
target/sh4/cpu.c | 2 +-
target/sparc/cpu.c | 2 +-
target/tricore/cpu.c | 2 +-
target/xtensa/cpu.c | 2 +-
24 files changed, 29 insertions(+), 28 deletions(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 6490fb070f2..7b7cf330cde 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -1178,7 +1178,8 @@ G_NORETURN void cpu_abort(CPUState *cpu, const char *fmt, ...)
*/
void qemu_process_cpu_events(CPUState *cpu);
-bool cpu_exec_realizefn(CPUState *cpu, Error **errp);
+/** cpu_common_realize: CPU DeviceRealize common handler */
+bool cpu_common_realize(CPUState *cpu, Error **errp);
void cpu_exec_unrealizefn(CPUState *cpu);
void cpu_exec_reset_hold(CPUState *cpu);
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 33e349d4402..732e32fade2 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -230,7 +230,7 @@ const char *parse_cpu_option(const char *cpu_option)
return cpu_type;
}
-bool cpu_exec_realizefn(CPUState *cpu, Error **errp)
+bool cpu_common_realize(CPUState *cpu, Error **errp)
{
if (!accel_cpu_common_realize(cpu, errp)) {
return false;
diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c
index 0c35067b202..12e86021663 100644
--- a/target/alpha/cpu.c
+++ b/target/alpha/cpu.c
@@ -117,7 +117,7 @@ static void alpha_cpu_realizefn(DeviceState *dev, Error **errp)
cs->tcg_cflags |= CF_PCREL;
#endif
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 787e4dc7ab2..77aa78f00e2 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1891,7 +1891,7 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
}
#endif
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/avr/cpu.c b/target/avr/cpu.c
index 35912192126..f8409f32ab9 100644
--- a/target/avr/cpu.c
+++ b/target/avr/cpu.c
@@ -131,7 +131,7 @@ static void avr_cpu_realizefn(DeviceState *dev, Error **errp)
AVRCPUClass *mcc = AVR_CPU_GET_CLASS(dev);
Error *local_err = NULL;
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c
index 12d27ce1381..8e3b900e8d9 100644
--- a/target/hexagon/cpu.c
+++ b/target/hexagon/cpu.c
@@ -450,7 +450,7 @@ static void hexagon_cpu_realize(DeviceState *dev, Error **errp)
HexagonCPUClass *mcc = HEXAGON_CPU_GET_CLASS(dev);
Error *local_err = NULL;
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c
index a68152f9682..07b49e51326 100644
--- a/target/hppa/cpu.c
+++ b/target/hppa/cpu.c
@@ -181,7 +181,7 @@ static void hppa_cpu_realizefn(DeviceState *dev, Error **errp)
HPPACPUClass *acc = HPPA_CPU_GET_CLASS(dev);
Error *local_err = NULL;
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 5805d33ab92..9b2aa178062 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -10164,7 +10164,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
* These may be set by the accel-specific code,
* and the results are subsequently checked / assumed in this function.
*/
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
@@ -10179,7 +10179,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
if (cpu->guest_phys_bits == -1) {
/*
* If it was not set by the user, or by the accelerator via
- * cpu_exec_realizefn, clear.
+ * cpu_common_realize, clear.
*/
cpu->guest_phys_bits = 0;
}
@@ -10188,7 +10188,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
/*
* The default is the same as KVM's. Note that this check
* needs to happen after the evenual setting of ucode_rev in
- * accel-specific code in cpu_exec_realizefn.
+ * accel-specific code in cpu_common_realize.
*/
if (IS_AMD_CPU(env)) {
cpu->ucode_rev = 0x01000065;
@@ -10201,7 +10201,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
* mwait extended info: needed for Core compatibility
* We always wake on interrupt even if host does not have the capability.
*
- * requires the accel-specific code in cpu_exec_realizefn to
+ * requires the accel-specific code in cpu_common_realize to
* have already acquired the CPUID data into cpu->mwait.
*/
cpu->mwait.ecx |= CPUID_MWAIT_EMX | CPUID_MWAIT_IBE;
@@ -10230,7 +10230,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
* Note that this code assumes features expansion has already been done
* (as it checks for CPUID_EXT2_LM), and also assumes that potential
* phys_bits adjustments to match the host have been already done in
- * accel-specific code in cpu_exec_realizefn.
+ * accel-specific code in cpu_common_realize.
*/
if (env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM) {
if (cpu->phys_bits && cpu->phys_bits < 32) {
diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c
index e164cef2036..da8d77ade06 100644
--- a/target/i386/kvm/kvm-cpu.c
+++ b/target/i386/kvm/kvm-cpu.c
@@ -57,7 +57,7 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp)
*
* x86_cpu_realizefn():
* x86_cpu_expand_features()
- * cpu_exec_realizefn():
+ * cpu_common_realize():
* accel_cpu_common_realize()
* kvm_cpu_realizefn()
* host_cpu_realizefn()
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index fb03424ffa8..cb07f15110f 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -704,7 +704,7 @@ static void loongarch_cpu_realizefn(DeviceState *dev, Error **errp)
LoongArchCPUClass *lacc = LOONGARCH_CPU_GET_CLASS(dev);
Error *local_err = NULL;
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
index 9ad3057d91c..ce2707dee5a 100644
--- a/target/m68k/cpu.c
+++ b/target/m68k/cpu.c
@@ -389,7 +389,7 @@ static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)
register_m68k_insns(&cpu->env);
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c
index a97c92a7b68..389a5124b12 100644
--- a/target/microblaze/cpu.c
+++ b/target/microblaze/cpu.c
@@ -251,7 +251,7 @@ static void mb_cpu_realizefn(DeviceState *dev, Error **errp)
int i = 0;
Error *local_err = NULL;
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index d72044aef61..669c7d99bb7 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -544,7 +544,7 @@ static void mips_cpu_realizefn(DeviceState *dev, Error **errp)
}
mips_cp0_period_set(cpu);
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/or1k/cpu.c b/target/or1k/cpu.c
index ea29b2e01fa..66c00c0930c 100644
--- a/target/or1k/cpu.c
+++ b/target/or1k/cpu.c
@@ -170,7 +170,7 @@ static void openrisc_cpu_realizefn(DeviceState *dev, Error **errp)
OpenRISCCPUClass *occ = OPENRISC_CPU_GET_CLASS(dev);
Error *local_err = NULL;
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index f404c7e549d..b07e9c3ff9c 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -6921,7 +6921,7 @@ static void ppc_cpu_realize(DeviceState *dev, Error **errp)
PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
Error *local_err = NULL;
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 5a82e6563bf..23b5023dd37 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -1226,7 +1226,7 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev);
Error *local_err = NULL;
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
index 495cb42dc89..97069bf597a 100644
--- a/target/riscv/kvm/kvm-cpu.c
+++ b/target/riscv/kvm/kvm-cpu.c
@@ -2006,7 +2006,7 @@ static void kvm_cpu_instance_init(CPUState *cs)
* We'll get here via the following path:
*
* riscv_cpu_realize()
- * -> cpu_exec_realizefn()
+ * -> cpu_common_realize()
* -> kvm_cpu_realize() (via accel_cpu_common_realize())
*/
static bool kvm_cpu_realize(CPUState *cs, Error **errp)
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index 4af5cd9c731..9e3cc87f8a3 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -1304,7 +1304,7 @@ static void riscv_cpu_set_profile(RISCVCPU *cpu,
* We'll get here via the following path:
*
* riscv_cpu_realize()
- * -> cpu_exec_realizefn()
+ * -> cpu_common_realize()
* -> tcg_cpu_realize() (via accel_cpu_common_realize())
*/
static bool riscv_tcg_cpu_realize(CPUState *cs, Error **errp)
diff --git a/target/rx/cpu.c b/target/rx/cpu.c
index 20b188c24cd..9b8473d71cf 100644
--- a/target/rx/cpu.c
+++ b/target/rx/cpu.c
@@ -147,7 +147,7 @@ static void rx_cpu_realize(DeviceState *dev, Error **errp)
RXCPUClass *rcc = RX_CPU_GET_CLASS(dev);
Error *local_err = NULL;
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
index c074e12ba2d..641ea96c8ea 100644
--- a/target/s390x/cpu.c
+++ b/target/s390x/cpu.c
@@ -249,7 +249,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp)
}
#endif
- cpu_exec_realizefn(cs, &err);
+ cpu_common_realize(cs, &err);
if (err != NULL) {
goto out;
}
diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
index 763424695c6..ad2ec28c1b7 100644
--- a/target/sh4/cpu.c
+++ b/target/sh4/cpu.c
@@ -250,7 +250,7 @@ static void superh_cpu_realizefn(DeviceState *dev, Error **errp)
SuperHCPUClass *scc = SUPERH_CPU_GET_CLASS(dev);
Error *local_err = NULL;
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
index 13ebb122a38..1bc14b586bb 100644
--- a/target/sparc/cpu.c
+++ b/target/sparc/cpu.c
@@ -892,7 +892,7 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)
/* Default NaN value: sign bit clear, all frac bits set */
set_float_default_nan_pattern(0b01111111, &env->fp_status);
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c
index 472c24ae32d..96e2817dee7 100644
--- a/target/tricore/cpu.c
+++ b/target/tricore/cpu.c
@@ -99,7 +99,7 @@ static void tricore_cpu_realizefn(DeviceState *dev, Error **errp)
CPUTriCoreState *env = &cpu->env;
Error *local_err = NULL;
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c
index 2015a4e3d0d..7c25b9ab707 100644
--- a/target/xtensa/cpu.c
+++ b/target/xtensa/cpu.c
@@ -257,7 +257,7 @@ static void xtensa_cpu_realizefn(DeviceState *dev, Error **errp)
xtensa_irq_init(&XTENSA_CPU(dev)->env);
#endif
- cpu_exec_realizefn(cs, &local_err);
+ cpu_common_realize(cs, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 6/8] hw/cpu: Rename cpu_exec_unrealizefn() -> cpu_common_unrealize()
2026-08-11 18:34 [PATCH 0/8] hw/cpu: Slightly sanitize CPU API Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2026-08-11 18:34 ` [PATCH 5/8] hw/cpu: Rename cpu_exec_realizefn() -> cpu_common_realize() Philippe Mathieu-Daudé
@ 2026-08-11 18:34 ` Philippe Mathieu-Daudé
2026-08-11 18:34 ` [PATCH 7/8] hw/cpu: Extract cpu_exec_realize() out of cpu_common_realizefn() Philippe Mathieu-Daudé
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-11 18:34 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
qemu-s390x, kvm, qemu-riscv
Keep cpu_common_*() pattern for publicly exposed common methods
used by target code. Use cpu_exec_*() pattern for internal ones,
mostly to distinct between system / user mode.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
include/hw/core/cpu.h | 4 +++-
hw/core/cpu-common.c | 4 ++--
target/ppc/cpu_init.c | 2 +-
3 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 7b7cf330cde..81af7b9ee1a 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -1180,7 +1180,9 @@ void qemu_process_cpu_events(CPUState *cpu);
/** cpu_common_realize: CPU DeviceRealize common handler */
bool cpu_common_realize(CPUState *cpu, Error **errp);
-void cpu_exec_unrealizefn(CPUState *cpu);
+/** cpu_common_realize: CPU DeviceUnrealize common handler */
+void cpu_common_unrealize(CPUState *cpu);
+
void cpu_exec_reset_hold(CPUState *cpu);
extern const VMStateDescription vmstate_cpu_common;
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 732e32fade2..59cd489b713 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -284,10 +284,10 @@ static void cpu_common_unrealizefn(DeviceState *dev)
#endif
/* NOTE: latest generic point before the cpu is fully unrealized */
- cpu_exec_unrealizefn(cpu);
+ cpu_common_unrealize(cpu);
}
-void cpu_exec_unrealizefn(CPUState *cpu)
+void cpu_common_unrealize(CPUState *cpu)
{
cpu_vmstate_unregister(cpu);
diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index b07e9c3ff9c..e3a1075aad3 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -6956,7 +6956,7 @@ static void ppc_cpu_realize(DeviceState *dev, Error **errp)
return;
unrealize:
- cpu_exec_unrealizefn(cs);
+ cpu_common_unrealize(cs);
}
static void ppc_cpu_unrealize(DeviceState *dev)
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 7/8] hw/cpu: Extract cpu_exec_realize() out of cpu_common_realizefn()
2026-08-11 18:34 [PATCH 0/8] hw/cpu: Slightly sanitize CPU API Philippe Mathieu-Daudé
` (5 preceding siblings ...)
2026-08-11 18:34 ` [PATCH 6/8] hw/cpu: Rename cpu_exec_unrealizefn() -> cpu_common_unrealize() Philippe Mathieu-Daudé
@ 2026-08-11 18:34 ` Philippe Mathieu-Daudé
2026-08-11 18:34 ` [PATCH 8/8] hw/cpu: Move system-specific cpu_exec_realize() to cpu-system.c Philippe Mathieu-Daudé
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-11 18:34 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
qemu-s390x, kvm, qemu-riscv
cpu_common_realizefn() contains code only used by system mode
emulation. Extract it to a new cpu_exec_realize() helper. In
the next commit this helper will be moved to cpu-system.c where
it belongs.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
hw/core/cpu-common.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 59cd489b713..cd7c8763cf5 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -246,9 +246,8 @@ bool cpu_common_realize(CPUState *cpu, Error **errp)
return true;
}
-static void cpu_exec_realize(DeviceState *dev, Error **errp)
+static void cpu_exec_realize(CPUState *cpu, Error **errp)
{
- CPUState *cpu = CPU(dev);
Object *machine = qdev_get_machine();
/* qdev_get_machine() can return something that's not TYPE_MACHINE
@@ -264,10 +263,15 @@ static void cpu_exec_realize(DeviceState *dev, Error **errp)
}
}
- if (dev->hotplugged) {
+ if (DEVICE(cpu)->hotplugged) {
cpu_synchronize_post_init(cpu);
cpu_resume(cpu);
}
+}
+
+static void cpu_common_realizefn(DeviceState *dev, Error **errp)
+{
+ cpu_exec_realize(CPU(dev), errp);
/* NOTE: latest generic point where the cpu is fully realized */
}
@@ -379,7 +383,7 @@ static void cpu_common_class_init(ObjectClass *klass, const void *data)
k->gdb_read_register = cpu_common_gdb_read_register;
k->gdb_write_register = cpu_common_gdb_write_register;
set_bit(DEVICE_CATEGORY_CPU, dc->categories);
- dc->realize = cpu_exec_realize;
+ dc->realize = cpu_common_realizefn;
dc->unrealize = cpu_common_unrealizefn;
rc->phases.hold = cpu_common_reset_hold;
rc->phases.exit = cpu_common_reset_exit;
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH 8/8] hw/cpu: Move system-specific cpu_exec_realize() to cpu-system.c
2026-08-11 18:34 [PATCH 0/8] hw/cpu: Slightly sanitize CPU API Philippe Mathieu-Daudé
` (6 preceding siblings ...)
2026-08-11 18:34 ` [PATCH 7/8] hw/cpu: Extract cpu_exec_realize() out of cpu_common_realizefn() Philippe Mathieu-Daudé
@ 2026-08-11 18:34 ` Philippe Mathieu-Daudé
2026-08-11 23:33 ` [PATCH 0/8] hw/cpu: Slightly sanitize CPU API Richard Henderson
2026-08-15 13:52 ` Philippe Mathieu-Daudé
9 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-11 18:34 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
qemu-s390x, kvm, qemu-riscv
Current cpu_exec_realize() body only contains system-mode
related code. Move that method out of cpu-common.c to
cpu-system.c, removing the system / machine mentions in
this common file. Add an empty stub for user-mode.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
hw/core/cpu-internal.h | 1 +
hw/core/cpu-common.c | 24 ------------------------
hw/core/cpu-system.c | 26 ++++++++++++++++++++++++++
hw/core/cpu-user.c | 5 +++++
4 files changed, 32 insertions(+), 24 deletions(-)
diff --git a/hw/core/cpu-internal.h b/hw/core/cpu-internal.h
index ae6a31bca2d..44715b44329 100644
--- a/hw/core/cpu-internal.h
+++ b/hw/core/cpu-internal.h
@@ -15,6 +15,7 @@ void cpu_class_init_props(DeviceClass *dc);
void cpu_exec_class_post_init(CPUClass *cc);
void cpu_exec_init(CPUState *cpu);
+void cpu_exec_realize(CPUState *cpu, Error **errp);
void cpu_vmstate_register(CPUState *cpu);
void cpu_vmstate_unregister(CPUState *cpu);
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index cd7c8763cf5..4f4c87f33a0 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -33,7 +33,6 @@
#include "exec/log.h"
#include "exec/gdbstub.h"
#include "system/tcg.h"
-#include "hw/core/boards.h"
#include "hw/core/qdev-properties.h"
#include "trace.h"
#ifdef CONFIG_PLUGIN
@@ -246,29 +245,6 @@ bool cpu_common_realize(CPUState *cpu, Error **errp)
return true;
}
-static void cpu_exec_realize(CPUState *cpu, Error **errp)
-{
- Object *machine = qdev_get_machine();
-
- /* qdev_get_machine() can return something that's not TYPE_MACHINE
- * if this is one of the user-only emulators; in that case there's
- * no need to check the ignore_memory_transaction_failures board flag.
- */
- if (object_dynamic_cast(machine, TYPE_MACHINE)) {
- MachineClass *mc = MACHINE_GET_CLASS(machine);
-
- if (mc) {
- cpu->ignore_memory_transaction_failures =
- mc->ignore_memory_transaction_failures;
- }
- }
-
- if (DEVICE(cpu)->hotplugged) {
- cpu_synchronize_post_init(cpu);
- cpu_resume(cpu);
- }
-}
-
static void cpu_common_realizefn(DeviceState *dev, Error **errp)
{
cpu_exec_realize(CPU(dev), errp);
diff --git a/hw/core/cpu-system.c b/hw/core/cpu-system.c
index 8a9f2fcea84..feadfb5af00 100644
--- a/hw/core/cpu-system.c
+++ b/hw/core/cpu-system.c
@@ -25,10 +25,12 @@
#include "exec/target_page.h"
#include "system/memory.h"
#include "qemu/target-info.h"
+#include "hw/core/boards.h"
#include "hw/core/qdev.h"
#include "hw/core/qdev-properties.h"
#include "hw/core/sysemu-cpu-ops.h"
#include "migration/vmstate.h"
+#include "system/hw_accel.h"
#include "system/tcg.h"
#include "cpu-internal.h"
@@ -221,6 +223,30 @@ static int cpu_common_pre_load(void *opaque)
return 0;
}
+void cpu_exec_realize(CPUState *cpu, Error **errp)
+{
+ Object *machine = qdev_get_machine();
+
+ /* qdev_get_machine() can return something that's not TYPE_MACHINE
+ * if this is one of the user-only emulators; in that case there's
+ * no need to check the ignore_memory_transaction_failures board flag.
+ */
+ if (object_dynamic_cast(machine, TYPE_MACHINE)) {
+ MachineClass *mc = MACHINE_GET_CLASS(machine);
+
+ if (mc) {
+ cpu->ignore_memory_transaction_failures =
+ mc->ignore_memory_transaction_failures;
+ }
+ }
+
+ if (DEVICE(cpu)->hotplugged) {
+ cpu_synchronize_post_init(cpu);
+ cpu_resume(cpu);
+ }
+
+}
+
static bool cpu_common_exception_index_needed(void *opaque)
{
CPUState *cpu = opaque;
diff --git a/hw/core/cpu-user.c b/hw/core/cpu-user.c
index c2cb00a85d3..1e38c88f9bd 100644
--- a/hw/core/cpu-user.c
+++ b/hw/core/cpu-user.c
@@ -38,6 +38,11 @@ void cpu_exec_init(CPUState *cpu)
/* nothing to do */
}
+void cpu_exec_realize(CPUState *cpu, Error **errp)
+{
+ /* nothing to do */
+}
+
void cpu_vmstate_register(CPUState *cpu)
{
assert(qdev_get_vmsd(DEVICE(cpu)) == NULL ||
--
2.53.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH 0/8] hw/cpu: Slightly sanitize CPU API
2026-08-11 18:34 [PATCH 0/8] hw/cpu: Slightly sanitize CPU API Philippe Mathieu-Daudé
` (7 preceding siblings ...)
2026-08-11 18:34 ` [PATCH 8/8] hw/cpu: Move system-specific cpu_exec_realize() to cpu-system.c Philippe Mathieu-Daudé
@ 2026-08-11 23:33 ` Richard Henderson
2026-08-15 13:52 ` Philippe Mathieu-Daudé
9 siblings, 0 replies; 11+ messages in thread
From: Richard Henderson @ 2026-08-11 23:33 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: qemu-ppc, Pierrick Bouvier, qemu-arm, qemu-s390x, kvm, qemu-riscv
On 8/11/26 11:34, Philippe Mathieu-Daudé wrote:
> API cleanups, mostly removing system-specific code out of
> cpu-common.c. Code churn renaming functions, in the hope
> to make things a bit simpler to understand.
>
> Small patch set extracted from a series clarifying CPU /
> accel synchronization, itself a preliminary work to introduce
> split acceleration, eventually.
>
> Philippe Mathieu-Daudé (8):
> hw/cpu: Correct CPU_GET_CLASS() comment
> hw/cpu: Include missing 'qemu/accel.h' header
> hw/cpu: Move internal declarations to new 'cpu-internal.h' header
> hw/cpu: Rename cpu_common_realizefn() -> cpu_exec_realize()
> hw/cpu: Rename cpu_exec_realizefn() -> cpu_common_realize()
> hw/cpu: Rename cpu_exec_unrealizefn() -> cpu_common_unrealize()
> hw/cpu: Extract cpu_exec_realize() out of cpu_common_realizefn()
> hw/cpu: Move system-specific cpu_exec_realize() to cpu-system.c
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH 0/8] hw/cpu: Slightly sanitize CPU API
2026-08-11 18:34 [PATCH 0/8] hw/cpu: Slightly sanitize CPU API Philippe Mathieu-Daudé
` (8 preceding siblings ...)
2026-08-11 23:33 ` [PATCH 0/8] hw/cpu: Slightly sanitize CPU API Richard Henderson
@ 2026-08-15 13:52 ` Philippe Mathieu-Daudé
9 siblings, 0 replies; 11+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-15 13:52 UTC (permalink / raw)
To: qemu-devel
Cc: Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
qemu-s390x, kvm, qemu-riscv
On 11/8/26 20:34, Philippe Mathieu-Daudé wrote:
> API cleanups, mostly removing system-specific code out of
> cpu-common.c. Code churn renaming functions, in the hope
> to make things a bit simpler to understand.
>
> Small patch set extracted from a series clarifying CPU /
> accel synchronization, itself a preliminary work to introduce
> split acceleration, eventually.
>
> Philippe Mathieu-Daudé (8):
> hw/cpu: Correct CPU_GET_CLASS() comment
> hw/cpu: Include missing 'qemu/accel.h' header
> hw/cpu: Move internal declarations to new 'cpu-internal.h' header
> hw/cpu: Rename cpu_common_realizefn() -> cpu_exec_realize()
> hw/cpu: Rename cpu_exec_realizefn() -> cpu_common_realize()
> hw/cpu: Rename cpu_exec_unrealizefn() -> cpu_common_unrealize()
> hw/cpu: Extract cpu_exec_realize() out of cpu_common_realizefn()
> hw/cpu: Move system-specific cpu_exec_realize() to cpu-system.c
Series queued.
^ permalink raw reply [flat|nested] 11+ messages in thread