Re: [PATCH] KVM: x86/mmu: add lockdep check before lookup_address_in_mm()

Sean Christopherson
2022-03-28T18:15:16Z

On Mon, Mar 28, 2022, Mingwei Zhang wrote:
> With that, I start to feel this is a bug. The issue is just so rare
> that it has never triggered a problem.
>
> lookup_address_in_mm() walks the host page table as if it is a
> sequence of _static_ memory chunks. This is clearly dangerous.

Yeah, it's broken. The proper fix is do something like what perf uses, or maybe
just genericize and reuse the code from commit 8af26be06272
("perf/core: Fix arch_perf_get_page_size()).

> But right now, kvm_mmu_max_mapping_level() are used in other places
> as well: kvm_mmu_zap_collapsible_spte(), which does not satisfy the
> strict requirement of walking the host page table.

The host pfn size is used only as a hueristic, so false postives/negatives are
ok, the only race that needs to be avoided is dereferencing freed page table
memory. lookup_address_in_pgd() is really broken because it doesn't even ensure
a given PxE is READ_ONCE(). I suppose one could argue the caller is broken, but
I doubt KVM is the only user that doesn't provide the necessary protections.