From: Christian Borntraeger <borntraeger@de.ibm.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
Alexei Starovoitov <alexei.starovoitov@gmail.com>
Cc: David Howells <dhowells@redhat.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
linux-mips <linux-mips@linux-mips.org>,
linux-x86_64@vger.kernel.org,
linux-s390 <linux-s390@vger.kernel.org>,
Paolo Bonzini <pbonzini@redhat.com>,
Paul McKenney <paulmck@linux.vnet.ibm.com>,
Ingo Molnar <mingo@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will.deacon@arm.com>
Subject: Re: [PATCH/RFC 7/7] kernel: Force ACCESS_ONCE to work only on scalar types
Date: Mon, 24 Nov 2014 20:07:03 +0100 [thread overview]
Message-ID: <547381D7.2070404@de.ibm.com> (raw)
In-Reply-To: <CA+55aFxc72VsGTw4yFdeC1Sq65RUjYLKPD1ORnXB2d18WBMzvg@mail.gmail.com>
Am 24.11.2014 um 19:35 schrieb Linus Torvalds:
> On Mon, Nov 24, 2014 at 10:02 AM, Alexei Starovoitov
> <alexei.starovoitov@gmail.com> wrote:
>>
>> If the goal is to catch non-scalar users, the following is shorter:
>> #define ACCESS_ONCE(x) (((typeof(x))0) + *(volatile typeof(x) *)&(x))
>
> Me likey. It probably works well in practice, although I think
>
> - the "(typeof(x))0)" seems unnecessary and wrong. Why not just "0"?
> The typeof is not just longer, but it is incorrect for pointer types
> (you can add 0 to a pointer, but you cannot add two pointers together)
>
> - it does mean that the resulting type ends up being upgraded to
> "int", for the usual C type reasons.
>
> Note that the "upgraded to 'int'" is true with or without the
> "(typeof(x))0". If you add two 'char' values, the addition is still
> done in 'int'.
>
> Maybe you *meant* that typeof to fix the second problem, like so:
>
> (typeof(x)) (0 + *(volatile typeof(x) *)&(x))
>
> Hmm? That casts the result of the addition, not the zero.
Looks really nice, but does not work with ACCESS_ONCE is on the left-hand side:
include/linux/rculist.h: In function 'hlist_add_before_rcu':
./arch/x86/include/asm/barrier.h:127:18: error: lvalue required as left operand of assignment
ACCESS_ONCE(*p) = (v); \
Alexei's variant is also broken:
include/linux/cgroup.h: In function 'task_css':
include/linux/compiler.h:381:40: error: invalid operands to binary + (have 'struct css_set *' and 'struct css_set * volatile')
#define ACCESS_ONCE(x) (((typeof(x))0) + *(volatile typeof(x) *)&(x))
Anyone with a new propopal? ;-) ^
Christian
next prev parent reply other threads:[~2014-11-24 19:07 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1416834210-61738-1-git-send-email-borntraeger@de.ibm.com>
[not found] ` <1416834210-61738-8-git-send-email-borntraeger@de.ibm.com>
2014-11-24 13:30 ` [PATCH/RFC 7/7] kernel: Force ACCESS_ONCE to work only on scalar types David Howells
2014-11-24 17:30 ` Linus Torvalds
2014-11-24 18:02 ` Alexei Starovoitov
2014-11-24 18:35 ` Linus Torvalds
2014-11-24 19:07 ` Christian Borntraeger [this message]
2014-11-24 19:14 ` Linus Torvalds
2014-11-24 19:42 ` Paul E. McKenney
2014-11-24 20:19 ` Linus Torvalds
2014-11-24 20:46 ` Paul E. McKenney
2014-11-24 20:28 ` Christian Borntraeger
2014-11-24 20:04 ` David Howells
2014-11-24 20:34 ` Linus Torvalds
2014-11-24 20:53 ` Christian Borntraeger
2014-11-24 21:02 ` Linus Torvalds
2014-11-24 21:16 ` Christian Borntraeger
[not found] ` <1416834210-61738-7-git-send-email-borntraeger@de.ibm.com>
2014-11-24 18:50 ` [PATCH/RFC 6/7] arm64: Replace ACCESS_ONCE for spinlock code with barriers Christian Borntraeger
2014-11-25 2:28 [PATCH/RFC 7/7] kernel: Force ACCESS_ONCE to work only on scalar types Alexei Starovoitov
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=547381D7.2070404@de.ibm.com \
--to=borntraeger@de.ibm.com \
--cc=alexei.starovoitov@gmail.com \
--cc=catalin.marinas@arm.com \
--cc=dhowells@redhat.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-x86_64@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=torvalds@linux-foundation.org \
--cc=will.deacon@arm.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;
as well as URLs for NNTP newsgroup(s).