From: Heiko Carstens <heiko.carstens@de.ibm.com>
To: George Spelvin <lkml@sdf.org>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>,
linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH v3] ubsan: Avoid unnecessary 128-bit shifts
Date: Tue, 9 Apr 2019 15:43:16 +0200 [thread overview]
Message-ID: <20190409134316.GC4227@osiris> (raw)
In-Reply-To: <201904050158.x351wr9f016512@sdf.org>
On Fri, Apr 05, 2019 at 01:58:53AM +0000, George Spelvin wrote:
> If CONFIG_ARCH_SUPPORTS_INT128, s_max is 128 bits, and variable
> sign-extending shifts of such a double-word data type are a non-trivial
> amount of code and complexity. Do a single-word sign-extension *before*
> the cast to (s_max), greatly simplifying the object code.
>
> Rasmus Villemoes suggested using sign_extend* from <linux/bitops.h>.
>
> On s390 (and perhaps some other arches), gcc implements variable
> 128-bit shifts using an __ashrti3 helper function which the kernel
> doesn't provide, causing a link error. In that case, this patch is
> a prerequisite for enabling INT128 support. Andrey Ryabinin has gven
> permission for any arch that needs it to cherry-pick it so they don't
> have to wait for ubsan to be merged into Linus' tree.
Still, this should go upstream via Andrew Morton.
As soon as this gets merged I'd like to select ARCH_SUPPORTS_INT128 on
s390 unconditionally.
However... ;)
> +static inline long sign_extend_long(unsigned long value, int index)
> +{
> + if (sizeof(value) == 4)
> + return sign_extend32(value);
> + return sign_extend64(value);
> +}
> +
This doesn't compile:
In file included from ./include/linux/kernel.h:12,
from ./arch/s390/include/asm/bug.h:5,
from ./include/linux/bug.h:5,
from ./include/linux/page-flags.h:10,
from kernel/bounds.c:10:
./include/linux/bitops.h: In function 'sign_extend_long':
./include/linux/bitops.h:163:10: error: too few arguments to function 'sign_extend32'
return sign_extend32(value);
^~~~~~~~~~~~~
./include/linux/bitops.h:143:21: note: declared here
static inline __s32 sign_extend32(__u32 value, int index)
^~~~~~~~~~~~~
./include/linux/bitops.h:164:9: error: too few arguments to function 'sign_extend64'
return sign_extend64(value);
^~~~~~~~~~~~~
./include/linux/bitops.h:154:21: note: declared here
static inline __s64 sign_extend64(__u64 value, int index)
^~~~~~~~~~~~~
prev parent reply other threads:[~2019-04-09 13:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-05 1:58 [PATCH v3] ubsan: Avoid unnecessary 128-bit shifts George Spelvin
2019-04-09 13:43 ` Heiko Carstens [this message]
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=20190409134316.GC4227@osiris \
--to=heiko.carstens@de.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=aryabinin@virtuozzo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=lkml@sdf.org \
/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).