Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2253200imm; Thu, 19 Jul 2018 16:30:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfPr1xzNYHU/Byro0SCLesjHnqm2+UsTo5XVed7Gywgm1AgX24Uxpg5jIg9brHIKx+L9MXb X-Received: by 2002:a63:920c:: with SMTP id o12-v6mr7396875pgd.141.1532043023251; Thu, 19 Jul 2018 16:30:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532043023; cv=none; d=google.com; s=arc-20160816; b=BJqpfA7w8KuLyPPlCXX8DT1OI2n9ztvSBRKtKB4o02CVTfWZ855Liy+QUKEMDpsnig Q4Vh2crXcAjDC/ihZWlMt2l6O+MxmvwfF9JhfXjZN5Y9AwpvYNlheoiADMNlDOS69dGh H8bn3tAeTlWslixDaTtNZb3cuWdoXHTlMVx2y1i3jUS5y/3YCv+4vFIDyuGOnA5ZKi/T wTWjUQSXZwxsindTrNsxsLku5UVFT8YQq4cEb+VAi0Uxe200Was222U4PCmUNdHTTMyU 0lnAMpnIZ+my12RmV/Fws398pxKFHH0pwSVSjFSPoVXvRfgyOyyMAHsJvE1VdUjgjTIA IzfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=/SIBBP2jktsyFoZNEwEZedOIdGWemcSGZMkqq31Wdt4=; b=r3vMOn4pbUJsFSw5F7+s1JxWjAWXIgW9JvYXtxYsBBtVcLXKDki5+x8JdbnaE2gJYi HAP5HeB6Y3LDtQA/+TJhJFZhcCiAgE8OHzTVxgv9PMvRK1jLTtrhl4qZxgJalKzBvoQn 8ezbZ3XmEumwGO396NLm/7ArmD7eAmcvtvc2I6XC6mxn3wVynMGJPIA1kZ8JxwnyhjSJ KSSj/cvNYdGO03UQxQa6gmZzUZqKvWquWczksZQrFBydLVpIiygO2DytCHV+PrUqaFHM hnTsoQ+9j7OazU6yXYpdyMxtsvb//xCekshqWHcXtxkAashF+0FUvk93sukm4oR3BlEd KwbQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y63-v6si434487pgb.5.2018.07.19.16.30.08; Thu, 19 Jul 2018 16:30:23 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731019AbeGTAON (ORCPT + 99 others); Thu, 19 Jul 2018 20:14:13 -0400 Received: from terminus.zytor.com ([198.137.202.136]:55497 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727553AbeGTAON (ORCPT ); Thu, 19 Jul 2018 20:14:13 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6JNRoGK2453429 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 19 Jul 2018 16:27:50 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6JNRoov2453425; Thu, 19 Jul 2018 16:27:50 -0700 Date: Thu, 19 Jul 2018 16:27:50 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Joerg Roedel Message-ID: Cc: David.Laight@aculab.com, boris.ostrovsky@oracle.com, bp@alien8.de, peterz@infradead.org, dvlasenk@redhat.com, torvalds@linux-foundation.org, mingo@kernel.org, pavel@ucw.cz, hpa@zytor.com, jpoimboe@redhat.com, dave.hansen@intel.com, will.deacon@arm.com, jkosina@suse.cz, jroedel@suse.de, jgross@suse.com, eduval@amazon.com, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, luto@kernel.org, llong@redhat.com, aarcange@redhat.com, dhgutteridge@sympatico.ca, brgerst@gmail.com, tglx@linutronix.de Reply-To: dvlasenk@redhat.com, torvalds@linux-foundation.org, peterz@infradead.org, David.Laight@aculab.com, boris.ostrovsky@oracle.com, bp@alien8.de, jpoimboe@redhat.com, hpa@zytor.com, mingo@kernel.org, pavel@ucw.cz, jgross@suse.com, jroedel@suse.de, jkosina@suse.cz, gregkh@linuxfoundation.org, eduval@amazon.com, linux-kernel@vger.kernel.org, will.deacon@arm.com, dave.hansen@intel.com, tglx@linutronix.de, dhgutteridge@sympatico.ca, brgerst@gmail.com, llong@redhat.com, luto@kernel.org, aarcange@redhat.com In-Reply-To: <1531906876-13451-19-git-send-email-joro@8bytes.org> References: <1531906876-13451-19-git-send-email-joro@8bytes.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] x86/pgtable: Move pgdp kernel/user conversion functions to pgtable.h Git-Commit-ID: 8372d66865deb45ee3ec21401a9c80f231b728c8 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 8372d66865deb45ee3ec21401a9c80f231b728c8 Gitweb: https://git.kernel.org/tip/8372d66865deb45ee3ec21401a9c80f231b728c8 Author: Joerg Roedel AuthorDate: Wed, 18 Jul 2018 11:40:55 +0200 Committer: Thomas Gleixner CommitDate: Fri, 20 Jul 2018 01:11:41 +0200 x86/pgtable: Move pgdp kernel/user conversion functions to pgtable.h Make them available on 32 bit and clone_pgd_range() happy. Signed-off-by: Joerg Roedel Signed-off-by: Thomas Gleixner Tested-by: Pavel Machek Cc: "H . Peter Anvin" Cc: linux-mm@kvack.org Cc: Linus Torvalds Cc: Andy Lutomirski Cc: Dave Hansen Cc: Josh Poimboeuf Cc: Juergen Gross Cc: Peter Zijlstra Cc: Borislav Petkov Cc: Jiri Kosina Cc: Boris Ostrovsky Cc: Brian Gerst Cc: David Laight Cc: Denys Vlasenko Cc: Eduardo Valentin Cc: Greg KH Cc: Will Deacon Cc: aliguori@amazon.com Cc: daniel.gruss@iaik.tugraz.at Cc: hughd@google.com Cc: keescook@google.com Cc: Andrea Arcangeli Cc: Waiman Long Cc: "David H . Gutteridge" Cc: joro@8bytes.org Link: https://lkml.kernel.org/r/1531906876-13451-19-git-send-email-joro@8bytes.org --- 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 5715647fc4fe..eb474329d751 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 9406c4fe1d38..4adba19c7bf6 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.