From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAE9D606A322 for ; Fri, 4 Dec 2026 11:59:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=iKX8G4nh; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=O7tXoKYY DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=n0EcWnQbQYAzLpDRKPWeGj2scKjeYxLCUp9d04IEwdo=; b=iKX8G4nhxB/h7F sP0hofmEmM9cmZxHDrhfoMRKflIlOtLppz9JxoZsPwQuezwHQdXgcmDem1vCGsePBWnVSRbNWWSG0 ar8FR8Ubt1GFxHmkv2onstU3Tm2vzn3Hq1rvr1psEN7om9Wl7ypkyRo2Fh0aHZeNCleUNlKNMq+uX Gq/WCA8PNIbGqMJhoIFMjuR0kdVp7hi6ZlnRWGv/NQ1fD9D5/fysmAoIVpYpJmbmPrTrGKAVuc6w/ tTUSt/FtvePRS19K/cRGmA9kN1RF4di+QaIS/2g8WexJw5neBzDOjsG8ws6LEyEJKx5hF2L/0cr29 KKVFe1u7DSWTNsuXoyCg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZRvz-00000000Cmm-1F4d; Fri, 04 Dec 2026 11:58:39 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZRvl-00000000Ce4-2205 for linux-arm-kernel@lists.infradead.org; Fri, 04 Dec 2026 11:58:37 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0A1571684; Fri, 4 Dec 2026 03:58:22 -0800 (PST) Received: from e122027.cambridge.arm.com (e122027.cambridge.arm.com [10.0.128.193]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7CBC33F632; Fri, 4 Dec 2026 03:58:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796385504; bh=0DJQSoqQ2CpZBKGG97reZY+AusMsjOneqRF4jU3K4TY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O7tXoKYYqlbP6XHzFO2z3RP2TOgw3UdCLgbKVnQNFlRvFz+5PLAvjOzJNg5Kk8WKf DCulhQP4H/LfsTrndTis+3vBiJeSTm3gH3VAC+I4rWUj6WhIom4USOX5+9nkvcDuHv U2+89iZXIyvRkreh7IvArTfWeHOI0lvJMTaiMrrE= From: Steven Price To: kvm@vger.kernel.org, kvmarm@lists.linux.dev Cc: Steven Price , Catalin Marinas , Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni , Gavin Shan , Shanker Donthineni , Alper Gun , "Aneesh Kumar K . V" , Emi Kisanuki , Vishal Annapurve , WeiLin.Chang@arm.com, Lorenzo Pieralisi , Kohei Enju Subject: [PATCH v6 09/11] KVM: arm64: Select protected VM behaviour by VM flavour Date: Fri, 4 Dec 2026 11:57:16 +0000 Message-ID: <20261204115725.45272-10-steven.price@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261204115725.45272-1-steven.price@arm.com> References: <20261204115725.45272-1-steven.price@arm.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261204_035831_854963_A996A645 X-CRM114-Status: GOOD ( 14.19 ) X-Spam-Score: -4.4 (----) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-19.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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 --- 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