Re: [PATCH 27/28] KVM: x86/mmu: Do remote TLB flush before dropping RCU in TDP MMU resched

From: Sean Christopherson
Date: Tue Nov 30 2021 - 10:45:14 EST


On Tue, Nov 30, 2021, Paolo Bonzini wrote:
> On 11/20/21 05:50, Sean Christopherson wrote:
> > if (need_resched() || rwlock_needbreak(&kvm->mmu_lock)) {
> > - rcu_read_unlock();
> > -
> > if (flush)
> > kvm_flush_remote_tlbs(kvm);
> > + rcu_read_unlock();
> > +
>
> Couldn't this sleep in kvm_make_all_cpus_request, whilst in an RCU read-side
> critical section?

No. And if kvm_make_all_cpus_request() can sleep, the TDP MMU is completely hosed
as tdp_mmu_zap_spte_atomic() and handle_removed_tdp_mmu_page() currently call
kvm_flush_remote_tlbs_with_range() while under RCU protection.

kvm_make_all_cpus_request_except() disables preemption via get_cpu(), and
smp_call_function() doubles down on disabling preemption as the inner helpers
require preemption to be disabled, so anything below them should complain if
there's a might_sleep(). hv_remote_flush_tlb_with_range() takes a spinlock, so
nothing in there should be sleeping either.