From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DDB76284B29 for ; Wed, 26 Nov 2025 10:53:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764154381; cv=none; b=lCSsVKc3aMiizmqnsypj3O4MFbzC4GR9OBGP0B9XPM1Gf8HMfSlJeS3GkMtZwj8+JkFzLPlLU/klg+pO2q4MULgeGYcax49rsN3bz43TKDTi4wJoPxPwO5xWWukD6QaAMkAhGby0GBIb0PhNic7dCXrOA77FZESQ8nyZ6nLFq4s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764154381; c=relaxed/simple; bh=MDN12d2nJbSInDxPygyi+YoQ0BHEFi3212+fJiwfjyk=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=knIWmPKpc67Ur2Rrboor7gv2DWTKsI1MRgYg5YexSLeWmlaVIPfBTgfmHhsfXIRV1NlllLG3XkBsQFAaLmhXz+RQvHe1PjE9ycbVGZDP7fGJFWz09OYgEl7+IGJr1Vf1XUWnHZr0/tVFVUJpX1TW87DV6PGPpp94lEbE91spp0A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GAGNANgA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GAGNANgA" 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) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: 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 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.