From: Linus Torvalds <torvalds@linux-foundation.org>
To: Andy Lutomirski <luto@kernel.org>
Cc: Stas Sergeev <stsp@list.ru>,
"Bae, Chang Seok" <chang.seok.bae@intel.com>,
X86 ML <x86@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Borislav Petkov <bpetkov@suse.de>,
Brian Gerst <brgerst@gmail.com>,
Bart Oldeman <bartoldeman@users.sourceforge.net>
Subject: Re: FSGSBASE ABI considerations
Date: Mon, 7 Aug 2017 10:35:43 -0700 [thread overview]
Message-ID: <CA+55aFwkhYpGpng55xOzTfuavTMf6LMfSYazf2Gx2Rvyo9+hfw@mail.gmail.com> (raw)
In-Reply-To: <CALCETrVdt3FARBvfJyOtP2x=_yu8iakBLnELf_X6hk43Fx-gtA@mail.gmail.com>
On Mon, Aug 7, 2017 at 9:20 AM, Andy Lutomirski <luto@kernel.org> wrote:
>
> Windows does something sort of like this (I think), but I don't like
> this solution. I fully expect that someone will write a program that
> does:
>
> old = rdgsbase();
> wrgsbase(new);
> call_very_fast_function();
> wrgsbase(old);
>
> This will work if GS == 0, which is fine. The problem is that it will
> *also* work if GS != 0 with very high probability, especially if this
> code sequence is right after some operation that sleeps. And then
> we'll get random crashes with very low probability, depending on where
> the scheduler hits.
It will work reliably if you just make the scheduler save/restore the
base rather than the selector.
I really think you need to walk away from the "selector is meaningful"
model. Yes, yes, it's the legacy model, but it's the *insane* model.
So screw the selector. It doesn't matter. We'll need to save/restore
the value, but that's it. What we *really* save and restore is just
the base pointer.
Why do you care so much about the selector? If people *don't* use the
fsgsbase, then the selector and the base of the segment will always
match anyway (modulo the system calls that actually change the
gdt/ldt, and we can just sat that *then* selectors matter).
And if people *do* use fsgsbase, then the selector is by definition
not important.
So just make the scheduler save the base first, and restore it last.
End of problem. Your user-space code above just works. There is no
race, i doesn't matter one whit whether GS is 0 ir not, there simply
is no problem.
So just what is the problem you're trying to solve?
Linus
next prev parent reply other threads:[~2017-08-07 17:35 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-31 3:05 FSGSBASE ABI considerations Andy Lutomirski
2017-07-31 4:38 ` Linus Torvalds
2017-07-31 14:14 ` Andy Lutomirski
2017-07-31 10:55 ` Kirill A. Shutemov
2017-07-31 14:16 ` Andy Lutomirski
2017-07-31 21:23 ` Bae, Chang Seok
2017-08-07 16:14 ` Andy Lutomirski
2017-08-07 8:06 ` Stas Sergeev
2017-08-07 16:20 ` Andy Lutomirski
2017-08-07 16:49 ` Christopher Lameter
2017-08-07 17:35 ` Linus Torvalds [this message]
2017-08-07 19:07 ` Andy Lutomirski
2017-08-07 21:32 ` Stas Sergeev
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+55aFwkhYpGpng55xOzTfuavTMf6LMfSYazf2Gx2Rvyo9+hfw@mail.gmail.com \
--to=torvalds@linux-foundation.org \
--cc=bartoldeman@users.sourceforge.net \
--cc=bpetkov@suse.de \
--cc=brgerst@gmail.com \
--cc=chang.seok.bae@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=stsp@list.ru \
--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).