From patchwork Wed Jul 18 09:40:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 10531857 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 601EF600F4 for ; Wed, 18 Jul 2018 09:42:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4ED5728FBC for ; Wed, 18 Jul 2018 09:42:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 420BE28FC6; Wed, 18 Jul 2018 09:42:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2DDF28FBC for ; Wed, 18 Jul 2018 09:42:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE5136B0280; Wed, 18 Jul 2018 05:41:34 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D6A8A6B0285; Wed, 18 Jul 2018 05:41:34 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E9876B0284; Wed, 18 Jul 2018 05:41:34 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id 37B606B0280 for ; Wed, 18 Jul 2018 05:41:34 -0400 (EDT) Received: by mail-ed1-f72.google.com with SMTP id w10-v6so1684968eds.7 for ; Wed, 18 Jul 2018 02:41:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=gP0q3U4ApL0dO5I/dNeSaMeVSE47kfimqJAT4KZqvmY=; b=CeIs53HK1t9SOqRBfNgZUG99WKqHBRIfrmkf3EQrKlVyRb+klLbb0e0WDa7fNgOynq JlS8sL4/GMEPdniTtS6ybES9JIjeVbi5EZLYdqlws1GmTt337dwJdDkSTDmkwTBCRhb1 4h3aaAIYWd+tFZWv0jNptOfTM6jJCToyYr63A5ml9tUVqvt0MIlMfcQQFESMt0RlmUwQ olBKHMH0BmDKcKlV7WtMBj+ar6P8BCA8GE6pI+NF335UzKcKy6rxmDqeTfmPBWkBpJ3L Sg03DrrqmZEhGbhYfT/vWllTu6XyW7UXoVgN2t1LaK66/O2V94aGfx7Lgn0CiB2y2sN8 MRLw== X-Gm-Message-State: AOUpUlEhdTX/Qqb/i+CLgLvRahsGIEOs9Nx3UfX28UWm+m2fj87AgULh VDTE6A9T8NHDZPTJ+EuZ7++EBh1y03QO2Hp2zy12NLRfQcFqPyxmtQUd2d0A0i3DeXXDdk0El+l BvGUBS+Ir7yKRptbkrKYERs6d+lSh4aaIK2QNEwgCHKzcAeXLQyNvsRbSjdPivj5ZOg== X-Received: by 2002:a50:b003:: with SMTP id i3-v6mr6135774edd.120.1531906893781; Wed, 18 Jul 2018 02:41:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc6OQHu+k0C92D/mLQiha7PXMhTa/FakL2V3EyJoVRrWj3DakCgU0J/UfH/m9KSIbiH47nj X-Received: by 2002:a50:b003:: with SMTP id i3-v6mr6135727edd.120.1531906892929; Wed, 18 Jul 2018 02:41:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531906892; cv=none; d=google.com; s=arc-20160816; b=A8iOP7mFiOTEUf75Jygpp0fl5OYC9ZHFKm+snMCKcopQqRS2T2r9/npR0POkHf4zAV rTDSujQJCpICL4y2GDKkFZJbBkc6f99aLGKozuKdC9ZkCwCncKGM1wYvfZ+vI58zjdee HDmaErgbYT11zTm/HyOZmkYFhl5w2ibfsKEiJYpZXMBW6msEmTSMyfiE1dr7EO1zGZUH ZcRBefuRIm93DrrKgjyy3tAjp4Z6eK+R/AHprFWFMM/hRlNjxpva2h+8UP0ZS3ZCv0pW gpSKCuOoWazdIyl8147PCOR54UIlYh6HrF0By+89NfXEEZQFtDfCoHu4dk0tphBKf3sj ujvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=gP0q3U4ApL0dO5I/dNeSaMeVSE47kfimqJAT4KZqvmY=; b=CdW+jttDpO71nBFmFdpYDlvlg5IXhkOnRNBcYtSSPlNSj2d47LlYIMdBwRjZWMBeKG lQdYMsAPsQREFPNJ23zkCaFNUVQocT26f0Yp09sQWyIUFoUWbsS6mTVCVjbl5asQGRJ5 6zVnYw+fLTVMjMpfziFD9tx8esSxFwIoqFgbAe4Kw60WyR9FNYtvyvxKet6EFGCAvoX+ R0pbkcx/4MmW/Vo8/RyRGNaZNCsb0k3ST68LORcHggBpALut5ebc3hicR2LghuuPQL5c uH0AMhDcxj+vdSz/e6fYxfRESxOQgZMDWqkMQS/A8ayzhW1A+orRy0TYjcgmkzVmv/3R D35Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@8bytes.org header.s=mail-1 header.b=FoL2Vsns; spf=pass (google.com: domain of joro@8bytes.org designates 81.169.241.247 as permitted sender) smtp.mailfrom=joro@8bytes.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: from theia.8bytes.org (8bytes.org. [81.169.241.247]) by mx.google.com with ESMTPS id i34-v6si88158edc.289.2018.07.18.02.41.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 02:41:32 -0700 (PDT) Received-SPF: pass (google.com: domain of joro@8bytes.org designates 81.169.241.247 as permitted sender) client-ip=81.169.241.247; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@8bytes.org header.s=mail-1 header.b=FoL2Vsns; spf=pass (google.com: domain of joro@8bytes.org designates 81.169.241.247 as permitted sender) smtp.mailfrom=joro@8bytes.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: by theia.8bytes.org (Postfix, from userid 1000) id 70B4260C; Wed, 18 Jul 2018 11:41:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1531906882; bh=qgF5TKSPeKfV3RwP/ojIqp2J5p8p9GJpm4hHUAmlDu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FoL2Vsns0udndUH2iZNZ0o8pBYrmtAMZ4dqd1oNtexUV5UhAWLgoX8tETN9Wl2crV gmLL2OOPQ2mFVO+/1VKM2UdxhvDh/kAl6atrbm18OElQWsOPw0V0pE9yA9Y8ucJ/35 ETTJJwReXPq5B5sqYz582HYIB//p7F6pOAGU4StcZBCpNOxo8SLRlCcvG8FDOEsJ6f CjuYvgdsNKHMeOGah5tMx6fRz6ujtMJrQZYqC5CAqQdjv6+pTNYE3kmJFJ5C6cPV+k GAu2m/7svNaVchjfnXavBGdy7BL5DvFminUvHWoTcshyYzucx6+AYfW2kae4YwjJc2 dTKsTD1vnP4jw== 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/39] x86/pgtable: Move two more functions from pgtable_64.h to pgtable.h Date: Wed, 18 Jul 2018 11:40:57 +0200 Message-Id: <1531906876-13451-21-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531906876-13451-1-git-send-email-joro@8bytes.org> References: <1531906876-13451-1-git-send-email-joro@8bytes.org> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 | 36 ----------------------------- arch/x86/include/asm/pgtable_64_types.h | 2 ++ 6 files changed, 21 insertions(+), 38 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 cc117161..e39088cb 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1177,6 +1177,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 4adba19..acb6970 100644 --- a/arch/x86/include/asm/pgtable_64.h +++ b/arch/x86/include/asm/pgtable_64.h @@ -132,41 +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); -} - -#ifdef CONFIG_PAGE_TABLE_ISOLATION -pgd_t __pti_set_user_pgtbl(pgd_t *pgdp, pgd_t pgd); - -/* - * Take a PGD location (pgdp) and a pgd value that needs to be set there. - * Populates the user and returns the resulting PGD that must be set in - * the kernel copy of the page tables. - */ -static inline pgd_t pti_set_user_pgtbl(pgd_t *pgdp, pgd_t pgd) -{ - if (!static_cpu_has(X86_FEATURE_PTI)) - return pgd; - return __pti_set_user_pgtbl(pgdp, pgd); -} -#else -static inline pgd_t pti_set_user_pgtbl(pgd_t *pgdp, pgd_t pgd) -{ - return pgd; -} -#endif - static inline void native_set_p4d(p4d_t *p4dp, p4d_t p4d) { pgd_t pgd; @@ -206,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 054765a..066e0ab 100644 --- a/arch/x86/include/asm/pgtable_64_types.h +++ b/arch/x86/include/asm/pgtable_64_types.h @@ -153,4 +153,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 */