Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: Fuad Tabba <tabba@google.com>
To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org
Cc: maz@kernel.org, oliver.upton@linux.dev, will@kernel.org,
	 joey.gouly@arm.com, suzuki.poulose@arm.com,
	yuzenghui@huawei.com,  catalin.marinas@arm.com,
	broonie@kernel.org, vdonnefort@google.com,  qperret@google.com,
	sebastianene@google.com, keirf@google.com,  smostafa@google.com,
	tabba@google.com
Subject: [PATCH v4 0/9] KVM: arm64: Reserve pKVM VM handle during initial VM setup
Date: Tue,  9 Sep 2025 08:24:27 +0100	[thread overview]
Message-ID: <20250909072437.4110547-1-tabba@google.com> (raw)

Changes since v3 [1]:
- NOTE: only the last patch (9/9) has changed.
- Fix bug reported by Mark [2]. The existing call to pkvm_init_host_vm()
  wasn't gated by protected mode being enabled, unlike the call to
  pkvm_destroy_hyp_vm(). This imbalance caused failures in non-protected
  mode, especially when creating and destroying multiple VMs. Tested
  with kvm demand_paging_test using nvhe, vhe, and protected.
- Rebase on Linux 6.17-rc5

All VMs in pKVM identified by their handle, a unique per-VM ID. This
handle is shared between the host kernel and the hypvervisor, and used
to track the VM across both.

In pKVM, this handle is allocated when the VM is initialized at the
hypervisor, which is on the first vCPU run. However, the host starts
initializing the VM and setting up its data structures earlier. MMU
notifiers for the VMs are also registered before VM initialization at
the hypervisor, and rely on the handle to identify the VM [3].
Therefore, there is a potential gap between when the VM is (partially)
setup at the host, but still without a valid pKVM handle to identify it
when communicating with the hypervisor.

Additionally, in the future, the host needs to communicate with
TrustZone about the before the VM first run. Therefore, move handle
creation to when the VM is first initialized at the host.

This patch series also takes the oportunity to do some refactoring
(mostly renaming and fixing documentation) of the code. We are in the
process of upstreaming pKVM. Refactoring this code now would generate
less churn than postponing it, as the upstreamed codebase grows.
Moreover, the exsiting names and documentation are at best misleading
(and in cases actually wrong), which could lead to more confusion and
problems reviewing code in the future.

This patch series is divided into two parts:

- Patches 1-5: Renaming, refactoring, and tidying up to lay the
  groundwork for moving handle initialization and to fix existing
  issues.
- Patches 6-9: Decouple handle creation from VM initialization at the
  hypervisor and move the handle creation to VM initialization at the
  host.

Cheers,
/fuad

[1] https://lore.kernel.org/all/20250827101949.4089456-1-tabba@google.com/
[2] https://lore.kernel.org/all/1a248f14-60f2-4f8f-8b4d-3c63e602fd54@sirena.org.uk/
[3] https://lore.kernel.org/all/20250303214947.GA30619@willie-the-truck/

Fuad Tabba (9):
  KVM: arm64: Add build-time check for duplicate DECLARE_REG use
  KVM: arm64: Rename pkvm.enabled to pkvm.is_protected
  KVM: arm64: Rename 'host_kvm' to 'kvm' in pKVM host code
  KVM: arm64: Clarify comments to distinguish pKVM mode from protected
    VMs
  KVM: arm64: Decouple hyp VM creation state from its handle
  KVM: arm64: Separate allocation and insertion of pKVM VM table entries
  KVM: arm64: Consolidate pKVM hypervisor VM initialization logic
  KVM: arm64: Introduce separate hypercalls for pKVM VM reservation and
    initialization
  KVM: arm64: Reserve pKVM handle during pkvm_init_host_vm()

 arch/arm64/include/asm/kvm_asm.h              |   2 +
 arch/arm64/include/asm/kvm_host.h             |   5 +-
 arch/arm64/include/asm/kvm_pkvm.h             |   1 +
 arch/arm64/kvm/arm.c                          |  14 +-
 arch/arm64/kvm/hyp/include/nvhe/pkvm.h        |   4 +-
 .../arm64/kvm/hyp/include/nvhe/trap_handler.h |   3 +-
 arch/arm64/kvm/hyp/nvhe/hyp-main.c            |  14 ++
 arch/arm64/kvm/hyp/nvhe/pkvm.c                | 177 +++++++++++++-----
 arch/arm64/kvm/pkvm.c                         |  76 +++++---
 9 files changed, 221 insertions(+), 75 deletions(-)


base-commit: 76eeb9b8de9880ca38696b2fb56ac45ac0a25c6c
-- 
2.51.0.384.g4c02a37b29-goog


             reply	other threads:[~2025-09-09  7:24 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-09  7:24 Fuad Tabba [this message]
2025-09-09  7:24 ` [PATCH v4 1/9] KVM: arm64: Add build-time check for duplicate DECLARE_REG use Fuad Tabba
2025-09-09  7:24 ` [PATCH v4 2/9] KVM: arm64: Rename pkvm.enabled to pkvm.is_protected Fuad Tabba
2025-09-09  7:24 ` [PATCH v4 3/9] KVM: arm64: Rename 'host_kvm' to 'kvm' in pKVM host code Fuad Tabba
2025-09-09  7:24 ` [PATCH v4 4/9] KVM: arm64: Clarify comments to distinguish pKVM mode from protected VMs Fuad Tabba
2025-09-09  7:24 ` [PATCH v4 5/9] KVM: arm64: Decouple hyp VM creation state from its handle Fuad Tabba
2025-09-09  7:24 ` [PATCH v4 6/9] KVM: arm64: Separate allocation and insertion of pKVM VM table entries Fuad Tabba
2025-09-09  7:24 ` [PATCH v4 7/9] KVM: arm64: Consolidate pKVM hypervisor VM initialization logic Fuad Tabba
2025-09-09  7:24 ` [PATCH v4 8/9] KVM: arm64: Introduce separate hypercalls for pKVM VM reservation and initialization Fuad Tabba
2025-09-09  7:24 ` [PATCH v4 9/9] KVM: arm64: Reserve pKVM handle during pkvm_init_host_vm() Fuad Tabba
2025-09-09 21:17 ` [PATCH v4 0/9] KVM: arm64: Reserve pKVM VM handle during initial VM setup Mark Brown
2025-09-10  8:42   ` Fuad Tabba
2025-09-15  9:50 ` Marc Zyngier

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=20250909072437.4110547-1-tabba@google.com \
    --to=tabba@google.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=joey.gouly@arm.com \
    --cc=keirf@google.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=maz@kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=qperret@google.com \
    --cc=sebastianene@google.com \
    --cc=smostafa@google.com \
    --cc=suzuki.poulose@arm.com \
    --cc=vdonnefort@google.com \
    --cc=will@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox