From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E73D9D1037B for ; Wed, 26 Nov 2025 10:53:09 +0000 (UTC) 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-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=dzRtqTq+dzSMhQVk6tIU43MwjCuC6ZNMugFec9uvagA=; b=EDYabRIch09JQ7a+Qmn7Z0zDtA XyhRutk+tBiHd4t+LirFWkoHjwbpbHeeR8bbkLv19nX042pscjdD3PsX/GAr5eYTCsJNZ+InTAbAk 3n8UEVBEOpCbBpLgFbMxtLr1IKt1J6DIDqm45PkX8hc7go02FNPWzyGvK3rEk/cQryoX+kpIV2wEo tqVLjvtZpktrDh7cwfAc7noWkmP6ZyyK7Fxf4YyqmQPa5Juv4Us+uRuSUvaB/eURYNYMuwj1oHv/c 7AHQSWvddEgUz19fWCulo65aemSG05SuLpqKLa0VV/hc2XKMsuHeosLr+2Mt8Pu/rXHOIJYx7Lmem h1fhlo3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vOD8x-0000000Eq4P-42jR; Wed, 26 Nov 2025 10:53:03 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vOD8v-0000000Eq42-0xYW for linux-arm-kernel@lists.infradead.org; Wed, 26 Nov 2025 10:53:02 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 8E66040BF7; Wed, 26 Nov 2025 10:53:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 685E7C113D0; Wed, 26 Nov 2025 10:53:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764154380; bh=MDN12d2nJbSInDxPygyi+YoQ0BHEFi3212+fJiwfjyk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=GAGNANgAsD6nr9qzNhc+DvO0VnQ5eLsiIBClgFgZGLcB+fvWsutOewDQ6fWjTpnMA ZNcJizu80qxSfsat8L9mZob65U92TGbaRYq1NTwdslNNlMhlvrCqWXhxLte6jwaS0+ FYTItEE/Ewnu42S/t8jIvCyOdYb4u9ntoc/5sHnQ3fBzbd420rEuKcgQfItVXBG3wA cnVct+doesYIzoh+rO3PbDKv6XDy8ebpgYAtCP4Ahlpf4tMfq/qozlusqRs6Ty+Rze ycx4gmWhsf4BpcRj8Hk4oDp4HZBrpDbywhCG35JAQEV8CH2KRBL9ffwCF8dVxuNKdy PbChoSLqXeaYw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vOD8s-00000008Rdf-0SSY; Wed, 26 Nov 2025 10:52:58 +0000 Date: Wed, 26 Nov 2025 10:52:57 +0000 Message-ID: <867bvdqd4m.wl-maz@kernel.org> From: Marc Zyngier To: Fuad Tabba Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oliver.upton@linux.dev, will@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, vladimir.murzin@arm.com Subject: Re: [PATCH v5 5/9] KVM: arm64: Include VM type when checking VM capabilities in pKVM In-Reply-To: <20251118103807.707500-6-tabba@google.com> References: <20251118103807.707500-1-tabba@google.com> <20251118103807.707500-6-tabba@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: tabba@google.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, oliver.upton@linux.dev, will@kernel.org, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, vladimir.murzin@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251126_025301_306963_70DAF450 X-CRM114-Status: GOOD ( 30.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, 18 Nov 2025 10:38:02 +0000, Fuad Tabba wrote: > > Certian features and capabilities are restricted in protected mode. Most > of these features are restricted only for protected VMs, but some > are restricted for ALL VMs in protected mode. > > Extend the pKVM capability check to pass the VM (kvm), and use that when > determining supported features. Moreover, extend the check to disallow > MTE for all VM types in protected mode. > > Signed-off-by: Fuad Tabba > --- > arch/arm64/include/asm/kvm_pkvm.h | 10 ++++++---- > arch/arm64/kvm/arm.c | 4 ++-- > arch/arm64/kvm/hyp/nvhe/pkvm.c | 10 +++++----- > 3 files changed, 13 insertions(+), 11 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_pkvm.h b/arch/arm64/include/asm/kvm_pkvm.h > index 08be89c95466..7195be508d99 100644 > --- a/arch/arm64/include/asm/kvm_pkvm.h > +++ b/arch/arm64/include/asm/kvm_pkvm.h > @@ -23,10 +23,12 @@ void pkvm_destroy_hyp_vm(struct kvm *kvm); > int pkvm_create_hyp_vcpu(struct kvm_vcpu *vcpu); > > /* > - * This functions as an allow-list of protected VM capabilities. > - * Features not explicitly allowed by this function are denied. > + * Check whether the specific capability is allowed in pKVM. > + * > + * Certain features are allowed only for non-protected VMs in pKVM, which is why > + * this takes the VM (kvm) as a parameter. > */ > -static inline bool kvm_pvm_ext_allowed(long ext) > +static inline bool kvm_pkvm_ext_allowed(struct kvm *kvm, long ext) > { > switch (ext) { > case KVM_CAP_IRQCHIP: > @@ -43,7 +45,7 @@ static inline bool kvm_pvm_ext_allowed(long ext) > case KVM_CAP_ARM_PTRAUTH_GENERIC: > return true; > default: > - return false; > + return !kvm || !kvm_vm_is_protected(kvm); I find this expression a bit unreadable. IMO it would be better if written as: return !(kvm && kvm_vm_is_protected(kvm)); which makes it "clear" that you claim to support everything when either kvm == NULL or described an unprotected VM. But it then begs the question: - in what circumstances is kvm == NULL? Is there any case outside of kvm_vm_check_extension()? - do you really support everything? > } > } > > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index 870953b4a8a7..10d853f2722e 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -87,7 +87,7 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm, > if (cap->flags) > return -EINVAL; > > - if (kvm_vm_is_protected(kvm) && !kvm_pvm_ext_allowed(cap->cap)) > + if (is_protected_kvm_enabled() && !kvm_pkvm_ext_allowed(kvm, cap->cap)) > return -EINVAL; > > switch (cap->cap) { > @@ -299,7 +299,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) > { > int r; > > - if (kvm && kvm_vm_is_protected(kvm) && !kvm_pvm_ext_allowed(ext)) > + if (is_protected_kvm_enabled() && !kvm_pkvm_ext_allowed(kvm, ext)) > return 0; But that's a change in semantics here. Calling this function outside of the context of a VM (kvm == NULL) will now report that *ALL* extensions are valid, instead of limiting it to the allow-list. With that, userspace can no longer detect what is available and what isn't before creating a VM with the correct VM type. I don't think this is the right way to do this, unless you really want to break the existing UAPI (rhetorical question). Thanks, M. -- Without deviation from the norm, progress is not possible.