* [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler
@ 2026-08-20 20:13 Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 01/15] target/tricore: Document architectural interrupts as not implemented Philippe Mathieu-Daudé
` (15 more replies)
0 siblings, 16 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé
Missing review: 2,12,14,15
Since v1:
- use _Generic (rth)
- no more RFC
- Patches 2-11 trivially add const qualifier for various
cpu_is/has() getters
- Patch 12-14 add const-qualified variants of cpu_env(),
env_cpu(), and env_archcpu() using _Generic() macros;
consolidate the redundant env_cpu_const() alias and update
linux-user to use the generic accessor
- Patch 15 finally convert the SysemuCPUOps::has_work
hook and all target implementations.
No functional change; purely const-correctness improvment
to enforce has_work() callees don't mutate CPUState.
Build-tested.
Following checkpatch.pl errors ignored:
13/15 Checking commit efef90983aa7 (cpus: Add const-qualified CPU environment accessors)
ERROR: spaces required around that ':' (ctx:VxE)
#46: FILE: include/exec/cpu-common.h:89:
+ CPUArchState: \
^
ERROR: spaces required around that ':' (ctx:VxE)
#62: FILE: include/exec/cpu-common.h:101:
+ CPUArchState: \
^
ERROR: spaces required around that ':' (ctx:VxE)
#90: FILE: include/hw/core/cpu.h:605:
+ CPUState: \
^
total: 3 errors, 0 warnings, 64 lines checked
Philippe Mathieu-Daudé (15):
target/tricore: Document architectural interrupts as not implemented
system/cpus: Constify various CPUState arguments
target/avr: Constify CPUAVRState for some cpu_*() getters
target/hexagon: Constify CPUHexagonState in
hexagon_thread_is_enabled()
target/i386: Constify CPU*State for cpu_*_interrupt() getters
target/loongarch: Constify CPULoongArchState for various cpu_*()
getters
target/mips: Constify CPUMIPSState for various cpu_*() getters
target/s390x: Constify S390CPU for cpu_has_*() getters
target/riscv: Constify @iprio argument in riscv_cpu_pending_to_irq()
target/riscv: Constify CPURISCVState for various cpu_*() getters
target/sparc: Constify CPUSPARCState for various cpu_*() getters
linux-user: Uncast void pointer argument as Object in
target_cpu_free()
cpus: Add const-qualified CPU environment accessors
linux-user: Replace env_cpu_const() by generic env_cpu() equivalent
cpus: Constify @cpu in SysemuCPUOps::has_work() handler
include/exec/cpu-common.h | 29 ++++++++++-------------------
include/hw/core/cpu.h | 21 ++++++++++++++-------
include/hw/core/sysemu-cpu-ops.h | 4 ++--
include/system/cpus.h | 4 ++--
target/avr/cpu.h | 6 +++---
target/hexagon/cpu.h | 2 +-
target/i386/cpu.h | 4 ++--
target/loongarch/cpu.h | 6 +++---
target/loongarch/internals.h | 2 +-
target/mips/cpu.h | 6 +++---
target/mips/internal.h | 10 +++++-----
target/riscv/cpu.h | 29 +++++++++++++++--------------
target/s390x/cpu.h | 2 +-
target/s390x/s390x-internal.h | 12 ++++++------
target/sparc/cpu.h | 12 ++++++------
linux-user/elfload.c | 2 +-
linux-user/i386/cpu_loop.c | 5 +++--
linux-user/i386/elfload.c | 2 +-
linux-user/x86_64/elfload.c | 2 +-
system/cpus.c | 6 +++---
target/alpha/cpu.c | 2 +-
target/arm/cpu.c | 4 ++--
target/avr/cpu.c | 3 ++-
target/hexagon/cpu.c | 8 ++++----
target/hppa/cpu.c | 2 +-
target/i386/cpu.c | 7 +++----
target/loongarch/cpu.c | 4 ++--
target/m68k/cpu.c | 2 +-
target/microblaze/cpu.c | 2 +-
target/mips/cpu.c | 4 ++--
target/or1k/cpu.c | 2 +-
target/ppc/cpu_init.c | 2 +-
target/riscv/cpu.c | 17 ++++++++---------
target/rx/cpu.c | 2 +-
target/s390x/cpu-system.c | 4 ++--
target/s390x/interrupt.c | 22 +++++++++++-----------
target/sh4/cpu.c | 2 +-
target/sparc/cpu.c | 2 +-
target/tricore/cpu.c | 3 ++-
target/xtensa/cpu.c | 4 ++--
40 files changed, 132 insertions(+), 132 deletions(-)
--
2.53.0
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 01/15] target/tricore: Document architectural interrupts as not implemented
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
@ 2026-08-20 20:13 ` Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 02/15] system/cpus: Constify various CPUState arguments Philippe Mathieu-Daudé
` (14 subsequent siblings)
15 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé
As mentioned in commit de680286b52 ("accel/tcg: Make
cpu_exec_interrupt hook mandatory"):
> Tricore doesn't currently implement the architectural
> interrupt handling.
Add a comment to help understanding why this SysemuCPUOps
has_work() handler is simply always returning %true.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
target/tricore/cpu.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c
index 6d448727005..82b56c3cd56 100644
--- a/target/tricore/cpu.c
+++ b/target/tricore/cpu.c
@@ -113,6 +113,7 @@ static void tricore_cpu_reset_hold(Object *obj, ResetType type)
static bool tricore_cpu_has_work(CPUState *cs)
{
+ /* Interrupts are not implemented */
return true;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 02/15] system/cpus: Constify various CPUState arguments
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 01/15] target/tricore: Document architectural interrupts as not implemented Philippe Mathieu-Daudé
@ 2026-08-20 20:13 ` Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 03/15] target/avr: Constify CPUAVRState for some cpu_*() getters Philippe Mathieu-Daudé
` (13 subsequent siblings)
15 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé, Philippe Mathieu-Daudé,
Zhao Liu
Mark the CPUState structure const when it is only accessed read-only.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
include/hw/core/cpu.h | 4 ++--
include/system/cpus.h | 4 ++--
system/cpus.c | 6 +++---
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 81af7b9ee1a..a16acf14370 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -893,7 +893,7 @@ void qemu_cpu_kick(CPUState *cpu);
* Returns: %true if run state is not running or if artificially stopped;
* %false otherwise.
*/
-bool cpu_is_stopped(CPUState *cpu);
+bool cpu_is_stopped(const CPUState *cpu);
/**
* do_run_on_cpu:
@@ -1000,7 +1000,7 @@ void cpu_interrupt(CPUState *cpu, int mask);
*
* Checks if any of interrupts in @mask are pending on @cpu.
*/
-static inline bool cpu_test_interrupt(CPUState *cpu, int mask)
+static inline bool cpu_test_interrupt(const CPUState *cpu, int mask)
{
return qatomic_load_acquire(&cpu->interrupt_request) & mask;
}
diff --git a/include/system/cpus.h b/include/system/cpus.h
index 508444ccf1c..bf36b823769 100644
--- a/include/system/cpus.h
+++ b/include/system/cpus.h
@@ -13,10 +13,10 @@ const AccelOpsClass *cpus_get_accel(void);
#define VCPU_THREAD_NAME_SIZE 16
void cpus_kick_thread(CPUState *cpu);
-bool cpu_work_list_empty(CPUState *cpu);
+bool cpu_work_list_empty(const CPUState *cpu);
bool cpu_thread_is_idle(CPUState *cpu);
bool all_cpu_threads_idle(void);
-bool cpu_can_run(CPUState *cpu);
+bool cpu_can_run(const CPUState *cpu);
void qemu_process_cpu_events_common(CPUState *cpu);
void cpu_thread_signal_created(CPUState *cpu);
void cpu_thread_signal_destroyed(CPUState *cpu);
diff --git a/system/cpus.c b/system/cpus.c
index f37e215c586..e11a5aab6a6 100644
--- a/system/cpus.c
+++ b/system/cpus.c
@@ -69,12 +69,12 @@ static QemuMutex bql;
*/
static const AccelOpsClass *cpus_accel;
-bool cpu_is_stopped(CPUState *cpu)
+bool cpu_is_stopped(const CPUState *cpu)
{
return cpu->stopped || !runstate_is_running();
}
-bool cpu_work_list_empty(CPUState *cpu)
+bool cpu_work_list_empty(const CPUState *cpu)
{
return QSIMPLEQ_EMPTY_ATOMIC(&cpu->work_list);
}
@@ -271,7 +271,7 @@ void cpu_interrupt(CPUState *cpu, int mask)
cpus_accel->handle_interrupt(cpu, mask);
}
-bool cpu_can_run(CPUState *cpu)
+bool cpu_can_run(const CPUState *cpu)
{
if (cpu->stop) {
return false;
--
2.53.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 03/15] target/avr: Constify CPUAVRState for some cpu_*() getters
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 01/15] target/tricore: Document architectural interrupts as not implemented Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 02/15] system/cpus: Constify various CPUState arguments Philippe Mathieu-Daudé
@ 2026-08-20 20:13 ` Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 04/15] target/hexagon: Constify CPUHexagonState in hexagon_thread_is_enabled() Philippe Mathieu-Daudé
` (12 subsequent siblings)
15 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé, Marc-André Lureau,
Michael Rolnik
Add the const qualifier to CPUAVRState when the
argument is accessed without modification.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
target/avr/cpu.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/target/avr/cpu.h b/target/avr/cpu.h
index a818db753b2..1e4e839bd83 100644
--- a/target/avr/cpu.h
+++ b/target/avr/cpu.h
@@ -183,7 +183,7 @@ int avr_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
int avr_print_insn(bfd_vma addr, disassemble_info *info);
vaddr avr_cpu_gdb_adjust_breakpoint(CPUState *cpu, vaddr addr);
-static inline int avr_feature(CPUAVRState *env, AVRFeature feature)
+static inline int avr_feature(const CPUAVRState *env, AVRFeature feature)
{
return (env->features & (1U << feature)) != 0;
}
@@ -204,12 +204,12 @@ enum {
TB_FLAGS_SKIP = 2,
};
-static inline int cpu_interrupts_enabled(CPUAVRState *env)
+static inline int cpu_interrupts_enabled(const CPUAVRState *env)
{
return env->sregI != 0;
}
-static inline uint8_t cpu_get_sreg(CPUAVRState *env)
+static inline uint8_t cpu_get_sreg(const CPUAVRState *env)
{
return (env->sregC) << 0
| (env->sregZ) << 1
--
2.53.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 04/15] target/hexagon: Constify CPUHexagonState in hexagon_thread_is_enabled()
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
` (2 preceding siblings ...)
2026-08-20 20:13 ` [PATCH v2 03/15] target/avr: Constify CPUAVRState for some cpu_*() getters Philippe Mathieu-Daudé
@ 2026-08-20 20:13 ` Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 05/15] target/i386: Constify CPU*State for cpu_*_interrupt() getters Philippe Mathieu-Daudé
` (11 subsequent siblings)
15 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé, Marc-André Lureau, Brian Cain
@env argument is accessed without modification in
hexagon_thread_is_enabled(), qualify it as const.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Brian Cain <brian.cain@oss.qualcomm.com>
---
target/hexagon/cpu.h | 2 +-
target/hexagon/cpu.c | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/target/hexagon/cpu.h b/target/hexagon/cpu.h
index c50fbb3f72a..e4f120eda17 100644
--- a/target/hexagon/cpu.h
+++ b/target/hexagon/cpu.h
@@ -216,7 +216,7 @@ G_NORETURN void hexagon_raise_exception_err(CPUHexagonState *env,
* @return true if the @a thread_env hardware thread is
* not stopped.
*/
-bool hexagon_thread_is_enabled(CPUHexagonState *thread_env);
+bool hexagon_thread_is_enabled(const CPUHexagonState *thread_env);
uint32_t hexagon_greg_read(CPUHexagonState *env, uint32_t reg);
void hexagon_cpu_soft_reset(CPUHexagonState *env);
#endif
diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c
index 9765716b516..4cc6bd67c28 100644
--- a/target/hexagon/cpu.c
+++ b/target/hexagon/cpu.c
@@ -345,9 +345,9 @@ static void hexagon_cpu_synchronize_from_tb(CPUState *cs,
}
#ifndef CONFIG_USER_ONLY
-bool hexagon_thread_is_enabled(CPUHexagonState *env)
+bool hexagon_thread_is_enabled(const CPUHexagonState *env)
{
- HexagonCPU *cpu = env_archcpu(env);
+ const HexagonCPU *cpu = env_archcpu(env);
uint32_t modectl;
uint32_t thread_enabled_mask;
bool E_bit;
--
2.53.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 05/15] target/i386: Constify CPU*State for cpu_*_interrupt() getters
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
` (3 preceding siblings ...)
2026-08-20 20:13 ` [PATCH v2 04/15] target/hexagon: Constify CPUHexagonState in hexagon_thread_is_enabled() Philippe Mathieu-Daudé
@ 2026-08-20 20:13 ` Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 06/15] target/loongarch: Constify CPULoongArchState for various cpu_*() getters Philippe Mathieu-Daudé
` (10 subsequent siblings)
15 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé, Marc-André Lureau, Zhao Liu
x86_cpu_pending_interrupt() and x86_cpu_interrupts_enabled()
only read CPU state without modification, add the const
qualifiers to CPUState and CPUX86State parameters.
Simplify directly using cpu_env() in x86_cpu_pending_interrupt.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
target/i386/cpu.h | 4 ++--
target/i386/cpu.c | 5 ++---
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/target/i386/cpu.h b/target/i386/cpu.h
index e6a197602d8..72adf075bfd 100644
--- a/target/i386/cpu.h
+++ b/target/i386/cpu.h
@@ -2584,7 +2584,7 @@ void x86_cpu_gdb_init(CPUState *cs);
int cpu_x86_support_mca_broadcast(CPUX86State *env);
#ifndef CONFIG_USER_ONLY
-int x86_cpu_pending_interrupt(CPUState *cs, int interrupt_request);
+int x86_cpu_pending_interrupt(const CPUState *cs, int interrupt_request);
bool x86_cpu_translate_for_debug(CPUState *cpu, vaddr addr,
TranslateForDebugResult *result);
@@ -3092,7 +3092,7 @@ static inline bool ctl_has_irq(CPUX86State *env)
return (env->int_ctl & V_IRQ_MASK) && (int_prio >= tpr);
}
-static inline bool x86_cpu_interrupts_enabled(CPUX86State *env)
+static inline bool x86_cpu_interrupts_enabled(const CPUX86State *env)
{
return ((env->eflags & IF_MASK) &&
!(env->hflags & HF_INHIBIT_IRQ_MASK)) ||
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index e5ffb10d156..1fc02cf94e6 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -10601,10 +10601,9 @@ static vaddr x86_cpu_get_pc(CPUState *cs)
}
#if !defined(CONFIG_USER_ONLY)
-int x86_cpu_pending_interrupt(CPUState *cs, int interrupt_request)
+int x86_cpu_pending_interrupt(const CPUState *cs, int interrupt_request)
{
- X86CPU *cpu = X86_CPU(cs);
- CPUX86State *env = &cpu->env;
+ const CPUX86State *env = cpu_env(cs);
if (interrupt_request & CPU_INTERRUPT_POLL) {
return CPU_INTERRUPT_POLL;
--
2.53.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 06/15] target/loongarch: Constify CPULoongArchState for various cpu_*() getters
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
` (4 preceding siblings ...)
2026-08-20 20:13 ` [PATCH v2 05/15] target/i386: Constify CPU*State for cpu_*_interrupt() getters Philippe Mathieu-Daudé
@ 2026-08-20 20:13 ` Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 07/15] target/mips: Constify CPUMIPSState " Philippe Mathieu-Daudé
` (9 subsequent siblings)
15 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé, Marc-André Lureau, Song Gao,
Bibo Mao, Xianglai Li
Add the const qualifier to CPULoongArchStatCPUMIPSStatee when
the argument is accessed without modification.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
target/loongarch/cpu.h | 6 +++---
target/loongarch/internals.h | 2 +-
target/loongarch/cpu.c | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index ad30c73167e..494744788b8 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -485,7 +485,7 @@ struct LoongArchCPUClass {
#define MMU_USER_IDX MMU_PLV_USER
#define MMU_DA_IDX 4
-static inline CPUSysState *env_sys(CPULoongArchState *env)
+static inline CPUSysState *env_sys(const CPULoongArchState *env)
{
return env->sys_state;
}
@@ -495,12 +495,12 @@ static inline void set_sys_state(CPULoongArchState *env, CPUSysState *sys)
env->sys_state = sys;
}
-static inline bool is_la64(CPULoongArchState *env)
+static inline bool is_la64(const CPULoongArchState *env)
{
return FIELD_EX32(env->cpucfg[1], CPUCFG1, ARCH) == CPUCFG1_ARCH_LA64;
}
-static inline bool is_va32(CPULoongArchState *env)
+static inline bool is_va32(const CPULoongArchState *env)
{
/* VA32 if !LA64 or VA32L[1-3] */
bool va32 = !is_la64(env);
diff --git a/target/loongarch/internals.h b/target/loongarch/internals.h
index 50f0fe2e9be..d6f31161e85 100644
--- a/target/loongarch/internals.h
+++ b/target/loongarch/internals.h
@@ -38,7 +38,7 @@ uint64_t cpu_loongarch_get_constant_timer_counter(LoongArchCPU *cpu);
uint64_t cpu_loongarch_get_constant_timer_ticks(LoongArchCPU *cpu);
void cpu_loongarch_store_constant_timer_config(LoongArchCPU *cpu,
uint64_t value);
-bool cpu_loongarch_hw_interrupts_pending(CPULoongArchState *env);
+bool cpu_loongarch_hw_interrupts_pending(const CPULoongArchState *env);
#endif /* !CONFIG_USER_ONLY */
uint64_t read_fcc(CPULoongArchState *env);
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index 2e938d7880f..b638ac25040 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -82,7 +82,7 @@ void loongarch_cpu_set_irq(void *opaque, int irq, int level)
}
/* Check if there is pending and not masked out interrupt */
-bool cpu_loongarch_hw_interrupts_pending(CPULoongArchState *env)
+bool cpu_loongarch_hw_interrupts_pending(const CPULoongArchState *env)
{
uint32_t pending;
uint32_t status;
--
2.53.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 07/15] target/mips: Constify CPUMIPSState for various cpu_*() getters
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
` (5 preceding siblings ...)
2026-08-20 20:13 ` [PATCH v2 06/15] target/loongarch: Constify CPULoongArchState for various cpu_*() getters Philippe Mathieu-Daudé
@ 2026-08-20 20:13 ` Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 08/15] target/s390x: Constify S390CPU for cpu_has_*() getters Philippe Mathieu-Daudé
` (8 subsequent siblings)
15 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé, Marc-André Lureau,
Philippe Mathieu-Daudé, Aurelien Jarno, Jiaxun Yang,
Aleksandar Rikalo
Add the const qualifier to CPUMIPSState when
the argument is accessed without modification.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
target/mips/cpu.h | 6 +++---
target/mips/internal.h | 10 +++++-----
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/target/mips/cpu.h b/target/mips/cpu.h
index 319147a948c..6404b342a5d 100644
--- a/target/mips/cpu.h
+++ b/target/mips/cpu.h
@@ -1372,19 +1372,19 @@ static inline bool ase_3d_available(const CPUMIPSState *env)
}
/* Check presence of MSA implementation */
-static inline bool ase_msa_available(CPUMIPSState *env)
+static inline bool ase_msa_available(const CPUMIPSState *env)
{
return env->CP0_Config3 & (1 << CP0C3_MSAP);
}
/* Check presence of Loongson CSR instructions */
-static inline bool ase_lcsr_available(CPUMIPSState *env)
+static inline bool ase_lcsr_available(const CPUMIPSState *env)
{
return env->lcsr_cpucfg2 & (1 << CPUCFG2_LCSRP);
}
/* Check presence of multi-threading ASE implementation */
-static inline bool ase_mt_available(CPUMIPSState *env)
+static inline bool ase_mt_available(const CPUMIPSState *env)
{
return env->CP0_Config3 & (1 << CP0C3_MT);
}
diff --git a/target/mips/internal.h b/target/mips/internal.h
index c5c286872eb..7dba22300b1 100644
--- a/target/mips/internal.h
+++ b/target/mips/internal.h
@@ -165,7 +165,7 @@ void cpu_mips_store_cause(CPUMIPSState *env, target_ulong val);
extern const VMStateDescription vmstate_mips_cpu;
-static inline bool cpu_mips_hw_interrupts_enabled(CPUMIPSState *env)
+static inline bool cpu_mips_hw_interrupts_enabled(const CPUMIPSState *env)
{
return (env->CP0_Status & (1 << CP0St_IE)) &&
!(env->CP0_Status & (1 << CP0St_EXL)) &&
@@ -180,7 +180,7 @@ static inline bool cpu_mips_hw_interrupts_enabled(CPUMIPSState *env)
}
/* Check if there is pending and not masked out interrupt */
-static inline bool cpu_mips_hw_interrupts_pending(CPUMIPSState *env)
+static inline bool cpu_mips_hw_interrupts_pending(const CPUMIPSState *env)
{
int32_t pending;
int32_t status;
@@ -247,9 +247,9 @@ static inline void restore_pamask(CPUMIPSState *env)
}
}
-static inline int mips_vpe_active(CPUMIPSState *env)
+static inline int mips_vpe_active(const CPUMIPSState *env)
{
- MIPSCPU *cpu = env_archcpu(env);
+ const MIPSCPU *cpu = env_archcpu(env);
int active = 1;
/* Check that the VPE is enabled. */
@@ -281,7 +281,7 @@ static inline int mips_vpe_active(CPUMIPSState *env)
return active;
}
-static inline int mips_vp_active(CPUMIPSState *env)
+static inline int mips_vp_active(const CPUMIPSState *env)
{
CPUState *cs;
--
2.53.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 08/15] target/s390x: Constify S390CPU for cpu_has_*() getters
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
` (6 preceding siblings ...)
2026-08-20 20:13 ` [PATCH v2 07/15] target/mips: Constify CPUMIPSState " Philippe Mathieu-Daudé
@ 2026-08-20 20:13 ` Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 09/15] target/riscv: Constify @iprio argument in riscv_cpu_pending_to_irq() Philippe Mathieu-Daudé
` (7 subsequent siblings)
15 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé, Ilya Leoshkevich,
Marc-André Lureau, Eric Farman, David Hildenbrand,
Cornelia Huck, Matthew Rosato
Add the const qualifier to S390CPU when the argument
is accessed without modification.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Acked-by: Eric Farman <farman@linux.ibm.com>
---
target/s390x/cpu.h | 2 +-
target/s390x/s390x-internal.h | 12 ++++++------
target/s390x/interrupt.c | 22 +++++++++++-----------
3 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h
index f55b79ef8ac..998bbb0d7ff 100644
--- a/target/s390x/cpu.h
+++ b/target/s390x/cpu.h
@@ -854,7 +854,7 @@ static inline unsigned int s390_cpu_set_state(uint8_t cpu_state, S390CPU *cpu)
return 0;
}
#endif /* CONFIG_USER_ONLY */
-static inline uint8_t s390_cpu_get_state(S390CPU *cpu)
+static inline uint8_t s390_cpu_get_state(const S390CPU *cpu)
{
return cpu->env.cpu_state;
}
diff --git a/target/s390x/s390x-internal.h b/target/s390x/s390x-internal.h
index 50782fac3ce..ca4445e6474 100644
--- a/target/s390x/s390x-internal.h
+++ b/target/s390x/s390x-internal.h
@@ -333,12 +333,12 @@ void cpu_inject_clock_comparator(S390CPU *cpu);
void cpu_inject_cpu_timer(S390CPU *cpu);
void cpu_inject_emergency_signal(S390CPU *cpu, uint16_t src_cpu_addr);
int cpu_inject_external_call(S390CPU *cpu, uint16_t src_cpu_addr);
-bool s390_cpu_has_io_int(S390CPU *cpu);
-bool s390_cpu_has_ext_int(S390CPU *cpu);
-bool s390_cpu_has_mcck_int(S390CPU *cpu);
-bool s390_cpu_has_int(S390CPU *cpu);
-bool s390_cpu_has_restart_int(S390CPU *cpu);
-bool s390_cpu_has_stop_int(S390CPU *cpu);
+bool s390_cpu_has_io_int(const S390CPU *cpu);
+bool s390_cpu_has_ext_int(const S390CPU *cpu);
+bool s390_cpu_has_mcck_int(const S390CPU *cpu);
+bool s390_cpu_has_int(const S390CPU *cpu);
+bool s390_cpu_has_restart_int(const S390CPU *cpu);
+bool s390_cpu_has_stop_int(const S390CPU *cpu);
void cpu_inject_restart(S390CPU *cpu);
void cpu_inject_stop(S390CPU *cpu);
#endif /* CONFIG_USER_ONLY */
diff --git a/target/s390x/interrupt.c b/target/s390x/interrupt.c
index 1dca835c5d8..d7e3fd45e4b 100644
--- a/target/s390x/interrupt.c
+++ b/target/s390x/interrupt.c
@@ -139,10 +139,10 @@ void s390_crw_mchk(void)
fsc->inject_crw_mchk(fs);
}
-bool s390_cpu_has_mcck_int(S390CPU *cpu)
+bool s390_cpu_has_mcck_int(const S390CPU *cpu)
{
QEMUS390FLICState *flic = s390_get_qemu_flic(s390_get_flic());
- CPUS390XState *env = &cpu->env;
+ const CPUS390XState *env = &cpu->env;
if (!(env->psw.mask & PSW_MASK_MCHECK)) {
return false;
@@ -157,10 +157,10 @@ bool s390_cpu_has_mcck_int(S390CPU *cpu)
return false;
}
-bool s390_cpu_has_ext_int(S390CPU *cpu)
+bool s390_cpu_has_ext_int(const S390CPU *cpu)
{
QEMUS390FLICState *flic = s390_get_qemu_flic(s390_get_flic());
- CPUS390XState *env = &cpu->env;
+ const CPUS390XState *env = &cpu->env;
if (!(env->psw.mask & PSW_MASK_EXT)) {
return false;
@@ -199,10 +199,10 @@ bool s390_cpu_has_ext_int(S390CPU *cpu)
return false;
}
-bool s390_cpu_has_io_int(S390CPU *cpu)
+bool s390_cpu_has_io_int(const S390CPU *cpu)
{
QEMUS390FLICState *flic = s390_get_qemu_flic(s390_get_flic());
- CPUS390XState *env = &cpu->env;
+ const CPUS390XState *env = &cpu->env;
if (!(env->psw.mask & PSW_MASK_IO)) {
return false;
@@ -211,21 +211,21 @@ bool s390_cpu_has_io_int(S390CPU *cpu)
return qemu_s390_flic_has_io(flic, env->cregs[6]);
}
-bool s390_cpu_has_restart_int(S390CPU *cpu)
+bool s390_cpu_has_restart_int(const S390CPU *cpu)
{
- CPUS390XState *env = &cpu->env;
+ const CPUS390XState *env = &cpu->env;
return env->pending_int & INTERRUPT_RESTART;
}
-bool s390_cpu_has_stop_int(S390CPU *cpu)
+bool s390_cpu_has_stop_int(const S390CPU *cpu)
{
- CPUS390XState *env = &cpu->env;
+ const CPUS390XState *env = &cpu->env;
return env->pending_int & INTERRUPT_STOP;
}
-bool s390_cpu_has_int(S390CPU *cpu)
+bool s390_cpu_has_int(const S390CPU *cpu)
{
if (!tcg_enabled()) {
return false;
--
2.53.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 09/15] target/riscv: Constify @iprio argument in riscv_cpu_pending_to_irq()
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
` (7 preceding siblings ...)
2026-08-20 20:13 ` [PATCH v2 08/15] target/s390x: Constify S390CPU for cpu_has_*() getters Philippe Mathieu-Daudé
@ 2026-08-20 20:13 ` Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 10/15] target/riscv: Constify CPURISCVState for various cpu_*() getters Philippe Mathieu-Daudé
` (6 subsequent siblings)
15 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé, Marc-André Lureau,
Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, Chao Liu
@iprio[] is an array only accessed read-only.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
target/riscv/cpu.h | 2 +-
target/riscv/cpu.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 376cff656fa..bb4c8563554 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -642,7 +642,7 @@ int riscv_cpu_sirq_pending(CPURISCVState *env);
int riscv_cpu_vsirq_pending(CPURISCVState *env);
int riscv_cpu_pending_to_irq(CPURISCVState *env,
int extirq, unsigned int extirq_def_prio,
- uint64_t pending, uint8_t *iprio);
+ uint64_t pending, const uint8_t *iprio);
bool riscv_cpu_fp_enabled(CPURISCVState *env);
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 7bf098319f8..858fbf865fd 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -866,7 +866,7 @@ uint8_t riscv_cpu_default_priority(int irq)
int riscv_cpu_pending_to_irq(CPURISCVState *env,
int extirq, unsigned int extirq_def_prio,
- uint64_t pending, uint8_t *iprio)
+ uint64_t pending, const uint8_t *iprio)
{
int irq, best_irq = RISCV_EXCP_NONE;
unsigned int prio, best_prio = UINT_MAX;
--
2.53.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 10/15] target/riscv: Constify CPURISCVState for various cpu_*() getters
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
` (8 preceding siblings ...)
2026-08-20 20:13 ` [PATCH v2 09/15] target/riscv: Constify @iprio argument in riscv_cpu_pending_to_irq() Philippe Mathieu-Daudé
@ 2026-08-20 20:13 ` Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 11/15] target/sparc: Constify CPUSPARCState " Philippe Mathieu-Daudé
` (5 subsequent siblings)
15 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé, Marc-André Lureau,
Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, Chao Liu
Add the const qualifier to CPURISCVState when the
argument is accessed without modification.
Simplify directly using cpu_env() in riscv_cpu_has_work().
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
target/riscv/cpu.h | 27 ++++++++++++++-------------
target/riscv/cpu.c | 13 ++++++-------
2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index bb4c8563554..c51e0d5f919 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -636,11 +636,11 @@ int riscv_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg);
int riscv_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg);
int riscv_cpu_hviprio_index2irq(int index, int *out_irq, int *out_rdzero);
uint8_t riscv_cpu_default_priority(int irq);
-uint64_t riscv_cpu_all_pending(CPURISCVState *env);
-int riscv_cpu_mirq_pending(CPURISCVState *env);
-int riscv_cpu_sirq_pending(CPURISCVState *env);
-int riscv_cpu_vsirq_pending(CPURISCVState *env);
-int riscv_cpu_pending_to_irq(CPURISCVState *env,
+uint64_t riscv_cpu_all_pending(const CPURISCVState *env);
+int riscv_cpu_mirq_pending(const CPURISCVState *env);
+int riscv_cpu_sirq_pending(const CPURISCVState *env);
+int riscv_cpu_vsirq_pending(const CPURISCVState *env);
+int riscv_cpu_pending_to_irq(const CPURISCVState *env,
int extirq, unsigned int extirq_def_prio,
uint64_t pending, const uint8_t *iprio);
@@ -746,20 +746,20 @@ FIELD(EXT_TB_FLAGS, BIG_ENDIAN, 33, 1)
#ifdef TARGET_RISCV32
#define riscv_cpu_mxl(env) ((void)(env), MXL_RV32)
#else
-static inline RISCVMXL riscv_cpu_mxl(CPURISCVState *env)
+static inline RISCVMXL riscv_cpu_mxl(const CPURISCVState *env)
{
return env->misa_mxl;
}
#endif
#define riscv_cpu_mxl_bits(env) (1UL << (4 + riscv_cpu_mxl(env)))
-static inline const RISCVCPUConfig *riscv_cpu_cfg(CPURISCVState *env)
+static inline const RISCVCPUConfig *riscv_cpu_cfg(const CPURISCVState *env)
{
return &env_archcpu(env)->cfg;
}
#if !defined(CONFIG_USER_ONLY)
-static inline privilege_mode_t cpu_address_mode(CPURISCVState *env)
+static inline privilege_mode_t cpu_address_mode(const CPURISCVState *env)
{
privilege_mode_t mode = env->priv;
@@ -769,7 +769,8 @@ static inline privilege_mode_t cpu_address_mode(CPURISCVState *env)
return mode;
}
-static inline RISCVMXL cpu_get_xl(CPURISCVState *env, privilege_mode_t mode)
+static inline RISCVMXL cpu_get_xl(const CPURISCVState *env,
+ privilege_mode_t mode)
{
RISCVMXL xl = env->misa_mxl;
/*
@@ -797,7 +798,7 @@ static inline RISCVMXL cpu_get_xl(CPURISCVState *env, privilege_mode_t mode)
#if defined(TARGET_RISCV32)
#define cpu_recompute_xl(env) ((void)(env), MXL_RV32)
#else
-static inline RISCVMXL cpu_recompute_xl(CPURISCVState *env)
+static inline RISCVMXL cpu_recompute_xl(const CPURISCVState *env)
{
#if !defined(CONFIG_USER_ONLY)
return cpu_get_xl(env, env->priv);
@@ -810,7 +811,7 @@ static inline RISCVMXL cpu_recompute_xl(CPURISCVState *env)
#if defined(TARGET_RISCV32)
#define cpu_address_xl(env) ((void)(env), MXL_RV32)
#else
-static inline RISCVMXL cpu_address_xl(CPURISCVState *env)
+static inline RISCVMXL cpu_address_xl(const CPURISCVState *env)
{
#ifdef CONFIG_USER_ONLY
return env->xl;
@@ -822,7 +823,7 @@ static inline RISCVMXL cpu_address_xl(CPURISCVState *env)
}
#endif
-static inline uint16_t riscv_cpu_xlen(CPURISCVState *env)
+static inline uint16_t riscv_cpu_xlen(const CPURISCVState *env)
{
return 16 << env->xl;
}
@@ -830,7 +831,7 @@ static inline uint16_t riscv_cpu_xlen(CPURISCVState *env)
#ifdef TARGET_RISCV32
#define riscv_cpu_sxl(env) ((void)(env), MXL_RV32)
#else
-static inline RISCVMXL riscv_cpu_sxl(CPURISCVState *env)
+static inline RISCVMXL riscv_cpu_sxl(const CPURISCVState *env)
{
#ifdef CONFIG_USER_ONLY
return env->misa_mxl;
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 858fbf865fd..4abf20d057a 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -864,7 +864,7 @@ uint8_t riscv_cpu_default_priority(int irq)
return default_iprio[irq] ? default_iprio[irq] : IPRIO_MMAXIPRIO;
};
-int riscv_cpu_pending_to_irq(CPURISCVState *env,
+int riscv_cpu_pending_to_irq(const CPURISCVState *env,
int extirq, unsigned int extirq_def_prio,
uint64_t pending, const uint8_t *iprio)
{
@@ -908,7 +908,7 @@ int riscv_cpu_pending_to_irq(CPURISCVState *env,
* using hvip bits 13:63 from HS-mode. Those are returned in
* riscv_cpu_sirq_pending() and riscv_cpu_vsirq_pending().
*/
-uint64_t riscv_cpu_all_pending(CPURISCVState *env)
+uint64_t riscv_cpu_all_pending(const CPURISCVState *env)
{
uint32_t gein = get_field(env->hstatus, HSTATUS_VGEIN);
uint64_t vsgein = (env->hgeip & (1ULL << gein)) ? MIP_VSEIP : 0;
@@ -917,7 +917,7 @@ uint64_t riscv_cpu_all_pending(CPURISCVState *env)
return (env->mip | vsgein | vstip) & env->mie;
}
-int riscv_cpu_mirq_pending(CPURISCVState *env)
+int riscv_cpu_mirq_pending(const CPURISCVState *env)
{
uint64_t irqs = riscv_cpu_all_pending(env) & ~env->mideleg &
~(MIP_SGEIP | MIP_VSSIP | MIP_VSTIP | MIP_VSEIP);
@@ -926,7 +926,7 @@ int riscv_cpu_mirq_pending(CPURISCVState *env)
irqs, env->miprio);
}
-int riscv_cpu_sirq_pending(CPURISCVState *env)
+int riscv_cpu_sirq_pending(const CPURISCVState *env)
{
uint64_t irqs = riscv_cpu_all_pending(env) & env->mideleg & ~env->hideleg;
uint64_t irqs_f = env->mvip & env->mvien & ~env->mideleg & env->sie;
@@ -935,7 +935,7 @@ int riscv_cpu_sirq_pending(CPURISCVState *env)
irqs | irqs_f, env->siprio);
}
-int riscv_cpu_vsirq_pending(CPURISCVState *env)
+int riscv_cpu_vsirq_pending(const CPURISCVState *env)
{
uint64_t irqs = riscv_cpu_all_pending(env) & env->mideleg & env->hideleg;
uint64_t irqs_f_vs = env->hvip & env->hvien & ~env->hideleg & env->vsie;
@@ -952,8 +952,7 @@ int riscv_cpu_vsirq_pending(CPURISCVState *env)
static bool riscv_cpu_has_work(CPUState *cs)
{
- RISCVCPU *cpu = RISCV_CPU(cs);
- CPURISCVState *env = &cpu->env;
+ CPURISCVState *env = cpu_env(cs);
/*
* Definition of the WFI instruction requires it to ignore the privilege
* mode and delegation registers, but respect individual enables
--
2.53.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 11/15] target/sparc: Constify CPUSPARCState for various cpu_*() getters
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
` (9 preceding siblings ...)
2026-08-20 20:13 ` [PATCH v2 10/15] target/riscv: Constify CPURISCVState for various cpu_*() getters Philippe Mathieu-Daudé
@ 2026-08-20 20:13 ` Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 12/15] linux-user: Uncast void pointer argument as Object in target_cpu_free() Philippe Mathieu-Daudé
` (4 subsequent siblings)
15 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé, Marc-André Lureau,
Mark Cave-Ayland, Artyom Tarasenko
Add the const qualifier to CPUSPARCState when
the argument is accessed without modification.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
target/sparc/cpu.h | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/target/sparc/cpu.h b/target/sparc/cpu.h
index 5f583ed9de2..31a16c2af03 100644
--- a/target/sparc/cpu.h
+++ b/target/sparc/cpu.h
@@ -680,28 +680,28 @@ hwaddr cpu_get_phys_page_nofault(CPUSPARCState *env, target_ulong addr,
#endif
#if defined (TARGET_SPARC64)
-static inline int cpu_has_hypervisor(CPUSPARCState *env1)
+static inline int cpu_has_hypervisor(const CPUSPARCState *env1)
{
return env1->def.features & CPU_FEATURE_HYPV;
}
-static inline int cpu_hypervisor_mode(CPUSPARCState *env1)
+static inline int cpu_hypervisor_mode(const CPUSPARCState *env1)
{
return cpu_has_hypervisor(env1) && (env1->hpstate & HS_PRIV);
}
-static inline int cpu_supervisor_mode(CPUSPARCState *env1)
+static inline int cpu_supervisor_mode(const CPUSPARCState *env1)
{
return env1->pstate & PS_PRIV;
}
#else
-static inline int cpu_supervisor_mode(CPUSPARCState *env1)
+static inline int cpu_supervisor_mode(const CPUSPARCState *env1)
{
return env1->psrs;
}
#endif
-static inline int cpu_interrupts_enabled(CPUSPARCState *env1)
+static inline int cpu_interrupts_enabled(const CPUSPARCState *env1)
{
#if !defined (TARGET_SPARC64)
if (env1->psret != 0)
@@ -715,7 +715,7 @@ static inline int cpu_interrupts_enabled(CPUSPARCState *env1)
return 0;
}
-static inline int cpu_pil_allowed(CPUSPARCState *env1, int pil)
+static inline int cpu_pil_allowed(const CPUSPARCState *env1, int pil)
{
#if !defined(TARGET_SPARC64)
/* level 15 is non-maskable on sparc v8 */
--
2.53.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 12/15] linux-user: Uncast void pointer argument as Object in target_cpu_free()
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
` (10 preceding siblings ...)
2026-08-20 20:13 ` [PATCH v2 11/15] target/sparc: Constify CPUSPARCState " Philippe Mathieu-Daudé
@ 2026-08-20 20:13 ` Philippe Mathieu-Daudé
2026-08-20 23:21 ` Richard Henderson
2026-08-20 20:13 ` [PATCH v2 13/15] cpus: Add const-qualified CPU environment accessors Philippe Mathieu-Daudé
` (3 subsequent siblings)
15 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé, Laurent Vivier, Helge Deller
init_main_thread() is registered as Object::free() hook, thus
take an Object* argument. Uncast the void pointer as such.
While now cpu_env() accept any pointer type, next commit will
restrict it to CPUState* type. QOM-cast the Object to CPU type,
otherwise we will get:
../linux-user/i386/cpu_loop.c: In function ‘target_cpu_free’:
include/hw/core/cpu.h:604:31: error: ‘_Generic’ selector of type ‘void’ is not compatible with any association
../linux-user/x86_64/../i386/cpu_loop.c:331:19: note: in expansion of macro ‘cpu_env’
331 | target_munmap(cpu_env(obj)->gdt.base,
| ^~~~~~~
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
linux-user/i386/cpu_loop.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
index fe922fceb5a..a0790f3f352 100644
--- a/linux-user/i386/cpu_loop.c
+++ b/linux-user/i386/cpu_loop.c
@@ -326,9 +326,10 @@ void cpu_loop(CPUX86State *env)
}
}
-static void target_cpu_free(void *obj)
+static void target_cpu_free(void *ptr)
{
- target_munmap(cpu_env(obj)->gdt.base,
+ Object *obj = ptr;
+ target_munmap(cpu_env(CPU(obj))->gdt.base,
sizeof(uint64_t) * TARGET_GDT_ENTRIES);
g_free(obj);
}
--
2.53.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 13/15] cpus: Add const-qualified CPU environment accessors
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
` (11 preceding siblings ...)
2026-08-20 20:13 ` [PATCH v2 12/15] linux-user: Uncast void pointer argument as Object in target_cpu_free() Philippe Mathieu-Daudé
@ 2026-08-20 20:13 ` Philippe Mathieu-Daudé
2026-08-20 23:17 ` Richard Henderson
2026-08-20 20:13 ` [PATCH v2 14/15] linux-user: Replace env_cpu_const() by generic env_cpu() equivalent Philippe Mathieu-Daudé
` (2 subsequent siblings)
15 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé, Philippe Mathieu-Daudé,
Marc-André Lureau, Philippe Mathieu-Daudé, Zhao Liu
From: Philippe Mathieu-Daudé <philmd@linaro.org>
Use _Generic() controlling-expression to add the const-qualified
variants of cpu_env(), env_cpu() and env_archcpu(). This allows to
safely access CPU architecture state when it should not be modified.
Alias env_cpu_const() which is still used.
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
include/exec/cpu-common.h | 30 +++++++++++-------------------
include/hw/core/cpu.h | 17 ++++++++++++-----
2 files changed, 23 insertions(+), 24 deletions(-)
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index 6594f7fa1be..bffef677607 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -85,21 +85,11 @@ static inline bool cpu_loop_exit_requested(const CPUState *cpu)
*
* Return the ArchCPU associated with the environment.
*/
-static inline ArchCPU *env_archcpu(CPUArchState *env)
-{
- return (void *)env - sizeof(CPUState);
-}
-
-/**
- * env_cpu_const(env)
- * @env: The architecture environment
- *
- * Return the CPUState associated with the environment.
- */
-static inline const CPUState *env_cpu_const(const CPUArchState *env)
-{
- return (void *)env - sizeof(CPUState);
-}
+#define env_archcpu(env) _Generic(*(env), \
+ CPUArchState: \
+ (ArchCPU *)((void *)env - sizeof(CPUState)), \
+ const CPUArchState: \
+ (const ArchCPU *)((const void *)env - sizeof(CPUState)))
/**
* env_cpu(env)
@@ -107,9 +97,11 @@ static inline const CPUState *env_cpu_const(const CPUArchState *env)
*
* Return the CPUState associated with the environment.
*/
-static inline CPUState *env_cpu(CPUArchState *env)
-{
- return (CPUState *)env_cpu_const(env);
-}
+#define env_cpu(env) _Generic(*(env), \
+ CPUArchState: \
+ (CPUState *)((void *)env - sizeof(CPUState)), \
+ const CPUArchState: \
+ (const CPUState *)((const void *)env - sizeof(CPUState)))
+#define env_cpu_const(cpu) env_cpu(cpu)
#endif /* CPU_COMMON_H */
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index a16acf14370..372485a2e54 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -594,11 +594,18 @@ struct CPUState {
QEMU_BUILD_BUG_ON(offsetof(CPUState, neg) !=
sizeof(CPUState) - sizeof(CPUNegativeOffsetState));
-static inline CPUArchState *cpu_env(CPUState *cpu)
-{
- /* We validate that CPUArchState follows CPUState in cpu-target.c */
- return (CPUArchState *)(cpu + 1);
-}
+/**
+ * cpu_env(cpu)
+ * @cpu: The vCPU
+ *
+ * Return the CPUArchState associated with the CPU.
+ */
+#define cpu_env(cpu) _Generic(*(cpu), \
+ /* We validate that CPUArchState follows CPUState in cpu-target.c */ \
+ CPUState: \
+ (CPUArchState *)(cpu + 1), \
+ const CPUState: \
+ (const CPUArchState *)(cpu + 1))
#ifdef CONFIG_TCG
/*
--
2.53.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 14/15] linux-user: Replace env_cpu_const() by generic env_cpu() equivalent
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
` (12 preceding siblings ...)
2026-08-20 20:13 ` [PATCH v2 13/15] cpus: Add const-qualified CPU environment accessors Philippe Mathieu-Daudé
@ 2026-08-20 20:13 ` Philippe Mathieu-Daudé
2026-08-20 23:17 ` Richard Henderson
2026-08-20 20:13 ` [PATCH v2 15/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
2026-08-21 10:28 ` [PATCH v2 00/15] " Philippe Mathieu-Daudé
15 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé, Philippe Mathieu-Daudé,
Laurent Vivier, Helge Deller
Use the generic env_cpu() macro introduced in the previous
commit and remove the few env_cpu_const() uses.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
include/exec/cpu-common.h | 1 -
linux-user/elfload.c | 2 +-
linux-user/i386/elfload.c | 2 +-
linux-user/x86_64/elfload.c | 2 +-
4 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h
index bffef677607..d67d008236f 100644
--- a/include/exec/cpu-common.h
+++ b/include/exec/cpu-common.h
@@ -102,6 +102,5 @@ static inline bool cpu_loop_exit_requested(const CPUState *cpu)
(CPUState *)((void *)env - sizeof(CPUState)), \
const CPUArchState: \
(const CPUState *)((const void *)env - sizeof(CPUState)))
-#define env_cpu_const(cpu) env_cpu(cpu)
#endif /* CPU_COMMON_H */
diff --git a/linux-user/elfload.c b/linux-user/elfload.c
index 88508deac50..c4bdaa146a7 100644
--- a/linux-user/elfload.c
+++ b/linux-user/elfload.c
@@ -2128,7 +2128,7 @@ static int wmr_write_region(void *opaque, vaddr start,
#endif
static int elf_core_dump(int signr, const CPUArchState *env)
{
- const CPUState *cpu = env_cpu_const(env);
+ const CPUState *cpu = env_cpu(env);
const TaskState *ts = (const TaskState *)get_task_state((CPUState *)cpu);
struct rlimit dumpsize;
CountAndSizeRegions css;
diff --git a/linux-user/i386/elfload.c b/linux-user/i386/elfload.c
index 26b12001a3e..2e10f38a412 100644
--- a/linux-user/i386/elfload.c
+++ b/linux-user/i386/elfload.c
@@ -38,7 +38,7 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env)
r->pt.es = tswapal(env->segs[R_ES].selector & 0xffff);
r->pt.fs = tswapal(env->segs[R_FS].selector & 0xffff);
r->pt.gs = tswapal(env->segs[R_GS].selector & 0xffff);
- r->pt.orig_ax = tswapal(get_task_state(env_cpu_const(env))->orig_ax);
+ r->pt.orig_ax = tswapal(get_task_state(env_cpu(env))->orig_ax);
r->pt.ip = tswapal(env->eip);
r->pt.cs = tswapal(env->segs[R_CS].selector & 0xffff);
r->pt.flags = tswapal(env->eflags);
diff --git a/linux-user/x86_64/elfload.c b/linux-user/x86_64/elfload.c
index 49a6f6180e0..121a8167acc 100644
--- a/linux-user/x86_64/elfload.c
+++ b/linux-user/x86_64/elfload.c
@@ -59,7 +59,7 @@ void elf_core_copy_regs(target_elf_gregset_t *r, const CPUX86State *env)
r->pt.dx = tswapal(env->regs[R_EDX]);
r->pt.si = tswapal(env->regs[R_ESI]);
r->pt.di = tswapal(env->regs[R_EDI]);
- r->pt.orig_ax = tswapal(get_task_state(env_cpu_const(env))->orig_ax);
+ r->pt.orig_ax = tswapal(get_task_state(env_cpu(env))->orig_ax);
r->pt.ip = tswapal(env->eip);
r->pt.cs = tswapal(env->segs[R_CS].selector & 0xffff);
r->pt.flags = tswapal(env->eflags);
--
2.53.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 15/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
` (13 preceding siblings ...)
2026-08-20 20:13 ` [PATCH v2 14/15] linux-user: Replace env_cpu_const() by generic env_cpu() equivalent Philippe Mathieu-Daudé
@ 2026-08-20 20:13 ` Philippe Mathieu-Daudé
2026-08-21 10:28 ` [PATCH v2 00/15] " Philippe Mathieu-Daudé
15 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-20 20:13 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm,
Philippe Mathieu-Daudé, Michael Rolnik, Brian Cain,
Helge Deller, Zhao Liu, Song Gao, Bibo Mao, Xianglai Li,
Laurent Vivier, Edgar E. Iglesias, Philippe Mathieu-Daudé,
Aurelien Jarno, Jiaxun Yang, Aleksandar Rikalo, Stafford Horne,
Nicholas Piggin, Chinmay Rath, Glenn Miles, Harsh Prateek Bora,
Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, Chao Liu, Yoshinori Sato,
Ilya Leoshkevich, David Hildenbrand, Cornelia Huck, Eric Farman,
Matthew Rosato, Mark Cave-Ayland, Artyom Tarasenko, Max Filippov
All functions called by target has_work() handler take a const @cpu
argument. We can now fulfill the comment added in commit c2804566f6
("target/arm: do not clear halting reason in has_work helper"),
qualifying the handler const to denote its idempotency.
Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
---
include/hw/core/sysemu-cpu-ops.h | 4 ++--
target/alpha/cpu.c | 2 +-
target/arm/cpu.c | 4 ++--
target/avr/cpu.c | 3 ++-
target/hexagon/cpu.c | 4 ++--
target/hppa/cpu.c | 2 +-
target/i386/cpu.c | 2 +-
target/loongarch/cpu.c | 2 +-
target/m68k/cpu.c | 2 +-
target/microblaze/cpu.c | 2 +-
target/mips/cpu.c | 4 ++--
target/or1k/cpu.c | 2 +-
target/ppc/cpu_init.c | 2 +-
target/riscv/cpu.c | 2 +-
target/rx/cpu.c | 2 +-
target/s390x/cpu-system.c | 4 ++--
target/sh4/cpu.c | 2 +-
target/sparc/cpu.c | 2 +-
target/tricore/cpu.c | 2 +-
target/xtensa/cpu.c | 4 ++--
20 files changed, 27 insertions(+), 26 deletions(-)
diff --git a/include/hw/core/sysemu-cpu-ops.h b/include/hw/core/sysemu-cpu-ops.h
index 9a45596169a..095bdcd997a 100644
--- a/include/hw/core/sysemu-cpu-ops.h
+++ b/include/hw/core/sysemu-cpu-ops.h
@@ -19,10 +19,10 @@ typedef struct SysemuCPUOps {
/**
* @has_work: Callback for checking if there is work to do.
*
- * This function should be idempotent (i.e. not change state) as
+ * This function is idempotent (i.e. not change state) as
* it will likely be queried multiple times before a CPU resumes.
*/
- bool (*has_work)(CPUState *cpu); /* MANDATORY NON-NULL */
+ bool (*has_work)(const CPUState *cpu); /* MANDATORY NON-NULL */
/**
* @get_memory_mapping: Callback for obtaining the memory mappings.
*/
diff --git a/target/alpha/cpu.c b/target/alpha/cpu.c
index 7d1d036e1d3..21d4f8ac23b 100644
--- a/target/alpha/cpu.c
+++ b/target/alpha/cpu.c
@@ -77,7 +77,7 @@ static void alpha_restore_state_to_opc(CPUState *cs,
}
#ifndef CONFIG_USER_ONLY
-static bool alpha_cpu_has_work(CPUState *cs)
+static bool alpha_cpu_has_work(const CPUState *cs)
{
/* Here we are checking to see if the CPU should wake up from HALT.
We will have gotten into this state only for WTINT from PALmode. */
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 9761bb173c1..ba66359d410 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -141,9 +141,9 @@ int arm_cpu_mmu_index(CPUState *cs, bool ifetch)
* CPU_INTERRUPT_*NMI anyway. So we might as well accept NMI here
* unconditionally.
*/
-static bool arm_cpu_has_work(CPUState *cs)
+static bool arm_cpu_has_work(const CPUState *cs)
{
- ARMCPU *cpu = ARM_CPU(cs);
+ const ARMCPU *cpu = ARM_CPU(cs);
/*
* Only another PSCI call can wake the CPU up in which case the
diff --git a/target/avr/cpu.c b/target/avr/cpu.c
index a01e6fa4751..a96bef46ff1 100644
--- a/target/avr/cpu.c
+++ b/target/avr/cpu.c
@@ -23,6 +23,7 @@
#include "qemu/qemu-print.h"
#include "exec/translation-block.h"
#include "system/address-spaces.h"
+#include "hw/core/cpu.h"
#include "cpu.h"
#include "disas/dis-asm.h"
#include "tcg/debug-assert.h"
@@ -43,7 +44,7 @@ static vaddr avr_cpu_get_pc(CPUState *cs)
return cpu->env.pc_w * 2;
}
-static bool avr_cpu_has_work(CPUState *cs)
+static bool avr_cpu_has_work(const CPUState *cs)
{
return cpu_test_interrupt(cs, CPU_INTERRUPT_HARD | CPU_INTERRUPT_RESET)
&& cpu_interrupts_enabled(cpu_env(cs));
diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c
index 4cc6bd67c28..868aef0cde4 100644
--- a/target/hexagon/cpu.c
+++ b/target/hexagon/cpu.c
@@ -364,9 +364,9 @@ bool hexagon_thread_is_enabled(const CPUHexagonState *env)
return E_bit;
}
-static bool hexagon_cpu_has_work(CPUState *cs)
+static bool hexagon_cpu_has_work(const CPUState *cs)
{
- CPUHexagonState *env = cpu_env(cs);
+ const CPUHexagonState *env = cpu_env(cs);
return hexagon_thread_is_enabled(env) &&
(cs->interrupt_request & (CPU_INTERRUPT_HARD | CPU_INTERRUPT_SWI
diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c
index 7b1309a7c38..dbf58466c24 100644
--- a/target/hppa/cpu.c
+++ b/target/hppa/cpu.c
@@ -134,7 +134,7 @@ static void hppa_restore_state_to_opc(CPUState *cs,
}
#ifndef CONFIG_USER_ONLY
-static bool hppa_cpu_has_work(CPUState *cs)
+static bool hppa_cpu_has_work(const CPUState *cs)
{
return cpu_test_interrupt(cs, CPU_INTERRUPT_HARD | CPU_INTERRUPT_NMI);
}
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 1fc02cf94e6..0606ac16664 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -10638,7 +10638,7 @@ int x86_cpu_pending_interrupt(const CPUState *cs, int interrupt_request)
return 0;
}
-static bool x86_cpu_has_work(CPUState *cs)
+static bool x86_cpu_has_work(const CPUState *cs)
{
return x86_cpu_pending_interrupt(cs, cs->interrupt_request) != 0;
}
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index b638ac25040..0ce18a89b63 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -96,7 +96,7 @@ bool cpu_loongarch_hw_interrupts_pending(const CPULoongArchState *env)
#endif
#ifndef CONFIG_USER_ONLY
-static bool loongarch_cpu_has_work(CPUState *cs)
+static bool loongarch_cpu_has_work(const CPUState *cs)
{
bool has_work = false;
diff --git a/target/m68k/cpu.c b/target/m68k/cpu.c
index 523694d8fbf..da3681fab1f 100644
--- a/target/m68k/cpu.c
+++ b/target/m68k/cpu.c
@@ -76,7 +76,7 @@ static void m68k_restore_state_to_opc(CPUState *cs,
}
#ifndef CONFIG_USER_ONLY
-static bool m68k_cpu_has_work(CPUState *cs)
+static bool m68k_cpu_has_work(const CPUState *cs)
{
return cpu_test_interrupt(cs, CPU_INTERRUPT_HARD);
}
diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c
index 6013a8def8e..d1d2f0ec7e3 100644
--- a/target/microblaze/cpu.c
+++ b/target/microblaze/cpu.c
@@ -127,7 +127,7 @@ static void mb_restore_state_to_opc(CPUState *cs,
}
#ifndef CONFIG_USER_ONLY
-static bool mb_cpu_has_work(CPUState *cs)
+static bool mb_cpu_has_work(const CPUState *cs)
{
return cpu_test_interrupt(cs, CPU_INTERRUPT_HARD | CPU_INTERRUPT_NMI);
}
diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index c069aa1c0b7..0f39f8fe0a5 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -134,9 +134,9 @@ static vaddr mips_cpu_get_pc(CPUState *cs)
}
#if !defined(CONFIG_USER_ONLY)
-static bool mips_cpu_has_work(CPUState *cs)
+static bool mips_cpu_has_work(const CPUState *cs)
{
- CPUMIPSState *env = cpu_env(cs);
+ const CPUMIPSState *env = cpu_env(cs);
bool has_work = false;
/*
diff --git a/target/or1k/cpu.c b/target/or1k/cpu.c
index 42d9351b6d7..10b13ae69cd 100644
--- a/target/or1k/cpu.c
+++ b/target/or1k/cpu.c
@@ -76,7 +76,7 @@ static void openrisc_restore_state_to_opc(CPUState *cs,
}
#ifndef CONFIG_USER_ONLY
-static bool openrisc_cpu_has_work(CPUState *cs)
+static bool openrisc_cpu_has_work(const CPUState *cs)
{
return cpu_test_interrupt(cs, CPU_INTERRUPT_HARD | CPU_INTERRUPT_TIMER);
}
diff --git a/target/ppc/cpu_init.c b/target/ppc/cpu_init.c
index 85a91ff4bb6..fd63cd6ab09 100644
--- a/target/ppc/cpu_init.c
+++ b/target/ppc/cpu_init.c
@@ -7224,7 +7224,7 @@ static int ppc_cpu_mmu_index(CPUState *cs, bool ifetch)
#endif /* CONFIG_TCG */
#ifndef CONFIG_USER_ONLY
-static bool ppc_cpu_has_work(CPUState *cs)
+static bool ppc_cpu_has_work(const CPUState *cs)
{
return cpu_test_interrupt(cs, CPU_INTERRUPT_HARD);
}
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 4abf20d057a..3560fbd445e 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -950,7 +950,7 @@ int riscv_cpu_vsirq_pending(const CPURISCVState *env)
(irqs | irqs_f_vs), env->hviprio);
}
-static bool riscv_cpu_has_work(CPUState *cs)
+static bool riscv_cpu_has_work(const CPUState *cs)
{
CPURISCVState *env = cpu_env(cs);
/*
diff --git a/target/rx/cpu.c b/target/rx/cpu.c
index 69946928995..dfa09a85bce 100644
--- a/target/rx/cpu.c
+++ b/target/rx/cpu.c
@@ -73,7 +73,7 @@ static void rx_restore_state_to_opc(CPUState *cs,
cpu->env.pc = data[0];
}
-static bool rx_cpu_has_work(CPUState *cs)
+static bool rx_cpu_has_work(const CPUState *cs)
{
return cpu_test_interrupt(cs, CPU_INTERRUPT_HARD | CPU_INTERRUPT_FIR);
}
diff --git a/target/s390x/cpu-system.c b/target/s390x/cpu-system.c
index 84faceb3338..3a0ff46e144 100644
--- a/target/s390x/cpu-system.c
+++ b/target/s390x/cpu-system.c
@@ -39,9 +39,9 @@
#include "system/tcg.h"
#include "hw/core/sysemu-cpu-ops.h"
-static bool s390_cpu_has_work(CPUState *cs)
+static bool s390_cpu_has_work(const CPUState *cs)
{
- S390CPU *cpu = S390_CPU(cs);
+ const S390CPU *cpu = S390_CPU(cs);
/* STOPPED cpus can never wake up */
if (s390_cpu_get_state(cpu) != S390_CPU_STATE_LOAD &&
diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
index 55c73a1da35..b0ed356d0f7 100644
--- a/target/sh4/cpu.c
+++ b/target/sh4/cpu.c
@@ -107,7 +107,7 @@ static bool superh_io_recompile_replay_branch(CPUState *cs,
return false;
}
-static bool superh_cpu_has_work(CPUState *cs)
+static bool superh_cpu_has_work(const CPUState *cs)
{
return cpu_test_interrupt(cs, CPU_INTERRUPT_HARD);
}
diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
index 2baa5036871..8dd9b0d5ee3 100644
--- a/target/sparc/cpu.c
+++ b/target/sparc/cpu.c
@@ -783,7 +783,7 @@ static void sparc_restore_state_to_opc(CPUState *cs,
}
#ifndef CONFIG_USER_ONLY
-static bool sparc_cpu_has_work(CPUState *cs)
+static bool sparc_cpu_has_work(const CPUState *cs)
{
return cpu_test_interrupt(cs, CPU_INTERRUPT_HARD) &&
cpu_interrupts_enabled(cpu_env(cs));
diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c
index 82b56c3cd56..357f3737053 100644
--- a/target/tricore/cpu.c
+++ b/target/tricore/cpu.c
@@ -111,7 +111,7 @@ static void tricore_cpu_reset_hold(Object *obj, ResetType type)
cpu_state_reset(cpu_env(cs));
}
-static bool tricore_cpu_has_work(CPUState *cs)
+static bool tricore_cpu_has_work(const CPUState *cs)
{
/* Interrupts are not implemented */
return true;
diff --git a/target/xtensa/cpu.c b/target/xtensa/cpu.c
index 99c8bd4b5fb..1b299568776 100644
--- a/target/xtensa/cpu.c
+++ b/target/xtensa/cpu.c
@@ -140,9 +140,9 @@ static void xtensa_restore_state_to_opc(CPUState *cs,
}
#ifndef CONFIG_USER_ONLY
-static bool xtensa_cpu_has_work(CPUState *cs)
+static bool xtensa_cpu_has_work(const CPUState *cs)
{
- CPUXtensaState *env = cpu_env(cs);
+ const CPUXtensaState *env = cpu_env(cs);
return !env->runstall && env->pending_irq_level;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [PATCH v2 13/15] cpus: Add const-qualified CPU environment accessors
2026-08-20 20:13 ` [PATCH v2 13/15] cpus: Add const-qualified CPU environment accessors Philippe Mathieu-Daudé
@ 2026-08-20 23:17 ` Richard Henderson
0 siblings, 0 replies; 20+ messages in thread
From: Richard Henderson @ 2026-08-20 23:17 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x, qemu-ppc,
Pierrick Bouvier, qemu-arm, Philippe Mathieu-Daudé,
Marc-André Lureau, Philippe Mathieu-Daudé, Zhao Liu
On 8/20/26 13:13, Philippe Mathieu-Daudé wrote:
> From: Philippe Mathieu-Daudé<philmd@linaro.org>
>
> Use _Generic() controlling-expression to add the const-qualified
> variants of cpu_env(), env_cpu() and env_archcpu(). This allows to
> safely access CPU architecture state when it should not be modified.
>
> Alias env_cpu_const() which is still used.
>
> Suggested-by: Richard Henderson<richard.henderson@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@oss.qualcomm.com>
> Reviewed-by: Marc-André Lureau<marcandre.lureau@redhat.com>
> ---
> include/exec/cpu-common.h | 30 +++++++++++-------------------
> include/hw/core/cpu.h | 17 ++++++++++++-----
> 2 files changed, 23 insertions(+), 24 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v2 14/15] linux-user: Replace env_cpu_const() by generic env_cpu() equivalent
2026-08-20 20:13 ` [PATCH v2 14/15] linux-user: Replace env_cpu_const() by generic env_cpu() equivalent Philippe Mathieu-Daudé
@ 2026-08-20 23:17 ` Richard Henderson
0 siblings, 0 replies; 20+ messages in thread
From: Richard Henderson @ 2026-08-20 23:17 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x, qemu-ppc,
Pierrick Bouvier, qemu-arm, Philippe Mathieu-Daudé,
Laurent Vivier, Helge Deller
On 8/20/26 13:13, Philippe Mathieu-Daudé wrote:
> Use the generic env_cpu() macro introduced in the previous
> commit and remove the few env_cpu_const() uses.
>
> Signed-off-by: Philippe Mathieu-Daudé<philmd@oss.qualcomm.com>
> ---
> include/exec/cpu-common.h | 1 -
> linux-user/elfload.c | 2 +-
> linux-user/i386/elfload.c | 2 +-
> linux-user/x86_64/elfload.c | 2 +-
> 4 files changed, 3 insertions(+), 4 deletions(-)
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v2 12/15] linux-user: Uncast void pointer argument as Object in target_cpu_free()
2026-08-20 20:13 ` [PATCH v2 12/15] linux-user: Uncast void pointer argument as Object in target_cpu_free() Philippe Mathieu-Daudé
@ 2026-08-20 23:21 ` Richard Henderson
0 siblings, 0 replies; 20+ messages in thread
From: Richard Henderson @ 2026-08-20 23:21 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x, qemu-ppc,
Pierrick Bouvier, qemu-arm, Laurent Vivier, Helge Deller
On 8/20/26 13:13, Philippe Mathieu-Daudé wrote:
> init_main_thread() is registered as Object::free() hook, thus
> take an Object* argument. Uncast the void pointer as such.
>
> While now cpu_env() accept any pointer type, next commit will
> restrict it to CPUState* type. QOM-cast the Object to CPU type,
> otherwise we will get:
>
> ../linux-user/i386/cpu_loop.c: In function ‘target_cpu_free’:
> include/hw/core/cpu.h:604:31: error: ‘_Generic’ selector of type ‘void’ is not compatible with any association
> ../linux-user/x86_64/../i386/cpu_loop.c:331:19: note: in expansion of macro ‘cpu_env’
> 331 | target_munmap(cpu_env(obj)->gdt.base,
> | ^~~~~~~
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@oss.qualcomm.com>
> ---
> linux-user/i386/cpu_loop.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/linux-user/i386/cpu_loop.c b/linux-user/i386/cpu_loop.c
> index fe922fceb5a..a0790f3f352 100644
> --- a/linux-user/i386/cpu_loop.c
> +++ b/linux-user/i386/cpu_loop.c
> @@ -326,9 +326,10 @@ void cpu_loop(CPUX86State *env)
> }
> }
>
> -static void target_cpu_free(void *obj)
> +static void target_cpu_free(void *ptr)
> {
> - target_munmap(cpu_env(obj)->gdt.base,
> + Object *obj = ptr;
> + target_munmap(cpu_env(CPU(obj))->gdt.base,
If you're going to have any dynamic cast, you might as well use
X86_CPU(obj)->env.gdt.base.
Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
` (14 preceding siblings ...)
2026-08-20 20:13 ` [PATCH v2 15/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
@ 2026-08-21 10:28 ` Philippe Mathieu-Daudé
15 siblings, 0 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-08-21 10:28 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, Peter Maydell, Paolo Bonzini, qemu-s390x,
Richard Henderson, qemu-ppc, Pierrick Bouvier, qemu-arm
On 20/8/26 22:13, Philippe Mathieu-Daudé wrote:
> Missing review: 2,12,14,15
>
> Since v1:
> - use _Generic (rth)
> - no more RFC
>
> - Patches 2-11 trivially add const qualifier for various
> cpu_is/has() getters
> - Patch 12-14 add const-qualified variants of cpu_env(),
> env_cpu(), and env_archcpu() using _Generic() macros;
> consolidate the redundant env_cpu_const() alias and update
> linux-user to use the generic accessor
After reworking _Generic from v1, this patchset ordering is not
bisectable anymore. Patches 12-14 must come first.
> - Patch 15 finally convert the SysemuCPUOps::has_work
> hook and all target implementations.
>
> No functional change; purely const-correctness improvment
> to enforce has_work() callees don't mutate CPUState.
> Philippe Mathieu-Daudé (15):
> target/tricore: Document architectural interrupts as not implemented
> system/cpus: Constify various CPUState arguments
> target/avr: Constify CPUAVRState for some cpu_*() getters
> target/hexagon: Constify CPUHexagonState in
> hexagon_thread_is_enabled()
> target/i386: Constify CPU*State for cpu_*_interrupt() getters
> target/loongarch: Constify CPULoongArchState for various cpu_*()
> getters
> target/mips: Constify CPUMIPSState for various cpu_*() getters
> target/s390x: Constify S390CPU for cpu_has_*() getters
> target/riscv: Constify @iprio argument in riscv_cpu_pending_to_irq()
> target/riscv: Constify CPURISCVState for various cpu_*() getters
> target/sparc: Constify CPUSPARCState for various cpu_*() getters
> linux-user: Uncast void pointer argument as Object in
> target_cpu_free()
> cpus: Add const-qualified CPU environment accessors
> linux-user: Replace env_cpu_const() by generic env_cpu() equivalent
> cpus: Constify @cpu in SysemuCPUOps::has_work() handler
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2026-08-21 10:29 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-20 20:13 [PATCH v2 00/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 01/15] target/tricore: Document architectural interrupts as not implemented Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 02/15] system/cpus: Constify various CPUState arguments Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 03/15] target/avr: Constify CPUAVRState for some cpu_*() getters Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 04/15] target/hexagon: Constify CPUHexagonState in hexagon_thread_is_enabled() Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 05/15] target/i386: Constify CPU*State for cpu_*_interrupt() getters Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 06/15] target/loongarch: Constify CPULoongArchState for various cpu_*() getters Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 07/15] target/mips: Constify CPUMIPSState " Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 08/15] target/s390x: Constify S390CPU for cpu_has_*() getters Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 09/15] target/riscv: Constify @iprio argument in riscv_cpu_pending_to_irq() Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 10/15] target/riscv: Constify CPURISCVState for various cpu_*() getters Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 11/15] target/sparc: Constify CPUSPARCState " Philippe Mathieu-Daudé
2026-08-20 20:13 ` [PATCH v2 12/15] linux-user: Uncast void pointer argument as Object in target_cpu_free() Philippe Mathieu-Daudé
2026-08-20 23:21 ` Richard Henderson
2026-08-20 20:13 ` [PATCH v2 13/15] cpus: Add const-qualified CPU environment accessors Philippe Mathieu-Daudé
2026-08-20 23:17 ` Richard Henderson
2026-08-20 20:13 ` [PATCH v2 14/15] linux-user: Replace env_cpu_const() by generic env_cpu() equivalent Philippe Mathieu-Daudé
2026-08-20 23:17 ` Richard Henderson
2026-08-20 20:13 ` [PATCH v2 15/15] cpus: Constify @cpu in SysemuCPUOps::has_work() handler Philippe Mathieu-Daudé
2026-08-21 10:28 ` [PATCH v2 00/15] " Philippe Mathieu-Daudé
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.