Re: [PATCH] KVM: SVM: Disable TDP MMU when running on Hyper-V

From: Jeremi Piotrowski
Date: Wed Mar 08 2023 - 11:08:43 EST




On 08/03/2023 01:39, Sean Christopherson wrote:
> On Wed, Mar 08, 2023, Paolo Bonzini wrote:
>> On Tue, Mar 7, 2023 at 6:36 PM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
>>> Thinking about this more, I would rather revert commit 1e0c7d40758b ("KVM: SVM:
>>> hyper-v: Remote TLB flush for SVM") or fix the thing properly straitaway. KVM
>>> doesn't magically handle the flushes correctly for the shadow/legacy MMU, KVM just
>>> happens to get lucky and not run afoul of the underlying bugs.
>>
>> I don't think it's about luck---the legacy MMU's zapping/invalidation
>> seems to invoke the flush hypercall correctly:
>
> ...for the paths that Jeremi has exercised, and for which a stale TLB entry is
> fatal to L2. E.g. kvm_unmap_gfn_range() does not have a range-based TLB flush
> in its path and fully relies on the buggy kvm_flush_remote_tlbs().
>

Why do you say "buggy kvm_flush_remote_tlbs"? kvm_flush_remote_tlbs calls the hypercall
that is needed, I don't see how this might be an issue of a missing "range-based TLB flush".

kvm_unmap_gfn_range is called from kvm_mmu_notifier_invalidate_range_start and 'flush_on_ret=true'
is set, so it is followed by kvm_flush_remote_tlbs which calls hv_remote_flush_tlb.

> In other words, KVM is getting lucky :-)
>
>> Jeremi, did you ever track the call stack where
>> hyperv_nested_flush_guest_mapping is triggered?
>
> I don't think it matters. As above, it only takes one path where KVM is fully
> relying on kvm_flush_remote_tlbs() for the whole thing to fall apart