From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Andy Lutomirski <luto@amacapital.net>, X86 ML <x86@kernel.org>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Borislav Petkov <bp@alien8.de>,
Steven Rostedt <rostedt@goodmis.org>,
"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: Getting rid of invalid SYSCALL RSP under Xen?
Date: Sun, 26 Jul 2015 20:34:14 +0100 [thread overview]
Message-ID: <55B53636.80304@citrix.com> (raw)
In-Reply-To: <CALCETrVJNZVLBHsMeYi6G9eaV5N_O8YssY+L7qwYnih3x9KC9w@mail.gmail.com>
On 23/07/2015 17:49, Andy Lutomirski wrote:
> Hi-
Hi. Apologies for the delay. I have been out of the office for a few days.
>
> In entry_64.S, we have:
>
> ENTRY(entry_SYSCALL_64)
> /*
> * Interrupts are off on entry.
> * We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON,
> * it is too small to ever cause noticeable irq latency.
> */
> SWAPGS_UNSAFE_STACK
> /*
> * A hypervisor implementation might want to use a label
> * after the swapgs, so that it can do the swapgs
> * for the guest and jump here on syscall.
> */
> GLOBAL(entry_SYSCALL_64_after_swapgs)
>
> movq %rsp, PER_CPU_VAR(rsp_scratch)
> movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
>
> It would be really, really nice if Xen entered the SYSCALL path
> *after* the mov to %rsp.
>
> Similarly, we have:
>
> movq RSP(%rsp), %rsp
> /* big comment */
> USERGS_SYSRET64
>
> It would be really nice if we could just mov to %rsp, swapgs, and
> sysret, without worrying that the sysret is actually a jump on Xen.
>
> I suspect that making Xen stop using these code paths would actually
> be a simplification. On SYSCALL entry, Xen lands in
> xen_syscall_target (AFAICT) and clearly has rsp pointing somewhere
> valid. Xen obligingly shoves the user RSP into the hardware RSP
> register and jumps into the entry code.
>
> Is that stuff running on the normal kernel stack?
Yes. The Xen ABI takes what is essentially tss->esp0 and uses that stack
for all "switch to kernel" actions, including syscall and sysenter.
> If so, can we just
> enter later on:
>
> pushq %r11 /* pt_regs->flags */
> pushq $__USER_CS /* pt_regs->cs */
> pushq %rcx /* pt_regs->ip */
>
> <-- Xen enters here
>
> pushq %rax /* pt_regs->orig_ax */
> pushq %rdi /* pt_regs->di */
> pushq %rsi /* pt_regs->si */
> pushq %rdx /* pt_regs->dx */
This looks plausible, and indeed preferable to the current doublestep
with undo_xen_syscall.
One slight complication is that xen_enable_syscall() will want to
special case register_callback() to not set CALLBACKF_mask_events, as
the entry point is now after re-enabling interrupts.
>
> For SYSRET, I think the way to go is to force Xen to always use the
> syscall slow path. Instead, Xen could hook into
> syscall_return_via_sysret or even right before the opportunistic
> sysret stuff. Then we could remove the USERGS_SYSRET hooks entirely.
>
> Would this work?
None of the opportunistic sysret stuff makes sense under Xen. The path
will inevitably end up in xen_iret making a hypercall. Short circuiting
all of this seems like a good idea, especially if it allows for the
removal of the UERGS_SYSRET.
~Andrew
next prev parent reply other threads:[~2015-07-26 19:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-23 16:49 Getting rid of invalid SYSCALL RSP under Xen? Andy Lutomirski
2015-07-26 19:34 ` Andrew Cooper [this message]
2015-07-26 22:08 ` Andy Lutomirski
2015-07-26 23:05 ` Andrew Cooper
2015-07-26 23:05 ` Andrew Cooper
2015-07-26 23:27 ` Andy Lutomirski
2015-07-26 23:27 ` Andy Lutomirski
2015-07-27 13:52 ` Andrew Cooper
2015-07-27 13:52 ` Andrew Cooper
2015-07-26 22:08 ` Andy Lutomirski
2015-07-26 19:34 ` Andrew Cooper
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=55B53636.80304@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=boris.ostrovsky@oracle.com \
--cc=bp@alien8.de \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=rostedt@goodmis.org \
--cc=x86@kernel.org \
--cc=xen-devel@lists.xen.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.