From: Nick Desaulniers <ndesaulniers@google.com>
To: Borislav Petkov <bp@alien8.de>, Roman Kiryanov <rkir@google.com>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
Pavel Machek <pavel@ucw.cz>, Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>,
"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
<x86@kernel.org>,
linux-pm@vger.kernel.org, Greg KH <gregkh@linuxfoundation.org>,
Alistair Delva <adelva@google.com>,
Haitao Shan <hshan@google.com>,
lkml <linux-kernel@vger.kernel.org>,
Sami Tolvanen <samitolvanen@google.com>,
clang-built-linux <clang-built-linux@googlegroups.com>
Subject: Re: [PATCH] arch: x86: power: cpu: init %gs before __restore_processor_state (clang)
Date: Tue, 15 Sep 2020 11:00:30 -0700 [thread overview]
Message-ID: <CAKwvOdm9bQmL=gZypkosH0MG=S28=jJ6wZiTMCNP6=Z+NfN1AA@mail.gmail.com> (raw)
In-Reply-To: <20200915174643.GT14436@zn.tnic>
On Tue, Sep 15, 2020 at 10:46 AM Borislav Petkov <bp@alien8.de> wrote:
>
> On Tue, Sep 15, 2020 at 10:26:58AM -0700, rkir@google.com wrote:
> > From: Haitao Shan <hshan@google.com>
> >
> > This is a workaround which fixes triple fault
> > in __restore_processor_state on clang when
> > built with LTO.
> >
> > When load_TR_desc and load_mm_ldt are inlined into
> > fix_processor_context due to LTO, they cause
> > fix_processor_context (or in this case __restore_processor_state,
> > as fix_processor_context was inlined into __restore_processor_state)
> > to access the stack canary through %gs, but before
> > __restore_processor_state has restored the previous value
> > of %gs properly. LLVM appears to be inlining functions with stack
> > protectors into functions compiled with -fno-stack-protector,
> > which is likely a bug in LLVM's inliner that needs to be fixed.
> >
> > The LLVM bug is here: https://bugs.llvm.org/show_bug.cgi?id=47479
> >
> > Signed-off-by: Haitao Shan <hshan@google.com>
> > Signed-off-by: Roman Kiryanov <rkir@google.com>
>
> Ok, google guys, pls make sure you Cc LKML too as this is where *all*
> patches and discussions are archived. Adding it now to Cc.
Roman, please use ./scripts/get_maintainer.pl (in the kernel tree) for that.
>
> > ---
> > arch/x86/power/cpu.c | 10 ++++++++++
> > 1 file changed, 10 insertions(+)
> >
> > diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
> > index db1378c6ff26..e5677adb2d28 100644
> > --- a/arch/x86/power/cpu.c
> > +++ b/arch/x86/power/cpu.c
> > @@ -274,6 +274,16 @@ static void notrace __restore_processor_state(struct saved_context *ctxt)
> > /* Needed by apm.c */
> > void notrace restore_processor_state(void)
> > {
> > +#ifdef __clang__
Should be CONFIG_CC_IS_CLANG; is more canonical throughout the tree.
Or if this is only a bug when doing builds with LTO, and LTO is not
yet upstream, then maybe Sami should carry this in his series, at
least until I can fix the bug in Clang. Or guard this with the
CONFIG_LTO_CLANG config (not upstream yet; see Sami's series).
> > + // The following code snippet is copied from __restore_processor_state.
> > + // Its purpose is to prepare GS segment before the function is called.
> > +#ifdef CONFIG_X86_64
> > + wrmsrl(MSR_GS_BASE, saved_context.kernelmode_gs_base);
> > +#else
> > + loadsegment(fs, __KERNEL_PERCPU);
> > + loadsegment(gs, __KERNEL_STACK_CANARY);
> > +#endif
> > +#endif
>
> Ok, so why is the kernel supposed to take yet another ugly workaround
> because there's a bug in the compiler?
This is exactly the same code from __restore_processor_state. If it's
ugly, talk to the author of 7ee18d677989e. ;) All this patch is doing
is moving this up a call frame (though now this is effectively being
run twice).
> If it is too late to fix it there, then maybe disable LTO builds for the
> buggy version only.
We could do that, too. (We can disable LTO on a per translation unit
basis in KBuild). Note the author of the bug report linked above. :^P
"Revenge of the stack protector"
>
> We had a similar discussion this week and we already have one buggy
> compiler to deal with and this second one is not making it any easier...
--
Thanks,
~Nick Desaulniers
next prev parent reply other threads:[~2020-09-15 18:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-15 17:26 [PATCH] arch: x86: power: cpu: init %gs before __restore_processor_state (clang) rkir
2020-09-15 17:46 ` Borislav Petkov
2020-09-15 17:57 ` Roman Kiryanov
2020-09-15 18:27 ` Borislav Petkov
2020-09-15 18:36 ` Roman Kiryanov
2020-09-15 18:52 ` Borislav Petkov
2020-09-15 18:55 ` Roman Kiryanov
2020-09-18 22:25 ` Pavel Machek
2020-09-21 23:28 ` Roman Kiryanov
2020-10-04 9:59 ` Pavel Machek
2020-09-15 18:00 ` Nick Desaulniers [this message]
2020-09-15 18:25 ` Borislav Petkov
2020-09-15 19:51 ` Nick Desaulniers
2020-09-15 20:20 ` Borislav Petkov
2020-09-15 21:49 ` Nick Desaulniers
2020-09-16 9:23 ` Borislav Petkov
2020-09-19 16:48 ` Pavel Machek
2020-09-16 8:17 ` peterz
2020-09-15 20:44 ` Arvind Sankar
2020-09-15 22:17 ` Pavel Machek
2020-09-15 22:21 ` Nick Desaulniers
2020-09-18 22:20 ` Pavel Machek
2020-09-15 23:13 ` Roman Kiryanov
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='CAKwvOdm9bQmL=gZypkosH0MG=S28=jJ6wZiTMCNP6=Z+NfN1AA@mail.gmail.com' \
--to=ndesaulniers@google.com \
--cc=adelva@google.com \
--cc=bp@alien8.de \
--cc=clang-built-linux@googlegroups.com \
--cc=gregkh@linuxfoundation.org \
--cc=hshan@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pavel@ucw.cz \
--cc=rjw@rjwysocki.net \
--cc=rkir@google.com \
--cc=samitolvanen@google.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.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;
as well as URLs for NNTP newsgroup(s).