]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: vgic-v5: Cast vgic_apr to u32 to avoid undefined behaviours
authorMarc Zyngier <maz@kernel.org>
Wed, 1 Apr 2026 10:36:03 +0000 (11:36 +0100)
committerMarc Zyngier <maz@kernel.org>
Wed, 1 Apr 2026 14:42:26 +0000 (15:42 +0100)
Passing a u64 to __builtin_ctz() is odd, and requires some digging to
figure out why this construct is indeed safe as long as the HW is
correct.

But it is much easier to make it clear to the compiler by casting
the u64 into an intermediate u32, and be done with the UD.

Reviewed-by: Sascha Bischoff <sascha.bischoff@arm.com>
Fixes: 933e5288fa971 ("KVM: arm64: gic-v5: Check for pending PPIs")
Link: https://sashiko.dev/#/patchset/20260319154937.3619520-1-sascha.bischoff%40arm.com
Link: https://patch.msgid.link/20260401103611.357092-9-maz@kernel.org
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/vgic/vgic-v5.c

index 422741c86c6a8940bcbbbbad6f77198e7a0a08f8..0f269321ece4b1cd457e38c4bdec31ad24677bdb 100644 (file)
@@ -212,7 +212,7 @@ int vgic_v5_finalize_ppi_state(struct kvm *kvm)
 static u32 vgic_v5_get_effective_priority_mask(struct kvm_vcpu *vcpu)
 {
        struct vgic_v5_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v5;
-       u32 highest_ap, priority_mask;
+       u32 highest_ap, priority_mask, apr;
 
        /*
         * If the guest's CPU has not opted to receive interrupts, then the
@@ -227,7 +227,8 @@ static u32 vgic_v5_get_effective_priority_mask(struct kvm_vcpu *vcpu)
         * priority. Explicitly use the 32-bit version here as we have 32
         * priorities. 32 then means that there are no active priorities.
         */
-       highest_ap = cpu_if->vgic_apr ? __builtin_ctz(cpu_if->vgic_apr) : 32;
+       apr = cpu_if->vgic_apr;
+       highest_ap = apr ? __builtin_ctz(apr) : 32;
 
        /*
         * An interrupt is of sufficient priority if it is equal to or