Re: [PATCH 2/2] LoongArch: KVM:: simplify kvm_deliver_intr()

From: Yury Norov
Date: Fri Jul 18 2025 - 09:25:16 EST


On Fri, Jul 18, 2025 at 12:13:46PM +0800, Huacai Chen wrote:
> Hi, Yury,
>
> On Thu, Jul 17, 2025 at 12:59 AM Yury Norov <yury.norov@xxxxxxxxx> wrote:
> >
> > From: "Yury Norov (NVIDIA)" <yury.norov@xxxxxxxxx>
> >
> > The function opencodes for_each_set_bit() macro, which makes it bulky.
> > Using the proper API makes all the housekeeping code going away.
> >
> > Signed-off-by: Yury Norov (NVIDIA) <yury.norov@xxxxxxxxx>
> > ---
> > arch/loongarch/kvm/interrupt.c | 25 ++++---------------------
> > 1 file changed, 4 insertions(+), 21 deletions(-)
> >
> > diff --git a/arch/loongarch/kvm/interrupt.c b/arch/loongarch/kvm/interrupt.c
> > index 4c3f22de4b40..8462083f0301 100644
> > --- a/arch/loongarch/kvm/interrupt.c
> > +++ b/arch/loongarch/kvm/interrupt.c
> > @@ -83,28 +83,11 @@ void kvm_deliver_intr(struct kvm_vcpu *vcpu)
> > unsigned long *pending = &vcpu->arch.irq_pending;
> > unsigned long *pending_clr = &vcpu->arch.irq_clear;
> >
> > - if (!(*pending) && !(*pending_clr))
> > - return;
> Is it necessary to keep these two lines?

No. They duplicate the existing logic, and the new one based on
for_each_set_bit(). That's why I remove them.

Thanks,
Yury

> > -
> > - if (*pending_clr) {
> > - priority = __ffs(*pending_clr);
> > - while (priority <= INT_IPI) {
> > - kvm_irq_clear(vcpu, priority);
> > - priority = find_next_bit(pending_clr,
> > - BITS_PER_BYTE * sizeof(*pending_clr),
> > - priority + 1);
> > - }
> > - }
> > + for_each_set_bit(priority, pending_clr, INT_IPI + 1)
> > + kvm_irq_clear(vcpu, priority);
> >
> > - if (*pending) {
> > - priority = __ffs(*pending);
> > - while (priority <= INT_IPI) {
> > - kvm_irq_deliver(vcpu, priority);
> > - priority = find_next_bit(pending,
> > - BITS_PER_BYTE * sizeof(*pending),
> > - priority + 1);
> > - }
> > - }
> > + for_each_set_bit(priority, pending, INT_IPI + 1)
> > + kvm_irq_deliver(vcpu, priority);
> > }
> >
> > int kvm_pending_timer(struct kvm_vcpu *vcpu)
> > --
> > 2.43.0
> >
> >