From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753535AbdKXMRL (ORCPT ); Fri, 24 Nov 2017 07:17:11 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:40720 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753464AbdKXMRK (ORCPT ); Fri, 24 Nov 2017 07:17:10 -0500 X-Google-Smtp-Source: AGs4zMb19KbYwU4E0Fo4uAzjBrpaBhmSq4fDxSKrIO+e2x+PINgOjxbVgaGK+zLuUK9BF8/qaKvvhQ== Date: Fri, 24 Nov 2017 13:17:06 +0100 From: Ingo Molnar To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Dave Hansen , Andy Lutomirski , Thomas Gleixner , "H . Peter Anvin" , Borislav Petkov , Linus Torvalds Subject: Re: [PATCH 22/43] x86/mm/kaiser: Prepare assembly for entry/exit CR3 switching Message-ID: <20171124121706.ldrmycmmquenhap7@gmail.com> References: <20171124091448.7649-1-mingo@kernel.org> <20171124091448.7649-23-mingo@kernel.org> <20171124120516.wacb2zdbczk4tafv@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171124120516.wacb2zdbczk4tafv@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Peter Zijlstra wrote: > On Fri, Nov 24, 2017 at 10:14:27AM +0100, Ingo Molnar wrote: > > Interactions with SWAPGS: previous versions of the KAISER code > > relied on having per-cpu scratch space to save/restore a register > > that can be used for the CR3 MOV. The %GS register is used to > > index into our per-cpu space, so SWAPGS *had* to be done before > > the CR3 switch. That scratch space is gone now, but the semantic > > that SWAPGS must be done before the CR3 MOV is retained. This is > > good to keep because it is not that hard to do and it allows us > > to do things like add per-cpu debugging information to help us > > figure out what goes wrong sometimes. > > > +.macro SAVE_AND_SWITCH_TO_KERNEL_CR3 scratch_reg:req save_reg:req > > + movq %cr3, %r\scratch_reg > > + movq %r\scratch_reg, \save_reg > > + /* > > + * Is the switch bit zero? This means the address is > > + * up in real KAISER patches in a moment. > > + */ > > + testq $(KAISER_SWITCH_MASK), %r\scratch_reg > > + jz .Ldone_\@ > > + > > + ADJUST_KERNEL_CR3 %r\scratch_reg > > + movq %r\scratch_reg, %cr3 > > + > > +.Ldone_\@: > > +.endm > > > @@ -1333,6 +1362,7 @@ ENTRY(error_entry) > > * gsbase and proceed. We'll fix up the exception and land in > > * .Lgs_change's error handler with kernel gsbase. > > */ > > + SWITCH_TO_KERNEL_CR3 scratch_reg=%rax > > SWAPGS > > jmp .Lerror_entry_done > > > > > @@ -1343,9 +1373,10 @@ ENTRY(error_entry) > > > > .Lerror_bad_iret: > > /* > > - * We came from an IRET to user mode, so we have user gsbase. > > - * Switch to kernel gsbase: > > + * We came from an IRET to user mode, so we have user > > + * gsbase and CR3. Switch to kernel gsbase and CR3: > > */ > > + SWITCH_TO_KERNEL_CR3 scratch_reg=%rax > > SWAPGS > > > > /* > > The Changelog states SWAPGS must be done before, yet the code does > after. Yes, so this is the SWAPGS that is done before we go back to user-space. Thanks, Ingo