[PATCH v21 05/23] KVM: arm64: Track the type of VM in kvm_arch

Marc Zyngier maz at kernel.org
Fri Oct 2 05:57:11 PDT 2026


On Fri, 02 Oct 2026 11:06:52 +0100,
Fuad Tabba <tabba at google.com> wrote:
> 
> Hi Suzuki,
> 
> On Thu, 01 Oct 2026 22:06:45 +0100, Suzuki K Poulose
> <suzuki.poulose at arm.com> wrote:
> [...]
> > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> [...]
> > +#define vcpu_is_protected(vcpu)                                                \
> [...]
> > +                        if (is_nvhe_hyp_code() &&                        \
> > +                            !is_protected_kvm_enabled())                 \
> > +                                __kvm = kern_hyp_va(__kvm);                 \
> 
> On a non-pKVM nVHE host, the hyp callers of this in switch.c and
> timer-sr.c now translate vcpu->kvm and load vm_flavor on every guest
> entry and exit, where the is_protected_kvm_enabled() check used to
> short-circuit. Could they use vcpu_is_protected_pkvm(), and drop the
> kern_hyp_va() here?

Just to make sure. Is that what you had in mind?

diff --git a/arch/arm64/kvm/hyp/nvhe/switch.c b/arch/arm64/kvm/hyp/nvhe/switch.c
index 7318e3e6a5f36..2a3e6d83682d5 100644
--- a/arch/arm64/kvm/hyp/nvhe/switch.c
+++ b/arch/arm64/kvm/hyp/nvhe/switch.c
@@ -217,7 +217,7 @@ static const exit_handler_fn pvm_exit_handlers[] = {
 
 static const exit_handler_fn *kvm_get_exit_handler_array(struct kvm_vcpu *vcpu)
 {
-	if (unlikely(vcpu_is_protected(vcpu)))
+	if (unlikely(vcpu_is_protected_pkvm(vcpu)))
 		return pvm_exit_handlers;
 
 	return hyp_exit_handlers;
@@ -238,7 +238,7 @@ static inline bool fixup_guest_exit(struct kvm_vcpu *vcpu, u64 *exit_code)
 	 * it.  The check below is based on the one in
 	 * kvm_arch_vcpu_ioctl_run().
 	 */
-	if (unlikely(vcpu_is_protected(vcpu) && vcpu_mode_is_32bit(vcpu))) {
+	if (unlikely(vcpu_is_protected_pkvm(vcpu) && vcpu_mode_is_32bit(vcpu))) {
 		/*
 		 * As we have caught the guest red-handed, decide that it isn't
 		 * fit for purpose anymore by making the vcpu invalid. The VMM
diff --git a/arch/arm64/kvm/hyp/nvhe/timer-sr.c b/arch/arm64/kvm/hyp/nvhe/timer-sr.c
index 9930657169133..17bd1ff621ab6 100644
--- a/arch/arm64/kvm/hyp/nvhe/timer-sr.c
+++ b/arch/arm64/kvm/hyp/nvhe/timer-sr.c
@@ -48,7 +48,7 @@ void __timer_enable_traps(struct kvm_vcpu *vcpu)
 	 * or running a protected VM (we don't offset anything in this case).
 	 */
 	clr = CNTHCTL_EL1PCEN;
-	if (vcpu_is_protected(vcpu) ||
+	if (vcpu_is_protected_pkvm(vcpu) ||
 	    !timer_get_offset(vcpu_ptimer(vcpu)))
 		set |= CNTHCTL_EL1PCTEN;
 	else


	M.

-- 
Without deviation from the norm, progress is not possible.



More information about the linux-arm-kernel mailing list