On Fri, Mar 21, 2025, Thomas Gleixner wrote: > On Wed, Feb 26 2025 at 14:35, Neeraj Upadhyay wrote: > > +static int find_highest_isr(void *backing_page) > > +{ > > + int vec_per_reg = 32; > > + int max_vec = 256; > > + u32 reg; > > + int vec; > > + > > + for (vec = max_vec - 32; vec >= 0; vec -= vec_per_reg) { > > + reg = get_reg(backing_page, APIC_ISR + REG_POS(vec)); > > + if (reg) > > + return __fls(reg) + vec; > > + } > > + > > + return -1; > > Congrats. You managed to re-implement find_last_bit() in the most > incomprehesible way. Heh, having burned myself quite badly by trying to use find_last_bit() to get pending/in-service IRQs in KVM code... Using find_last_bit() doesn't work because the ISR chunks aren't contiguous, they're 4-byte registers at 16-byte strides. That said, copy+pasting the aforementioned KVM code is absurd. Please extract KVM's find_highest_vector() to common code, along with any other APIC utilities in KVM that would be useful. I haven't looked at this series, but I suspect there's a _lot_ of code in KVM's local APIC emulation that can be shared.