From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751545AbeAPQsx (ORCPT + 1 other); Tue, 16 Jan 2018 11:48:53 -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 S1751436AbeAPQsg (ORCPT ); Tue, 16 Jan 2018 11:48:36 -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 09/16] x86/mm/pti: Clone CPU_ENTRY_AREA on PMD level on x86_32 Date: Tue, 16 Jan 2018 17:36:52 +0100 Message-Id: <1516120619-1159-10-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 Cloning on the P4D level would clone the complete kernel address space into the user-space page-tables for PAE kernels. Cloning on PMD level is fine for PAE and legacy paging. Signed-off-by: Joerg Roedel --- arch/x86/mm/pti.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c index ce38f165489b..20be21301a59 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -308,6 +308,7 @@ pti_clone_pmds(unsigned long start, unsigned long end, pmdval_t clear) } } +#ifdef CONFIG_X86_64 /* * Clone a single p4d (i.e. a top-level entry on 4-level systems and a * next-level entry on 5-level systems. @@ -322,13 +323,29 @@ static void __init pti_clone_p4d(unsigned long addr) kernel_p4d = p4d_offset(kernel_pgd, addr); *user_p4d = *kernel_p4d; } +#endif /* * Clone the CPU_ENTRY_AREA into the user space visible page table. */ static void __init pti_clone_user_shared(void) { +#ifdef CONFIG_X86_32 + /* + * On 32 bit PAE systems with 1GB of Kernel address space there is only + * one pgd/p4d for the whole kernel. Cloning that would map the whole + * address space into the user page-tables, making PTI useless. So clone + * the page-table on the PMD level to prevent that. + */ + unsigned long start, end; + + start = CPU_ENTRY_AREA_BASE; + end = start + (PAGE_SIZE * CPU_ENTRY_AREA_PAGES); + + pti_clone_pmds(start, end, _PAGE_GLOBAL); +#else pti_clone_p4d(CPU_ENTRY_AREA_BASE); +#endif } /* -- 2.13.6 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f72.google.com (mail-wm0-f72.google.com [74.125.82.72]) by kanga.kvack.org (Postfix) with ESMTP id 64002280244 for ; Fri, 19 Jan 2018 10:28:48 -0500 (EST) Received: by mail-wm0-f72.google.com with SMTP id z83so1225076wmc.5 for ; Fri, 19 Jan 2018 07:28:48 -0800 (PST) Received: from theia.8bytes.org (8bytes.org. [2a01:238:4383:600:38bc:a715:4b6d:a889]) by mx.google.com with ESMTPS id p90si2509759edp.379.2018.01.16.08.39.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jan 2018 08:39:21 -0800 (PST) From: Joerg Roedel Subject: [PATCH 09/16] x86/mm/pti: Clone CPU_ENTRY_AREA on PMD level on x86_32 Date: Tue, 16 Jan 2018 17:36:52 +0100 Message-Id: <1516120619-1159-10-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 Cloning on the P4D level would clone the complete kernel address space into the user-space page-tables for PAE kernels. Cloning on PMD level is fine for PAE and legacy paging. Signed-off-by: Joerg Roedel --- arch/x86/mm/pti.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c index ce38f165489b..20be21301a59 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -308,6 +308,7 @@ pti_clone_pmds(unsigned long start, unsigned long end, pmdval_t clear) } } +#ifdef CONFIG_X86_64 /* * Clone a single p4d (i.e. a top-level entry on 4-level systems and a * next-level entry on 5-level systems. @@ -322,13 +323,29 @@ static void __init pti_clone_p4d(unsigned long addr) kernel_p4d = p4d_offset(kernel_pgd, addr); *user_p4d = *kernel_p4d; } +#endif /* * Clone the CPU_ENTRY_AREA into the user space visible page table. */ static void __init pti_clone_user_shared(void) { +#ifdef CONFIG_X86_32 + /* + * On 32 bit PAE systems with 1GB of Kernel address space there is only + * one pgd/p4d for the whole kernel. Cloning that would map the whole + * address space into the user page-tables, making PTI useless. So clone + * the page-table on the PMD level to prevent that. + */ + unsigned long start, end; + + start = CPU_ENTRY_AREA_BASE; + end = start + (PAGE_SIZE * CPU_ENTRY_AREA_PAGES); + + pti_clone_pmds(start, end, _PAGE_GLOBAL); +#else pti_clone_p4d(CPU_ENTRY_AREA_BASE); +#endif } /* -- 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