All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yan Zhao <yan.y.zhao@intel.com>
Subject: [PATCH 0/2] KVM: Pre-check mmu_notifier retry on x86
Date: Thu, 24 Aug 2023 19:07:31 -0700	[thread overview]
Message-ID: <20230825020733.2849862-1-seanjc@google.com> (raw)

Pre-check for an mmu_notifier retry on x86 to avoid contending mmu_lock,
which is quite problematic on preemptible kernels due to the way x86's TDP
MMU reacts to mmu_lock contentions.  If mmu_lock contention is detected when
zapping SPTEs for an mmu_notifier invalidation, the TDP MMU drops mmu_lock
and yields.

The idea behind yielding is to let vCPUs that are trying to fault-in memory
make forward progress while the invalidation is ongoing.  This works
because x86 uses the precise(ish) version of retry which checks for hva
overlap.  At least, it works so long as vCPUs are hitting the region that's
being zapped.

Yielding turns out to be really bad when the vCPU is trying to fault-in a
page that *is* covered by the invalidation, because the vCPU ends up
retrying over and over, which puts mmu_lock under constant contention, and
ultimately causes the invalidation to take much longer due to the zapping
task constantly yielding.  And in the worst case scenario, if the
invalidation is finding SPTEs to zap, every yield will trigger a remote
(*cough* VM-wide) TLB flush.

Sean Christopherson (2):
  KVM: Allow calling mmu_invalidate_retry_hva() without holding mmu_lock
  KVM: x86/mmu: Retry fault before acquiring mmu_lock if mapping is
    changing

 arch/x86/kvm/mmu/mmu.c   |  3 +++
 include/linux/kvm_host.h | 17 ++++++++++++++---
 2 files changed, 17 insertions(+), 3 deletions(-)


base-commit: fff2e47e6c3b8050ca26656693caa857e3a8b740
-- 
2.42.0.rc2.253.gd59a3bf2b4-goog


             reply	other threads:[~2023-08-25  2:08 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-25  2:07 Sean Christopherson [this message]
2023-08-25  2:07 ` [PATCH 1/2] KVM: Allow calling mmu_invalidate_retry_hva() without holding mmu_lock Sean Christopherson
2023-09-07 23:30   ` Huang, Kai
2023-09-08 17:36     ` Sean Christopherson
2023-08-25  2:07 ` [PATCH 2/2] KVM: x86/mmu: Retry fault before acquiring mmu_lock if mapping is changing Sean Christopherson
2023-09-06 23:03   ` Huang, Kai
2023-09-07 14:45     ` Sean Christopherson
2023-09-07 22:34       ` Huang, Kai

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=20230825020733.2849862-1-seanjc@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=yan.y.zhao@intel.com \
    /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.