Received: by 10.223.185.116 with SMTP id b49csp2474690wrg; Mon, 5 Mar 2018 03:37:32 -0800 (PST) X-Google-Smtp-Source: AG47ELuptYB+Sr/0OTjSaMNllr8fygSzoJi3IbUjpWHaMHl28CdAesOeAWHSeGQ3zG1o34cyQarr X-Received: by 10.99.123.74 with SMTP id k10mr12057872pgn.217.1520249851913; Mon, 05 Mar 2018 03:37:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520249851; cv=none; d=google.com; s=arc-20160816; b=uoGxPAu1cdlWp/r0QCSfMPVfUCF+jDCJvzH1NaJg00nBP5UQq/Gne4Uvqh4pP/uxGD ixkjeO2n/AcAA8wani9fGEFNgPLZrtvxCDn3UUP3+dDrE68WCcevf2LqcJsP4xaN6/cV 8c2xTmpRpv8cIAdAKLjRNmtiTn2PRYFib/kIjOTF6L+WRaMeyxLEM5GPMucQaUNR31wQ 2GaikZ2fXA8NTtZbNWulb71hbp4tOrKZEflNs+Jj+cQmXya9CBcXWca3jo60YA5vDOmI +YBL+vyvkaZ4LLvA6FPJ9l4fWSIHXjRqSxUDhVL8XMAm2xAqMZ/4EEZjMIIVYhmSsm3z 8qfA== 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=vGtwEtmHlJEHWHJ5MOcJ6tilXxZjkLHR0q81fXNzmc4=; b=GL8rqenuN4xEmm7SA8/7CUr2TVaPsKoHZoyE8YhpNZHHG3i6v5St58ou2mdGQsEBT8 jXWj8HwZ/ZOjn8/LGdWZvXbL6LtaXTMzI2bnwDQbMwFCt+3FTG4k5dtBGZTe0yPv5LQe W85QXwFjuMkolndh+ROiAvw++I/IOr1ScjYL5UOmk8CwqVQfZz0DDHpYgdJLuvSIqFOC V5X427dOfjBXprb4t4PV6Y+ctGFocJkSpUYDQ1jqmrgAucauXLFq/G0BP7olO+Wd4R5a zwvjFxpw2tj0rhGzlST/4v4qR+5zXWXrEc8Fy0lpFRMNdPhHQ9m1L3xGyRRb2w8J3h+v 0vlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=OdPuL4oG; 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 q188si8269587pga.547.2018.03.05.03.37.17; Mon, 05 Mar 2018 03:37:31 -0800 (PST) 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=OdPuL4oG; 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 S934148AbeCEK3v (ORCPT + 99 others); Mon, 5 Mar 2018 05:29:51 -0500 Received: from 8bytes.org ([81.169.241.247]:54954 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933779AbeCEK0S (ORCPT ); Mon, 5 Mar 2018 05:26:18 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id D32291B0E; Mon, 5 Mar 2018 11:26:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1520245568; bh=Yx5z1dLBSWMvK7xDQld0/5zRdLMYCfoBLvm8Mr2L4KA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OdPuL4oGrztNLSVukPGug1Ijop7IETFvHrYZ3tsobFbg4/HzknfreHE3OVvyZbF8W BBEKvd5INJrYEvyB24QJfIbpqLj3s7gZiHQ67k5YW6qzixq8bdIXdhwBJ4ngndq4oT Yo5skzyRjq9VVH3vcVPO5OWclCUQ+gtKvXdmUN4BRn5YOSoDNULBsLijcQMEDKCC+E UmwnclW+ibzpB/vvp9cw7iVGh4R+miIpl4Qd3eDf5WCPttqMmHBdrPbQjhhULb0NOe zJphLwzqulREwreeE2SZk52UwS6+oUiGMIACa7U+SoMh421G3/o285YMkGf/vSLku4 Kd36N2pvp9enw== 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 , jroedel@suse.de, joro@8bytes.org Subject: [PATCH 20/34] x86/pgtable: Move two more functions from pgtable_64.h to pgtable.h Date: Mon, 5 Mar 2018 11:25:49 +0100 Message-Id: <1520245563-8444-21-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520245563-8444-1-git-send-email-joro@8bytes.org> References: <1520245563-8444-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 | 16 ++++++++++++++++ arch/x86/include/asm/pgtable_64.h | 15 --------------- arch/x86/include/asm/pgtable_64_types.h | 2 ++ 5 files changed, 22 insertions(+), 15 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 ed8a200..925ac1b 100644 --- a/arch/x86/include/asm/pgtable-3level_types.h +++ b/arch/x86/include/asm/pgtable-3level_types.h @@ -45,5 +45,6 @@ typedef union { */ #define PTRS_PER_PTE 512 +#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 1e900c1..981e49a 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1132,6 +1132,22 @@ static inline int pud_write(pud_t pud) return pud_flags(pud) & _PAGE_RW; } +/* + * 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 /* * All top-level PAGE_TABLE_ISOLATION page tables are order-1 pages diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h index 4cbf517..e11b925 100644 --- a/arch/x86/include/asm/pgtable_64.h +++ b/arch/x86/include/asm/pgtable_64.h @@ -131,20 +131,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) { #if defined(CONFIG_PAGE_TABLE_ISOLATION) && !defined(CONFIG_X86_5LEVEL) @@ -187,7 +173,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 6b8f73d..e57003a 100644 --- a/arch/x86/include/asm/pgtable_64_types.h +++ b/arch/x86/include/asm/pgtable_64_types.h @@ -124,4 +124,6 @@ typedef struct { pteval_t pte; } pte_t; #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