From: David Laight <David.Laight@ACULAB.COM>
To: 'Alan Huang' <mmpgouride@gmail.com>,
Joel Fernandes <joel@joelfernandes.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
"Eric Dumazet" <edumazet@google.com>,
"roman.gushchin@linux.dev" <roman.gushchin@linux.dev>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"rcu@vger.kernel.org" <rcu@vger.kernel.org>
Subject: RE: Question about the barrier() in hlist_nulls_for_each_entry_rcu()
Date: Sat, 22 Jul 2023 14:06:47 +0000 [thread overview]
Message-ID: <8e1885b62d124cca9198ff6cdb52c7f5@AcuMS.aculab.com> (raw)
In-Reply-To: <76552616-5DF1-4A05-BA5A-AE0677F861FC@gmail.com>
....
> > Found a related discussion:
> >
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102714
> >
> > Looks like GCC 10, 11 have been backported, not sure whether GCC 8 has been backported.
> >
> > So, I have the following questions:
> >
> > Given that some people might not update their GCC, do they need to be notified?
> >
> > Do we need to CC Linus?
>
> No need.
>
> I put the following code into a kernel module:
>
> typedef struct list_head_shit {
> int next;
> struct list_head *first;
> } list_head_shit;
>
> static void noinline so_shit(void) {
> list_head_shit *head = (list_head_shit *)kmalloc(sizeof(list_head_shit), GFP_KERNEL);
> head->first = 0;
> head->next = 1;
>
> READ_ONCE(head->first);
> READ_ONCE(head->first);
>
> kfree(head);
> }
>
> x86_64-linux-gnu-gcc-11 generate the following code:
>
> 0000000000000000 <so_shit>:
> 0: 48 8b 3d 00 00 00 00 mov 0x0(%rip),%rdi # 7 <so_shit+0x7>
> 7: ba 10 00 00 00 mov $0x10,%edx
> c: be c0 0c 00 00 mov $0xcc0,%esi
> 11: e8 00 00 00 00 call 16 <so_shit+0x16>
> 16: 48 c7 40 08 00 00 00 movq $0x0,0x8(%rax)
> 1d: 00
> 1e: 48 89 c7 mov %rax,%rdi
> 21: c7 00 01 00 00 00 movl $0x1,(%rax)
> 27: 48 8b 47 08 mov 0x8(%rdi),%rax # READ_ONCE here
> 2b: 48 8b 47 08 mov 0x8(%rdi),%rax # READ_ONCE here
> 2f: e9 00 00 00 00 jmp 34 <so_shit+0x34>
> 34: 66 66 2e 0f 1f 84 00 data16 cs nopw 0x0(%rax,%rax,1)
> 3b: 00 00 00 00
> 3f: 90 nop
>
> The conclusion is that we can rely on READ_ONCE when writing kernel code.
>
> The kernel’s READ_ONCE is different with the one Joel wrote yesterday. (Joel’s is the same as the old
> ACCESS_ONCE)
You do need to reproduce the error with code that looks like
the loop in the (old) udp.c code.
Then see if changing the implementation of READ_ONCE() from
a simple 'volatile' access the newer variant makes a difference.
You also need to check with the oldest version of gcc that is
still supported - that is much older than gcc 11.
In the udp code the volatile access was on a pointer (which should
qualify as a scaler type) so it may well be the inlining bug you
mentioned earlier, not the 'volatile on non-scaler' feature that
READ_ONCE() fixed.
That fix hasn't been back-ported to all the versions of gcc
that the kernel build supports.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2023-07-22 14:06 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-20 18:53 Question about the barrier() in hlist_nulls_for_each_entry_rcu() Alan Huang
2023-07-20 19:22 ` Eric Dumazet
2023-07-20 19:59 ` Alan Huang
2023-07-20 21:11 ` Eric Dumazet
2023-07-21 14:31 ` Alan Huang
2023-07-21 14:47 ` Eric Dumazet
2023-07-21 15:21 ` Alan Huang
2023-07-21 12:54 ` Joel Fernandes
2023-07-21 14:27 ` Alan Huang
2023-07-21 15:21 ` Joel Fernandes
2023-07-21 15:54 ` Alan Huang
2023-07-21 16:00 ` Joel Fernandes
2023-07-21 15:59 ` David Laight
2023-07-21 17:14 ` Joel Fernandes
2023-07-21 20:08 ` Alan Huang
2023-07-21 20:40 ` Alan Huang
2023-07-21 21:25 ` Alan Huang
2023-07-22 13:32 ` Alan Huang
2023-07-22 14:06 ` David Laight [this message]
2023-07-22 15:00 ` Alan Huang
2023-07-31 20:09 ` Paul E. McKenney
2023-08-03 13:40 ` Alan Huang
2023-08-03 13:53 ` Paul E. McKenney
2023-08-03 14:39 ` David Laight
2023-07-21 11:51 ` David Laight
2023-07-21 15:55 ` Alan Huang
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=8e1885b62d124cca9198ff6cdb52c7f5@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=edumazet@google.com \
--cc=joel@joelfernandes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mmpgouride@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=paulmck@kernel.org \
--cc=rcu@vger.kernel.org \
--cc=roman.gushchin@linux.dev \
/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