[PATCH v2 00/18] accel, cpus: clean up cpu->exit_request

Paolo Bonzini posted 18 patches 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250829152909.1589668-1-pbonzini@redhat.com
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>, Phil Dennis-Jordan <phil@philjordan.eu>, Mads Ynddal <mads@ynddal.dk>, Riku Voipio <riku.voipio@iki.fi>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, Nicholas Piggin <npiggin@gmail.com>, Chinmay Rath <rathc@linux.ibm.com>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Laurent Vivier <laurent@vivier.eu>, Brian Cain <brian.cain@oss.qualcomm.com>, "Alex Bennée" <alex.bennee@linaro.org>, Peter Maydell <peter.maydell@linaro.org>, Michael Rolnik <mrolnik@gmail.com>, Marcelo Tosatti <mtosatti@redhat.com>, Reinoud Zandijk <reinoud@netbsd.org>, Sunil Muthuswamy <sunilmut@microsoft.com>, Stafford Horne <shorne@gmail.com>, Yoshinori Sato <yoshinori.sato@nifty.com>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Thomas Huth <thuth@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Artyom Tarasenko <atar4qemu@gmail.com>
docs/devel/tcg-icount.rst           |   2 +-
accel/tcg/tcg-accel-ops-mttcg.h     |   3 -
accel/tcg/tcg-accel-ops.h           |   1 +
bsd-user/aarch64/target_arch_cpu.h  |   2 +-
bsd-user/arm/target_arch_cpu.h      |   2 +-
bsd-user/i386/target_arch_cpu.h     |   2 +-
bsd-user/riscv/target_arch_cpu.h    |   2 +-
bsd-user/x86_64/target_arch_cpu.h   |   2 +-
include/hw/core/cpu.h               |  22 +-
include/system/cpus.h               |   1 -
target/arm/internals.h              |   5 +
accel/dummy-cpus.c                  |   2 +-
accel/hvf/hvf-accel-ops.c           |   2 +-
accel/kvm/kvm-accel-ops.c           |   3 +-
accel/kvm/kvm-all.c                 |  23 +-
accel/tcg/cpu-exec.c                |  34 ++-
accel/tcg/tcg-accel-ops-mttcg.c     |  12 +-
accel/tcg/tcg-accel-ops-rr.c        |  42 +--
accel/tcg/tcg-accel-ops.c           |   4 +-
accel/tcg/user-exec.c               |  11 +-
bsd-user/main.c                     |   5 -
cpu-common.c                        |   3 +-
hw/core/cpu-common.c                |  19 +-
hw/core/cpu-system.c                |   2 +-
hw/ppc/ppc.c                        |   2 +
hw/ppc/spapr_hcall.c                |   7 +-
hw/ppc/spapr_rtas.c                 |   2 +-
linux-user/aarch64/cpu_loop.c       |   2 +-
linux-user/alpha/cpu_loop.c         |   2 +-
linux-user/arm/cpu_loop.c           |   2 +-
linux-user/hexagon/cpu_loop.c       |   2 +-
linux-user/hppa/cpu_loop.c          |   2 +-
linux-user/i386/cpu_loop.c          |   2 +-
linux-user/loongarch64/cpu_loop.c   |   2 +-
linux-user/m68k/cpu_loop.c          |   2 +-
linux-user/main.c                   |   5 -
linux-user/microblaze/cpu_loop.c    |   2 +-
linux-user/mips/cpu_loop.c          |   2 +-
linux-user/openrisc/cpu_loop.c      |   2 +-
linux-user/ppc/cpu_loop.c           |   2 +-
linux-user/riscv/cpu_loop.c         |   2 +-
linux-user/s390x/cpu_loop.c         |   2 +-
linux-user/sh4/cpu_loop.c           |   2 +-
linux-user/sparc/cpu_loop.c         |   2 +-
linux-user/xtensa/cpu_loop.c        |   2 +-
replay/replay-events.c              |   3 +-
system/cpu-timers.c                 |   6 +-
system/cpus.c                       |   9 +-
target/arm/cpu-irq.c                | 381 ++++++++++++++++++++++++++++
target/arm/cpu.c                    | 370 ---------------------------
target/arm/el2-stubs.c              |  37 +++
target/arm/helper.c                 |   4 +
target/arm/tcg/mte_helper.c         |   2 +-
target/avr/helper.c                 |   4 +-
target/i386/helper.c                |   2 +
target/i386/hvf/x86hvf.c            |   8 +-
target/i386/kvm/hyperv.c            |   1 -
target/i386/kvm/kvm.c               |  20 +-
target/i386/nvmm/nvmm-accel-ops.c   |   8 +-
target/i386/nvmm/nvmm-all.c         |  19 +-
target/i386/tcg/system/seg_helper.c |  13 +-
target/i386/tcg/system/svm_helper.c |   2 +-
target/i386/whpx/whpx-accel-ops.c   |   6 +-
target/i386/whpx/whpx-all.c         |  23 +-
target/openrisc/sys_helper.c        |   2 +-
target/ppc/helper_regs.c            |   2 +
target/rx/helper.c                  |   4 +-
target/s390x/tcg/excp_helper.c      |   2 +-
target/sparc/int32_helper.c         |   2 +
target/sparc/int64_helper.c         |   2 +
target/arm/meson.build              |   2 +
71 files changed, 631 insertions(+), 559 deletions(-)
create mode 100644 target/arm/cpu-irq.c
create mode 100644 target/arm/el2-stubs.c
[PATCH v2 00/18] accel, cpus: clean up cpu->exit_request
Posted by Paolo Bonzini 1 week ago
cpu->exit_request is used to kick vCPU threads into qemu_wait_io_event().
The code that handles the signaling of cpu->exit_request is messy, mostly
due to no one ever taking a look at it as a whole.  In fact already in commit
4b8523ee896 ("kvm: First step to push iothread lock out of inner run loop",
2015-07-01), the read of cpu->exit_request was placed outside the BQL
critical section without much attention to ordering; and it only got
worse from that point, in no small part due to a young and naive me.

This series is complementary to the cpu->interrupt_request cleanups
that Igor did in "memory: reintroduce BQL-free fine-grained PIO/MMIO"
(https://lore.kernel.org/qemu-devel/20250808120137.2208800-1-imammedo@redhat.com/T/),
and in fact includes some extra changes to interrupt_request at the
beginning.

v1->v2:
- new patches 1-8, leftovers from Igor's own cleanup
- patch 9: use "true" instead of 1, editorial cleanups
- dropped "accel/hvf: check exit_request before running the vCPU"
- patch 10: add more comments, use "true" instead of 1
- patch 12: use accel/tcg/tcg-accel-ops.h for prototype, split out
  patch 12 ("accel/tcg: inline cpu_exit()"), place user-mode
  emulation version of qemu_cpu_kick() in accel/tcg/user-exec.c
- patch 14: fix compilation errors
- patch 15: new, fixes infinite loops in user-mode emulation
- patches 16-17: split in two parts
- patch 18: improve commit message

Paolo Bonzini (18):
  target/ppc: limit cpu_interrupt_exittb to system emulation
  target/sparc: limit cpu_check_irqs to system emulation
  target/i386: limit a20 to system emulation
  target-arm: remove uses of cpu_interrupt() for user-mode emulation
  user-exec: remove cpu_interrupt() stub
  treewide: clear bits of cs->interrupt_request with
    cpu_reset_interrupt()
  cpu-common: use atomic access for interrupt_request
  cpus: document that qemu_cpu_kick() can be used for BQL-less operation
  accel: use store_release/load_acquire for cross-thread exit_request
  accel: use atomic accesses for exit_request
  accel/tcg: create a thread-kick function for TCG
  accel/tcg: inline cpu_exit()
  cpus: remove TCG-ism from cpu_exit()
  cpus: properly kick CPUs out of inner execution loop
  bsd-user, linux-user: introduce qemu_wait_io_event
  cpus: clear exit_request in qemu_wait_io_event
  accel: make all calls to qemu_wait_io_event look the same
  tcg/user: do not set exit_request gratuitously

 docs/devel/tcg-icount.rst           |   2 +-
 accel/tcg/tcg-accel-ops-mttcg.h     |   3 -
 accel/tcg/tcg-accel-ops.h           |   1 +
 bsd-user/aarch64/target_arch_cpu.h  |   2 +-
 bsd-user/arm/target_arch_cpu.h      |   2 +-
 bsd-user/i386/target_arch_cpu.h     |   2 +-
 bsd-user/riscv/target_arch_cpu.h    |   2 +-
 bsd-user/x86_64/target_arch_cpu.h   |   2 +-
 include/hw/core/cpu.h               |  22 +-
 include/system/cpus.h               |   1 -
 target/arm/internals.h              |   5 +
 accel/dummy-cpus.c                  |   2 +-
 accel/hvf/hvf-accel-ops.c           |   2 +-
 accel/kvm/kvm-accel-ops.c           |   3 +-
 accel/kvm/kvm-all.c                 |  23 +-
 accel/tcg/cpu-exec.c                |  34 ++-
 accel/tcg/tcg-accel-ops-mttcg.c     |  12 +-
 accel/tcg/tcg-accel-ops-rr.c        |  42 +--
 accel/tcg/tcg-accel-ops.c           |   4 +-
 accel/tcg/user-exec.c               |  11 +-
 bsd-user/main.c                     |   5 -
 cpu-common.c                        |   3 +-
 hw/core/cpu-common.c                |  19 +-
 hw/core/cpu-system.c                |   2 +-
 hw/ppc/ppc.c                        |   2 +
 hw/ppc/spapr_hcall.c                |   7 +-
 hw/ppc/spapr_rtas.c                 |   2 +-
 linux-user/aarch64/cpu_loop.c       |   2 +-
 linux-user/alpha/cpu_loop.c         |   2 +-
 linux-user/arm/cpu_loop.c           |   2 +-
 linux-user/hexagon/cpu_loop.c       |   2 +-
 linux-user/hppa/cpu_loop.c          |   2 +-
 linux-user/i386/cpu_loop.c          |   2 +-
 linux-user/loongarch64/cpu_loop.c   |   2 +-
 linux-user/m68k/cpu_loop.c          |   2 +-
 linux-user/main.c                   |   5 -
 linux-user/microblaze/cpu_loop.c    |   2 +-
 linux-user/mips/cpu_loop.c          |   2 +-
 linux-user/openrisc/cpu_loop.c      |   2 +-
 linux-user/ppc/cpu_loop.c           |   2 +-
 linux-user/riscv/cpu_loop.c         |   2 +-
 linux-user/s390x/cpu_loop.c         |   2 +-
 linux-user/sh4/cpu_loop.c           |   2 +-
 linux-user/sparc/cpu_loop.c         |   2 +-
 linux-user/xtensa/cpu_loop.c        |   2 +-
 replay/replay-events.c              |   3 +-
 system/cpu-timers.c                 |   6 +-
 system/cpus.c                       |   9 +-
 target/arm/cpu-irq.c                | 381 ++++++++++++++++++++++++++++
 target/arm/cpu.c                    | 370 ---------------------------
 target/arm/el2-stubs.c              |  37 +++
 target/arm/helper.c                 |   4 +
 target/arm/tcg/mte_helper.c         |   2 +-
 target/avr/helper.c                 |   4 +-
 target/i386/helper.c                |   2 +
 target/i386/hvf/x86hvf.c            |   8 +-
 target/i386/kvm/hyperv.c            |   1 -
 target/i386/kvm/kvm.c               |  20 +-
 target/i386/nvmm/nvmm-accel-ops.c   |   8 +-
 target/i386/nvmm/nvmm-all.c         |  19 +-
 target/i386/tcg/system/seg_helper.c |  13 +-
 target/i386/tcg/system/svm_helper.c |   2 +-
 target/i386/whpx/whpx-accel-ops.c   |   6 +-
 target/i386/whpx/whpx-all.c         |  23 +-
 target/openrisc/sys_helper.c        |   2 +-
 target/ppc/helper_regs.c            |   2 +
 target/rx/helper.c                  |   4 +-
 target/s390x/tcg/excp_helper.c      |   2 +-
 target/sparc/int32_helper.c         |   2 +
 target/sparc/int64_helper.c         |   2 +
 target/arm/meson.build              |   2 +
 71 files changed, 631 insertions(+), 559 deletions(-)
 create mode 100644 target/arm/cpu-irq.c
 create mode 100644 target/arm/el2-stubs.c

-- 
2.51.0