All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: David Matlack <dmatlack@google.com>,
	Ignat Korchagin <ignat@cloudflare.com>
Cc: kvm@vger.kernel.org, Sean Christopherson <seanjc@google.com>,
	stevensd@chromium.org, kernel-team <kernel-team@cloudflare.com>
Subject: Re: Potential bug in TDP MMU
Date: Sat, 11 Dec 2021 02:49:02 +0100	[thread overview]
Message-ID: <e995aceb-40cc-e4cc-f3c8-2e8c2877a896@redhat.com> (raw)
In-Reply-To: <CALzav=fyaXAn4CLRW2qKTrROGUh6+F4bphhfoMZ13Qp5Njx3gw@mail.gmail.com>

On 12/11/21 02:34, David Matlack wrote:
> The stacks help, thanks for including them. It seems like a race
> during do_exit teardown. One thing I notice is that
> do_exit->mmput->kvm_mmu_zap_all can interleave with
> kvm_vcpu_release->kvm_tdp_mmu_put_root (full call chains omitted),
> since the former path allows yielding. But I don't yet see that could
> lead to any issues, let alone cause us to encounter a PFN in the EPT
> with a zero refcount.

Can it? The call chains are

     zap_gfn_range+2229
     kvm_tdp_mmu_put_root+465
     kvm_mmu_free_roots+629
     kvm_mmu_unload+28
     kvm_arch_destroy_vm+510
     kvm_put_kvm+1017
     kvm_vcpu_release+78
     __fput+516
     task_work_run+206
     do_exit+2615
     do_group_exit+236

and

     zap_gfn_range+2229
     __kvm_tdp_mmu_zap_gfn_range+162
     kvm_tdp_mmu_zap_all+34
     kvm_mmu_zap_all+518
     kvm_mmu_notifier_release+83
     __mmu_notifier_release+420
     exit_mmap+965
     mmput+167
     do_exit+2482
     do_group_exit+236

but there can be no parallelism or interleaving here, because the call 
to kvm_vcpu_release() is scheduled in exit_files() (and performed in 
exit_task_work()).  That comes after exit_mm(), where mmput() is called.

Even if the two could interleave, they go through the same zap_gfn_range 
path.  That path takes the lock for write and only yields on the 512 
top-level page structures.  Anything below is handled by 
tdp_mmu_set_spte's (with mutual recursion between handle_changed_spte 
and handle_removed_tdp_mmu_page), and there are no yields on that path.

Paolo

  reply	other threads:[~2021-12-11  1:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-29 21:44 Potential bug in TDP MMU Ignat Korchagin
2021-11-30  9:29 ` Paolo Bonzini
2021-11-30 10:58   ` Ignat Korchagin
2021-11-30 10:59     ` Ignat Korchagin
2021-11-30 11:11     ` Paolo Bonzini
2021-11-30 11:19       ` Ignat Korchagin
2021-11-30 11:43         ` Ignat Korchagin
2021-11-30 11:49           ` Paolo Bonzini
2021-11-30 12:13           ` Paolo Bonzini
2021-11-30 20:23     ` Sean Christopherson
2021-12-01 23:44       ` Ignat Korchagin
2021-12-10 23:04         ` Ignat Korchagin
2021-12-11  1:34           ` David Matlack
2021-12-11  1:49             ` Paolo Bonzini [this message]
2021-12-11 17:46               ` David Matlack
2021-12-11  1:37           ` Paolo Bonzini
2021-12-11  2:39           ` Sean Christopherson
2021-12-11  9:38             ` Ignat Korchagin
2021-12-11 20:49             ` Paolo Bonzini
2021-12-13 16:14               ` Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e995aceb-40cc-e4cc-f3c8-2e8c2877a896@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=dmatlack@google.com \
    --cc=ignat@cloudflare.com \
    --cc=kernel-team@cloudflare.com \
    --cc=kvm@vger.kernel.org \
    --cc=seanjc@google.com \
    --cc=stevensd@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.