From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932130AbbCWQra (ORCPT ); Mon, 23 Mar 2015 12:47:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55146 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932080AbbCWQr1 (ORCPT ); Mon, 23 Mar 2015 12:47:27 -0400 From: Denys Vlasenko To: Andy Lutomirski Cc: Denys Vlasenko , Linus Torvalds , Steven Rostedt , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Oleg Nesterov , Frederic Weisbecker , Alexei Starovoitov , Will Drewry , Kees Cook , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] x86: vdso32/syscall.S: do not load __USER32_DS to %ss Date: Mon, 23 Mar 2015 17:47:20 +0100 Message-Id: <1427129240-15543-1-git-send-email-dvlasenk@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This vDSO code only gets used by 64-bit kernel, not 32-bit. In 64-bit kernels, data segment is the same for 32-bit and 64-bit userspace, and SYSRET insn does load %ss with its selector. No need to repeat it by hand. Segment loads are somewhat expensive: tens of cycles. Signed-off-by: Denys Vlasenko CC: Linus Torvalds CC: Steven Rostedt CC: Ingo Molnar CC: Borislav Petkov CC: "H. Peter Anvin" CC: Andy Lutomirski CC: Oleg Nesterov CC: Frederic Weisbecker CC: Alexei Starovoitov CC: Will Drewry CC: Kees Cook CC: x86@kernel.org CC: linux-kernel@vger.kernel.org --- Patch was run-tested. arch/x86/vdso/vdso32/syscall.S | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/x86/vdso/vdso32/syscall.S b/arch/x86/vdso/vdso32/syscall.S index 5415b56..ccdb9ef 100644 --- a/arch/x86/vdso/vdso32/syscall.S +++ b/arch/x86/vdso/vdso32/syscall.S @@ -19,8 +19,15 @@ __kernel_vsyscall: .Lpush_ebp: movl %ecx, %ebp syscall - movl $__USER32_DS, %ecx - movl %ecx, %ss + /* + * Used to load __USER32_DS to %ss here, + * but it's not necessary: this vDSO is only used if our kernel + * is 64-bit one (and we are on AMD CPU). + * For 64-bit kernels, __USER32_DS and __USER_DS are the same. + * SYSRET restores %ss to the same value when returning to + * either 64- or 32-bit userspace, and 64-bit kernel uses the same + * descriptor for %ss in 64- and 32-bit userspace. + */ movl %ebp, %ecx popl %ebp .Lpop_ebp: -- 1.8.1.4