From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753104AbdLDQv6 (ORCPT ); Mon, 4 Dec 2017 11:51:58 -0500 Received: from Galois.linutronix.de ([146.0.238.70]:60160 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752733AbdLDQvZ (ORCPT ); Mon, 4 Dec 2017 11:51:25 -0500 Message-Id: <20171204150607.722883469@linutronix.de> User-Agent: quilt/0.63-1 Date: Mon, 04 Dec 2017 15:07:41 +0100 From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Linus Torvalds , Andy Lutomirsky , Peter Zijlstra , Dave Hansen , Borislav Petkov , Greg KH , keescook@google.com, hughd@google.com, Brian Gerst , Josh Poimboeuf , Denys Vlasenko , Rik van Riel , Boris Ostrovsky , Juergen Gross , David Laight , Eduardo Valentin , aliguori@amazon.com, Will Deacon , daniel.gruss@iaik.tugraz.at, Dave Hansen Subject: [patch 35/60] x86/espfix: Ensure that ESPFIX is visible in user PGD References: <20171204140706.296109558@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Disposition: inline; filename=x86-espfix--Ensure_that_ESPFIX_is_visible_in_user_PGD.patch Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Hansen Clone the ESPFIX alias mapping area so the entry/exit code has access to it even with the user space page tables. [ tglx: Remove the per cpu user mapped oddity ] Signed-off-by: Dave Hansen Signed-off-by: Thomas Gleixner --- arch/x86/kernel/espfix_64.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) --- a/arch/x86/kernel/espfix_64.c +++ b/arch/x86/kernel/espfix_64.c @@ -129,6 +129,22 @@ void __init init_espfix_bsp(void) p4d = p4d_alloc(&init_mm, pgd, ESPFIX_BASE_ADDR); p4d_populate(&init_mm, p4d, espfix_pud_page); + /* + * Just copy the top-level PGD that is mapping the espfix area to + * ensure it is mapped into the user page tables. + * + * For 5-level paging, the espfix pgd was populated when + * kpti_init() pre-populated all the pgd entries. The above + * p4d_alloc() would never do anything and the p4d_populate() would + * be done to a p4d already mapped in the userspace pgd. + */ +#ifdef CONFIG_KERNEL_PAGE_TABLE_ISOLATION + if (CONFIG_PGTABLE_LEVELS <= 4) { + set_pgd(kernel_to_user_pgdp(pgd), + __pgd(_KERNPG_TABLE | (p4d_pfn(*p4d) << PAGE_SHIFT))); + } +#endif + /* Randomize the locations */ init_espfix_random();