All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oliver Upton <oliver.upton@linux.dev>
To: kvmarm@lists.linux.dev
Cc: Marc Zyngier <maz@kernel.org>, Joey Gouly <joey.gouly@arm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Oliver Upton <oliver.upton@linux.dev>
Subject: [PATCH 0/3] KVM: arm64: nv: Fixes for stage-2 MMU recycling
Date: Tue,  1 Oct 2024 00:17:06 +0000	[thread overview]
Message-ID: <20241001001709.1303668-1-oliver.upton@linux.dev> (raw)

I recently found that the path for reclaiming stage-2 MMUs is a bit
dodgy. We call kvm_stage2_unmap_range() from vcpu_load() when
repurposing a valid MMU, which itself is allowed to block. We repeat
this silliness on the next vcpu_load(), eventually leading to a stack
overflow.

It also looks like the nested hooks into the MMU notifiers are similarly
screwed up, ignoring the @may_block parameter and allowing the page
table walk to block unconditionally.

In addition to that, we are not handling vcpu->arch.hw_mmu safely in
preemptible code, i.e. we could be using a stale pointer on the loaded
hardware MMU.

Set of fixes to address all of the above, by:

1) Allowing vCPUs to 'pin' the loaded stage-2 MMU, guaranteeing that
   vcpu->arch.hw_mmu is stable when used in preemptible code

2) Preventing unmap walks from blocking when disallowed by the calling
   context.

   This is the correct fix for the MMU notifiers, and a "fix" for the
   reclaim case. Unmapping a whole MMU behind the write lock w/o periodically
   releasing the lock hurts vCPU scheduling, especially on larger VMs.

3) Push the cleanup of reclaimed MMUs into a vCPU request, allowing the
   walk to release the lock + CPU as needed.

Applies to 6.12-rc1, tested on M2. An easy way to force the reclaim case
is to constantly rerun a KVM selftest inside the L1 guest, which is how
I found this in the first place.

Oliver Upton (3):
  KVM: arm64: Treat stage-2 MMUs as refcounted generally
  KVM: arm64: nv: Do not block when unmapping stage-2 if disallowed
  KVM: arm64: nv: Punt stage-2 recycling to a vCPU request

 arch/arm64/include/asm/kvm_host.h   | 13 ++++++++--
 arch/arm64/include/asm/kvm_mmu.h    | 40 ++++++++++++++++++++++++++++-
 arch/arm64/include/asm/kvm_nested.h |  4 ++-
 arch/arm64/kvm/arm.c                | 12 +++++----
 arch/arm64/kvm/hyp/nvhe/hyp-main.c  |  2 +-
 arch/arm64/kvm/hyp/nvhe/pkvm.c      |  2 +-
 arch/arm64/kvm/hyp/nvhe/switch.c    |  2 +-
 arch/arm64/kvm/hyp/nvhe/tlb.c       |  4 +--
 arch/arm64/kvm/hyp/vhe/switch.c     |  2 +-
 arch/arm64/kvm/hyp/vhe/tlb.c        |  4 +--
 arch/arm64/kvm/mmu.c                | 34 +++++++++++++-----------
 arch/arm64/kvm/nested.c             | 39 ++++++++++++++++++++--------
 arch/arm64/kvm/sys_regs.c           |  6 ++---
 13 files changed, 119 insertions(+), 45 deletions(-)


base-commit: 9852d85ec9d492ebef56dc5f229416c925758edc
-- 
2.46.1.824.gd892dcdcdd-goog


             reply	other threads:[~2024-10-01  0:17 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-01  0:17 Oliver Upton [this message]
2024-10-01  0:17 ` [PATCH 1/3] KVM: arm64: Treat stage-2 MMUs as refcounted generally Oliver Upton
2024-10-01  0:17 ` [PATCH 2/3] KVM: arm64: nv: Do not block when unmapping stage-2 if disallowed Oliver Upton
2024-10-01  0:17 ` [PATCH 3/3] KVM: arm64: nv: Punt stage-2 recycling to a vCPU request Oliver Upton
2024-10-01 19:05   ` Sean Christopherson
2024-10-01 20:41     ` Oliver Upton
2024-10-01 23:28       ` Sean Christopherson
2024-10-01 23:49         ` Marc Zyngier
2024-10-02  0:06           ` Oliver Upton
2024-10-02  0:23             ` Sean Christopherson
2024-10-02 23:31               ` Marc Zyngier
2024-10-03  0:04                 ` Oliver Upton
2024-10-03  0:12                   ` Oliver Upton
2024-10-03 16:45                     ` Sean Christopherson
2024-10-03 17:52                       ` Oliver Upton
2024-10-03 18:23                         ` Sean Christopherson
2024-10-03 22:03                           ` Oliver Upton
2024-10-01 23:23   ` Marc Zyngier
2024-10-02  0:06     ` Oliver Upton

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=20241001001709.1303668-1-oliver.upton@linux.dev \
    --to=oliver.upton@linux.dev \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=yuzenghui@huawei.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.