[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20200608130006.GN2428291@smile.fi.intel.com>
Date: Mon, 8 Jun 2020 16:00:06 +0300
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Alexander Gordeev <agordeev@...ux.ibm.com>
Cc: Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
linux-s390@...r.kernel.org, Stable <stable@...r.kernel.org>,
Andrew Morton <akpm@...ux-foundation.org>,
Yury Norov <yury.norov@...il.com>,
Amritha Nambiar <amritha.nambiar@...el.com>,
Arnaldo Carvalho de Melo <acme@...hat.com>,
Chris Wilson <chris@...is-wilson.co.uk>,
Kees Cook <keescook@...omium.org>,
Matthew Wilcox <willy@...radead.org>,
Miklos Szeredi <mszeredi@...hat.com>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Steffen Klassert <steffen.klassert@...unet.com>,
"Tobin C . Harding" <tobin@...nel.org>,
Vineet Gupta <vineet.gupta1@...opsys.com>,
Will Deacon <will.deacon@....com>,
Willem de Bruijn <willemb@...gle.com>
Subject: Re: [PATCH RESEND2] lib: fix bitmap_parse() on 64-bit big endian
archs
On Mon, Jun 08, 2020 at 02:44:34PM +0200, Alexander Gordeev wrote:
> On Mon, Jun 08, 2020 at 03:03:05PM +0300, Andy Shevchenko wrote:
> > On Mon, Jun 8, 2020 at 1:26 PM Alexander Gordeev <agordeev@...ux.ibm.com> wrote:
> > >
> > > Commit 2d6261583be0 ("lib: rework bitmap_parse()") does not
> > > take into account order of halfwords on 64-bit big endian
> > > architectures. As result (at least) Receive Packet Steering,
> > > IRQ affinity masks and runtime kernel test "test_bitmap" get
> > > broken on s390.
> >
> > ...
> >
> > > +#if defined(__BIG_ENDIAN) && defined(CONFIG_64BIT)
> >
> > I think it's better to re-use existing patterns.
> >
> > ipc/sem.c:1682:#if defined(CONFIG_64BIT) && defined(__BIG_ENDIAN)
> >
> > > +static void save_x32_chunk(unsigned long *maskp, u32 chunk, int chunk_idx)
> > > +{
> > > + maskp += (chunk_idx / 2);
> > > + ((u32 *)maskp)[(chunk_idx & 1) ^ 1] = chunk;
> > > +}
> > > +#else
> > > +static void save_x32_chunk(unsigned long *maskp, u32 chunk, int chunk_idx)
> > > +{
> > > + ((u32 *)maskp)[chunk_idx] = chunk;
> > > +}
> > > +#endif
> >
> > See below.
> >
> > ...
> >
> > > - end = bitmap_get_x32_reverse(start, end, bitmap++);
> > > + end = bitmap_get_x32_reverse(start, end, &chunk);
> > > if (IS_ERR(end))
> > > return PTR_ERR(end);
> > > +
> > > + save_x32_chunk(maskp, chunk, chunk_idx++);
> >
> > Can't we simple do
> >
> > int chunk_index = 0;
> > ...
> > do {
> > #if defined(CONFIG_64BIT) && defined(__BIG_ENDIAN)
> > end = bitmap_get_x32_reverse(start, end,
> > bitmap[chunk_index ^ 1]);
> > #else
> > end = bitmap_get_x32_reverse(start, end, bitmap[chunk_index]);
> > #endif
> > ...
> > } while (++chunk_index);
> >
> > ?
>
> Well, unless we ignore coding style 21) Conditional Compilation
> we could. Do you still insist it would be better?
I think it's okay to do here
- it's not a big function
- it has no stub versions (you always do something)
- the result pretty much readable (5 lines any editor can keep on screen)
- and it's not ignoring, see "Wherever possible...", compare readability of
two versions, for yours reader needs to go somewhere to read, calculate and
return, when everything already being forgotten
- last but not least, I bet it makes code shorter (at least in C)
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists