]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
LoongArch: KVM: Rework kvm_send_pv_ipi()
authorYury Norov (NVIDIA) <yury.norov@gmail.com>
Mon, 21 Jul 2025 01:26:32 +0000 (09:26 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Mon, 21 Jul 2025 01:26:32 +0000 (09:26 +0800)
The function in fact traverses a "bitmap" stored in GPR regs A1 and A2,
but does it in a non-obvious way by creating a single-word bitmap twice.

This patch switches the function to create a single 2-word bitmap, and
also employs for_each_set_bit() macro, as it helps to drop most of the
housekeeping code.

While there, convert the function to return void to not confuse readers
with unchecked result.

Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/kvm/exit.c

index fa52251b3bf1c889e27a055fe8b126ac4ae50563..a0ceb49a060f7636de827cea52c380c2fce955a2 100644 (file)
@@ -821,32 +821,25 @@ static int kvm_handle_lbt_disabled(struct kvm_vcpu *vcpu, int ecode)
        return RESUME_GUEST;
 }
 
-static int kvm_send_pv_ipi(struct kvm_vcpu *vcpu)
+static void kvm_send_pv_ipi(struct kvm_vcpu *vcpu)
 {
-       unsigned int min, cpu, i;
-       unsigned long ipi_bitmap;
+       unsigned int min, cpu;
        struct kvm_vcpu *dest;
+       DECLARE_BITMAP(ipi_bitmap, BITS_PER_LONG * 2) = {
+               kvm_read_reg(vcpu, LOONGARCH_GPR_A1),
+               kvm_read_reg(vcpu, LOONGARCH_GPR_A2)
+       };
 
        min = kvm_read_reg(vcpu, LOONGARCH_GPR_A3);
-       for (i = 0; i < 2; i++, min += BITS_PER_LONG) {
-               ipi_bitmap = kvm_read_reg(vcpu, LOONGARCH_GPR_A1 + i);
-               if (!ipi_bitmap)
+       for_each_set_bit(cpu, ipi_bitmap, BITS_PER_LONG * 2) {
+               dest = kvm_get_vcpu_by_cpuid(vcpu->kvm, cpu + min);
+               if (!dest)
                        continue;
 
-               cpu = find_first_bit((void *)&ipi_bitmap, BITS_PER_LONG);
-               while (cpu < BITS_PER_LONG) {
-                       dest = kvm_get_vcpu_by_cpuid(vcpu->kvm, cpu + min);
-                       cpu = find_next_bit((void *)&ipi_bitmap, BITS_PER_LONG, cpu + 1);
-                       if (!dest)
-                               continue;
-
-                       /* Send SWI0 to dest vcpu to emulate IPI interrupt */
-                       kvm_queue_irq(dest, INT_SWI0);
-                       kvm_vcpu_kick(dest);
-               }
+               /* Send SWI0 to dest vcpu to emulate IPI interrupt */
+               kvm_queue_irq(dest, INT_SWI0);
+               kvm_vcpu_kick(dest);
        }
-
-       return 0;
 }
 
 /*