From: Paolo Bonzini <pbonzini@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>,
Andy Lutomirski <luto@amacapital.net>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
the arch/x86 maintainers <x86@kernel.org>,
"H. Peter Anvin" <h.peter.anvin@intel.com>,
Steven Rostedt <rostedt@goodmis.org>,
Gleb Natapov <gleb@kernel.org>
Subject: Re: [RFC/HACK] x86: Fast return to kernel
Date: Mon, 05 May 2014 01:46:43 +0200 [thread overview]
Message-ID: <5366D163.9000503@redhat.com> (raw)
In-Reply-To: <CA+55aFygkoYnJKdLas3WOq9q9pCEEk6mBOuj-zbLyLumdhStAA@mail.gmail.com>
Il 02/05/2014 21:51, Linus Torvalds ha scritto:
>> > Also, are you *really* sure that "popf" has the same one-instruction
>> > interrupt shadow that "sti" has? Because I'm not at all sure that is
>> > true, and it's not documented as far as I can tell. In contrast, the
>> > one-instruction shadow after "sti" very much _is_ documented.
> Yeah, I'm pretty sure about this. The only instructions with an
> interrupt shadow are "sti", "mov ss" and "pop ss".
Yep.
> There may be specific microarchitectures that do it for a "popf" that
> enables interrupts too, but that is not documented _anywhere_ I could
> find.
>
> Btw, on the "really easy to get wrong in emulation" note and looking
> at the kernel sources: it looks like KVM gets "pop ss" wrong, and only
> does the shadow on "mov ss".
Thanks, that's useful to know (and easy to fix). Note that in practice
arch/x86/kvm/emulate.c will only emulate POP SS in big real mode or if
the stack is in MMIO memory. The interrupt shadow will be handled by
the processor in all other cases, and Intel calls the bit "Blocking by
MOV SS" even if it also applies to POP SS.
Your suggested trick of splitting the return paths for IF=0/IF=1 can be
also done like this:
movq EFLAGS-ARGOFFSET(%rsp), %rdi
btrq $9, %rdi # Clear IF, save old value in CF
movq %rdi, (%rsi)
...
popfq
jnc 1f # If IF was 0, just return
sti # Using STI gets us an interrupt shadow
1f:
retq
Paolo
next prev parent reply other threads:[~2014-05-04 23:46 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-02 19:04 [RFC/HACK] x86: Fast return to kernel Andy Lutomirski
2014-05-02 19:31 ` Linus Torvalds
2014-05-02 19:50 ` Andy Lutomirski
2014-05-04 18:40 ` Ingo Molnar
2014-05-04 19:59 ` H. Peter Anvin
2014-05-04 21:31 ` Linus Torvalds
2014-05-04 22:01 ` H. Peter Anvin
2014-05-02 19:51 ` Linus Torvalds
2014-05-02 20:07 ` H. Peter Anvin
2014-05-02 20:30 ` Thomas Gleixner
2014-05-02 21:01 ` Linus Torvalds
2014-05-02 21:04 ` Andy Lutomirski
2014-05-02 21:07 ` Linus Torvalds
2014-05-02 21:37 ` H. Peter Anvin
2014-05-02 21:42 ` Andy Lutomirski
2014-05-02 21:44 ` H. Peter Anvin
2014-05-02 21:28 ` Thomas Gleixner
2014-05-04 23:46 ` Paolo Bonzini [this message]
2014-05-04 23:49 ` H. Peter Anvin
2014-05-02 20:19 ` Steven Rostedt
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=5366D163.9000503@redhat.com \
--to=pbonzini@redhat.com \
--cc=gleb@kernel.org \
--cc=h.peter.anvin@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=rostedt@goodmis.org \
--cc=torvalds@linux-foundation.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