From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752466AbdK0K4c (ORCPT ); Mon, 27 Nov 2017 05:56:32 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:42652 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752529AbdK0Kvu (ORCPT ); Mon, 27 Nov 2017 05:51:50 -0500 X-Google-Smtp-Source: AGs4zMarQAxPWtKIMhnZjx6lHYvDPt8ugUwapNyi4wu571LiW0xZuEKr1XF7nuFc0HVLbEXXBjEVcg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Dave Hansen , Andy Lutomirski , Thomas Gleixner , "H . Peter Anvin" , Peter Zijlstra , Borislav Petkov , Linus Torvalds Subject: [PATCH 09/24] x86/mm/kaiser: Map the espfix structures Date: Mon, 27 Nov 2017 11:49:08 +0100 Message-Id: <20171127104923.14378-10-mingo@kernel.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171127104923.14378-1-mingo@kernel.org> References: <20171127104923.14378-1-mingo@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Hansen There is some rather arcane code to help when an IRET returns to 16-bit segments. It is referred to as the "espfix" code. This consists of a few per-CPU variables: espfix_stack: tells us where the stack is allocated (the bottom) espfix_waddr: tells us to where %rsp may be pointed (the top) These are in addition to the stack itself. All three things must be mapped for the espfix code to function. Note: the espfix code runs with a kernel GSBASE, but user (shadow) page tables. A switch to the kernel page tables could be performed instead of mapping these structures, but mapping them is simpler and less likely to break the assembly. To switch over to the kernel copy, additional temporary storage would be required which is in short supply in this context. The original KAISER patch missed this case. Signed-off-by: Dave Hansen Signed-off-by: Thomas Gleixner Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Josh Poimboeuf Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Rik van Riel Cc: daniel.gruss@iaik.tugraz.at Cc: hughd@google.com Cc: keescook@google.com Cc: linux-mm@kvack.org Cc: michael.schwarz@iaik.tugraz.at Cc: moritz.lipp@iaik.tugraz.at Cc: richard.fellner@student.tugraz.at Link: https://lkml.kernel.org/r/20171123003457.EB854D0D@viggo.jf.intel.com Signed-off-by: Ingo Molnar --- arch/x86/kernel/espfix_64.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c index 7b95cb47a3cf..319033f5bbd9 100644 --- a/arch/x86/kernel/espfix_64.c +++ b/arch/x86/kernel/espfix_64.c @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -41,7 +42,6 @@ #include #include #include -#include /* * Note: we only need 6*8 = 48 bytes for the espfix stack, but round @@ -61,8 +61,8 @@ #define PGALLOC_GFP (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO) /* This contains the *bottom* address of the espfix stack */ -DEFINE_PER_CPU_READ_MOSTLY(unsigned long, espfix_stack); -DEFINE_PER_CPU_READ_MOSTLY(unsigned long, espfix_waddr); +DEFINE_PER_CPU_USER_MAPPED(unsigned long, espfix_stack); +DEFINE_PER_CPU_USER_MAPPED(unsigned long, espfix_waddr); /* Initialization mutex - should this be a spinlock? */ static DEFINE_MUTEX(espfix_init_mutex); @@ -226,4 +226,10 @@ void init_espfix_ap(int cpu) per_cpu(espfix_stack, cpu) = addr; per_cpu(espfix_waddr, cpu) = (unsigned long)stack_page + (addr & ~PAGE_MASK); + /* + * _PAGE_GLOBAL is not really required. This is not a hot + * path, but we do it here for consistency. + */ + kaiser_add_mapping((unsigned long)stack_page, PAGE_SIZE, + __PAGE_KERNEL | _PAGE_GLOBAL); } -- 2.14.1