Re: [PATCH] KVM: x86/mmu: Always guard rmaps with mmu_lock on PREEMPT_RT=y kernels

From: Sean Christopherson

Date: Wed Sep 02 2026 - 18:33:02 EST


On Wed, Sep 02, 2026, James Houghton wrote:
> On Wed, Sep 2, 2026 at 2:29 PM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
> > @@ -1745,11 +1776,15 @@ static bool kvm_rmap_age_gfn_range(struct kvm *kvm,
> > gfn_t gfn;
> > int level;
> >
> > +#ifdef CONFIG_PREEMPT_RT
> > + guard(read_lock)(&kvm->mmu_lock);
> > +#endif
>
> Future me would be happier if there were a comment here. :)
>
> Also, how about BUILD_BUG_ON(!CONFIG_KVM_MMU_LOCKLESS_AGING)?

I completely forgot we even had that Kconfig. I'm somewhat tempted to gate the
alternative implementation on KVM_MMU_LOCKLESS_AGING=n, not take mmu_lock here,
and then "select KVM_MMU_LOCKLESS_AGING if PREEMPT_RT=n".

My main hesitation is that taking mmu_lock for read would be impossible without
extending kvm_handle_hva_range() even further, which IMO isn't worth doing unless
multiple architectures want to take mmu_lock for read.

Ugh, I shouldn't have thought those thoughts. s390 does exactly that.

Oh, wait, never mind. That doesn't work for x86, because we want truly lockless
aging for the TDP MMU. So ignore that train of thought, this patch is the way
to go. +1 to adding a BUILD_BUG_ON() and comment thought.