All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/21] accel/tcg: Make halt-to-exec transition explicit and remove cpu_exec_halt
@ 2026-09-23 17:10 Philippe Mathieu-Daudé
  2026-09-23 17:10 ` [PATCH v3 01/21] system: Document has_work() synchronization requirements Philippe Mathieu-Daudé
                   ` (20 more replies)
  0 siblings, 21 replies; 29+ messages in thread
From: Philippe Mathieu-Daudé @ 2026-09-23 17:10 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-s390x, qemu-ppc, qemu-arm, Paolo Bonzini, qemu-riscv,
	Richard Henderson, Peter Maydell, Philippe Mathieu-Daudé

Missing review: 4, 7, 9-12, 17

Since v2:
- Make all ARM halt_reason accesses atomic, including WFI/WFE helpers
  and halt-exit handling, and read event_register atomically.
- Keep the RISC-V changes focused on MIP: skip empty updates, add a
  shared accessor, and convert existing MIP reads to use it.

Since v1:
- Collected Richard R-b tags (sometimes commit description updated).
- Documented the BQL and synchronization requirements of has_work().
- Renamed the callbacks to poll_during_halt() and leaving_halt().
- Addressed Peter's comments by removing racy halt-work assertions,
  documenting the BQL contract, and explaining why x86 #DB delivery
  through do_interrupt_all() is safe without the BQL.
- Addressed Paolo's comments by making ARM PSCI state updates atomic,
  kicking remote vCPUs after power-state changes, and ensuring x86
  APIC polling runs before cpu_has_work() with the BQL held only
  around APIC access.
- Sanitized s390_cpu_get_state() for atomic accesses without BQL.

This series was inspired by a previous thread on the list [*].

Refactor the CPU halt-to-execution transition logic in TCG as
something more explicit and composable.

Core problem: TCGCPUOps::cpu_exec_halt callback mixed concerns,
it checked for work, processed async events, and handled state
transitions all in one place.

Solution: introduces two dedicated callbacks:

  * poll_during_halt(): Process target-specific async events
    before checking for work. Called early in cpu_exec().

  * leaving_halt(): Perform target-specific state updates
    when transitioning from halt to execution.

This separation allows the generic cpu_exec() code to orchestrate
the flow cleanly (process events, check for work, transition state).

Only 2 targets need to be migrated (x86 and ARM) then we can remove
the redundant cpu_exec_halt() hook.

The changes are expected to be purely refactoring with no functional
impact.

[*] https://lore.kernel.org/qemu-devel/CABgObfaDAhrpnVqQaKgG6uxPQe1YDu77YOsUEx9nqrN=3M2cGw@mail.gmail.com/

Philippe Mathieu-Daudé (21):
  system: Document has_work() synchronization requirements
  target/s390x: Use s390_cpu_get_state() consistently
  target/s390x: Make s390_cpu_set_state() return void
  target/s390x: Use S390CpuState for CPU state APIs
  target/s390x: Access S390CpuState atomically
  target/arm: Un-inline arm_set_cpu_power_state()
  target/arm: Kick vCPU after updating PSCI power state
  target/arm: Access PSCI state atomically
  target/arm: Access halt state atomically
  target/riscv: Skip empty MIP updates
  target/riscv: Add riscv_cpu_get_mip()
  target/riscv: Access MIP atomically
  accel/tcg: Refactor poll-while-halted flow in cpu_exec()
  accel/tcg: Introduce poll_during_halt() and leaving_halt()
  target/arm: Split leaving-halt handling from arm_cpu_exec_halt()
  target/arm: Convert cpu_exec_halt() to leaving_halt()
  target/i386: Use an acquire load for interrupt_request
  target/i386: Split APIC polling from x86_cpu_exec_halt()
  target/i386: Split leaving-halt handling from x86_cpu_exec_halt()
  target/i386: Use generic halt transition handlers
  accel/tcg: Remove the redundant cpu_exec_halt() hook

 include/accel/tcg/cpu-ops.h         | 36 ++++++++++++++++-------------
 include/hw/core/sysemu-cpu-ops.h    |  6 +++--
 target/arm/internals.h              | 11 +--------
 target/i386/tcg/helper-tcg.h        |  3 ++-
 target/loongarch/internals.h        |  1 -
 target/riscv/cpu.h                  |  1 +
 target/riscv/internals.h            |  5 ----
 target/s390x/cpu.h                  |  9 ++++----
 target/s390x/kvm/kvm_s390x.h        |  2 +-
 target/s390x/s390x-internal.h       |  1 -
 accel/tcg/cpu-exec.c                | 20 ++++++++++------
 hw/intc/riscv_aclint.c              |  2 +-
 hw/intc/s390_flic.c                 |  7 ++++--
 target/alpha/cpu.c                  |  1 -
 target/arm/arm-powerctl.c           | 13 +++++++++++
 target/arm/cpu.c                    | 31 +++++++++++--------------
 target/arm/tcg/cpu-v7m.c            |  1 -
 target/arm/tcg/op_helper.c          |  8 +++----
 target/avr/cpu.c                    |  1 -
 target/hexagon/cpu.c                |  1 -
 target/hppa/cpu.c                   |  1 -
 target/i386/cpu.c                   |  5 +++-
 target/i386/tcg/system/seg_helper.c | 17 +++++++++-----
 target/i386/tcg/tcg-cpu.c           |  3 ++-
 target/loongarch/cpu.c              |  2 +-
 target/loongarch/tcg/tcg_cpu.c      |  1 -
 target/m68k/cpu.c                   |  1 -
 target/microblaze/cpu.c             |  1 -
 target/mips/cpu.c                   |  1 -
 target/or1k/cpu.c                   |  1 -
 target/ppc/cpu_init.c               |  1 -
 target/riscv/cpu.c                  |  5 ++--
 target/riscv/tcg/cpu_helper.c       | 20 ++++++++++++----
 target/riscv/tcg/csr.c              |  6 +++--
 target/riscv/tcg/tcg-cpu.c          |  1 -
 target/rx/cpu.c                     |  1 -
 target/s390x/cpu-system.c           | 26 ++++++++++++---------
 target/s390x/cpu.c                  |  3 +--
 target/s390x/kvm/kvm.c              |  4 ++--
 target/s390x/kvm/stubs.c            |  2 +-
 target/s390x/machine.c              |  2 +-
 target/s390x/sigp.c                 |  9 ++++++--
 target/sh4/cpu.c                    |  1 -
 target/sparc/cpu.c                  |  1 -
 target/tricore/cpu.c                |  1 -
 target/xtensa/cpu.c                 |  1 -
 46 files changed, 150 insertions(+), 127 deletions(-)

-- 
2.53.0



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

end of thread, other threads:[~2026-09-28  6:27 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-23 17:10 [PATCH v3 00/21] accel/tcg: Make halt-to-exec transition explicit and remove cpu_exec_halt Philippe Mathieu-Daudé
2026-09-23 17:10 ` [PATCH v3 01/21] system: Document has_work() synchronization requirements Philippe Mathieu-Daudé
2026-09-23 17:10 ` [PATCH v3 02/21] target/s390x: Use s390_cpu_get_state() consistently Philippe Mathieu-Daudé
2026-09-23 17:10 ` [PATCH v3 03/21] target/s390x: Make s390_cpu_set_state() return void Philippe Mathieu-Daudé
2026-09-23 17:10 ` [PATCH v3 04/21] target/s390x: Use S390CpuState for CPU state APIs Philippe Mathieu-Daudé
2026-09-23 17:32   ` Eric Farman
2026-09-23 17:10 ` [PATCH v3 05/21] target/s390x: Access S390CpuState atomically Philippe Mathieu-Daudé
2026-09-23 17:11 ` [PATCH v3 06/21] target/arm: Un-inline arm_set_cpu_power_state() Philippe Mathieu-Daudé
2026-09-23 17:11 ` [PATCH v3 07/21] target/arm: Kick vCPU after updating PSCI power state Philippe Mathieu-Daudé
2026-09-23 17:11 ` [PATCH v3 08/21] target/arm: Access PSCI state atomically Philippe Mathieu-Daudé
2026-09-23 17:11 ` [PATCH v3 09/21] target/arm: Access halt " Philippe Mathieu-Daudé
2026-09-23 17:29   ` Richard Henderson
2026-09-23 17:11 ` [PATCH v3 10/21] target/riscv: Skip empty MIP updates Philippe Mathieu-Daudé
2026-09-23 19:02   ` Richard Henderson
2026-09-23 17:11 ` [PATCH v3 11/21] target/riscv: Add riscv_cpu_get_mip() Philippe Mathieu-Daudé
2026-09-23 19:04   ` Richard Henderson
2026-09-23 17:11 ` [PATCH v3 12/21] target/riscv: Access MIP atomically Philippe Mathieu-Daudé
2026-09-23 19:05   ` Richard Henderson
2026-09-23 17:11 ` [PATCH v3 13/21] accel/tcg: Refactor poll-while-halted flow in cpu_exec() Philippe Mathieu-Daudé
2026-09-23 17:11 ` [PATCH v3 14/21] accel/tcg: Introduce poll_during_halt() and leaving_halt() Philippe Mathieu-Daudé
2026-09-23 17:11 ` [PATCH v3 15/21] target/arm: Split leaving-halt handling from arm_cpu_exec_halt() Philippe Mathieu-Daudé
2026-09-23 17:11 ` [PATCH v3 16/21] target/arm: Convert cpu_exec_halt() to leaving_halt() Philippe Mathieu-Daudé
2026-09-23 17:11 ` [PATCH v3 17/21] target/i386: Use an acquire load for interrupt_request Philippe Mathieu-Daudé
2026-09-23 19:18   ` Richard Henderson
2026-09-28  6:26   ` Zhao Liu
2026-09-23 17:11 ` [PATCH v3 18/21] target/i386: Split APIC polling from x86_cpu_exec_halt() Philippe Mathieu-Daudé
2026-09-23 17:11 ` [PATCH v3 19/21] target/i386: Split leaving-halt handling " Philippe Mathieu-Daudé
2026-09-23 17:11 ` [PATCH v3 20/21] target/i386: Use generic halt transition handlers Philippe Mathieu-Daudé
2026-09-23 17:11 ` [PATCH v3 21/21] accel/tcg: Remove the redundant cpu_exec_halt() hook 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.