From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751972AbeAPQ4U (ORCPT + 1 other); Tue, 16 Jan 2018 11:56:20 -0500 Received: from 8bytes.org ([81.169.241.247]:54752 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751353AbeAPQsd (ORCPT ); Tue, 16 Jan 2018 11:48:33 -0500 From: Joerg Roedel To: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" Cc: x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Andy Lutomirski , Dave Hansen , Josh Poimboeuf , Juergen Gross , Peter Zijlstra , Borislav Petkov , Jiri Kosina , Boris Ostrovsky , Brian Gerst , David Laight , Denys Vlasenko , Eduardo Valentin , Greg KH , Will Deacon , aliguori@amazon.com, daniel.gruss@iaik.tugraz.at, hughd@google.com, keescook@google.com, Andrea Arcangeli , Waiman Long , jroedel@suse.de, joro@8bytes.org Subject: [PATCH 15/16] x86/entry/32: Switch between kernel and user cr3 on entry/exit Date: Tue, 16 Jan 2018 17:36:58 +0100 Message-Id: <1516120619-1159-16-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516120619-1159-1-git-send-email-joro@8bytes.org> References: <1516120619-1159-1-git-send-email-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: From: Joerg Roedel Add the cr3 switches between the kernel and the user page-table when PTI is enabled. Signed-off-by: Joerg Roedel --- arch/x86/entry/entry_32.S | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S index 14018eeb11c3..6a1d9f1e1f89 100644 --- a/arch/x86/entry/entry_32.S +++ b/arch/x86/entry/entry_32.S @@ -221,6 +221,25 @@ POP_GS_EX .endm +#define PTI_SWITCH_MASK (1 << PAGE_SHIFT) + +.macro SWITCH_TO_KERNEL_CR3 + ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI + movl %cr3, %edi + andl $(~PTI_SWITCH_MASK), %edi + movl %edi, %cr3 +.Lend_\@: +.endm + +.macro SWITCH_TO_USER_CR3 + ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI + mov %cr3, %edi + /* Flip the PGD to the user version */ + orl $(PTI_SWITCH_MASK), %edi + mov %edi, %cr3 +.Lend_\@: +.endm + /* * Switch from the entry-trampline stack to the kernel stack of the * running task. @@ -240,6 +259,7 @@ .endif pushl %edi + SWITCH_TO_KERNEL_CR3 movl %esp, %edi /* @@ -309,9 +329,12 @@ .endif pushl 4(%edi) /* fs */ + pushl (%edi) /* edi */ + + SWITCH_TO_USER_CR3 /* Restore user %edi and user %fs */ - movl (%edi), %edi + popl %edi popl %fs .Lend_\@: -- 2.13.6 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ua0-f199.google.com (mail-ua0-f199.google.com [209.85.217.199]) by kanga.kvack.org (Postfix) with ESMTP id D80F46B0069 for ; Fri, 19 Jan 2018 10:28:27 -0500 (EST) Received: by mail-ua0-f199.google.com with SMTP id v26so1254195uaj.19 for ; Fri, 19 Jan 2018 07:28:27 -0800 (PST) Received: from theia.8bytes.org (8bytes.org. [81.169.241.247]) by mx.google.com with ESMTPS id i5si1312103edc.211.2018.01.16.08.39.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jan 2018 08:39:23 -0800 (PST) From: Joerg Roedel Subject: [PATCH 15/16] x86/entry/32: Switch between kernel and user cr3 on entry/exit Date: Tue, 16 Jan 2018 17:36:58 +0100 Message-Id: <1516120619-1159-16-git-send-email-joro@8bytes.org> In-Reply-To: <1516120619-1159-1-git-send-email-joro@8bytes.org> References: <1516120619-1159-1-git-send-email-joro@8bytes.org> Sender: owner-linux-mm@kvack.org List-ID: To: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" Cc: x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Andy Lutomirski , Dave Hansen , Josh Poimboeuf , Juergen Gross , Peter Zijlstra , Borislav Petkov , Jiri Kosina , Boris Ostrovsky , Brian Gerst , David Laight , Denys Vlasenko , Eduardo Valentin , Greg KH , Will Deacon , aliguori@amazon.com, daniel.gruss@iaik.tugraz.at, hughd@google.com, keescook@google.com, Andrea Arcangeli , Waiman Long , jroedel@suse.de, joro@8bytes.org From: Joerg Roedel Add the cr3 switches between the kernel and the user page-table when PTI is enabled. Signed-off-by: Joerg Roedel --- arch/x86/entry/entry_32.S | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/arch/x86/entry/entry_32.S b/arch/x86/entry/entry_32.S index 14018eeb11c3..6a1d9f1e1f89 100644 --- a/arch/x86/entry/entry_32.S +++ b/arch/x86/entry/entry_32.S @@ -221,6 +221,25 @@ POP_GS_EX .endm +#define PTI_SWITCH_MASK (1 << PAGE_SHIFT) + +.macro SWITCH_TO_KERNEL_CR3 + ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI + movl %cr3, %edi + andl $(~PTI_SWITCH_MASK), %edi + movl %edi, %cr3 +.Lend_\@: +.endm + +.macro SWITCH_TO_USER_CR3 + ALTERNATIVE "jmp .Lend_\@", "", X86_FEATURE_PTI + mov %cr3, %edi + /* Flip the PGD to the user version */ + orl $(PTI_SWITCH_MASK), %edi + mov %edi, %cr3 +.Lend_\@: +.endm + /* * Switch from the entry-trampline stack to the kernel stack of the * running task. @@ -240,6 +259,7 @@ .endif pushl %edi + SWITCH_TO_KERNEL_CR3 movl %esp, %edi /* @@ -309,9 +329,12 @@ .endif pushl 4(%edi) /* fs */ + pushl (%edi) /* edi */ + + SWITCH_TO_USER_CR3 /* Restore user %edi and user %fs */ - movl (%edi), %edi + popl %edi popl %fs .Lend_\@: -- 2.13.6 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org