Skip to contentSkip to conversation

KVM: x86: Question on lock protection in handle_ept_misconfig

PATCH In review zoudongjie (A) 2 participants 2 messages Jul 9, 2025 KVM

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 KVM: x86: Question on lock protection in handle_ept_misconfig

Resending as plain text to fix formatting issues.
---

Hi all,

I noticed that in handle_ept_misconfig(), kvm_io_bus_write() is called. And within kvm_io_bus_write(), BUS is obtained through srcu_dereference(). During this process, kvm->slots_lock is not acquired, nor is srcu_read_lock() called for protection. If another process is synchronizing BUS at the same time, synchronize_srcu_expedited() cannot safely reclaim space(it cannot protect srcu_dereference() outside the critical section?), how can we ensure that BUS obtained by kvm_io_bus_write() is the latest?

Thanks,
Junjie Cai

Reported by: Junjie Cai <mailto:[email protected]>

maintainer
#1 lore raw

Il mer 9 lug 2025, 08:50 zoudongjie (A) <[email protected]> ha scritto:

Quoted 10 lines

Resending as plain text to fix formatting issues.
---

Hi all,

I noticed that in handle_ept_misconfig(), kvm_io_bus_write() is called. And within kvm_io_bus_write(), BUS is obtained through srcu_dereference(). During this process, kvm->slots_lock is not acquired, nor is srcu_read_lock() called for protection.

Hi, srcu_read_lock() is guaranteed by the caller (see vcpu_enter_guest in arch/x86/kvm/x86.c).

In fact, almost all of KVM_RUN is covered by a SRCU read critical section, except for:

1) the part where the processor is in guest mode and the nearby preparations (that's vcpu_enter_guest)

2) when the vCPU goes to a non-runnable state, for example waiting for an interrupt (search for kvm_vcpu_block and kvm_vcpu_halt)

Thanks,

Paolo

Quoted 10 lines

If another process is synchronizing BUS at the same time, synchronize_srcu_expedited() cannot safely reclaim space(it cannot protect srcu_dereference() outside the critical section?), how can we ensure that BUS obtained by kvm_io_bus_write() is the latest?

Thanks,
Junjie Cai

Reported by: Junjie Cai <mailto:[email protected]>