All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for 11.0-rc3] accel/kvm: Fix BQL lock imbalance in kvm_cpu_exec
@ 2026-04-09 16:10 Harsh Prateek Bora
  2026-04-10  3:42 ` Ani Sinha
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Harsh Prateek Bora @ 2026-04-09 16:10 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc
  Cc: anisinha, pbonzini, npiggin, misanjum, gautam, peter.maydell

When kvm_cpu_exec() returns EXCP_HLT due to kvm_arch_process_async_events()
returning true, it was returning before releasing the BQL (Big QEMU Lock).
This caused a lock imbalance where the vCPU thread would loop back to
kvm_cpu_exec() while still holding the BQL, leading to deadlocks.

The issue manifests as boot hangs on PowerPC pseries machines with multiple
vCPUs, where secondary vCPUs with start-powered-off=true remain halted and
repeatedly call kvm_cpu_exec() which returns EXCP_HLT. Each iteration held
the BQL, preventing other operations from proceeding.

The fix has two parts:

1. In kvm_cpu_exec() (kvm-all.c):
   Release the BQL before returning EXCP_HLT in the early return path,
   matching the behavior of the normal execution path where bql_unlock()
   is called before entering the main KVM execution loop.

2. In kvm_vcpu_thread_fn() (kvm-accel-ops.c):
   Re-acquire the BQL after kvm_cpu_exec() returns EXCP_HLT, since the
   loop expects to hold the BQL when calling kvm_cpu_exec() again.

This ensures proper BQL lock/unlock pairing:
- kvm_vcpu_thread_fn() holds BQL before calling kvm_cpu_exec()
- kvm_cpu_exec() releases BQL before returning (for EXCP_HLT)
- kvm_vcpu_thread_fn() re-acquires BQL if EXCP_HLT was returned
- Next iteration has BQL held as expected

This is a regression introduced by commit 98884e0cc1 ("accel/kvm: add
changes required to support KVM VM file descriptor change") which
refactored kvm_irqchip_create() and changed the initialization timing,
exposing this lock imbalance issue.

Fixes: 98884e0cc1 ("accel/kvm: add changes required to support KVM VM file descriptor change")
Reported-by: Misbah Anjum N <misanjum@linux.ibm.com>
Reported-by: Gautam Menghani <gautam@linux.ibm.com>
Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
---
 accel/kvm/kvm-accel-ops.c | 4 ++++
 accel/kvm/kvm-all.c       | 1 +
 2 files changed, 5 insertions(+)

diff --git a/accel/kvm/kvm-accel-ops.c b/accel/kvm/kvm-accel-ops.c
index 6d9140e549..d684fd0840 100644
--- a/accel/kvm/kvm-accel-ops.c
+++ b/accel/kvm/kvm-accel-ops.c
@@ -52,6 +52,10 @@ static void *kvm_vcpu_thread_fn(void *arg)
 
         if (cpu_can_run(cpu)) {
             r = kvm_cpu_exec(cpu);
+            if (r == EXCP_HLT) {
+                /* kvm_cpu_exec() released BQL, re-acquire for next iteration */
+                bql_lock();
+            }
             if (r == EXCP_DEBUG) {
                 cpu_handle_guest_debug(cpu);
             }
diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c
index 774499d34f..00b8018664 100644
--- a/accel/kvm/kvm-all.c
+++ b/accel/kvm/kvm-all.c
@@ -3439,6 +3439,7 @@ int kvm_cpu_exec(CPUState *cpu)
     trace_kvm_cpu_exec();
 
     if (kvm_arch_process_async_events(cpu)) {
+        bql_unlock();
         return EXCP_HLT;
     }
 
-- 
2.52.0



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

end of thread, other threads:[~2026-04-13  7:40 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-09 16:10 [PATCH for 11.0-rc3] accel/kvm: Fix BQL lock imbalance in kvm_cpu_exec Harsh Prateek Bora
2026-04-10  3:42 ` Ani Sinha
2026-04-10  5:25   ` Harsh Prateek Bora
2026-04-10  6:35     ` Ani Sinha
2026-04-10  8:15       ` Ani Sinha
2026-04-10  8:18       ` Harsh Prateek Bora
2026-04-10  8:29         ` Ani Sinha
2026-04-10  9:01           ` Harsh Prateek Bora
2026-04-10  9:31             ` Ani Sinha
2026-04-10 10:02               ` Harsh Prateek Bora
2026-04-10 10:05                 ` Ani Sinha
2026-04-10 10:16                   ` Harsh Prateek Bora
2026-04-10 13:04             ` BALATON Zoltan
2026-04-10 13:37               ` Ani Sinha
2026-04-10 15:07                 ` BALATON Zoltan
2026-04-10  7:16 ` Misbah Anjum N
2026-04-10 18:12 ` Fabiano Rosas
2026-04-13  5:44   ` Harsh Prateek Bora
2026-04-13  7:13     ` Ani Sinha
2026-04-13  7:39       ` Harsh Prateek Bora

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.