Re: [PATCH RFC 02/10] KVM: Allow reading memslots while holding slots_arch_lock

From: Sean Christopherson

Date: Thu Sep 10 2026 - 12:42:59 EST


On Thu, Sep 10, 2026, Marco Elver wrote:
> kvm_swap_active_memslots() updates kvm->memslots[as_id] while holding both
> kvm->slots_lock and kvm->slots_arch_lock. Holding either lock guarantees
> that memslots cannot be concurrently modified.

Sure, but that's irrelevant. The goal of the srcu_dereference_check() is to
ensure that readers see a stable view of the VM's overall memory, not simply that
kvm->memslots can't be written.

> Allow reading memslots in __kvm_memslots() when kvm->slots_arch_lock is
> held.

Why?

>
> Signed-off-by: Marco Elver <elver@xxxxxxxxxx>
> ---
> include/linux/kvm_host.h | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 03bfc92864b6..5ed8260ef01f 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -1089,6 +1089,7 @@ static inline struct kvm_memslots *__kvm_memslots(struct kvm *kvm, int as_id)
> as_id = array_index_nospec(as_id, KVM_MAX_NR_ADDRESS_SPACES);
> return srcu_dereference_check(kvm->memslots[as_id], &kvm->srcu,
> lockdep_is_held(&kvm->slots_lock) ||
> + lockdep_is_held(&kvm->slots_arch_lock) ||
> !refcount_read(&kvm->users_count));
> }
>
> --
> 2.55.0.1003.g10538fe699-goog
>