Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

KVM: arm64: vgic-v5: Cast vgic_apr to u32 to avoid undefined behaviours

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>

+3 -2
+3 -2
arch/arm64/kvm/vgic/vgic-v5.c
··· 212 212 static u32 vgic_v5_get_effective_priority_mask(struct kvm_vcpu *vcpu) 213 213 { 214 214 struct vgic_v5_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v5; 215 - u32 highest_ap, priority_mask; 215 + u32 highest_ap, priority_mask, apr; 216 216 217 217 /* 218 218 * If the guest's CPU has not opted to receive interrupts, then the ··· 227 227 * priority. Explicitly use the 32-bit version here as we have 32 228 228 * priorities. 32 then means that there are no active priorities. 229 229 */ 230 - highest_ap = cpu_if->vgic_apr ? __builtin_ctz(cpu_if->vgic_apr) : 32; 230 + apr = cpu_if->vgic_apr; 231 + highest_ap = apr ? __builtin_ctz(apr) : 32; 231 232 232 233 /* 233 234 * An interrupt is of sufficient priority if it is equal to or