Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [PATCH v2 0/1] RISC-V: KVM: Serialize virtual interrupt pending state updates
@ 2026-07-08  3:35 Xie Bo
  2026-07-08  3:35 ` [PATCH v2 1/1] " Xie Bo
  0 siblings, 1 reply; 3+ messages in thread
From: Xie Bo @ 2026-07-08  3:35 UTC (permalink / raw)
  To: Anup Patel, kvm-riscv
  Cc: Atish Patra, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, Paolo Bonzini, Alexander Graf, kvm, linux-riscv,
	linux-kernel, stable, Xie Bo

Hi,

This is v2 of the RISC-V KVM virtual interrupt synchronization fix.

The first version described the irqs_pending/irqs_pending_mask race, but
it did not provide enough context on:

  - the exact lost-interrupt interleaving
  - the user-visible failure mode
  - why the existing lockless protocol is replaced instead of being
    repaired with additional barriers
  - what was exercised during validation

This version updates only the commit message and keeps the code change
the same.

Problem summary
===============

The current code treats irqs_pending and irqs_pending_mask as a lockless
multiple-producer, single-consumer state machine.  In practice,
kvm_riscv_vcpu_sync_interrupts() is not a pure consumer because it also
writes both bitmaps while synchronizing guest-visible HVIP state back
into KVM state.

That means the two bitmaps represent one logical state transition, but
they are updated independently.  A host-side interrupt injection can
race with guest-side VSSIP clearing and lose the newly injected pending
bit.

Observed symptom
================

The failure that motivated this patch was an occasional guest hang where
the guest remained blocked in WFI even though host-side virtual
interrupt injection and vCPU kick had already happened.

Why replace the lockless protocol
=================================

This is not just a missing barrier.  The bug comes from encoding one
shared state machine in two separate bitmaps while allowing both
producers and the sync path to modify them.

Repairing that while staying lockless would require redesigning the
state transition protocol itself.  A per-vCPU raw spinlock makes the
state transition explicit and keeps the fix small enough for stable
backporting.

Validation
==========

The issue was reproduced under RISC-V KVM stress workloads that exposed
guest stalls in WFI.  After applying this patch, the same stress setup
no longer reproduced the lost-VSSIP hang.

Thanks,
Xie Bo

Xie Bo (1):
  RISC-V: KVM: Serialize virtual interrupt pending state updates

 arch/riscv/include/asm/kvm_host.h | 10 +++++-----
 arch/riscv/kvm/aia.c              | 28 +++++++++++++++++++++-------
 arch/riscv/kvm/vcpu.c             | 27 ++++++++++++++++++++++-----
 arch/riscv/kvm/vcpu_onereg.c      | 13 +++++++++----
 4 files changed, 57 insertions(+), 21 deletions(-)

-- 
2.54.0


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

end of thread, other threads:[~2026-07-08  3:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08  3:35 [PATCH v2 0/1] RISC-V: KVM: Serialize virtual interrupt pending state updates Xie Bo
2026-07-08  3:35 ` [PATCH v2 1/1] " Xie Bo
2026-07-08  3:55   ` sashiko-bot

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