From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752077AbdJ0UEz (ORCPT ); Fri, 27 Oct 2017 16:04:55 -0400 Received: from mx2.suse.de ([195.135.220.15]:55837 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750998AbdJ0UEv (ORCPT ); Fri, 27 Oct 2017 16:04:51 -0400 Date: Fri, 27 Oct 2017 22:04:47 +0200 From: Borislav Petkov To: Andy Lutomirski Cc: X86 ML , "linux-kernel@vger.kernel.org" , Brian Gerst , Dave Hansen , Linus Torvalds Subject: Re: [PATCH 02/18] x86/asm/64: Split the iret-to-user and iret-to-kernel paths Message-ID: <20171027200447.GA12039@nazgul.tnic> References: <8042a4bd5882599dd8e3f9b17f1f40a2fdda0450.1509006199.git.luto@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <8042a4bd5882599dd8e3f9b17f1f40a2fdda0450.1509006199.git.luto@kernel.org> User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 26, 2017 at 01:26:34AM -0700, Andy Lutomirski wrote: > These code paths will diverge soon. > > Signed-off-by: Andy Lutomirski > --- > arch/x86/entry/entry_64.S | 32 +++++++++++++++++++++++--------- > arch/x86/entry/entry_64_compat.S | 2 +- > arch/x86/kernel/head_64.S | 2 +- > 3 files changed, 25 insertions(+), 11 deletions(-) > > diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S > index afe1f403fa0e..493e5e234d36 100644 > --- a/arch/x86/entry/entry_64.S > +++ b/arch/x86/entry/entry_64.S > @@ -321,7 +321,7 @@ syscall_return_via_sysret: > > opportunistic_sysret_failed: > SWAPGS > - jmp restore_regs_and_iret > + jmp restore_regs_and_return_to_usermode rstor_regs_ret_user still sounds pretty ok to me and it is shorter and it is using the *RSTOR spelling the respective FPU insns use, so should be recognizable. :-) And the other one could be rstor_regs_ret_kernel of course. > END(entry_SYSCALL_64) > > ENTRY(stub_ptregs_64) > @@ -423,7 +423,7 @@ ENTRY(ret_from_fork) > call syscall_return_slowpath /* returns with IRQs disabled */ > TRACE_IRQS_ON /* user mode is traced as IRQS on */ > SWAPGS > - jmp restore_regs_and_iret > + jmp restore_regs_and_return_to_usermode > > 1: > /* kernel thread */ > @@ -612,7 +612,19 @@ GLOBAL(retint_user) > call prepare_exit_to_usermode > TRACE_IRQS_IRETQ > SWAPGS > - jmp restore_regs_and_iret > + > +GLOBAL(restore_regs_and_return_to_usermode) > +#ifdef CONFIG_DEBUG_ENTRY > + testl $3, CS(%rsp) testb ditto for the other spot. > + jnz 1f > + ud2 > +1: > +#endif Why aren't we exploding here unconditionally? I mean, we don't want to return with RPL != 3 CS for whatever reason... > + RESTORE_EXTRA_REGS > + RESTORE_C_REGS > + REMOVE_PT_GPREGS_FROM_STACK 8 > + INTERRUPT_RETURN > + > > /* Returning to kernel space */ > retint_kernel: > @@ -632,11 +644,13 @@ retint_kernel: > */ > TRACE_IRQS_IRETQ > > -/* > - * At this label, code paths which return to kernel and to user, > - * which come from interrupts/exception and from syscalls, merge. > - */ > -GLOBAL(restore_regs_and_iret) > +GLOBAL(restore_regs_and_return_to_kernel) > +#ifdef CONFIG_DEBUG_ENTRY > + testl $3, CS(%rsp) > + jz 1f > + ud2 > +1: > +#endif I guess here too, as a sanity-check. TEST and Jcc should be very cheap compared to everything else jumping-through-hoops we'll be doing :-\ -- Regards/Gruss, Boris. SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg) --