linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@amd64.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Randy Dunlap <randy.dunlap@oracle.com>,
	lkml <linux-kernel@vger.kernel.org>,
	Doug Thompson <dougthompson@xmission.com>,
	akpm <akpm@linux-foundation.org>,
	linux-arch@vger.kernel.org
Subject: Re: [PATCH] bitops.h: Widen BIT macro to support 64-bit types
Date: Thu, 14 Oct 2010 17:36:33 +0200	[thread overview]
Message-ID: <20101014153633.GA4261@kryptos.osrc.amd.com> (raw)
In-Reply-To: <AANLkTi=ZjR3bWtZ2x9wRzpzBb1K8Wst3Xg_K4mGX-b6o@mail.gmail.com>

From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Thu, Oct 14, 2010 at 08:03:17AM -0700

> On Thu, Oct 14, 2010 at 3:58 AM, Borislav Petkov <bp@amd64.org> wrote:
> >>
> >> Ok, so BIT() should be fixed to work with the largest type available,
> >> IMHO. Let me cook up something.
> >
> > Maybe something like the following. Build-tested with the crosstool
> > (http://www.kernel.org/pub/tools/crosstool) on the following arches:
> > alpha blackfin cris hppa64 ia64 mips64 sparc.
> >
> > Any objections?
> 
> Yeah. I object. I have no idea what this will change for everything
> else that expects bitops to work on unsigned long values.
> 
> I really think that the bug is not in the BIT() definition, but in the
> use. If somebody wants a non-unsigned-long bit field, they had better
> not use bitops.h.
> 
> And no, just changing the BIT() macro to return a 64-bit value is
> _not_ trivially safe. Due to C type rules, now all arithmetic using
> BIT() will suddenly be 64-bit, which is often *much* slower, and can
> introduce real bugs.
> 
> On many architectures, a 64-bit non-constant shift will even end up
> being a function call. And if the thing is used in a varargs function,
> the argument layout will be totally different. We've also had several
> issues with 64-bit types and switch() statements, for example. And a
> quick grep for '\<BIT(' shows that non-constant cases are not unheard
> of, and there's a lot of random use where it is not at all obvious
> that it's safe (because it's used for defining other defines).

Concerning safety, I actually had a version which did check the bit
number supplied as an arg for overflowing but this failed when using
BIT() in struct initializers:

	.struct_member = { BIT(bla) }

But thanks for the detailed explanation! This makes perfect sense; it
was too much wishful thinking on my part to assume that a ULL BIT()
would be fine after checking that all arches support the unsigned 64-bit
type.

I'm much better off with a local BIT_64() or similar, definition.

Thanks.

-- 
Regards/Gruss,
Boris.

Advanced Micro Devices GmbH
Einsteinring 24, 85609 Dornach
General Managers: Alberto Bozzo, Andrew Bowd
Registration: Dornach, Gemeinde Aschheim, Landkreis Muenchen
Registergericht Muenchen, HRB Nr. 43632

      reply	other threads:[~2010-10-14 15:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20101013131057.88238be6.randy.dunlap@oracle.com>
     [not found] ` <20101014042409.GB29342@aftab>
2010-10-14 10:58   ` [PATCH] bitops.h: Widen BIT macro to support 64-bit types Borislav Petkov
2010-10-14 11:12     ` Matthew Wilcox
2010-10-14 12:12       ` Borislav Petkov
2010-10-14 14:27         ` Matthew Wilcox
2010-10-14 15:03     ` Linus Torvalds
2010-10-14 15:36       ` Borislav Petkov [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=20101014153633.GA4261@kryptos.osrc.amd.com \
    --to=bp@amd64.org \
    --cc=akpm@linux-foundation.org \
    --cc=dougthompson@xmission.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=randy.dunlap@oracle.com \
    --cc=torvalds@linux-foundation.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).