linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Randy Dunlap <rdunlap@infradead.org>
To: "Matthias Görgens" <matthias.goergens@gmail.com>,
	linux-arch@vger.kernel.org, linux-mm <linux-mm@kvack.org>
Subject: Re: Fwd: [PATCH] tools/headers: Fix undefined behaviour (34 << 26)
Date: Sat, 3 Sep 2022 15:03:47 -0700	[thread overview]
Message-ID: <a8f4cf90-8ae7-0542-8363-d425dfdecb0a@infradead.org> (raw)
In-Reply-To: <CA+X7ob-XeKwM0r=6e+O=Se=pGQFjKVGZVihHC-Mc6YoRFf=6SQ@mail.gmail.com>

Hi--

[adding linux-mm mailing list]

On 9/2/22 23:59, Matthias Görgens wrote:
> Hello,
> 
> This is my first patch to the Linux kernel.  I hope sending it via
> gmail is OK?  I have attached the git-generated patch file.
> 
gmail's web UI won't do it AFAIK.
And most people won't accept patches as attachments.
(more difficult to review and reply with comments to them)


The easiest fix for that (IMO) while continuing to use gmail is to
use 'git send-email'.

> This is a simple fix to a problem I encountered when I tried to build
> CPython.  Some digging suggested that the problem is actually with
> kernel header files.
> 
> Basically the problem is that when calculating
> `HUGETLB_FLAG_ENCODE_16GB` we essentially run (34 << 26).  That's
> undefined behaviour in C, because C tries to do these calculations as
> signed ints, but signed signed ints don't have enough bits.
> 
> The fix is to cast to unsigned first: ((unsigned) 32 << 26).  Unsigned
> ints have enough bits, at least on 32 bit systems and above.

Instead of casting to (unsigned), can you use a constant suffix format,
like 34U << 26 ?

> I suspect the way the kernel build uses GCC and Clang this is probably
> not a problem, but the headers are used by outside projects (like
> CPython), and for that it's probably best to stick to the C standard,
> when it's easy to do so.
> 
> Thanks,
> Matthias.
> 
> P.S. Please pardon, if you received this email a second time, I had
> some trouble getting GMail to send in plain text.

-- 
~Randy


       reply	other threads:[~2022-09-03 22:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CA+X7ob9QaUxiusEBC2eW8Wk+2FnGVATeC8pmb9pdU0Tg7-XfyA@mail.gmail.com>
     [not found] ` <CA+X7ob-XeKwM0r=6e+O=Se=pGQFjKVGZVihHC-Mc6YoRFf=6SQ@mail.gmail.com>
2022-09-03 22:03   ` Randy Dunlap [this message]
2022-09-05  3:19     ` Matthias Goergens
2022-09-05 20:30       ` Randy Dunlap

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=a8f4cf90-8ae7-0542-8363-d425dfdecb0a@infradead.org \
    --to=rdunlap@infradead.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=matthias.goergens@gmail.com \
    /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