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

From: Paolo Bonzini
Date: Tue Apr 26 2022 - 13:51:50 EST


On 3/28/22 20:15, Sean Christopherson wrote:
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()).


Indeed, KVM could use perf_get_pgtable_size(). The conversion from the result of *_leaf_size() to level is basically (ctz(size) - 12) / 9.

Alternatively, there are the three difference between perf_get_page_size() and lookup_address_in_pgd():

* the *_offset_lockless() macros, which are unnecessary on x86

* READ_ONCE, which is important but in practice unlikely to make a difference

* local_irq_{save,restore} around the walk


The last is the important one and it should be added to lookup_address_in_pgd().

Paolo