linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Ingo Molnar <mingo@kernel.org>,
	Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Thomas Gleixner <tglx@linutronix.de>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [GIT PULL] locking fixes
Date: Fri, 20 Feb 2015 17:51:56 -0800	[thread overview]
Message-ID: <CA+55aFwT8TCfOh25FH-MP8FB2EBg-gexmU9Cn9beBAx+TQ1N4Q@mail.gmail.com> (raw)
In-Reply-To: <CA+55aFy5sxUO7Hfjq70cyjhQqOE_j6nKsJf7v0iSGg=srLPBcw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2114 bytes --]

So here's my try at fixing READ_ONCE() so that it is happy with 'const' sources.

It is entirely untested. Comments/testing?

Christian, I guess I could just have forced a cast instead of the
union. I'd like you to take a look at this, because right now it's
holding up me pulling from Ingo.

And Ingo, I think you need to add some kind of test for "horrible new
warnings". I think your pull request *worked*, but the tens of lines
of new warnings it generates is unacceptable, and will just cause me
to undo the pull if I notice in time (like I did this time).

                            Linus

On Fri, Feb 20, 2015 at 4:03 PM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
> How does this work for you at all?
>
> On Fri, Feb 20, 2015 at 5:37 AM, Ingo Molnar <mingo@kernel.org> wrote:
>> diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
>> index 94f643484300..e354cc6446ab 100644
>> --- a/arch/x86/kernel/kvm.c
>> +++ b/arch/x86/kernel/kvm.c
>> @@ -803,8 +808,8 @@ static void kvm_unlock_kick(struct arch_spinlock *lock, __ticket_t ticket)
>>         add_stats(RELEASED_SLOW, 1);
>>         for_each_cpu(cpu, &waiting_cpus) {
>>                 const struct kvm_lock_waiting *w = &per_cpu(klock_waiting, cpu);
>> -               if (ACCESS_ONCE(w->lock) == lock &&
>> -                   ACCESS_ONCE(w->want) == ticket) {
>> +               if (READ_ONCE(w->lock) == lock &&
>> +                   READ_ONCE(w->want) == ticket) {
>>                         add_stats(RELEASED_SLOW_KICKED, 1);
>>                         kvm_kick_cpu(cpu);
>>                         break;
>
> I get horrible compile warnings from this, because of how 'w' is a
> pointer to a 'const' structure, which then causes things like
>
>     include/linux/compiler.h:262:39: warning: passing argument 1 of
> ‘__read_once_size’ discards ‘const’ qualifier from pointer target type
>       ({ typeof(x) __val; __read_once_size(&x, &__val, sizeof(__val)); __val; })
>
> which is fairly hard to avoid (looks like it might need a union)
>
>                        Linus

[-- Attachment #2: patch.diff --]
[-- Type: text/plain, Size: 1509 bytes --]

commit 1cb20581b0a32673fa3d056829ca89db4fa0de09
Author: Linus Torvalds <torvalds@linux-foundation.org>
Date:   Fri Feb 20 15:46:31 2015 -0800

    kernel: make READ_ONCE() valid on const pointers
    
    There is certainly nothing wrong with using READ_ONCE() on a const
    pointer, but the helper function __read_once_size() would cause warnings
    because it would drop the 'const' qualifier.
    
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
 include/linux/compiler.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index d1ec10a940ff..312cf710e26a 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -202,7 +202,7 @@ static __always_inline void data_access_exceeds_word_size(void)
 {
 }
 
-static __always_inline void __read_once_size(volatile void *p, void *res, int size)
+static __always_inline void __read_once_size(const volatile void *p, void *res, int size)
 {
 	switch (size) {
 	case 1: *(__u8 *)res = *(volatile __u8 *)p; break;
@@ -259,7 +259,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
  */
 
 #define READ_ONCE(x) \
-	({ typeof(x) __val; __read_once_size(&x, &__val, sizeof(__val)); __val; })
+	({ union { typeof(x) __val; char __c[1]; } __u; __read_once_size(&(x), __u.__c, sizeof((x))); __u.__val; })
 
 #define WRITE_ONCE(x, val) \
 	({ typeof(x) __val; __val = val; __write_once_size(&x, &__val, sizeof(__val)); __val; })

  reply	other threads:[~2015-02-21  1:51 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-20 13:37 [GIT PULL] locking fixes Ingo Molnar
2015-02-21  0:03 ` Linus Torvalds
2015-02-21  1:51   ` Linus Torvalds [this message]
2015-02-23  8:35     ` Christian Borntraeger
2015-02-21  5:07   ` Ingo Molnar
2015-02-21  5:16     ` Ingo Molnar
2015-02-21  5:28       ` Ingo Molnar
  -- strict thread matches above, loose matches on Subject: below --
2023-09-22 10:12 Ingo Molnar
2023-09-22 20:19 ` pr-tracker-bot
2021-07-11 13:22 Ingo Molnar
2021-07-11 18:22 ` pr-tracker-bot
2021-04-11 12:14 Ingo Molnar
2021-04-11 18:56 ` pr-tracker-bot
2021-03-21 10:53 Ingo Molnar
2021-03-21 18:45 ` pr-tracker-bot
2020-12-27  9:50 Ingo Molnar
2020-12-27 17:27 ` pr-tracker-bot
2020-08-15 11:13 Ingo Molnar
2020-08-16  1:55 ` pr-tracker-bot
2020-01-18 17:53 Ingo Molnar
2020-01-18 21:05 ` pr-tracker-bot
2019-12-17 11:27 Ingo Molnar
2019-12-17 19:20 ` pr-tracker-bot
2019-04-20  7:30 Ingo Molnar
2019-04-20 16:51 ` Linus Torvalds
2019-04-21 18:23   ` Ingo Molnar
2019-04-20 19:25 ` pr-tracker-bot
2019-02-10  8:53 Ingo Molnar
2019-02-10 18:30 ` pr-tracker-bot
2018-10-05  9:36 Ingo Molnar
2018-10-05 23:06 ` Greg Kroah-Hartman
2018-09-15 12:56 Ingo Molnar
2018-07-30 17:49 Ingo Molnar
2018-03-25  8:49 Ingo Molnar
2018-02-15  0:50 Ingo Molnar
2018-01-17 15:24 Ingo Molnar
2018-01-22  9:43 ` Geert Uytterhoeven
2018-01-22 10:39   ` Peter Zijlstra
2018-01-12 13:45 Ingo Molnar
2017-12-15 15:55 Ingo Molnar
2017-10-14 16:01 Ingo Molnar
2017-03-07 20:27 Ingo Molnar
2017-02-28  7:57 Ingo Molnar
2017-02-28 18:37 ` Linus Torvalds
2017-05-03 23:21 ` Linus Torvalds
2017-05-04  5:40   ` Peter Zijlstra
     [not found]     ` <CA+55aFymvtCAYHdz__3Lj=YqmORB7_A-NXrw=+h+60znJVsDTw@mail.gmail.com>
2017-05-04 22:44       ` Greg Kroah-Hartman
2016-12-07 18:42 Ingo Molnar
2016-10-18 10:55 Ingo Molnar
2016-08-18 20:34 Ingo Molnar
2016-08-12 19:32 Ingo Molnar
2016-06-10 12:45 Ingo Molnar
2016-04-28 17:52 Ingo Molnar
2016-04-23 11:22 Ingo Molnar
2016-03-24  7:47 Ingo Molnar
2015-09-17  7:57 Ingo Molnar
2015-04-18 15:15 Ingo Molnar
2015-01-11  8:39 Ingo Molnar
2014-10-31 11:06 Ingo Molnar
2014-04-16 11:39 Ingo Molnar
2014-01-15 18:15 Ingo Molnar
2009-12-10 19:45 Ingo Molnar

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=CA+55aFwT8TCfOh25FH-MP8FB2EBg-gexmU9Cn9beBAx+TQ1N4Q@mail.gmail.com \
    --to=torvalds@linux-foundation.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=borntraeger@de.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    /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).