All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Mark Rutland' <mark.rutland@arm.com>,
	Christoph Hellwig <hch@infradead.org>
Cc: Joe Richey <joerichey94@gmail.com>,
	"trivial@kernel.org" <trivial@kernel.org>,
	Joe Richey <joerichey@google.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	"x86@kernel.org" <x86@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Zhangfei Gao <zhangfei.gao@linaro.org>,
	Zhou Wang <wangzhou1@hisilicon.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
	"linux-accelerators@lists.ozlabs.org" 
	<linux-accelerators@lists.ozlabs.org>
Subject: RE: [PATCH 0/6] Don't use BIT() macro in UAPI headers
Date: Mon, 24 May 2021 16:34:39 +0000	[thread overview]
Message-ID: <56cdb86fe8984a94b4a7a8073476d849@AcuMS.aculab.com> (raw)
In-Reply-To: <20210524122901.GH1040@C02TD0UTHF1T.local>

From: Mark Rutland
> Sent: 24 May 2021 13:29
> 
> On Mon, May 24, 2021 at 12:46:26PM +0100, Christoph Hellwig wrote:
> > On Thu, May 20, 2021 at 03:43:37AM -0700, Joe Richey wrote:
> > > This patch series changes all UAPI uses of BIT() to just be open-coded.
> > > However, there really should be a check for this in checkpatch.pl
> > > Currently, the script actually _encourages_ users to use the BIT macro
> > > even if adding things to UAPI.
> >
> > Yes.  In fact it should warn about BIT() in general.  It is totally
> > pointless obsfucation that doesn't even save any typing at all.
> 
> That's not quite true; the point is that if you use BIT() consistently,
> then even when you refer to bits 32 to 63 you won't accidentally
> introduce shifts of more than the width of int, and the definition will
> work equally well for assembly and C, which isn't true if you use `1UL`
> in the definition.
> 
> With that in mind it's shorter and clearer than its functional
> equivalent:
> 
>   BIT(x)
>   (UL(1) << (x))
> 
> So IMO it's preferable to use BIT() generally, or _BITUL() in uapi
> headers.

And then, suddenly the compiler warns about truncation of the
high bits when ~BIT(x) is used to mask a 32bit value on 64bit systems.

Once the C standard committee had decided to change from K&R's
'sign preserving' integer promotions to 'value preserving'
you always lose somewhere.

Personally I prefer hex constants - I can't count bits at all.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


WARNING: multiple messages have this Message-ID (diff)
From: David Laight <David.Laight@ACULAB.COM>
To: 'Mark Rutland' <mark.rutland@arm.com>,
	Christoph Hellwig <hch@infradead.org>
Cc: Joe Richey <joerichey94@gmail.com>,
	"trivial@kernel.org" <trivial@kernel.org>,
	Joe Richey <joerichey@google.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	"x86@kernel.org" <x86@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Zhangfei Gao <zhangfei.gao@linaro.org>,
	Zhou Wang <wangzhou1@hisilicon.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"linux-media@vger.kernel.org" <linux-media@vger.kernel.org>,
	"linux-accelerators@lists.ozlabs.org"
	<linux-accelerators@lists.ozlabs.org>
Subject: RE: [PATCH 0/6] Don't use BIT() macro in UAPI headers
Date: Mon, 24 May 2021 16:34:39 +0000	[thread overview]
Message-ID: <56cdb86fe8984a94b4a7a8073476d849@AcuMS.aculab.com> (raw)
In-Reply-To: <20210524122901.GH1040@C02TD0UTHF1T.local>

From: Mark Rutland
> Sent: 24 May 2021 13:29
> 
> On Mon, May 24, 2021 at 12:46:26PM +0100, Christoph Hellwig wrote:
> > On Thu, May 20, 2021 at 03:43:37AM -0700, Joe Richey wrote:
> > > This patch series changes all UAPI uses of BIT() to just be open-coded.
> > > However, there really should be a check for this in checkpatch.pl
> > > Currently, the script actually _encourages_ users to use the BIT macro
> > > even if adding things to UAPI.
> >
> > Yes.  In fact it should warn about BIT() in general.  It is totally
> > pointless obsfucation that doesn't even save any typing at all.
> 
> That's not quite true; the point is that if you use BIT() consistently,
> then even when you refer to bits 32 to 63 you won't accidentally
> introduce shifts of more than the width of int, and the definition will
> work equally well for assembly and C, which isn't true if you use `1UL`
> in the definition.
> 
> With that in mind it's shorter and clearer than its functional
> equivalent:
> 
>   BIT(x)
>   (UL(1) << (x))
> 
> So IMO it's preferable to use BIT() generally, or _BITUL() in uapi
> headers.

And then, suddenly the compiler warns about truncation of the
high bits when ~BIT(x) is used to mask a 32bit value on 64bit systems.

Once the C standard committee had decided to change from K&R's
'sign preserving' integer promotions to 'value preserving'
you always lose somewhere.

Personally I prefer hex constants - I can't count bits at all.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-05-24 16:34 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-20 10:43 [PATCH 0/6] Don't use BIT() macro in UAPI headers Joe Richey
2021-05-20 10:43 ` Joe Richey
2021-05-20 10:43 ` [PATCH 1/6] x86/elf: " Joe Richey
2021-05-20 10:43   ` Joe Richey
2021-05-20 10:43 ` [PATCH 2/6] KVM: X86: " Joe Richey
2021-05-20 10:43   ` Joe Richey
2021-05-20 15:46   ` Sean Christopherson
2021-05-20 15:46     ` Sean Christopherson
2021-05-20 10:43 ` [PATCH 3/6] drivers: firmware: psci: " Joe Richey
2021-05-20 10:43   ` Joe Richey
2021-05-20 10:43 ` [PATCH 4/6] uacce: " Joe Richey
2021-05-20 10:43   ` Joe Richey
2021-05-20 10:43 ` [PATCH 5/6] media: vicodec: " Joe Richey
2021-05-20 10:43   ` Joe Richey
2021-05-20 10:43 ` [PATCH 6/6] tools headers UAPI: Sync pkt_sched.h with the kernel sources Joe Richey
2021-05-20 10:43   ` Joe Richey
2021-05-20 11:07 ` [PATCH 0/6] Don't use BIT() macro in UAPI headers Borislav Petkov
2021-05-20 11:07   ` Borislav Petkov
2021-05-20 11:50   ` Joseph Richey
2021-05-20 11:50     ` Joseph Richey
2021-05-20 15:59     ` Borislav Petkov
2021-05-20 15:59       ` Borislav Petkov
2021-05-20 15:50   ` Sean Christopherson
2021-05-20 15:50     ` Sean Christopherson
2021-05-20 11:11 ` Mark Rutland
2021-05-20 11:11   ` Mark Rutland
2021-05-20 11:40   ` Joseph Richey
2021-05-20 11:40     ` Joseph Richey
2021-05-20 12:09 ` Paolo Bonzini
2021-05-20 12:09   ` Paolo Bonzini
2021-05-20 15:47 ` Sean Christopherson
2021-05-20 15:47   ` Sean Christopherson
2021-05-21  8:58 ` [PATCH v2 0/7] " Joe Richey
2021-05-21  8:58   ` Joe Richey
2021-05-21  8:58   ` [PATCH v2 1/7] x86/elf: Use _BITUL() " Joe Richey
2021-05-21  8:58     ` Joe Richey
2021-05-21  9:25     ` [tip: x86/misc] " tip-bot2 for Joe Richey
2021-05-21  8:58   ` [PATCH v2 2/7] KVM: X86: " Joe Richey
2021-05-21  8:58     ` Joe Richey
2021-05-24 12:28     ` Paolo Bonzini
2021-05-24 12:28       ` Paolo Bonzini
2021-05-21  8:58   ` [PATCH v2 3/7] drivers: firmware: psci: " Joe Richey
2021-05-21  8:58     ` Joe Richey
2021-05-21 13:25     ` Mark Rutland
2021-05-21 13:25       ` Mark Rutland
2021-05-21  8:58   ` [PATCH v2 4/7] uacce: " Joe Richey
2021-05-21  8:58     ` Joe Richey
2021-05-21 13:56     ` Zhangfei Gao
2021-05-21 13:56       ` Zhangfei Gao
2021-05-21  8:58   ` [PATCH v2 5/7] media: vicodec: " Joe Richey
2021-05-21  8:58     ` Joe Richey
2021-05-21  8:58   ` [PATCH v2 6/7] tools headers UAPI: Sync pkt_sched.h with the kernel sources Joe Richey
2021-05-21  8:58     ` Joe Richey
2021-05-21  8:58   ` [PATCH v2 7/7] checkpatch: suggest _BITULL() and _BITUL() for UAPI headers Joe Richey
2021-05-21  8:58     ` Joe Richey
2021-05-21 14:45     ` Joe Perches
2021-05-21 14:45       ` Joe Perches
2021-05-24 11:46 ` [PATCH 0/6] Don't use BIT() macro in " Christoph Hellwig
2021-05-24 11:46   ` Christoph Hellwig
2021-05-24 12:29   ` Mark Rutland
2021-05-24 12:29     ` Mark Rutland
2021-05-24 16:34     ` David Laight [this message]
2021-05-24 16:34       ` David Laight

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=56cdb86fe8984a94b4a7a8073476d849@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=bp@alien8.de \
    --cc=hch@infradead.org \
    --cc=hpa@zytor.com \
    --cc=joerichey94@gmail.com \
    --cc=joerichey@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-accelerators@lists.ozlabs.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=lorenzo.pieralisi@arm.com \
    --cc=mark.rutland@arm.com \
    --cc=mchehab@kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=trivial@kernel.org \
    --cc=wangzhou1@hisilicon.com \
    --cc=x86@kernel.org \
    --cc=zhangfei.gao@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.