Received: by 10.223.185.116 with SMTP id b49csp2458718wrg; Mon, 5 Mar 2018 03:19:55 -0800 (PST) X-Google-Smtp-Source: AG47ELtI3qCjaSn8p7qvcckb9oLwCZ8+8EaWEACcLmipjibjxuxDsTwJaSDJ3QX25ifmrL41RbBx X-Received: by 10.99.109.70 with SMTP id i67mr12022307pgc.190.1520248795393; Mon, 05 Mar 2018 03:19:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520248795; cv=none; d=google.com; s=arc-20160816; b=nvwmhRH80Fa0rFBH21B1U6YppkYEfWDtGBTYNzeMAS2D/FXm0GuqJfbYs9lcN0PVXe 100jCW8agbZGlxvX2QRFvURHydrDQARiD46VAI5676tIsNEy88ppkspmU+z7VllhYYRm L7uRvang9eEdmk8LXQZqNq3RLDc2e9Yldia/RPqD9eTmmEb8/v/h/2W+hScPULAwX2am t4gtyvlD9f90y2z5/EVDXw5YL6vlAgzfGT3VTxotw8KVxiTsUnIADVGlRdr0fW1Qg0UH hvmYdCHpD7ElCjzsfCwUG9jevDY66ON9oeMeOqYcWjdJn/5ljBRGOG8N4y6H0GTsq30q WrJg== 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=lpPQrt5+tZXz1YmvWa9Hmx/PyB1QmLr8DFZyTmukmAg=; b=Z5hIP/cL1/KtFAT7Sm/ApAXI50i60NPVanr3fe92mu08rtUvjxcDrOru5gsjLEDW6N 5O7a2XncZq3JfQo59j7nXajgHiMN6+WBgSEJoMtBh7C8+tSaAo2ENR4VMPuYZi7Xt5bR Pmgv5+TpXeC6/Z7U2c7YZ8h77vgkzxLLM1Bu/fm4mlCKYAOE0w6aNLWWQfCYNMWKMAPw twhrevsEi9GvFLIw09WThCCnqH4xryI4di9BZg3pDD7Iq0mPvlNxzKyJxCQVnIw48qa1 7tC7h1FSh3huHElIJr5wxwtzP3zRegE1lwdEDgyJGFgv0gUR//QAHCBpAR6RkgQXelgk cDpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=nkWnUxCm; 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 f64si8241798pgc.490.2018.03.05.03.19.40; Mon, 05 Mar 2018 03:19:55 -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=nkWnUxCm; 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 S934127AbeCEK3s (ORCPT + 99 others); Mon, 5 Mar 2018 05:29:48 -0500 Received: from 8bytes.org ([81.169.241.247]:54502 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933782AbeCEK0S (ORCPT ); Mon, 5 Mar 2018 05:26:18 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id 1236F1BD9; Mon, 5 Mar 2018 11:26:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1520245569; bh=/SasBxav3RxB8Kr5BmUpbdW4vrE+vMToZ3TL7mreq8k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nkWnUxCmYJmX6ju3Cos1VwjuVCQ4qSZ2IN8ZDM7PYlajTnEbEDsvRHXvgZ641VE8W HUnvu6XYT9GciL15zeQp867g3MErtg0Vpk7D8eWF0RK417Ul1T1L9oZqdobdijTYUk EHt4EC09vBALz5nHHfWvIxwwKKY0gZufHSeVuuaVT3EbOe0xovn7OxlLZTV8dsbWRc 4Shvt0ozBIycZTafzMJVosYDVwL1ZuAIN/Ve18CkuY7WbCd0++xy6HMnhx4fKgo7M8 BPz+LcnFsZApqRQWqHnT1VWGa0oD11GxCqzq+W+hlpbwsFcJhrd1WT4+MDQmdQs5Ic P5QHheEcGJmMQ== 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 18/34] x86/pgtable: Move pgdp kernel/user conversion functions to pgtable.h Date: Mon, 5 Mar 2018 11:25:47 +0100 Message-Id: <1520245563-8444-19-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 Make them available on 32 bit and clone_pgd_range() happy. Signed-off-by: Joerg Roedel --- arch/x86/include/asm/pgtable.h | 49 +++++++++++++++++++++++++++++++++++++++ arch/x86/include/asm/pgtable_64.h | 49 --------------------------------------- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index e42b894..0a9f746 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1109,6 +1109,55 @@ static inline int pud_write(pud_t pud) return pud_flags(pud) & _PAGE_RW; } +#ifdef CONFIG_PAGE_TABLE_ISOLATION +/* + * All top-level PAGE_TABLE_ISOLATION page tables are order-1 pages + * (8k-aligned and 8k in size). The kernel one is at the beginning 4k and + * the user one is in the last 4k. To switch between them, you + * just need to flip the 12th bit in their addresses. + */ +#define PTI_PGTABLE_SWITCH_BIT PAGE_SHIFT + +/* + * This generates better code than the inline assembly in + * __set_bit(). + */ +static inline void *ptr_set_bit(void *ptr, int bit) +{ + unsigned long __ptr = (unsigned long)ptr; + + __ptr |= BIT(bit); + return (void *)__ptr; +} +static inline void *ptr_clear_bit(void *ptr, int bit) +{ + unsigned long __ptr = (unsigned long)ptr; + + __ptr &= ~BIT(bit); + return (void *)__ptr; +} + +static inline pgd_t *kernel_to_user_pgdp(pgd_t *pgdp) +{ + return ptr_set_bit(pgdp, PTI_PGTABLE_SWITCH_BIT); +} + +static inline pgd_t *user_to_kernel_pgdp(pgd_t *pgdp) +{ + return ptr_clear_bit(pgdp, PTI_PGTABLE_SWITCH_BIT); +} + +static inline p4d_t *kernel_to_user_p4dp(p4d_t *p4dp) +{ + return ptr_set_bit(p4dp, PTI_PGTABLE_SWITCH_BIT); +} + +static inline p4d_t *user_to_kernel_p4dp(p4d_t *p4dp) +{ + return ptr_clear_bit(p4dp, PTI_PGTABLE_SWITCH_BIT); +} +#endif /* CONFIG_PAGE_TABLE_ISOLATION */ + /* * clone_pgd_range(pgd_t *dst, pgd_t *src, int count); * diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h index b68bda5..5e68083 100644 --- a/arch/x86/include/asm/pgtable_64.h +++ b/arch/x86/include/asm/pgtable_64.h @@ -131,55 +131,6 @@ static inline pud_t native_pudp_get_and_clear(pud_t *xp) #endif } -#ifdef CONFIG_PAGE_TABLE_ISOLATION -/* - * All top-level PAGE_TABLE_ISOLATION page tables are order-1 pages - * (8k-aligned and 8k in size). The kernel one is at the beginning 4k and - * the user one is in the last 4k. To switch between them, you - * just need to flip the 12th bit in their addresses. - */ -#define PTI_PGTABLE_SWITCH_BIT PAGE_SHIFT - -/* - * This generates better code than the inline assembly in - * __set_bit(). - */ -static inline void *ptr_set_bit(void *ptr, int bit) -{ - unsigned long __ptr = (unsigned long)ptr; - - __ptr |= BIT(bit); - return (void *)__ptr; -} -static inline void *ptr_clear_bit(void *ptr, int bit) -{ - unsigned long __ptr = (unsigned long)ptr; - - __ptr &= ~BIT(bit); - return (void *)__ptr; -} - -static inline pgd_t *kernel_to_user_pgdp(pgd_t *pgdp) -{ - return ptr_set_bit(pgdp, PTI_PGTABLE_SWITCH_BIT); -} - -static inline pgd_t *user_to_kernel_pgdp(pgd_t *pgdp) -{ - return ptr_clear_bit(pgdp, PTI_PGTABLE_SWITCH_BIT); -} - -static inline p4d_t *kernel_to_user_p4dp(p4d_t *p4dp) -{ - return ptr_set_bit(p4dp, PTI_PGTABLE_SWITCH_BIT); -} - -static inline p4d_t *user_to_kernel_p4dp(p4d_t *p4dp) -{ - return ptr_clear_bit(p4dp, PTI_PGTABLE_SWITCH_BIT); -} -#endif /* CONFIG_PAGE_TABLE_ISOLATION */ - /* * Page table pages are page-aligned. The lower half of the top * level is used for userspace and the top half for the kernel. -- 2.7.4