From: Ingo Molnar <mingo@kernel.org>
To: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Andy Lutomirski <luto@amacapital.net>,
Linus Torvalds <torvalds@linux-foundation.org>,
Steven Rostedt <rostedt@goodmis.org>,
Borislav Petkov <bp@alien8.de>, "H. Peter Anvin" <hpa@zytor.com>,
Oleg Nesterov <oleg@redhat.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Alexei Starovoitov <ast@plumgrid.com>,
Will Drewry <wad@chromium.org>, Kees Cook <keescook@chromium.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] x86: entry_32.S: change ESPFIX test to not touch PT_OLDSS(%esp)
Date: Tue, 10 Mar 2015 08:57:43 +0100 [thread overview]
Message-ID: <20150310075743.GA20041@gmail.com> (raw)
In-Reply-To: <1425919450-19116-1-git-send-email-dvlasenk@redhat.com>
* Denys Vlasenko <dvlasenk@redhat.com> wrote:
> Old code was trying to avoid having three branch insns,
> but instead it has a chain of six insns where each insn
> depends on previos one.
>
> And it was touching PT_OLDSS(%esp) unconditionally, even when it may
> contain bogus data. Elsewhere we have to jump thru hoops
> just to make sure here PT_OLDSS(%esp) is at least in a valid page.
>
> All this just to have one branch instead of three?
>
> The new code simply checks each condition.
> All three checks can run in parallel on an out-of-order CPU.
> Most of the time, none of branches will be taken.
>
> Comparison of object code:
> Old:
> 1e6: 8b 44 24 38 mov 0x38(%esp),%eax
> 1ea: 8a 64 24 40 mov 0x40(%esp),%ah
> 1ee: 8a 44 24 34 mov 0x34(%esp),%al
> 1f2: 25 03 04 02 00 and $0x20403,%eax
> 1f7: 3d 03 04 00 00 cmp $0x403,%eax
> 1fc: 74 0f je 20d <ldt_ss>
> New:
> 1e6: f6 44 24 3a 02 testb $0x2,0x3a(%esp)
> 1eb: 75 0e jne 1fb <restore_nocheck>
> 1ed: f6 44 24 34 03 testb $0x3,0x34(%esp)
> 1f2: 74 07 je 1fb <restore_nocheck>
> 1f4: f6 44 24 40 04 testb $0x4,0x40(%esp)
> 1f9: 75 0f jne 20a <ldt_ss>
Please do some benchmarking of this: a tight loop of getpid or getppid
syscalls ought to be enough to be able to time this accurately.
Thanks,
Ingo
next prev parent reply other threads:[~2015-03-10 7:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-09 16:44 [PATCH v2] x86: entry_32.S: change ESPFIX test to not touch PT_OLDSS(%esp) Denys Vlasenko
2015-03-10 7:57 ` Ingo Molnar [this message]
2015-03-11 3:35 ` Andy Lutomirski
2015-03-11 12:50 ` Denys Vlasenko
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=20150310075743.GA20041@gmail.com \
--to=mingo@kernel.org \
--cc=ast@plumgrid.com \
--cc=bp@alien8.de \
--cc=dvlasenk@redhat.com \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=oleg@redhat.com \
--cc=rostedt@goodmis.org \
--cc=torvalds@linux-foundation.org \
--cc=wad@chromium.org \
--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).