[PATCH v2 0/1] RISC-V: KVM: Serialize virtual interrupt pending state updates

Xie Bo xb at ultrarisc.com
Tue Jul 7 20:35:36 PDT 2026


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




More information about the linux-riscv mailing list