From: Nathan Chancellor <natechancellor@gmail.com>
To: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Arnd Bergmann <arnd@arndb.de>,
Paul Burton <paulburton@kernel.org>,
"open list:BROADCOM NVRAM DRIVER" <linux-mips@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"Jason A. Donenfeld" <Jason@zx2c4.com>,
Christian Brauner <christian.brauner@canonical.com>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
"# 3.4.x" <stable@vger.kernel.org>,
clang-built-linux@googlegroups.com
Subject: Re: [PATCH] MIPS: Don't declare __current_thread_info globally
Date: Wed, 1 Jan 2020 20:02:29 -0700 [thread overview]
Message-ID: <20200102030229.GA4478@ubuntu-m2-xlarge-x86> (raw)
In-Reply-To: <20200102005343.GA495913@rani.riverdale.lan>
On Wed, Jan 01, 2020 at 07:53:45PM -0500, Arvind Sankar wrote:
> On Wed, Jan 01, 2020 at 09:51:02PM +0100, Arnd Bergmann wrote:
> > On Wed, Jan 1, 2020 at 6:57 PM Paul Burton <paulburton@kernel.org> wrote:
> > > diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
> > > index 4993db40482c..aceefc3f9a1a 100644
> > > --- a/arch/mips/include/asm/thread_info.h
> > > +++ b/arch/mips/include/asm/thread_info.h
> > > @@ -50,10 +50,10 @@ struct thread_info {
> > > }
> > >
> > > /* How to get the thread information struct from C. */
> > > -register struct thread_info *__current_thread_info __asm__("$28");
> > > -
> > > static inline struct thread_info *current_thread_info(void)
> > > {
> > > + register struct thread_info *__current_thread_info __asm__("$28");
> > > +
> > > return __current_thread_info;
> > > }
> >
> > This looks like a nice fix, but are you sure it doesn't allow the compiler to
> > reuse $28 for another purpose in the kernel under register pressure,
> > which would break current_thread_info()?
> >
> > I see in the MIPS ABI document that $28 is preserved across function
> > calls, but I don't see any indication that a function is not allowed
> > to modify it and later restore the original content.
> >
> > Arnd
>
> The compiler can already do that even with a global definition.
>
> The doc since gcc 9 [1] says:
>
> "Accesses to the variable may be optimized as usual and the register
> remains available for allocation and use in any computations, provided
> that observable values of the variable are not affected."
>
> and
>
> "Furthermore, since the register is not reserved exclusively for the
> variable, accessing it from handlers of asynchronous signals may observe
> unrelated temporary values residing in the register."
>
> I'm not sure if this was a change in gcc 9 or simply the doc was wrong
> earlier.
>
> Should there be a -ffixed-28 cflag for MIPS? alpha and hexagon seem to
> have that and they also keep current_thread_info in a register.
>
> Also, commit fe92da0f355e9 ("MIPS: Changed current_thread_info() to an
> equivalent supported by both clang and GCC") moved this from local to
> global because local apparently didn't work on clang?
>
> [1] https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Global-Register-Variables.html
Yeah this patch appears to break booting malta_defconfig in QEMU when
built with clang; additionally, there are a TON of warnings about this
variable being uninitialized:
../arch/mips/include/asm/thread_info.h:57:9: warning: variable '__current_thread_info' is uninitialized when used here [-Wuninitialized]
return __current_thread_info;
^~~~~~~~~~~~~~~~~~~~~
../arch/mips/include/asm/thread_info.h:55:52: note: initialize the variable '__current_thread_info' to silence this warning
register struct thread_info *__current_thread_info __asm__("$28");
^
= NULL
1 warning generated.
Seems like this is expected according to that previous commit? I
noticed there is another instance in arch/mips but it doesn't appear to
affect everything.
https://github.com/ClangBuiltLinux/linux/issues/606
Cheers,
Nathan
next prev parent reply other threads:[~2020-01-02 3:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-01 17:59 [PATCH] MIPS: Don't declare __current_thread_info globally Paul Burton
2020-01-01 20:51 ` Arnd Bergmann
2020-01-02 0:53 ` Arvind Sankar
2020-01-02 3:02 ` Nathan Chancellor [this message]
2020-01-02 4:50 ` [PATCH v2] MIPS: Avoid VDSO ABI breakage due to global register variable Paul Burton
2020-01-02 10:58 ` Jason A. Donenfeld
2020-01-02 16:56 ` Vincenzo Frascino
2020-01-03 0:42 ` Paul Burton
2020-01-03 9:15 ` Vincenzo Frascino
2020-01-03 0:42 ` Paul Burton
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=20200102030229.GA4478@ubuntu-m2-xlarge-x86 \
--to=natechancellor@gmail.com \
--cc=Jason@zx2c4.com \
--cc=arnd@arndb.de \
--cc=christian.brauner@canonical.com \
--cc=clang-built-linux@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=nivedita@alum.mit.edu \
--cc=paulburton@kernel.org \
--cc=stable@vger.kernel.org \
--cc=vincenzo.frascino@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).