Skip to content

Commit f2ccc51

Browse files
bibo-maoKexyBiscuit
authored andcommitted
FROMGIT: LoongArch: KVM: Use standard bitops API with eiointc
Standard bitops APIs such test_bit() is used here, rather than manually calculating the offset and mask. Also use non-atomic API __set_bit() and __clear_bit() rather than set_bit() and clear_bit(), since the global spinlock is held already. Signed-off-by: Bibo Mao <[email protected]> Signed-off-by: Huacai Chen <[email protected]> (cherry picked from commit d23bd87 https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson.git loongarch-next) Signed-off-by: Kexy Biscuit <[email protected]>
1 parent cd5730f commit f2ccc51

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

arch/loongarch/kvm/intc/eiointc.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
static void eiointc_set_sw_coreisr(struct loongarch_eiointc *s)
1111
{
12-
int ipnum, cpu, cpuid, irq_index, irq_mask, irq;
12+
int ipnum, cpu, cpuid, irq;
1313
struct kvm_vcpu *vcpu;
1414

1515
for (irq = 0; irq < EIOINTC_IRQS; irq++) {
@@ -18,25 +18,23 @@ static void eiointc_set_sw_coreisr(struct loongarch_eiointc *s)
1818
ipnum = count_trailing_zeros(ipnum);
1919
ipnum = (ipnum >= 0 && ipnum < 4) ? ipnum : 0;
2020
}
21-
irq_index = irq / 32;
22-
irq_mask = BIT(irq & 0x1f);
2321

2422
cpuid = s->coremap.reg_u8[irq];
2523
vcpu = kvm_get_vcpu_by_cpuid(s->kvm, cpuid);
2624
if (!vcpu)
2725
continue;
2826

2927
cpu = vcpu->vcpu_id;
30-
if (!!(s->coreisr.reg_u32[cpu][irq_index] & irq_mask))
31-
set_bit(irq, s->sw_coreisr[cpu][ipnum]);
28+
if (test_bit(irq, (unsigned long *)s->coreisr.reg_u32[cpu]))
29+
__set_bit(irq, s->sw_coreisr[cpu][ipnum]);
3230
else
33-
clear_bit(irq, s->sw_coreisr[cpu][ipnum]);
31+
__clear_bit(irq, s->sw_coreisr[cpu][ipnum]);
3432
}
3533
}
3634

3735
static void eiointc_update_irq(struct loongarch_eiointc *s, int irq, int level)
3836
{
39-
int ipnum, cpu, found, irq_index, irq_mask;
37+
int ipnum, cpu, found;
4038
struct kvm_vcpu *vcpu;
4139
struct kvm_interrupt vcpu_irq;
4240

@@ -48,19 +46,16 @@ static void eiointc_update_irq(struct loongarch_eiointc *s, int irq, int level)
4846

4947
cpu = s->sw_coremap[irq];
5048
vcpu = kvm_get_vcpu(s->kvm, cpu);
51-
irq_index = irq / 32;
52-
irq_mask = BIT(irq & 0x1f);
53-
5449
if (level) {
5550
/* if not enable return false */
56-
if (((s->enable.reg_u32[irq_index]) & irq_mask) == 0)
51+
if (!test_bit(irq, (unsigned long *)s->enable.reg_u32))
5752
return;
58-
s->coreisr.reg_u32[cpu][irq_index] |= irq_mask;
53+
__set_bit(irq, (unsigned long *)s->coreisr.reg_u32[cpu]);
5954
found = find_first_bit(s->sw_coreisr[cpu][ipnum], EIOINTC_IRQS);
60-
set_bit(irq, s->sw_coreisr[cpu][ipnum]);
55+
__set_bit(irq, s->sw_coreisr[cpu][ipnum]);
6156
} else {
62-
s->coreisr.reg_u32[cpu][irq_index] &= ~irq_mask;
63-
clear_bit(irq, s->sw_coreisr[cpu][ipnum]);
57+
__clear_bit(irq, (unsigned long *)s->coreisr.reg_u32[cpu]);
58+
__clear_bit(irq, s->sw_coreisr[cpu][ipnum]);
6459
found = find_first_bit(s->sw_coreisr[cpu][ipnum], EIOINTC_IRQS);
6560
}
6661

@@ -110,8 +105,8 @@ void eiointc_set_irq(struct loongarch_eiointc *s, int irq, int level)
110105
unsigned long flags;
111106
unsigned long *isr = (unsigned long *)s->isr.reg_u8;
112107

113-
level ? set_bit(irq, isr) : clear_bit(irq, isr);
114108
spin_lock_irqsave(&s->lock, flags);
109+
level ? __set_bit(irq, isr) : __clear_bit(irq, isr);
115110
eiointc_update_irq(s, irq, level);
116111
spin_unlock_irqrestore(&s->lock, flags);
117112
}

0 commit comments

Comments
 (0)