From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753647AbdKXMF1 (ORCPT ); Fri, 24 Nov 2017 07:05:27 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:46607 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752406AbdKXMF0 (ORCPT ); Fri, 24 Nov 2017 07:05:26 -0500 Date: Fri, 24 Nov 2017 13:05:16 +0100 From: Peter Zijlstra To: Ingo Molnar 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: <20171124120516.wacb2zdbczk4tafv@hirez.programming.kicks-ass.net> References: <20171124091448.7649-1-mingo@kernel.org> <20171124091448.7649-23-mingo@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20171124091448.7649-23-mingo@kernel.org> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.