Skip to content

Commit a728b39

Browse files
YuryNorovKexyBiscuit
authored andcommitted
FROMGIT: LoongArch: KVM: Rework kvm_send_pv_ipi()
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 <[email protected]> Signed-off-by: Yury Norov (NVIDIA) <[email protected]> Signed-off-by: Huacai Chen <[email protected]> (cherry picked from commit 640f842 https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson.git loongarch-next) Signed-off-by: Kexy Biscuit <[email protected]>
1 parent 69de9df commit a728b39

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

arch/loongarch/kvm/exit.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -821,32 +821,25 @@ static int kvm_handle_lbt_disabled(struct kvm_vcpu *vcpu, int ecode)
821821
return RESUME_GUEST;
822822
}
823823

824-
static int kvm_send_pv_ipi(struct kvm_vcpu *vcpu)
824+
static void kvm_send_pv_ipi(struct kvm_vcpu *vcpu)
825825
{
826-
unsigned int min, cpu, i;
827-
unsigned long ipi_bitmap;
826+
unsigned int min, cpu;
828827
struct kvm_vcpu *dest;
828+
DECLARE_BITMAP(ipi_bitmap, BITS_PER_LONG * 2) = {
829+
kvm_read_reg(vcpu, LOONGARCH_GPR_A1),
830+
kvm_read_reg(vcpu, LOONGARCH_GPR_A2)
831+
};
829832

830833
min = kvm_read_reg(vcpu, LOONGARCH_GPR_A3);
831-
for (i = 0; i < 2; i++, min += BITS_PER_LONG) {
832-
ipi_bitmap = kvm_read_reg(vcpu, LOONGARCH_GPR_A1 + i);
833-
if (!ipi_bitmap)
834+
for_each_set_bit(cpu, ipi_bitmap, BITS_PER_LONG * 2) {
835+
dest = kvm_get_vcpu_by_cpuid(vcpu->kvm, cpu + min);
836+
if (!dest)
834837
continue;
835838

836-
cpu = find_first_bit((void *)&ipi_bitmap, BITS_PER_LONG);
837-
while (cpu < BITS_PER_LONG) {
838-
dest = kvm_get_vcpu_by_cpuid(vcpu->kvm, cpu + min);
839-
cpu = find_next_bit((void *)&ipi_bitmap, BITS_PER_LONG, cpu + 1);
840-
if (!dest)
841-
continue;
842-
843-
/* Send SWI0 to dest vcpu to emulate IPI interrupt */
844-
kvm_queue_irq(dest, INT_SWI0);
845-
kvm_vcpu_kick(dest);
846-
}
839+
/* Send SWI0 to dest vcpu to emulate IPI interrupt */
840+
kvm_queue_irq(dest, INT_SWI0);
841+
kvm_vcpu_kick(dest);
847842
}
848-
849-
return 0;
850843
}
851844

852845
/*

0 commit comments

Comments
 (0)