Virtuozzo QEMU development (svt-core@virtuozzo.com)
 help / color / mirror / Atom feed
* [PATCH hci-8.0 00/12] system: add a watchdog for the Big QEMU Lock
@ 2026-09-16 13:33 Denis V. Lunev
  2026-09-16 13:33 ` [PATCH hci-8.0 01/12] bql: Fix bql_locked status with condvar APIs #VSTOR-144507 Denis V. Lunev
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: Denis V. Lunev @ 2026-09-16 13:33 UTC (permalink / raw)
  To: svt-core; +Cc: andrey.drobyshev, den

A vCPU thread reacquires the BQL on every exit that needs userspace. A
holder that keeps it for tens of seconds stops every vCPU, the guest
reports a soft lockup or panics, and qemu itself records nothing. The
guest log is the only evidence, and it cannot say whether the hypervisor
held the lock or the guest wedged on its own.

This series adds a BQL watchdog. A sampler thread watches a sequence
counter that bql_update_status() advances on every acquire and release.
One odd value across the whole window means one owner held the lock for
the whole window. On expiry the watchdog names the holder and prints the
state of every other thread:

  qemu-system-x86_64: 2026-09-16T13:21:04Z BQL held for more than 100 ms by thread 927240
    927240  qemu-system-x86  S
        pc 0x7f35a4871e06 ppoll+0xa6
        [<0>] poll_schedule_timeout.constprop.0+0x3a/0x80
        [<0>] do_sys_poll+0x1eb/0x290
        [<0>] __x64_sys_ppoll+0xe0/0x160
    927242  qemu-system-x86  S
        pc 0x7f35a487c57b syscall+0x1b
        [<0>] futex_do_wait+0x38/0x70
        [<0>] __futex_wait+0x92/0x100

Without CAP_SYS_ADMIN the kernel stack collapses to a single wchan line.
The pc line comes from signalling each thread and reading the program
counter out of its signal frame, which is what tells a thread spinning
in userspace from one asleep in a syscall.

The watchdog is off by default and stays quiet under a debugger. Two
machine properties drive it: bql-watchdog-ms sets the deadline, on the
command line or over qom-set at any time, and bql-watchdog-abort turns
the report into a core dump for hosts where the answer is worth more
than the guest.

Patches 3 to 8 are the pieces: a fix for bql_locked across the timed
condvar wait, a debugger check, the per-thread state reader and its
kernel stack and program counter extensions, and the signal reserved for
the latter. Patches 9 to 11 are the watchdog itself. Patch 12 is a
functional test that holds the BQL through an HMP qemu-io write to a
null-co node with a latency longer than the deadline.

This is the hci-8.0 port of the series posted upstream on 2026-09-15:
https://lore.kernel.org/qemu-devel/20260915203455.580999-1-den@openvz.org/

Patches 1 and 2 are the two upstream commits hci-8.0 does not carry and
the rest needs. Patch 1 gives bql_update_status(), which is where the
sequence counter hooks in, so patch 9 does not build without it; patch 2
makes real_time_iso8601() public, because the watchdog stamps its own
report rather than going through error_report(). Both are unmodified
cherry-picks.

Three things differ from the upstream posting, all because 10.1 lays the
tree out differently: the riscv signal-pc.h header goes in
host/include/riscv rather than host/include/riscv64, since meson maps
both riscv32 and riscv64 to host_arch 'riscv'; the functional test sits
in tests/functional rather than tests/functional/generic, and registers
in tests_generic_system there; and hw/core/machine.c has no
x-change-vmfd-on-reset property to anchor against. No code changed.

Built and tested on dev-cl04 with --enable-debug: func-quick passes,
including the two bql_watchdog subtests, and the report above is what
this build prints under -machine none,bql-watchdog-ms=100.

The program counter lives at a host specific offset in the signal frame,
so patch 8 reads it through a host/include header. The Linux headers for
aarch64, ppc64, riscv, s390x and loongarch64 repeat what linux-user's
host-signal.h already knows about those frames, but only the x86_64 one
has been compiled, here as upstream. The Windows half of patch 3 has not
been compiled either.

Signed-off-by: Denis V. Lunev <den@openvz.org>

Denis V. Lunev (10):
  util/qemu-thread: track bql_locked across the timed condvar wait
    #VSTOR-144507
  oslib: add qemu_debugger_attached() #VSTOR-144507
  oslib: add qemu_thread_states() #VSTOR-144507
  oslib: report kernel stacks in qemu_thread_states() #VSTOR-144507
  util/qemu-thread: reserve a signal for thread introspection
    #VSTOR-144507
  oslib: report each thread's program counter #VSTOR-144507
  system/cpus: report a BQL held past a deadline #VSTOR-144507
  system/cpus: hold off the BQL watchdog under a debugger #VSTOR-144507
  system/cpus: add bql-watchdog-abort #VSTOR-144507
  tests/functional: cover the BQL watchdog #VSTOR-144507

Peter Xu (1):
  bql: Fix bql_locked status with condvar APIs #VSTOR-144507

Vladimir Sementsov-Ogievskiy (1):
  error-report: make real_time_iso8601() public #VSTOR-144507

 host/include/aarch64/host/signal-pc.h     |  20 ++
 host/include/generic/host/signal-pc.h     |  11 +
 host/include/loongarch64/host/signal-pc.h |  20 ++
 host/include/ppc64/host/signal-pc.h       |  22 ++
 host/include/riscv/host/signal-pc.h       |  20 ++
 host/include/s390x/host/signal-pc.h       |  20 ++
 host/include/x86_64/host/signal-pc.h      |  20 ++
 hw/core/machine.c                         |  44 +++
 include/qemu/error-report.h               |   6 +
 include/qemu/main-loop.h                  |  18 ++
 include/qemu/osdep.h                      |  29 ++
 include/system/cpus.h                     |   8 +
 meson.build                               |   2 +
 qemu-options.hx                           |  11 +
 stubs/iothread-lock.c                     |   9 +
 system/cpus.c                             | 157 ++++++++++-
 tests/functional/meson.build              |   1 +
 tests/functional/test_bql_watchdog.py     |  60 ++++
 util/error-report.c                       |   3 +-
 util/oslib-posix.c                        | 316 ++++++++++++++++++++++
 util/oslib-win32.c                        |  10 +
 util/qemu-thread-common.h                 |   7 +
 util/qemu-thread-posix.c                  |   8 +-
 util/qemu-thread-win32.c                  |   4 +-
 24 files changed, 818 insertions(+), 8 deletions(-)
 create mode 100644 host/include/aarch64/host/signal-pc.h
 create mode 100644 host/include/generic/host/signal-pc.h
 create mode 100644 host/include/loongarch64/host/signal-pc.h
 create mode 100644 host/include/ppc64/host/signal-pc.h
 create mode 100644 host/include/riscv/host/signal-pc.h
 create mode 100644 host/include/s390x/host/signal-pc.h
 create mode 100644 host/include/x86_64/host/signal-pc.h
 create mode 100755 tests/functional/test_bql_watchdog.py

-- 
2.53.0


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

end of thread, other threads:[~2026-09-16 13:34 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-16 13:33 [PATCH hci-8.0 00/12] system: add a watchdog for the Big QEMU Lock Denis V. Lunev
2026-09-16 13:33 ` [PATCH hci-8.0 01/12] bql: Fix bql_locked status with condvar APIs #VSTOR-144507 Denis V. Lunev
2026-09-16 13:33 ` [PATCH hci-8.0 02/12] error-report: make real_time_iso8601() public #VSTOR-144507 Denis V. Lunev
2026-09-16 13:33 ` [PATCH hci-8.0 03/12] util/qemu-thread: track bql_locked across the timed condvar wait #VSTOR-144507 Denis V. Lunev
2026-09-16 13:33 ` [PATCH hci-8.0 04/12] oslib: add qemu_debugger_attached() #VSTOR-144507 Denis V. Lunev
2026-09-16 13:33 ` [PATCH hci-8.0 05/12] oslib: add qemu_thread_states() #VSTOR-144507 Denis V. Lunev
2026-09-16 13:33 ` [PATCH hci-8.0 06/12] oslib: report kernel stacks in " Denis V. Lunev
2026-09-16 13:33 ` [PATCH hci-8.0 07/12] util/qemu-thread: reserve a signal for thread introspection #VSTOR-144507 Denis V. Lunev
2026-09-16 13:33 ` [PATCH hci-8.0 08/12] oslib: report each thread's program counter #VSTOR-144507 Denis V. Lunev
2026-09-16 13:33 ` [PATCH hci-8.0 09/12] system/cpus: report a BQL held past a deadline #VSTOR-144507 Denis V. Lunev
2026-09-16 13:33 ` [PATCH hci-8.0 10/12] system/cpus: hold off the BQL watchdog under a debugger #VSTOR-144507 Denis V. Lunev
2026-09-16 13:33 ` [PATCH hci-8.0 11/12] system/cpus: add bql-watchdog-abort #VSTOR-144507 Denis V. Lunev
2026-09-16 13:33 ` [PATCH hci-8.0 12/12] tests/functional: cover the BQL watchdog #VSTOR-144507 Denis V. Lunev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox