Re: [PATCH v3 5/7] KVM: x86: Participate in bitmap-based PTE aging

From: James Houghton
Date: Fri Apr 19 2024 - 16:55:33 EST


On Fri, Apr 12, 2024 at 1:44 PM David Matlack <dmatlack@xxxxxxxxxx> wrote:
>
> On 2024-04-01 11:29 PM, James Houghton wrote:
> > Only handle the TDP MMU case for now. In other cases, if a bitmap was
> > not provided, fallback to the slowpath that takes mmu_lock, or, if a
> > bitmap was provided, inform the caller that the bitmap is unreliable.
>
> I think this patch will trigger a lockdep assert in
>
> kvm_tdp_mmu_age_gfn_range
> kvm_tdp_mmu_handle_gfn
> for_each_tdp_mmu_root
> __for_each_tdp_mmu_root
> kvm_lockdep_assert_mmu_lock_held
>
> ... because it walks tdp_mmu_roots without holding mmu_lock.

Indeed, thanks. I'll make sure to build with CONFIG_LOCKDEP for the
future versions and check for errors.

>
> Yu's patch[1] added a lockless walk to the TDP MMU. We'd need something
> similar here and also update the comment above tdp_mmu_roots describing
> how tdp_mmu_roots can be read locklessly.

I'll add the macro / function to do the lockless walk of tdp_mmu_roots
and explain why it is safe. Thanks for pointing out this big mistake.

> [1] https://lore.kernel.org/kvmarm/ZItX64Bbx5vdjo9M@xxxxxxxxxx/