Message ID | 1544516693-5395-2-git-send-email-wei.w.wang@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | virtio-balloon: free page hint support | expand |
* Wei Wang (wei.w.wang@intel.com) wrote: > BITMAP_LAST_WORD_MASK(nbits) returns 0xffffffff when "nbits=0", which > makes bitmap_count_one fail to handle the "nbits=0" case. It appears to be > preferred to remain BITMAP_LAST_WORD_MASK identical to the kernel > implementation that it is ported from. > > So this patch fixes bitmap_count_one to handle the nbits=0 case. OK; it's a little odd that it's only bitmap_count_one that's being fixed for this case; but OK. Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> > Inital Discussion Link: > https://www.mail-archive.com/qemu-devel@nongnu.org/msg554316.html > Signed-off-by: Wei Wang <wei.w.wang@intel.com> > CC: Juan Quintela <quintela@redhat.com> > CC: Dr. David Alan Gilbert <dgilbert@redhat.com> > CC: Peter Xu <peterx@redhat.com> > --- > include/qemu/bitmap.h | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h > index 509eedd..679f1bd 100644 > --- a/include/qemu/bitmap.h > +++ b/include/qemu/bitmap.h > @@ -221,6 +221,10 @@ static inline int bitmap_intersects(const unsigned long *src1, > > static inline long bitmap_count_one(const unsigned long *bitmap, long nbits) > { > + if (unlikely(!nbits)) { > + return 0; > + } > + > if (small_nbits(nbits)) { > return ctpopl(*bitmap & BITMAP_LAST_WORD_MASK(nbits)); > } else { > -- > 1.8.3.1 > -- Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
On 12/13/2018 10:28 PM, Dr. David Alan Gilbert wrote: > * Wei Wang (wei.w.wang@intel.com) wrote: >> BITMAP_LAST_WORD_MASK(nbits) returns 0xffffffff when "nbits=0", which >> makes bitmap_count_one fail to handle the "nbits=0" case. It appears to be >> preferred to remain BITMAP_LAST_WORD_MASK identical to the kernel >> implementation that it is ported from. >> >> So this patch fixes bitmap_count_one to handle the nbits=0 case. > OK; it's a little odd that it's only bitmap_count_one that's being fixed > for this case; but OK. > > > Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Thanks. We could also help fix other callers outside this series. (this one is put here as it helps this optimization feature avoid that issue). Best, Wei
diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h index 509eedd..679f1bd 100644 --- a/include/qemu/bitmap.h +++ b/include/qemu/bitmap.h @@ -221,6 +221,10 @@ static inline int bitmap_intersects(const unsigned long *src1, static inline long bitmap_count_one(const unsigned long *bitmap, long nbits) { + if (unlikely(!nbits)) { + return 0; + } + if (small_nbits(nbits)) { return ctpopl(*bitmap & BITMAP_LAST_WORD_MASK(nbits)); } else {
BITMAP_LAST_WORD_MASK(nbits) returns 0xffffffff when "nbits=0", which makes bitmap_count_one fail to handle the "nbits=0" case. It appears to be preferred to remain BITMAP_LAST_WORD_MASK identical to the kernel implementation that it is ported from. So this patch fixes bitmap_count_one to handle the nbits=0 case. Inital Discussion Link: https://www.mail-archive.com/qemu-devel@nongnu.org/msg554316.html Signed-off-by: Wei Wang <wei.w.wang@intel.com> CC: Juan Quintela <quintela@redhat.com> CC: Dr. David Alan Gilbert <dgilbert@redhat.com> CC: Peter Xu <peterx@redhat.com> --- include/qemu/bitmap.h | 4 ++++ 1 file changed, 4 insertions(+)