[PATCH v3 00/10] accel/tcg: Improve tb_flush usage

Richard Henderson posted 10 patches 4 days, 16 hours ago
Failed in applying to current master (apply log)
Maintainers: Richard Henderson <richard.henderson@linaro.org>, Paolo Bonzini <pbonzini@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.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>, Harsh Prateek Bora <harshpb@linux.ibm.com>, Laurent Vivier <laurent@vivier.eu>, Alexandre Iooss <erdnaxe@crans.org>, Mahmoud Mandour <ma.mandourr@gmail.com>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <dbarboza@ventanamicro.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>
include/exec/tb-flush.h     | 30 ++++++++++++++--------
linux-user/user-internals.h | 16 ++++++++++++
target/alpha/helper.h       |  1 -
accel/tcg/plugin-gen.c      |  4 +--
accel/tcg/tb-maint.c        | 50 +++++++++++++++++++++----------------
accel/tcg/tcg-all.c         | 21 ++++++++++++++++
accel/tcg/translate-all.c   |  6 ++++-
gdbstub/system.c            |  5 ----
gdbstub/user.c              |  3 ---
hw/core/cpu-system.c        |  9 -------
hw/ppc/spapr_hcall.c        |  4 +--
linux-user/alpha/cpu_loop.c |  5 ----
linux-user/mmap.c           | 13 ++--------
linux-user/syscall.c        |  7 +-----
plugins/core.c              |  6 ++---
plugins/loader.c            |  3 +--
target/alpha/sys_helper.c   |  6 -----
target/alpha/translate.c    | 21 +++++-----------
target/riscv/csr.c          |  3 ---
target/riscv/tcg/tcg-cpu.c  |  3 ++-
20 files changed, 108 insertions(+), 108 deletions(-)
[PATCH v3 00/10] accel/tcg: Improve tb_flush usage
Posted by Richard Henderson 4 days, 16 hours ago
It is too easy to mis-use tb_flush().  For instance, because of
the cpu argument, some parts assumed that it needed to call the
global flush function for every cpu.  It is easy to forget that
the flush is not complete when the call returns: we have merely
queued work to the cpu run loop.  So: remove tb_flush and expose
only the core as tb_flush__exclusive, to be used only when we
are already within an exclusive context.

In some cases (gdbstub, alpha, riscv, ppc spapr),
we can eliminate the need for tb_flush completely.

Changes for v3:
  - Rename to tb_flush__exclusive_or_serial; retain the serial
    check within, not updating to exclusive only.
  - Rename the existing tb_flush to queue_tb_flush; retain the
    sequence number check for duplicated flushes.
  - Drop EXCP_TB_FLUSH.
  - Improve buffer overflow flush when we're already serial.
  - Other minor comment/review updates.


r~


Richard Henderson (10):
  gdbstub: Remove tb_flush uses
  target/alpha: Simplify call_pal implementation
  target/riscv: Record misa_ext in TCGTBCPUState.cs_base
  hw/ppc/spapr: Use tb_invalidate_phys_range in h_page_init
  accel/tcg: Split out tb_flush__exclusive_or_serial
  accel/tcg: Move post-load tb_flush to vm_change_state hook
  plugins: Use tb_flush__exclusive_or_serial
  linux-user: Split out begin_parallel_context
  accel/tcg: Create queue_tb_flush from tb_flush
  accel/tcg: Improve buffer overflow in tb_gen_code

 include/exec/tb-flush.h     | 30 ++++++++++++++--------
 linux-user/user-internals.h | 16 ++++++++++++
 target/alpha/helper.h       |  1 -
 accel/tcg/plugin-gen.c      |  4 +--
 accel/tcg/tb-maint.c        | 50 +++++++++++++++++++++----------------
 accel/tcg/tcg-all.c         | 21 ++++++++++++++++
 accel/tcg/translate-all.c   |  6 ++++-
 gdbstub/system.c            |  5 ----
 gdbstub/user.c              |  3 ---
 hw/core/cpu-system.c        |  9 -------
 hw/ppc/spapr_hcall.c        |  4 +--
 linux-user/alpha/cpu_loop.c |  5 ----
 linux-user/mmap.c           | 13 ++--------
 linux-user/syscall.c        |  7 +-----
 plugins/core.c              |  6 ++---
 plugins/loader.c            |  3 +--
 target/alpha/sys_helper.c   |  6 -----
 target/alpha/translate.c    | 21 +++++-----------
 target/riscv/csr.c          |  3 ---
 target/riscv/tcg/tcg-cpu.c  |  3 ++-
 20 files changed, 108 insertions(+), 108 deletions(-)

-- 
2.43.0
Re: [PATCH v3 00/10] accel/tcg: Improve tb_flush usage
Posted by Philippe Mathieu-Daudé 4 days, 2 hours ago
On 23/9/25 23:54, Richard Henderson wrote:
> It is too easy to mis-use tb_flush().  For instance, because of
> the cpu argument, some parts assumed that it needed to call the
> global flush function for every cpu.  It is easy to forget that
> the flush is not complete when the call returns: we have merely
> queued work to the cpu run loop.  So: remove tb_flush and expose
> only the core as tb_flush__exclusive, to be used only when we
> are already within an exclusive context.
> 
> In some cases (gdbstub, alpha, riscv, ppc spapr),
> we can eliminate the need for tb_flush completely.
> 
> Changes for v3:
>    - Rename to tb_flush__exclusive_or_serial; retain the serial
>      check within, not updating to exclusive only.
>    - Rename the existing tb_flush to queue_tb_flush; retain the
>      sequence number check for duplicated flushes.
>    - Drop EXCP_TB_FLUSH.

When using my split-accel branch, I had good results with v2.

I'm getting crashes with v3:

Termination Reason:    Namespace SIGNAL, Code 4 Illegal instruction: 4

Thread 4 Crashed:
0   ???                           	       0x34400fb00 ???
1   qemu-system-aarch64-unsigned  	       0x100fd74dc cpu_tb_exec + 160 (cpu-exec.c:441)
2   qemu-system-aarch64-unsigned  	       0x100fd829c cpu_loop_exec_tb + 32 (cpu-exec.c:897) [inlined]
3   qemu-system-aarch64-unsigned  	       0x100fd829c cpu_exec_loop + 904 (cpu-exec.c:1009)
4   qemu-system-aarch64-unsigned  	       0x100fd7a30 cpu_exec_setjmp + 48 (cpu-exec.c:1026)
5   qemu-system-aarch64-unsigned  	       0x100fd7954 cpu_exec + 496 (cpu-exec.c:1052)
6   qemu-system-aarch64-unsigned  	       0x100ff9bc4 tcg_cpu_exec + 44 (tcg-accel-ops.c:97)
7   qemu-system-aarch64-unsigned  	       0x100ffa4c4 mttcg_cpu_exec + 28 (tcg-accel-ops-mttcg.c:146)
8   qemu-system-aarch64-unsigned  	       0x10140bdac split_cpu_thread_routine + 540 (split-accel-ops.c:87)
9   qemu-system-aarch64-unsigned  	       0x10158f7e0 qemu_thread_start + 132 (qemu-thread-posix.c:393)

Thread 5:
0   qemu-system-aarch64-unsigned  	       0x100fb04e0 tcg_out_ld + 160 (tcg-target.c.inc:1268)
1   qemu-system-aarch64-unsigned  	       0x100fab3f8 tcg_reg_alloc_op + 240 [inlined]
2   qemu-system-aarch64-unsigned  	       0x100fab3f8 tcg_gen_code + 7932 (tcg.c:7018)
3   qemu-system-aarch64-unsigned  	       0x100fe9e88 setjmp_gen_code + 184 (translate-all.c:257)
4   qemu-system-aarch64-unsigned  	       0x100fe9780 tb_gen_code + 364 (translate-all.c:324)
5   qemu-system-aarch64-unsigned  	       0x100fd8138 cpu_exec_loop + 548 (cpu-exec.c:980)
6   qemu-system-aarch64-unsigned  	       0x100fd7a30 cpu_exec_setjmp + 48 (cpu-exec.c:1026)
7   qemu-system-aarch64-unsigned  	       0x100fd7954 cpu_exec + 496 (cpu-exec.c:1052)
8   qemu-system-aarch64-unsigned  	       0x100ff9bc4 tcg_cpu_exec + 44 (tcg-accel-ops.c:97)
9   qemu-system-aarch64-unsigned  	       0x100ffa4c4 mttcg_cpu_exec + 28 (tcg-accel-ops-mttcg.c:146)
10  qemu-system-aarch64-unsigned  	       0x10140bdac split_cpu_thread_routine + 540 (split-accel-ops.c:87)
11  qemu-system-aarch64-unsigned  	       0x10158f7e0 qemu_thread_start + 132 (qemu-thread-posix.c:393)
Re: [PATCH v3 00/10] accel/tcg: Improve tb_flush usage
Posted by Richard Henderson 3 days, 22 hours ago
On 9/24/25 05:14, Philippe Mathieu-Daudé wrote:
> On 23/9/25 23:54, Richard Henderson wrote:
>> It is too easy to mis-use tb_flush().  For instance, because of
>> the cpu argument, some parts assumed that it needed to call the
>> global flush function for every cpu.  It is easy to forget that
>> the flush is not complete when the call returns: we have merely
>> queued work to the cpu run loop.  So: remove tb_flush and expose
>> only the core as tb_flush__exclusive, to be used only when we
>> are already within an exclusive context.
>>
>> In some cases (gdbstub, alpha, riscv, ppc spapr),
>> we can eliminate the need for tb_flush completely.
>>
>> Changes for v3:
>>    - Rename to tb_flush__exclusive_or_serial; retain the serial
>>      check within, not updating to exclusive only.
>>    - Rename the existing tb_flush to queue_tb_flush; retain the
>>      sequence number check for duplicated flushes.
>>    - Drop EXCP_TB_FLUSH.
> 
> When using my split-accel branch, I had good results with v2.
> 
> I'm getting crashes with v3:

Are you sure you didn't just get lucky with v2?
There's little functional change to v3...

Point me at your branch?  While I can't test HVF, I can double-check at how you integrated 
the flush.


r~