From: Denys Vlasenko <dvlasenk@redhat.com>
To: Andy Lutomirski <luto@amacapital.net>, Ingo Molnar <mingo@kernel.org>
Cc: Denys Vlasenko <vda.linux@googlemail.com>,
Brian Gerst <brgerst@gmail.com>, Borislav Petkov <bp@alien8.de>,
the arch/x86 maintainers <x86@kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] x86/asm/entry/64: better check for canonical address
Date: Tue, 31 Mar 2015 19:31:54 +0200 [thread overview]
Message-ID: <551ADA0A.7050701@redhat.com> (raw)
In-Reply-To: <CALCETrVHMEM7kRnhu7aVu8UFMSjiMLZBo=7vNfgK4fQx2oZMmg@mail.gmail.com>
On 03/31/2015 07:08 PM, Andy Lutomirski wrote:
> On Tue, Mar 31, 2015 at 9:43 AM, Ingo Molnar <mingo@kernel.org> wrote:
>>
>> * Denys Vlasenko <vda.linux@googlemail.com> wrote:
>>
>>>> I guess they could optimize it by adding a single "I am a modern
>>>> OS executing regular userspace" flag to the descriptor [or
>>>> expressing the same as a separate instruction], to avoid all that
>>>> legacy crap that won't trigger on like 99.999999% of systems ...
>>>
>>> Yes, that would be a useful addition. Interrupt servicing on x86
>>> takes a non-negligible hit because of IRET slowness.
>>
>> But ... to react to your other patch: detecting the common easy case
>> and doing a POPF+RET ourselves ought to be pretty good as well?
>>
>> But only if ptregs->rip != the magic RET itself, to avoid recursion.
>>
>> Even with all those extra checks it should still be much faster.
>>
>
> I have a smallish preference for doing sti;ret instead, because that
> keeps the funny special case entirely localized to the NMI code
> instead of putting it in the IRQ exit path. I suspect that the
> performance loss is at most a cycle or two (we're adding a branch, but
> sti itself is quite fast).
>
> That being said, I could easily be convinced otherwise.
Let me try to convince you. sti is 6 cycles.
The patch atop your code would be:
movq RIP-ARGOFFSET(%rsp), %rcx
+ cmp $magic_ret, %rcx
+ je real_iret
- btr $9, %rdi
movq %rdi, (%rsi)
movq %rcx, 8(%rsi)
movq %rsi, ORIG_RAX-ARGOFFSET(%rsp)
popq_cfi %r11
popq_cfi %r10
popq_cfi %r9
popq_cfi %r8
popq_cfi %rax
popq_cfi %rcx
popq_cfi %rdx
popq_cfi %rsi
popq_cfi %rdi
popq %rsp
- jc 1f
popfq_cfi
+magic_ret:
retq
-1:
- popfq_cfi
- sti
- retq
It's a clear (albeit small) win: the branch is almost never taken,
and we do not need sti.
next prev parent reply other threads:[~2015-03-31 17:32 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-26 12:42 [PATCH] x86/asm/entry/64: better check for canonical address Denys Vlasenko
2015-03-26 18:45 ` Andy Lutomirski
2015-03-27 8:57 ` Borislav Petkov
2015-03-30 14:27 ` Denys Vlasenko
2015-03-30 14:30 ` Andy Lutomirski
2015-03-30 14:45 ` Andy Lutomirski
2015-03-27 8:11 ` Ingo Molnar
2015-03-27 10:45 ` Denys Vlasenko
2015-03-27 11:17 ` Ingo Molnar
2015-03-27 11:28 ` Brian Gerst
2015-03-27 11:34 ` Ingo Molnar
2015-03-27 12:14 ` Denys Vlasenko
2015-03-27 12:16 ` Ingo Molnar
2015-03-27 12:31 ` Denys Vlasenko
2015-03-28 9:11 ` Ingo Molnar
2015-03-29 19:36 ` Denys Vlasenko
2015-03-29 21:12 ` Andy Lutomirski
2015-03-29 21:46 ` Denys Vlasenko
2015-03-31 16:43 ` Ingo Molnar
2015-03-31 17:08 ` Andy Lutomirski
2015-03-31 17:31 ` Denys Vlasenko [this message]
2015-03-27 11:27 ` Brian Gerst
2015-03-27 11:31 ` Ingo Molnar
2015-03-27 21:37 ` Andy Lutomirski
2015-04-02 17:37 ` Denys Vlasenko
2015-04-02 18:10 ` Ingo Molnar
-- strict thread matches above, loose matches on Subject: below --
2015-04-21 16:27 Denys Vlasenko
2015-04-21 18:08 ` Andy Lutomirski
2015-04-23 15:10 ` Borislav Petkov
2015-04-23 15:41 ` Andy Lutomirski
2015-04-23 15:49 ` Borislav Petkov
2015-04-23 15:52 ` Andy Lutomirski
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=551ADA0A.7050701@redhat.com \
--to=dvlasenk@redhat.com \
--cc=bp@alien8.de \
--cc=brgerst@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=vda.linux@googlemail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.