From: Steven Price <steven.price@arm.com>
To: kvm@vger.kernel.org, kvmarm@lists.linux.dev
Cc: Steven Price <steven.price@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Marc Zyngier <maz@kernel.org>, Will Deacon <will@kernel.org>,
James Morse <james.morse@arm.com>,
Oliver Upton <oliver.upton@linux.dev>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Joey Gouly <joey.gouly@arm.com>,
Alexandru Elisei <alexandru.elisei@arm.com>,
Christoffer Dall <christoffer.dall@arm.com>,
Fuad Tabba <tabba@google.com>,
linux-coco@lists.linux.dev,
Ganapatrao Kulkarni <gankulkarni@os.amperecomputing.com>,
Gavin Shan <gshan@redhat.com>,
Shanker Donthineni <sdonthineni@nvidia.com>,
Alper Gun <alpergun@google.com>,
"Aneesh Kumar K . V" <aneesh.kumar@kernel.org>,
Emi Kisanuki <fj0570is@fujitsu.com>,
Vishal Annapurve <vannapurve@google.com>,
WeiLin.Chang@arm.com, Lorenzo Pieralisi <lpieralisi@kernel.org>,
Kohei Enju <enju.kohei@fujitsu.com>
Subject: [PATCH v6 09/11] KVM: arm64: Select protected VM behaviour by VM flavour
Date: Fri, 4 Dec 2026 11:57:16 +0000 [thread overview]
Message-ID: <20261204115725.45272-10-steven.price@arm.com> (raw)
In-Reply-To: <20261204115725.45272-1-steven.price@arm.com>
Use the VM flavour when choosing the stage-2 fault lock, fault memory
cache, pre-fault policy and ptdump visibility. This prepares these paths
for Realm VMs, whose stage-2 tables are managed outside the host.
Move the VM flavour helper outside the nVHE guard so the shared
fault-lock helpers can use it.
Signed-off-by: Steven Price <steven.price@arm.com>
---
Changes since v5:
- New patch: select the fault lock, cache, pre-fault policy and
stage-2 debugfs visibility by VM flavour.
---
arch/arm64/include/asm/kvm_host.h | 4 ++--
arch/arm64/include/asm/kvm_mmu.h | 4 ++--
arch/arm64/kvm/mmu.c | 4 ++--
arch/arm64/kvm/ptdump.c | 4 ++--
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 55673d08e3eb..505c0c5b7dbb 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -1601,12 +1601,12 @@ struct kvm *kvm_arch_alloc_vm(void);
#define kvm_vm_is_protected(kvm) ((kvm)->arch.vm_flavor >= __VM_PROTECTED)
#define vcpu_is_protected(vcpu) kvm_vm_is_protected((vcpu)->kvm)
-#define kvm_vm_hyp_is_distrusting(kvm) ((kvm)->arch.vm_flavor >= __VM_DISTRUSTING_HYP)
-
#endif /* __KVM_NVHE_HYPERVISOR__ */
#define kvm_vm_is_realm(kvm) ((kvm)->arch.vm_flavor == VM_REALM)
+#define kvm_vm_hyp_is_distrusting(kvm) ((kvm)->arch.vm_flavor >= __VM_DISTRUSTING_HYP)
+
#define kvm_arch_has_private_mem(kvm) kvm_vm_is_realm(kvm)
#define kvm_has_mte(kvm) \
diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h
index 32392abf2e21..a70f8bd4b2b9 100644
--- a/arch/arm64/include/asm/kvm_mmu.h
+++ b/arch/arm64/include/asm/kvm_mmu.h
@@ -371,7 +371,7 @@ static inline bool kvm_is_nested_s2_mmu(struct kvm *kvm, struct kvm_s2_mmu *mmu)
static inline void kvm_fault_lock(struct kvm *kvm)
{
- if (is_protected_kvm_enabled())
+ if (kvm_vm_hyp_is_distrusting(kvm))
write_lock(&kvm->mmu_lock);
else
read_lock(&kvm->mmu_lock);
@@ -379,7 +379,7 @@ static inline void kvm_fault_lock(struct kvm *kvm)
static inline void kvm_fault_unlock(struct kvm *kvm)
{
- if (is_protected_kvm_enabled())
+ if (kvm_vm_hyp_is_distrusting(kvm))
write_unlock(&kvm->mmu_lock);
else
read_unlock(&kvm->mmu_lock);
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index ce7cea447f58..a1ae89ce3707 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -2317,7 +2317,7 @@ static int user_mem_abort(const struct kvm_s2_fault_desc *s2fd,
*/
memcache = get_mmu_memcache(s2fd->vcpu);
if (!perm_fault || memslot_is_logging(s2fd->memslot) ||
- is_protected_kvm_enabled()) {
+ kvm_vm_hyp_is_distrusting(s2fd->vcpu->kvm)) {
ret = topup_mmu_memcache(s2fd->mmu, memcache);
if (ret)
return ret;
@@ -3136,7 +3136,7 @@ pre_fault_bytes_consumed(gpa_t gpa, unsigned long granule_size,
int kvm_arch_pre_fault_allowed(struct kvm_vcpu *vcpu)
{
- if (is_protected_kvm_enabled())
+ if (kvm_vm_hyp_is_distrusting(vcpu->kvm))
return -EOPNOTSUPP;
if (!kvm_vcpu_initialized(vcpu))
return -ENOEXEC;
diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c
index 9f0aebacea5b..ec3acbefa1be 100644
--- a/arch/arm64/kvm/ptdump.c
+++ b/arch/arm64/kvm/ptdump.c
@@ -321,8 +321,8 @@ void kvm_nested_s2_ptdump_create_debugfs(struct kvm_s2_mmu *mmu, int idx)
void kvm_s2_ptdump_create_debugfs(struct kvm *kvm)
{
- /* pKVM handles the page-tables in the hypervisor */
- if (is_protected_kvm_enabled())
+ /* Protected VMs have stage-2 tables outside the host's access. */
+ if (kvm_vm_hyp_is_distrusting(kvm))
return;
debugfs_create_file("stage2_page_tables", 0400, kvm->debugfs_dentry,
--
2.43.0
next prev parent reply other threads:[~2026-12-04 11:58 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 11:57 [PATCH v6 00/11] KVM: arm64: CCA: Prepare Realm memory management Steven Price
2026-12-04 11:57 ` [PATCH v6 01/11] KVM: arm64: CCA: Introduce Realms Steven Price
2026-12-04 16:07 ` Kohei Enju
2026-12-04 17:05 ` Steven Price
2026-12-04 11:57 ` [PATCH v6 02/11] KVM: arm64: Pass range filter to stage2_unmap_range Steven Price
2026-12-04 11:57 ` [PATCH v6 03/11] KVM: arm64: Dispatch stage-2 destruction by VM flavor Steven Price
2026-12-04 11:57 ` [PATCH v6 04/11] KVM: arm64: CCA: Add basic infrastructure for creating a realm Steven Price
2026-12-04 11:57 ` [PATCH v6 05/11] KVM: arm64: CCA: Add Realm RTT mapping and invalidation helpers Steven Price
2026-12-04 11:57 ` [PATCH v6 06/11] KVM: arm64: CCA: Destroy RTTs Steven Price
2026-12-04 11:57 ` [PATCH v6 07/11] KVM: arm64: CCA: Restrict Realm memslots to the lower IPA half Steven Price
2026-12-04 15:48 ` Kohei Enju
2026-12-04 16:27 ` Steven Price
2026-12-04 11:57 ` [PATCH v6 08/11] KVM: arm64: CCA: Advertise private memory support for Realms Steven Price
2026-12-04 11:57 ` Steven Price [this message]
2026-12-04 13:21 ` [PATCH v6 09/11] KVM: arm64: Select protected VM behaviour by VM flavour Fuad Tabba
2026-12-04 11:57 ` [PATCH v6 10/11] KVM: arm64: CCA: Support runtime faulting of memory Steven Price
2026-12-04 15:32 ` Kohei Enju
2026-12-04 16:27 ` Steven Price
2026-12-04 11:57 ` [PATCH v6 11/11] KVM: arm64: CCA: Add Realm stage-2 MMU operations Steven Price
2026-12-04 16:30 ` [PATCH v6 00/11] KVM: arm64: CCA: Prepare Realm memory management Kohei Enju
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=20261204115725.45272-10-steven.price@arm.com \
--to=steven.price@arm.com \
--cc=WeiLin.Chang@arm.com \
--cc=alexandru.elisei@arm.com \
--cc=alpergun@google.com \
--cc=aneesh.kumar@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=christoffer.dall@arm.com \
--cc=enju.kohei@fujitsu.com \
--cc=fj0570is@fujitsu.com \
--cc=gankulkarni@os.amperecomputing.com \
--cc=gshan@redhat.com \
--cc=james.morse@arm.com \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=sdonthineni@nvidia.com \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=vannapurve@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