[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] linux-2.6.18/x86-64: streamline syscall code



System calls using the sysret exit path (or its VGCF_in_syscall IRET
equivalent on Xen) always go into user mode, hence the conditionals
in HYPERVISOR_IRET can be omitted entirely.

Further, there's no need to spill %rcx to the stack upon syscall entry
(neither does native code): No argument gets passed there, and due to
the use of the syscall instruction the register's contents don't need
to be preserved either.

Finally, rather than restoring %rcx and %r11 (not preserved by syscall/
sysret anyway) from the stack frame, we can as well simply clear them
out (to avoid leaking kernel data), thus reducing the necessary memory
(cache) bandwidth.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/arch/x86_64/kernel/entry-xen.S
+++ b/arch/x86_64/kernel/entry-xen.S
@@ -153,6 +153,7 @@ NMI_MASK = 0x80000000
          * with rax, r11, and rcx being taken care of in the hypercall stub.
          */
        .macro HYPERVISOR_IRET flag
+       .if \flag == 0  # return from syscall always uses the hypercall
        testb $3,1*8(%rsp)
        jnz   2f
        testl $NMI_MASK,2*8(%rsp)
@@ -165,6 +166,7 @@ NMI_MASK = 0x80000000
        orl   $3,1*8(%rsp)
        orl   $3,4*8(%rsp)
 1:     iretq
+       .endif
 
 2:     /* Slow iret via hypervisor. */
        andl  $~NMI_MASK, 2*8(%rsp)
@@ -248,7 +250,7 @@ END(ret_from_fork)
 
 ENTRY(system_call)
        _frame (RIP-0x10)
-       SAVE_ARGS -8,0
+       SAVE_ARGS -8,1
        movq  %rax,ORIG_RAX-ARGOFFSET(%rsp) 
        GET_THREAD_INFO(%rcx)
        testl 
$(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%rcx)
@@ -279,8 +281,9 @@ sysret_check:
         * sysretq will re-enable interrupts:
         */
        TRACE_IRQS_ON
-        XEN_UNBLOCK_EVENTS(%rsi)                
-       RESTORE_ARGS 0,8,0
+       RESTORE_ARGS 0,8,1,1
+       xor %ecx,%ecx
+       xor %r11,%r11
         HYPERVISOR_IRET VGCF_IN_SYSCALL
 
        /* Handle reschedules */




_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.