From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 791913033E6; Fri, 2 Oct 2026 14:15:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790950513; cv=none; b=aCIGyuBCwkkQvx7ZUlzl7pnwJFjuKWy3ZEb4QGho2AYtrCPzLg7vmaLP4hoV42JiE5nV7E1l3gO28jnlR6MJwvBX3UdpF92jWVRz+Y8KsKlvM0OCfaRvpQD8tDZrVgl1Ldf43UvdLtuKYHjPCZqdjlb55gVHfPCw6AQz3sWAxVM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790950513; c=relaxed/simple; bh=jbt6HMNpevO3Sru9Gr+rctah7k8MdelRY/4rnrM3z6A=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=clJlZMi/GMBqogEQknGeYdqikrfby58oU9zHaZkqiG6uN0NFr0YyO6x2rRNt7j1vYuIBrf75ae7pj9kCy2CFTs2hOOF8l3wODPo7+Z/GRJBhMWrKleSk1fVdaB4/+2jXJ7TLRUXRO62FP45QA4NHNFYL4upddWYTloEmhnHL/HU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YlKx3BnJ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YlKx3BnJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6B081F000FF; Fri, 2 Oct 2026 14:15:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790950508; bh=YbzZ3YWMbEwGiluxGV1MRuG2h8ePt79LduY47dgmoYk=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=YlKx3BnJP0wpNWoz5kgh4BYnGpuOexo95Vk32IOGkSgTygnkIl7+36f4ncWYXx4pX QNtHUCpfpDMikH0CQUbiDtpECeRXCKj/kDOX6YwOmqvEdI5S2rz4bxKvtqhy6Wdl9r XVRzqMuAav58TvbYpvuPsnWriI7M9bxxNvsb+8B216bEkiOmGF4Ike5ABp4QDoHFWH sWFFoJUsfZvmLNJOzgOV2pORfi0mozjJxMh/QY2l6z6rXXhJvB4kQO/xk3iaOsuUJg s5dspUXSNPKRMYPBpm33c6TvDMmqVSJA0XtmwweKRwkbRczVquE096NAhRJ6DxXpJq HN9jy3sf99Alw== 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 1xCe2U-0000000GG11-2M95; Fri, 02 Oct 2026 14:15:06 +0000 Date: Fri, 02 Oct 2026 15:15:06 +0100 Message-ID: <86pkxs2npx.wl-maz@kernel.org> From: Marc Zyngier To: Suzuki K Poulose , Fuad Tabba Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev, will@kernel.org, catalin.marinas@arm.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, steven.price@arm.com, aneesh.kumar@kernel.org, oupton@kernel.org, gshan@redhat.com, joey.gouly@arm.com, yuzenghui@huawei.com, linux-coco@lists.linux.dev, gankulkarni@os.amperecomputing.com, sdonthineni@nvidia.com, alpergun@google.com, fj0570is@fujitsu.com, WeiLin.Chang@arm.com, lpieralisi@kernel.org, enju.kohei@fujitsu.com, sudeep.holla@arm.com, jonathan.cameron@oss.qualcomm.com Subject: Re: [PATCH v21 05/23] KVM: arm64: Track the type of VM in kvm_arch In-Reply-To: References: <20261001210703.1597150-1-suzuki.poulose@arm.com> <20261001210703.1597150-6-suzuki.poulose@arm.com> <86se2o2rbs.wl-maz@kernel.org> 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: linux-kernel@vger.kernel.org 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: suzuki.poulose@arm.com, tabba@google.com, kvm@vger.kernel.org, kvmarm@lists.linux.dev, will@kernel.org, catalin.marinas@arm.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, steven.price@arm.com, aneesh.kumar@kernel.org, oupton@kernel.org, gshan@redhat.com, joey.gouly@arm.com, yuzenghui@huawei.com, linux-coco@lists.linux.dev, gankulkarni@os.amperecomputing.com, sdonthineni@nvidia.com, alpergun@google.com, fj0570is@fujitsu.com, WeiLin.Chang@arm.com, lpieralisi@kernel.org, enju.kohei@fujitsu.com, sudeep.holla@arm.com, jonathan.cameron@oss.qualcomm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Fri, 02 Oct 2026 14:05:17 +0100, Fuad Tabba wrote: > > Hi Marc, > > On Fri, 02 Oct 2026 13:57:11 +0100, Marc Zyngier wrote: > [...] > > Just to make sure. Is that what you had in mind? > > A diff is worth a thousand words :) Yes, that's it. With that, every > remaining hyp user of vcpu_is_protected() only runs with pKVM, so the > kern_hyp_va() case in the macro can go too. Actually, scratch all of that. The whole thing is written upside down, and makes little sense. I wish I had looked at it more closely... The *_protected__pkvm() shouldn't exist at all, because nVHE is the only context where it matters, and therefore we can specialise the *normal* accessors for the nVHE context (see below). No *_pkvm(), no kern_hyp_va(), nothing at all. I'm also dead against the unprotected_pkvm() stuff, as it looks pointlessly specialised. Specifically, this nugget is making my head spin: + if (!kvm_vm_is_unprotected_pkvm(vcpu->kvm)) return; Honestly, we introduce the flavor stuff to make it easy to match things on a particular VM type in a readable way. So why isn't this reading: if (vcpu->kvm->arch.vm_flavor != VM_PROTECTED_PKVM) return; which makes it pretty explicit. You can gate it with a is_protected_kvm_enabled() if you want, as it was before. M. diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 9e1fa00d96f7c..6b64f9610f3a3 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -1519,41 +1519,22 @@ struct kvm *kvm_arch_alloc_vm(void); #define __KVM_HAVE_ARCH_FLUSH_REMOTE_TLBS_RANGE -#define kvm_vm_is_protected(kvm) ((kvm)->arch.vm_flavor >= __VM_PROTECTED) -/* - * Accessing vcpu->kvm from nVHE hyp stub is tricky, as we need to convert the - * pointer to the hyp VA. With pKVM, the nVHE code runs with the hyp_vcpu, - * which is populated correctly. - */ -#define vcpu_is_protected(vcpu) \ - ({ \ - struct kvm *__kvm = READ_ONCE((vcpu)->kvm); \ - bool __protected = false; \ - \ - if (__kvm) { \ - if (is_nvhe_hyp_code() && \ - !is_protected_kvm_enabled()) \ - __kvm = kern_hyp_va(__kvm); \ - \ - __protected = kvm_vm_is_protected(__kvm); \ - } \ - __protected; \ - }) - -#define kvm_vm_is_protected_pkvm(kvm) \ +#ifdef __KVM_NVHE_HYPERVISOR__ +#define kvm_vm_is_protected(kvm) \ (is_protected_kvm_enabled() && ((kvm)->arch.vm_flavor == VM_PROTECTED_PKVM)) - /* * Rely on is_protected_kvm_enabled() check in kvm_vm_is_protected_pkvm() to * make sure the vcpu->kvm is always valid VA in the context */ -#define vcpu_is_protected_pkvm(vcpu) \ +#define vcpu_is_protected(vcpu) \ ({ \ struct kvm *__kvm = READ_ONCE((vcpu)->kvm); \ - \ - (__kvm && kvm_vm_is_protected_pkvm(__kvm)); \ + (__kvm && kvm_vm_is_protected(__kvm)); \ }) - +#else +#define kvm_vm_is_protected(kvm) ((kvm)->arch.vm_flavor >= __VM_PROTECTED) +#define vcpu_is_protected(vcpu) kvm_vm_is_protected((vcpu)->kvm) +#endif #define kvm_vm_is_unprotected_pkvm(kvm) \ (is_protected_kvm_enabled() && ((kvm)->arch.vm_flavor == VM_PKVM)) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 0f4e8b71fa85d..9ba86450fe4af 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -2624,7 +2624,7 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, hva_t hva, reg_end; int ret = 0; - if (kvm_vm_is_protected_pkvm(kvm)) { + if (kvm_vm_is_protected(kvm)) { /* Cannot modify memslots once a pVM has run. */ if (pkvm_hyp_vm_is_created(kvm) && (change == KVM_MR_DELETE || change == KVM_MR_MOVE)) { -- Without deviation from the norm, progress is not possible.