linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vadim Pasternak <vadimp@mellanox.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "jacek.anaszewski@gmail.com" <jacek.anaszewski@gmail.com>,
	"pavel@ucw.cz" <pavel@ucw.cz>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-leds@vger.kernel.org" <linux-leds@vger.kernel.org>,
	Ido Schimmel <idosch@mellanox.com>,
	Andrey Ryabinin <aryabinin@virtuozzo.com>
Subject: RE: [PATCH v1 bitops] bitops: Fix UBSAN undefined behavior warning for rotation right
Date: Tue, 9 Apr 2019 07:36:06 +0000	[thread overview]
Message-ID: <AM6PR05MB52246C74B34F291F5D89A409A22D0@AM6PR05MB5224.eurprd05.prod.outlook.com> (raw)
In-Reply-To: <20190408155217.3f723554ae7fbcb34eeacb30@linux-foundation.org>



> -----Original Message-----
> From: Andrew Morton <akpm@linux-foundation.org>
> Sent: Tuesday, April 09, 2019 1:52 AM
> To: Vadim Pasternak <vadimp@mellanox.com>
> Cc: jacek.anaszewski@gmail.com; pavel@ucw.cz; linux-kernel@vger.kernel.org;
> linux-leds@vger.kernel.org; Ido Schimmel <idosch@mellanox.com>; Andrey
> Ryabinin <aryabinin@virtuozzo.com>
> Subject: Re: [PATCH v1 bitops] bitops: Fix UBSAN undefined behavior warning
> for rotation right
> 
> (resend, cc Andrey)
> 
> On Sun,  7 Apr 2019 12:53:25 +0000 Vadim Pasternak <vadimp@mellanox.com>
> wrote:
> 
> > The warning is caused by call to rorXX(), if the second parameters of
> > this function "shift" is zero. In such case UBSAN reports the warning
> > for the next expression: (word << (XX - shift), where XX is 64, 32,
> > 16, 8 for respectively ror64, ror32, ror16, ror8.
> > Fix adds validation of this parameter - in case it's equal zero, no
> > need to rotate, just original "word" is to be returned to caller.
> >
> > The UBSAN undefined behavior warning has been reported for call to
> > ror32():
> > [   11.426543] UBSAN: Undefined behaviour in ./include/linux/bitops.h:93:33
> > [   11.434045] shift exponent 32 is too large for 32-bit type 'unsigned int'
> 
> hm, do we care?

Hi Andrew,

Thank for reply.

We want to avoid UBSAN undefined behavior warning in case
"shift" parameter is not provided as a constant.

> 
> > ...
> >
> 
> > --- a/include/linux/bitops.h
> > +++ b/include/linux/bitops.h
> > @@ -70,6 +70,9 @@ static inline __u64 rol64(__u64 word, unsigned int shift)
> >   */
> >  static inline __u64 ror64(__u64 word, unsigned int shift)  {
> > +	if (!shift)
> > +		return word;
> > +
> >  	return (word >> shift) | (word << (64 - shift));  }
> 
> Is there any known architecture or compiler for which UL<<64 doesn't reliably
> produce zero?  Is there any prospect that this will become a problem in the
> future?

I don't know about such architecture.
Do you think it could be modified only for ro8, ror16, ror32?

  reply	other threads:[~2019-04-09  7:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-07 12:53 [PATCH v1 bitops] bitops: Fix UBSAN undefined behavior warning for rotation right Vadim Pasternak
2019-04-08 22:51 ` Andrew Morton
2019-04-08 22:52 ` Andrew Morton
2019-04-09  7:36   ` Vadim Pasternak [this message]
2019-04-09  8:08   ` Rasmus Villemoes
2019-04-09  8:57     ` Rasmus Villemoes
2019-04-09  9:50   ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM6PR05MB52246C74B34F291F5D89A409A22D0@AM6PR05MB5224.eurprd05.prod.outlook.com \
    --to=vadimp@mellanox.com \
    --cc=akpm@linux-foundation.org \
    --cc=aryabinin@virtuozzo.com \
    --cc=idosch@mellanox.com \
    --cc=jacek.anaszewski@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@ucw.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).