[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20260209094214.5ed5db27@pumpkin>
Date: Mon, 9 Feb 2026 09:42:14 +0000
From: David Laight <david.laight.linux@...il.com>
To: Yury Norov <ynorov@...dia.com>
Cc: Nathan Chancellor <nathan@...nel.org>, Greg Kroah-Hartman
<gregkh@...uxfoundation.org>, Thomas Gleixner <tglx@...utronix.de>, Peter
Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...nel.org>, Mathieu
Desnoyers <mathieu.desnoyers@...icios.com>, Arnd Bergmann <arnd@...db.de>,
linux-arch@...r.kernel.org, linux-kernel@...r.kernel.org, Yury Norov
<yury.norov@...il.com>, Lucas De Marchi <lucas.demarchi@...el.com>, Jani
Nikula <jani.nikula@...el.com>, Vincent Mailhol
<mailhol.vincent@...adoo.fr>, Andy Shevchenko
<andriy.shevchenko@...ux.intel.com>, Kees Cook <keescook@...omium.org>,
Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH next 08/14] bits: simplify GENMASK_TYPE()
On Sat, 7 Feb 2026 21:36:57 -0500
Yury Norov <ynorov@...dia.com> wrote:
> On Wed, Jan 21, 2026 at 02:57:25PM +0000, david.laight.linux@...il.com wrote:
> > From: David Laight <david.laight.linux@...il.com>
> >
> > Since the type is always unsigned (T)-1 is always the correct value
> > so there is no need to use type_max().
> >
> > Signed-off-by: David Laight <david.laight.linux@...il.com>
>
> Here you implicitly add a new restriction that all types passed in
> GENMASK_TYPE() must be unsigned. Can you enforce it with
> is_signed_type(), or at lease with a corresponding comment?
GENMASK_TYPE() is an internal define used in the expansions of,
for example, GENMASK_U32() - it is always passed an unsigned type.
I don't really think it should be used elsewhere at all.
In any case I don't think it makes any difference.
The value or type_max(t) has to match BITS_PER_TYPE(t) or else
the result is wrong, so it has never worked for signed types.
I did try adding a signedness check to FIELD_GET(), there is one
place in the x86-64 build that uses a signed type and requires the
right shift sign extend.
That code (in the fault handler) probably ought to be changed.
David
>
> > ---
> > include/linux/bits.h | 3 +--
> > 1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/include/linux/bits.h b/include/linux/bits.h
> > index a40cc861b3a7..697318f2a47d 100644
> > --- a/include/linux/bits.h
> > +++ b/include/linux/bits.h
> > @@ -45,8 +45,7 @@
> > */
> > #define GENMASK_TYPE(t, h, l) \
> > ((t)(GENMASK_INPUT_CHECK(h, l) + \
> > - (type_max(t) << (l) & \
> > - type_max(t) >> (BITS_PER_TYPE(t) - 1 - (h)))))
> > + ((t)-1 << (l) & (t)-1 >> (BITS_PER_TYPE(t) - 1 - (h)))))
> >
> > #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l)
> > #define GENMASK_ULL(h, l) GENMASK_TYPE(unsigned long long, h, l)
> > --
> > 2.39.5
Powered by blists - more mailing lists