[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v1 08/21] hw/i386/kvm/xen_evtchn: Fix off-by-one in do_remove_pci_vector()



On Wed, 2026-11-25 at 13:31 +0000, Paul Durrant wrote:
> On 25/11/2026 05:03, David Woodhouse wrote:
> > On Wed, 2026-11-25 at 11:16 +0000, Paul Durrant wrote:
> > > 
> > > I guess I'm missing a subtlety here, but the test only fires if pirq is
> > > a multiple of 64... so why is advancing to the next word by adding 64
> > > not correct?
> > 
> > You're missing the same subtlety that I missed when I wrote it in the
> > first place: the loop *itself* does pirq++ every time, so when we do
> > 'pirq += 64; continue;' we end up adding *65*.
> > 
> >      for (pirq = 0; pirq < s->nr_pirqs; pirq++) {
> >          /*
> >           * We could be cleverer here, but it isn't really a fast path, and
> >           * this trivial optimisation is enough to let us skip the big gap
> >           * in the middle a bit quicker (in terms of both loop iterations,
> >           * and cache lines).
> >           */
> >          if (!(pirq & 63) && !(pirq_inuse_word(s, pirq))) {
> >              pirq += 63;
> >              continue;
> >          }
> 
> Gah! Recoding as a while loop where the increment is either 1 or 64 
> would make this much less fragile.

Or refactor it completely to use ffs? Do we have a for_each_set_bit()
helper? Do we want one?

Attachment: smime.p7s
Description: S/MIME cryptographic signature


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.