Received: by 10.192.165.156 with SMTP id m28csp779514imm; Mon, 16 Apr 2018 08:35:36 -0700 (PDT) X-Google-Smtp-Source: AIpwx49ympUASoImuc1f5LjApewygz5p+rb45Ai6UwW7wQM6jTkio8aBHCF9bvKIxxnQDwTVUjHZ X-Received: by 10.98.194.133 with SMTP id w5mr22116277pfk.6.1523892936724; Mon, 16 Apr 2018 08:35:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523892936; cv=none; d=google.com; s=arc-20160816; b=YLaKl42C8Nsde9s/EFLvrcVoyvxqbs2TkJzx4vX9kuRWSGbi2Fes//H9ZLPAS/Dtmu SAaAUDlQ3hKNvD3x6NSTzthL/5WBgE1syenFYsDWvQo1P5oXybD04SBPADmFLp/ccr81 UT7GbEGkLrY3F1eMiEjVmjUbCRP3+Ww1FB7pgofNBXREdIJxEUsNrpcwX0pbzOm+kDhG GGgTIpvzQGYGBuDeKxXxumBgkYboVqEXKU4/ygdFzXiadqt0glnssjr5eibmY/Uu7wdh 4Bpg/+V1owbyn5iVfTWq4P3Je4oog0rNjusiBuAKf2ijWt2au2YHVdGKTLGVE6fkikXT XVUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=4KgEFRMmnQgOss+VhYorEuHDL2PukOhjh4h6mIuZ5hw=; b=ElpDLl7V/xfDqWjJjEqIJ4V+qvYK98+UCGCsFWLkByhicptHVCn54AZqYD51umdqcM DgMZU1ktMfxBeuZwViedKe/3PTa9zs5PtEkExc7d25fTcpbswy9YNkdsHgtDan0Ozt1m xNRqK/k4Qq4MvsOcR57qwLGMrNrVZQ6/4MBvA6CF18UZM/WQC/SW8xeDt7XCV1Di0TkW DSkF669wW6xV5sNpGD71yc7c7SOi7XKYAOoNu8QoiE7WoP54opJCbGMgufB/3GZs+g0R gIFeEiDqDKw/BIM+aX+YXCFN77mYWBPmylAJr3qhNflRDx4F/1MYkkYLWXsxdl7AFx/w rf5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=lv5VU8cp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u131si623874pgc.11.2018.04.16.08.35.22; Mon, 16 Apr 2018 08:35:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=lv5VU8cp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753164AbeDPPbn (ORCPT + 99 others); Mon, 16 Apr 2018 11:31:43 -0400 Received: from 8bytes.org ([81.169.241.247]:35888 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752902AbeDPPZs (ORCPT ); Mon, 16 Apr 2018 11:25:48 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id 3B076974; Mon, 16 Apr 2018 17:25:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1523892340; bh=im0KRcs3zd5Q37fvUrcnnlbIrbdYj7E0+eb9TbpXSt4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lv5VU8cpbzkwafhWXDfdvu7YVjA2Eaz96tIPvoAFNBrFNLgoWWp4xAooijjqbkfRo Brfb7R+vpwhbxC8+JznUA0nlvtT3HlOunaH9X+qDiUoY3IV1C8hS0s64kDA4U4HxE2 dvPUn2GH6VfmRrMyJPEJV1+F2/FAJkyqRthZqy8d7pqyOF54M3XEUE0kOhEiD6UO/i TCl3kk4z/4X3lToh92AyyB0QVSa9tqHh8gS6CxO1+1oOZcc4QZzUj4jOR5ZKagk4z4 bJfyTC173sdCtiW7JadsqAkpZOa7e71nBw9f1cuStXcLaHLyTp4n+7iMHndR7YnqU1 jxTY/BJ6tfVsQ== 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 , Pavel Machek , "David H . Gutteridge" , jroedel@suse.de, joro@8bytes.org Subject: [PATCH 20/35] x86/pgtable: Move two more functions from pgtable_64.h to pgtable.h Date: Mon, 16 Apr 2018 17:25:08 +0200 Message-Id: <1523892323-14741-21-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523892323-14741-1-git-send-email-joro@8bytes.org> References: <1523892323-14741-1-git-send-email-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel These two functions are required for PTI on 32 bit: * pgdp_maps_userspace() * pgd_large() Also re-implement pgdp_maps_userspace() so that it will work on 64 and 32 bit kernels. Signed-off-by: Joerg Roedel --- arch/x86/include/asm/pgtable-2level_types.h | 3 +++ arch/x86/include/asm/pgtable-3level_types.h | 1 + arch/x86/include/asm/pgtable.h | 15 +++++++++++++++ arch/x86/include/asm/pgtable_32.h | 2 -- arch/x86/include/asm/pgtable_64.h | 15 --------------- arch/x86/include/asm/pgtable_64_types.h | 2 ++ 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/arch/x86/include/asm/pgtable-2level_types.h b/arch/x86/include/asm/pgtable-2level_types.h index f982ef8..6deb6cd 100644 --- a/arch/x86/include/asm/pgtable-2level_types.h +++ b/arch/x86/include/asm/pgtable-2level_types.h @@ -35,4 +35,7 @@ typedef union { #define PTRS_PER_PTE 1024 +/* This covers all VMSPLIT_* and VMSPLIT_*_OPT variants */ +#define PGD_KERNEL_START (CONFIG_PAGE_OFFSET >> PGDIR_SHIFT) + #endif /* _ASM_X86_PGTABLE_2LEVEL_DEFS_H */ diff --git a/arch/x86/include/asm/pgtable-3level_types.h b/arch/x86/include/asm/pgtable-3level_types.h index 78038e0..858358a 100644 --- a/arch/x86/include/asm/pgtable-3level_types.h +++ b/arch/x86/include/asm/pgtable-3level_types.h @@ -46,5 +46,6 @@ typedef union { #define PTRS_PER_PTE 512 #define MAX_POSSIBLE_PHYSMEM_BITS 36 +#define PGD_KERNEL_START (CONFIG_PAGE_OFFSET >> PGDIR_SHIFT) #endif /* _ASM_X86_PGTABLE_3LEVEL_DEFS_H */ diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 557ddf8..55c236e 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1172,6 +1172,21 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma, } } #endif +/* + * Page table pages are page-aligned. The lower half of the top + * level is used for userspace and the top half for the kernel. + * + * Returns true for parts of the PGD that map userspace and + * false for the parts that map the kernel. + */ +static inline bool pgdp_maps_userspace(void *__ptr) +{ + unsigned long ptr = (unsigned long)__ptr; + + return (((ptr & ~PAGE_MASK) / sizeof(pgd_t)) < PGD_KERNEL_START); +} + +static inline int pgd_large(pgd_t pgd) { return 0; } #ifdef CONFIG_PAGE_TABLE_ISOLATION /* diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h index 88a056b..b3ec519 100644 --- a/arch/x86/include/asm/pgtable_32.h +++ b/arch/x86/include/asm/pgtable_32.h @@ -34,8 +34,6 @@ static inline void check_pgt_cache(void) { } void paging_init(void); void sync_initial_page_table(void); -static inline int pgd_large(pgd_t pgd) { return 0; } - /* * Define this if things work differently on an i386 and an i486: * it will (on an i486) warn about kernel memory accesses that are diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h index 6dd2eb6..84a5eb0 100644 --- a/arch/x86/include/asm/pgtable_64.h +++ b/arch/x86/include/asm/pgtable_64.h @@ -132,20 +132,6 @@ static inline pud_t native_pudp_get_and_clear(pud_t *xp) #endif } -/* - * Page table pages are page-aligned. The lower half of the top - * level is used for userspace and the top half for the kernel. - * - * Returns true for parts of the PGD that map userspace and - * false for the parts that map the kernel. - */ -static inline bool pgdp_maps_userspace(void *__ptr) -{ - unsigned long ptr = (unsigned long)__ptr; - - return (ptr & ~PAGE_MASK) < (PAGE_SIZE / 2); -} - static inline void native_set_p4d(p4d_t *p4dp, p4d_t p4d) { pgd_t pgd; @@ -185,7 +171,6 @@ extern void sync_global_pgds(unsigned long start, unsigned long end); /* * Level 4 access. */ -static inline int pgd_large(pgd_t pgd) { return 0; } #define mk_kernel_pgd(address) __pgd((address) | _KERNPG_TABLE) /* PUD - Level3 access */ diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h index d5c21a3..355b488 100644 --- a/arch/x86/include/asm/pgtable_64_types.h +++ b/arch/x86/include/asm/pgtable_64_types.h @@ -142,4 +142,6 @@ extern unsigned int ptrs_per_p4d; #define EARLY_DYNAMIC_PAGE_TABLES 64 +#define PGD_KERNEL_START ((PAGE_SIZE / 2) / sizeof(pgd_t)) + #endif /* _ASM_X86_PGTABLE_64_DEFS_H */ -- 2.7.4