]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: Clear __hyp_running_vcpu when flushing the pKVM hyp vCPU
authorHyunwoo Kim <imv4bel@gmail.com>
Sat, 6 Jun 2026 17:56:10 +0000 (02:56 +0900)
committerMarc Zyngier <maz@kernel.org>
Sun, 7 Jun 2026 13:07:06 +0000 (14:07 +0100)
flush_hyp_vcpu() copies the host vCPU context into the hyp's private
vCPU on every run. ctxt_to_vcpu() expects a guest context to have a
NULL __hyp_running_vcpu, which is only ever set on the host context, so
that it resolves the vCPU via container_of(). While this is generally
the case, flush_hyp_vcpu() copies the context verbatim and does not
enforce this, so a value provided by the host is dereferenced at EL2
(host -> EL2).

Fix by clearing __hyp_running_vcpu after the copy.

Cc: stable@vger.kernel.org
Fixes: be66e67f1750 ("KVM: arm64: Use the pKVM hyp vCPU structure in handle___kvm_vcpu_run()")
Signed-off-by: Hyunwoo Kim <imv4bel@gmail.com>
Reviewed-by: Fuad Tabba <tabba@google.com>
Tested-by: Fuad Tabba <tabba@google.com>
Link: https://patch.msgid.link/20260606175614.83273-2-imv4bel@gmail.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/hyp/nvhe/hyp-main.c

index 06db299c37a89a9873936014370e64ac9ac254f7..02c5d6e5abcbf06acace0e64ee447e8b6ad2ebbe 100644 (file)
@@ -128,6 +128,9 @@ static void flush_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu)
 
        hyp_vcpu->vcpu.arch.ctxt        = host_vcpu->arch.ctxt;
 
+       /* __hyp_running_vcpu must be NULL in a guest context. */
+       hyp_vcpu->vcpu.arch.ctxt.__hyp_running_vcpu = NULL;
+
        hyp_vcpu->vcpu.arch.mdcr_el2    = host_vcpu->arch.mdcr_el2;
        hyp_vcpu->vcpu.arch.hcr_el2 &= ~(HCR_TWI | HCR_TWE);
        hyp_vcpu->vcpu.arch.hcr_el2 |= READ_ONCE(host_vcpu->arch.hcr_el2) &