From patchwork Wed Jul 18 09:40:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 10531847 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 E355B602CA for ; Wed, 18 Jul 2018 09:42:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1B6A1FF0B for ; Wed, 18 Jul 2018 09:42:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3BE120856; Wed, 18 Jul 2018 09:42:16 +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=ham 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 3B7661FF0B for ; Wed, 18 Jul 2018 09:42:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B65A6B027E; Wed, 18 Jul 2018 05:41:33 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 642EC6B027D; Wed, 18 Jul 2018 05:41:33 -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 496026B0281; Wed, 18 Jul 2018 05:41:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id D74696B027E for ; Wed, 18 Jul 2018 05:41:32 -0400 (EDT) Received: by mail-ed1-f70.google.com with SMTP id b12-v6so1626530edi.12 for ; Wed, 18 Jul 2018 02:41:32 -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=OrnmTOXfzkEJCgjbaAcFYEuMOEXQw/hGjcfDkWOHbmA=; b=Aptkz8hvQPWIwgbJ8yMo3cIp6FMCrzssHAcFjXD4jb9bMhaXTpG9FiGcI8e6V1JVbN iszvFVkzyUAphjBpZl36eQ1e7tJPrtkjpGu+TgkkkpGfw1+3RMROXRpos3wETEt+senY mYL5X94aJ/bAFwBwSdKCw6aWEUNeMHa9cJQLRfPuj0pqYq/2LQxj3YANZxkXj0gsyCP3 v/7N3iUGpbVWAk9mB0z+G0GA3lFWBMmRlfAD4aQ+zjNXQOEAepg9p8cGWS4eKMVJGwGD 23aZCl66yYV4j2zjhx/7QEkXFqF8LfIsDKcVnVfefINa9VSswfS5WOi3yznuZor5YwYn 8PMA== X-Gm-Message-State: AOUpUlHN2cFgBKqAA9We5x2NhACxgbr0X7CDwTtcVjzyd5b4apJhxVRD 1pJAeTOwb5PrDif/8H6Aj98C3a5FWLCDG9pYg6t69jxFGVN/mWuJjkHw+NnFa6JSs/XUINOdcjp HyqDBlLr7S+9Cp/MFDBizsVv3fDL/LvjwFqM9TGo8GC+aKjrVilAbseTZ6Kg+0phq9Q== X-Received: by 2002:a50:dacf:: with SMTP id s15-v6mr6050573edj.241.1531906892436; Wed, 18 Jul 2018 02:41:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf8ZHNqqyB9rWlqTGpfmNUImaHmmVxOLgsek7JcHdmBFV+yFuFvfGbw2yiPM2QfU7VBglPj X-Received: by 2002:a50:dacf:: with SMTP id s15-v6mr6050532edj.241.1531906891695; Wed, 18 Jul 2018 02:41:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531906891; cv=none; d=google.com; s=arc-20160816; b=qqAlIntXkCuN+KB7bBob2q4ec8q5BWmisIEV3hGaicsBaEg1Hryged6XGrQ08zzmjv k2IMWdk45mGswmDFvSQQSe4ttRws2BaeoVeIeaAbGVYuwprYO13J4jd7ndyKUsiGLoRM 0bUnbPd0Zr3+cSi3astOMKlle/YlgcBP5juffOQytIivZiU26mHHU+w5YOtbcKWEj+Sf V1oqvpwdMwqsEG/uKtDGd6oy4m/fv0NBBR4p8OoG1WJSSm+IYRAKtTvy0XB0kd2GloXF 2JWO02plBMPaXfmssFo1Ug57uN3QTWoEc/687g1WIx2C29cYlEWistiwujIT1W/tbz2u fYuw== 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=OrnmTOXfzkEJCgjbaAcFYEuMOEXQw/hGjcfDkWOHbmA=; b=rxfIJiWgz8VacghCS1vHOcpNYJfE5GPs2RjaQ7nkkUT/31VdZitQ0clvfaO00yNi0J KnH0mlk54ttzxtX7ft2Tyb2QnOyCWJLmGrarRNrvRoYtXF33CxLdOnwU5jKTcPsfAjRF LnKXRYQLqB6Q4AiXlivPgu4xw6p997KZdFq6sbbvazDgBvZbX3d42b0sKT/S/RVoeZrL hmewHt9QviQIxXQCY2BbVwnM6pryFZ7q8yZJ5ONcUlXPMcceN2nSKORXoz/W0wJDmDfh 7wziaO1mxm5wY9ly69yG5tu0pLPoNBeGGfIenT1S+A/5YUUk2jBuJf4BUv57xLXYaJJs 1BtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@8bytes.org header.s=mail-1 header.b=l0VXA5zc; 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 u21-v6si215646edo.113.2018.07.18.02.41.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 02:41:31 -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=l0VXA5zc; 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 BF03B32E; 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=1531906881; bh=iEPn9yhr8K3WkTxVGik81NaWC4cuH7/tnosk3392xlQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=l0VXA5zczlqz0kuUJ2v+cNLP4RGH65IzpXn0rDLEwwJv549Z9TSKbfEP3dN1qINbR 8xZ/uoGUG6pvi5aDwyqe3gmxzvrYrhOXTYXxMx0QXXLLfb+0jkeAr4jEvXa6Ag9V37 frLIm9mEKa0vI47YXQGz/IhpZgMCSLyQOIR8Uts8D80YLZAyRaozzjqPPoYAg+TXNy sIpVQkB7dYByLs3hu072jgAW/cdx+dFBLHG+gwv05l329M7kzoNNyymZykY/7HGNGW 3FMWeSAGu7IKy79CCH93KrL+VsYGNOZC51jlP4Prm7csZQM6o/yokh5XTVznn4WbKt 7T9J1hR1qV1MA== 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 18/39] x86/pgtable: Move pgdp kernel/user conversion functions to pgtable.h Date: Wed, 18 Jul 2018 11:40:55 +0200 Message-Id: <1531906876-13451-19-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 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 5715647..eb47432 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1155,6 +1155,55 @@ static inline pmd_t pmdp_establish(struct vm_area_struct *vma, } #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 */ + /* * 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 9406c4f..4adba19 100644 --- a/arch/x86/include/asm/pgtable_64.h +++ b/arch/x86/include/asm/pgtable_64.h @@ -132,55 +132,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.