linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* bitmap API consistency
@ 2017-05-24 12:11 Andy Shevchenko
  2017-05-24 12:38 ` Rasmus Villemoes
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2017-05-24 12:11 UTC (permalink / raw)
  To: Rasmus Villemoes; +Cc: Andrew Morton, LKML, Martin Schwidefsky

Hi!

Surprisingly discovered today that bitmap API is not consistent in some
cases (at least one I found recently).

bitmap_fill() sets area of bits in a bitmap.
bitmap_zero() clears them.

However, if _fill() does something sane, _zero() clears _all_ bits up to
word size (long).

I think it should be fixed to be consistent with _fill() variant.

Thoughts?

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: bitmap API consistency
  2017-05-24 12:11 bitmap API consistency Andy Shevchenko
@ 2017-05-24 12:38 ` Rasmus Villemoes
  2017-05-24 12:43   ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Rasmus Villemoes @ 2017-05-24 12:38 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Andrew Morton, LKML, Martin Schwidefsky

On 24 May 2017 at 14:11, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> Hi!
>
> Surprisingly discovered today that bitmap API is not consistent in some
> cases (at least one I found recently).
>
> bitmap_fill() sets area of bits in a bitmap.
> bitmap_zero() clears them.
>
> However, if _fill() does something sane, _zero() clears _all_ bits up to
> word size (long).
>
> I think it should be fixed to be consistent with _fill() variant.

What do you want it to do? It always acts on whole words, so the last
word must be set to something. One might as well say that _zero and
_fill are consistent in that they both set the bits beyond nbits in
the last word to 0.

If anything, I'd change bitmap_fill to do a memset(0xff) of the entire
region. There used to be bugs where some of the bitmap_* functions
didn't actually ignore the trailing bits, making it somewhat important
that they were always 0, but I think they're fixed now.

Note that if one wants a guarantee that the trailing bits are not
touched at all, the APIs to use are bitmap_{set, clear}(dst, 0,
count). bitmap_{zero,fill} assumes that nbits is the total size of the
bitmap (i.e. that the user will never care about bits beyond nbits).
Maybe a few comments could be added somewhere.

Rasmus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: bitmap API consistency
  2017-05-24 12:38 ` Rasmus Villemoes
@ 2017-05-24 12:43   ` Andy Shevchenko
  2017-12-19 17:32     ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2017-05-24 12:43 UTC (permalink / raw)
  To: Rasmus Villemoes; +Cc: Andrew Morton, LKML, Martin Schwidefsky

On Wed, 2017-05-24 at 14:38 +0200, Rasmus Villemoes wrote:
> On 24 May 2017 at 14:11, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> > Hi!
> > 
> > Surprisingly discovered today that bitmap API is not consistent in
> > some
> > cases (at least one I found recently).
> > 
> > bitmap_fill() sets area of bits in a bitmap.
> > bitmap_zero() clears them.
> > 
> > However, if _fill() does something sane, _zero() clears _all_ bits
> > up to
> > word size (long).
> > 
> > I think it should be fixed to be consistent with _fill() variant.
> 
> What do you want it to do?

Based on my vision and your answer below, thanks for it, I think we need
to
a) make _fill() to fill entire _aligned_ area
b) update comments in the header and documentation, if needed, to
specify that _fill() / _zero() operates on aligned to word size area,
while _set() and _clear() do exact amount of bits.

>  It always acts on whole words, so the last
> word must be set to something. One might as well say that _zero and
> _fill are consistent in that they both set the bits beyond nbits in
> the last word to 0.
> 
> If anything, I'd change bitmap_fill to do a memset(0xff) of the entire
> region. There used to be bugs where some of the bitmap_* functions
> didn't actually ignore the trailing bits, making it somewhat important
> that they were always 0, but I think they're fixed now.
> 
> Note that if one wants a guarantee that the trailing bits are not
> touched at all, the APIs to use are bitmap_{set, clear}(dst, 0,
> count). bitmap_{zero,fill} assumes that nbits is the total size of the
> bitmap (i.e. that the user will never care about bits beyond nbits).
> Maybe a few comments could be added somewhere.
> 
> Rasmus

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: bitmap API consistency
  2017-05-24 12:43   ` Andy Shevchenko
@ 2017-12-19 17:32     ` Andy Shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2017-12-19 17:32 UTC (permalink / raw)
  To: Rasmus Villemoes; +Cc: Andrew Morton, LKML, Martin Schwidefsky

On Wed, 2017-05-24 at 15:43 +0300, Andy Shevchenko wrote:
> On Wed, 2017-05-24 at 14:38 +0200, Rasmus Villemoes wrote:
> > On 24 May 2017 at 14:11, Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > > Hi!
> > > 
> > > Surprisingly discovered today that bitmap API is not consistent in
> > > some
> > > cases (at least one I found recently).
> > > 
> > > bitmap_fill() sets area of bits in a bitmap.
> > > bitmap_zero() clears them.
> > > 
> > > However, if _fill() does something sane, _zero() clears _all_ bits
> > > up to
> > > word size (long).
> > > 
> > > I think it should be fixed to be consistent with _fill() variant.
> > 
> > What do you want it to do?
> 
> Based on my vision and your answer below, thanks for it, I think we
> need
> to
> a) make _fill() to fill entire _aligned_ area
> b) update comments in the header and documentation, if needed, to
> specify that _fill() / _zero() operates on aligned to word size area,
> while _set() and _clear() do exact amount of bits.

7 months passed, can we eventually do something about it?

> >  It always acts on whole words, so the last
> > word must be set to something. One might as well say that _zero and
> > _fill are consistent in that they both set the bits beyond nbits in
> > the last word to 0.
> > 
> > If anything, I'd change bitmap_fill to do a memset(0xff) of the
> > entire
> > region. There used to be bugs where some of the bitmap_* functions
> > didn't actually ignore the trailing bits, making it somewhat
> > important
> > that they were always 0, but I think they're fixed now.
> > 
> > Note that if one wants a guarantee that the trailing bits are not
> > touched at all, the APIs to use are bitmap_{set, clear}(dst, 0,
> > count). bitmap_{zero,fill} assumes that nbits is the total size of
> > the
> > bitmap (i.e. that the user will never care about bits beyond nbits).
> > Maybe a few comments could be added somewhere.

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-12-19 17:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-24 12:11 bitmap API consistency Andy Shevchenko
2017-05-24 12:38 ` Rasmus Villemoes
2017-05-24 12:43   ` Andy Shevchenko
2017-12-19 17:32     ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).