mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhouyi Zhou <zhouzhouyi@gmail.com>
To: Joel Fernandes <joel@joelfernandes.org>
Cc: Christophe Leroy <christophe.leroy@c-s.fr>,
	Peter Zijlstra <peterz@infradead.org>,
	Boqun Feng <boqun.feng@gmail.com>,
	Segher Boessenkool <segher@kernel.crashing.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
	rcu <rcu@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	lance@osuosl.org, "Paul E. McKenney" <paulmck@kernel.org>
Subject: Re: BUG : PowerPC RCU: torture test failed with __stack_chk_fail
Date: Tue, 25 Apr 2023 11:12:25 +0800	[thread overview]
Message-ID: <CAABZP2x5UMxuNYEr6ATsbZPywdnHYYMvi7Pyy80aSqpcHk9yTw@mail.gmail.com> (raw)
In-Reply-To: <CAEXW_YQEarLt7YGQZdwmcSyZcGRCGKf89ovxjQdXBO-TgXAk-w@mail.gmail.com>

On Tue, Apr 25, 2023 at 7:06 PM Joel Fernandes <joel@joelfernandes.org> wrote:
>
> On Tue, Apr 25, 2023 at 6:58 AM Zhouyi Zhou <zhouzhouyi@gmail.com> wrote:
> >
> > hi
> >
> > On Tue, Apr 25, 2023 at 6:13 PM Peter Zijlstra <peterz@infradead.org> wrote:
> > >
> > > On Mon, Apr 24, 2023 at 02:55:11PM -0400, Joel Fernandes wrote:
> > > > This is amazing debugging Boqun, like a boss! One comment below:
> > > >
> > > > > > > Or something simple I haven't thought of? :)
> > > > > >
> > > > > > At what points can r13 change?  Only when some particular functions are
> > > > > > called?
> > > > > >
> > > > >
> > > > > r13 is the local paca:
> > > > >
> > > > >         register struct paca_struct *local_paca asm("r13");
> > > > >
> > > > > , which is a pointer to percpu data.
> > > > >
> > > > > So if a task schedule from one CPU to anotehr CPU, the value gets
> > > > > changed.
> > > >
> > > > It appears the whole issue, per your analysis, is that the stack
> > > > checking code in gcc should not cache or alias r13, and must read its
> > > > most up-to-date value during stack checking, as its value may have
> > > > changed during a migration to a new CPU.
> > > >
> > > > Did I get that right?
> > > >
> > > > IMO, even without a reproducer, gcc on PPC should just not do that,
> > > > that feels terribly broken for the kernel. I wonder what clang does,
> > > > I'll go poke around with compilerexplorer after lunch.
> > > >
> > > > Adding +Peter Zijlstra as well to join the party as I have a feeling
> > > > he'll be interested. ;-)
> > >
> > > I'm a little confused; the way I understand the whole stack protector
> > > thing to work is that we push a canary on the stack at call and on
> > > return check it is still valid. Since in general tasks randomly migrate,
> > > the per-cpu validation canary should be the same on all CPUs.
> > >
> > > Additionally, the 'new' __srcu_read_{,un}lock_nmisafe() functions use
> > > raw_cpu_ptr() to get 'a' percpu sdp, preferably that of the local cpu,
> > > but no guarantees.
> > >
> > > Both cases use r13 (paca) in a racy manner, and in both cases it should
> > > be safe.
> > New test results today: both gcc build from git (git clone
> > git://gcc.gnu.org/git/gcc.git) and Ubuntu 22.04 gcc-12.1.0
> > are immune from the above issue. We can see the assembly code on
> > http://140.211.169.189/0425/srcu_gp_start_if_needed-gcc-12.txt
> >
> > while
> > Both native gcc on PPC vm (gcc version 9.4.0), and gcc cross compiler
> > on my x86 laptop (gcc version 10.4.0) will reproduce the bug.
>
> Do you know what fixes the issue? I would not declare victory yet. My
> feeling is something changes in timing, or compiler codegen which
> hides the issue. So the issue is still there but it is just a matter
> of time before someone else reports it.
I am going to try bisect on GCC, hope we can find some clue.
>
> Out of curiosity for PPC folks, why cannot 64-bit PPC use per-task
> canary? Michael, is this an optimization? Adding Christophe as well
> since it came in a few years ago via the following commit:
>
> commit 06ec27aea9fc84d9c6d879eb64b5bcf28a8a1eb7
> Author: Christophe Leroy <christophe.leroy@c-s.fr>
> Date:   Thu Sep 27 07:05:55 2018 +0000
>
>     powerpc/64: add stack protector support
>
>     On PPC64, as register r13 points to the paca_struct at all time,
>     this patch adds a copy of the canary there, which is copied at
>     task_switch.
>     That new canary is then used by using the following GCC options:
>     -mstack-protector-guard=tls
>     -mstack-protector-guard-reg=r13
>     -mstack-protector-guard-offset=offsetof(struct paca_struct, canary))
>
>     Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
>     Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
>
>  - Joel

  reply	other threads:[~2023-04-25 11:12 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-22 12:46 Zhouyi Zhou
2023-04-22 19:19 ` Joel Fernandes
2023-04-23  1:37   ` Zhouyi Zhou
2023-04-23  5:45     ` Zhouyi Zhou
2023-04-22 19:28 ` Joel Fernandes
2023-04-24  0:32   ` Boqun Feng
2023-04-24  4:00     ` Zhouyi Zhou
2023-04-24 13:14     ` Michael Ellerman
2023-04-24 15:13       ` Segher Boessenkool
2023-04-24 15:28         ` Boqun Feng
2023-04-24 17:29           ` Segher Boessenkool
2023-04-24 19:25             ` Boqun Feng
2023-04-24 18:55           ` Joel Fernandes
2023-04-25 10:13             ` Peter Zijlstra
2023-04-25 10:58               ` Zhouyi Zhou
2023-04-25 11:06                 ` Joel Fernandes
2023-04-25  3:12                   ` Zhouyi Zhou [this message]
2023-04-25 13:40                   ` Christophe Leroy
2023-04-25 13:49                     ` Zhouyi Zhou
2023-04-26  0:32                       ` Joel Fernandes
2023-04-26  1:31                         ` Zhouyi Zhou
2023-04-26  2:15                           ` Joel Fernandes
2023-04-26  2:37                             ` Zhouyi Zhou
2023-04-26  0:42                     ` Joel Fernandes
2023-04-26 12:29                   ` Michael Ellerman
2023-04-26 13:44                     ` Joel Fernandes
2023-04-26 14:20                       ` Peter Zijlstra
2023-04-26 14:45                         ` Michael Ellerman
2023-04-28 10:35                     ` Christophe Leroy
2023-04-25 10:59               ` Joel Fernandes
2023-04-25 11:53                 ` Peter Zijlstra
2023-04-25 13:36                   ` Christophe Leroy
2023-04-24 22:07 ` Michael Ellerman
2023-04-24 22:13   ` Zhouyi Zhou
2023-04-25  6:01   ` Zhouyi Zhou
2023-04-25  9:27     ` Zhouyi Zhou
2023-04-27  3:09       ` Michael Ellerman
2023-04-27  3:32         ` Zhouyi Zhou
2023-04-27  9:21         ` Zhouyi Zhou
2023-04-27 14:13           ` Michael Ellerman
2023-04-27 14:29             ` Zhouyi Zhou

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=CAABZP2x5UMxuNYEr6ATsbZPywdnHYYMvi7Pyy80aSqpcHk9yTw@mail.gmail.com \
    --to=zhouzhouyi@gmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=christophe.leroy@c-s.fr \
    --cc=joel@joelfernandes.org \
    --cc=lance@osuosl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rcu@vger.kernel.org \
    --cc=segher@kernel.crashing.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

all inboxes | Powered by JetHome®