Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2257091imm; Thu, 19 Jul 2018 16:35:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdjgen4+LgHtcp67hqhN9mZ1kFJrr7xj+knd5061pbJensz/zdX5SGPYQHtKWyPYV6HuDqp X-Received: by 2002:a63:5964:: with SMTP id j36-v6mr11979357pgm.222.1532043342017; Thu, 19 Jul 2018 16:35:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532043341; cv=none; d=google.com; s=arc-20160816; b=mEV0m+evp4dnBmSsvpjfQ5mYI7Srjz+yYPnfIzt3QMJB0Rid/TpfnrGwsfZp5NQPVq Hvb6AaS2Q+8KBi0WmWZfhrkQ58Cg3hjKzKF/1xf9heY7ppe+nWhNYro1XMnsGK2F9tNe E5Fh8yurOLcDlNe6gMjLWKuaFC+138taD60r/r7Lrz5yUi8QUYz0EyKoyDB3uLK52Ejr 1oAd292DsGvGQgE5pMCZpFu3VYx1EkKWGUSHy1rKQE+fdZ91uaBhiv8r2KxywKJm2thz Y7PQ4QpybpJuDAqcX5ERbY8RV92EK6iSK7n6Vb8C+RMeXgUphuJYNMfVMvxmLjxY/qxp rxxw== 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=hZhkxHtNqK4r2fahMrCKsH4Mhn3Kj+sBF79IMGTtoK0=; b=rD/Uz+lgp1UZ5e1/dSaQADV2943BaJ279NNhgRb/bMQfCP8lmtyGXy9+rNQMGgZqG3 W+945nsOnGZWR8z5fNH+sYVYq0Gt3nE9HBnt7BhsV6fZ2QdbK6IyVx75qkWjoERIok+8 4JAV6QGUcGBFPu4F77ECiKc0L/x5+lkqqHL6J2PCrNvI/1skydDQjJa5eXQacHGt24SP nMxKtiobSstn6qJ64VyMd1FdC0mdt2L4YMj+taUuz29TaG080zlQlhvpwOajFYMI1HCT fHwJF5Q/4f7An6ScjU1XdGQuy/637+6x7AThFzB02QGFtnKtKRT7aOY5UvBHfJseHpUS /iew== 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 200-v6si391350pgf.378.2018.07.19.16.35.27; Thu, 19 Jul 2018 16:35:41 -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 S1731235AbeGTAUM (ORCPT + 99 others); Thu, 19 Jul 2018 20:20:12 -0400 Received: from terminus.zytor.com ([198.137.202.136]:49987 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730369AbeGTAUM (ORCPT ); Thu, 19 Jul 2018 20:20:12 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6JNXmPj2454168 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 19 Jul 2018 16:33:48 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6JNXm5V2454165; Thu, 19 Jul 2018 16:33:48 -0700 Date: Thu, 19 Jul 2018 16:33:48 -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: torvalds@linux-foundation.org, dave.hansen@intel.com, llong@redhat.com, tglx@linutronix.de, brgerst@gmail.com, jgross@suse.com, peterz@infradead.org, pavel@ucw.cz, mingo@kernel.org, jpoimboe@redhat.com, boris.ostrovsky@oracle.com, luto@kernel.org, will.deacon@arm.com, dhgutteridge@sympatico.ca, jroedel@suse.de, aarcange@redhat.com, eduval@amazon.com, jkosina@suse.cz, gregkh@linuxfoundation.org, hpa@zytor.com, David.Laight@aculab.com, dvlasenk@redhat.com, bp@alien8.de, linux-kernel@vger.kernel.org Reply-To: boris.ostrovsky@oracle.com, jpoimboe@redhat.com, mingo@kernel.org, luto@kernel.org, will.deacon@arm.com, dhgutteridge@sympatico.ca, eduval@amazon.com, jroedel@suse.de, aarcange@redhat.com, torvalds@linux-foundation.org, tglx@linutronix.de, llong@redhat.com, dave.hansen@intel.com, brgerst@gmail.com, pavel@ucw.cz, peterz@infradead.org, jgross@suse.com, dvlasenk@redhat.com, bp@alien8.de, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, jkosina@suse.cz, hpa@zytor.com, David.Laight@aculab.com In-Reply-To: <1531906876-13451-30-git-send-email-joro@8bytes.org> References: <1531906876-13451-30-git-send-email-joro@8bytes.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] x86/mm/pti: Introduce pti_finalize() Git-Commit-ID: b976690f5db26fbc7c2be413bfa0fbd270547a94 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: b976690f5db26fbc7c2be413bfa0fbd270547a94 Gitweb: https://git.kernel.org/tip/b976690f5db26fbc7c2be413bfa0fbd270547a94 Author: Joerg Roedel AuthorDate: Wed, 18 Jul 2018 11:41:06 +0200 Committer: Thomas Gleixner CommitDate: Fri, 20 Jul 2018 01:11:45 +0200 x86/mm/pti: Introduce pti_finalize() Introduce a new function to finalize the kernel mappings for the userspace page-table after all ro/nx protections have been applied to the kernel mappings. Also move the call to pti_clone_kernel_text() to that function so that it will run on 32 bit kernels too. 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-30-git-send-email-joro@8bytes.org --- arch/x86/include/asm/pti.h | 3 +-- arch/x86/mm/init_64.c | 6 ------ arch/x86/mm/pti.c | 14 +++++++++++++- include/linux/pti.h | 1 + init/main.c | 7 +++++++ 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/pti.h b/arch/x86/include/asm/pti.h index 38a17f1d5c9d..5df09a0b80b8 100644 --- a/arch/x86/include/asm/pti.h +++ b/arch/x86/include/asm/pti.h @@ -6,10 +6,9 @@ #ifdef CONFIG_PAGE_TABLE_ISOLATION extern void pti_init(void); extern void pti_check_boottime_disable(void); -extern void pti_clone_kernel_text(void); +extern void pti_finalize(void); #else static inline void pti_check_boottime_disable(void) { } -static inline void pti_clone_kernel_text(void) { } #endif #endif /* __ASSEMBLY__ */ diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c index a688617c727e..9b19f9a8948e 100644 --- a/arch/x86/mm/init_64.c +++ b/arch/x86/mm/init_64.c @@ -1291,12 +1291,6 @@ void mark_rodata_ro(void) (unsigned long) __va(__pa_symbol(_sdata))); debug_checkwx(); - - /* - * Do this after all of the manipulation of the - * kernel text page tables are complete. - */ - pti_clone_kernel_text(); } int kern_addr_valid(unsigned long addr) diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c index e41ee93c430d..fcfb815d420f 100644 --- a/arch/x86/mm/pti.c +++ b/arch/x86/mm/pti.c @@ -462,7 +462,7 @@ static inline bool pti_kernel_image_global_ok(void) * For some configurations, map all of kernel text into the user page * tables. This reduces TLB misses, especially on non-PCID systems. */ -void pti_clone_kernel_text(void) +static void pti_clone_kernel_text(void) { /* * rodata is part of the kernel image and is normally @@ -526,3 +526,15 @@ void __init pti_init(void) pti_setup_espfix64(); pti_setup_vsyscall(); } + +/* + * Finalize the kernel mappings in the userspace page-table. + */ +void pti_finalize(void) +{ + /* + * Do this after all of the manipulation of the + * kernel text page tables are complete. + */ + pti_clone_kernel_text(); +} diff --git a/include/linux/pti.h b/include/linux/pti.h index 0174883a935a..1a941efcaa62 100644 --- a/include/linux/pti.h +++ b/include/linux/pti.h @@ -6,6 +6,7 @@ #include #else static inline void pti_init(void) { } +static inline void pti_finalize(void) { } #endif #endif diff --git a/init/main.c b/init/main.c index 3b4ada11ed52..fcfef46c935a 100644 --- a/init/main.c +++ b/init/main.c @@ -1065,6 +1065,13 @@ static int __ref kernel_init(void *unused) jump_label_invalidate_initmem(); free_initmem(); mark_readonly(); + + /* + * Kernel mappings are now finalized - update the userspace page-table + * to finalize PTI. + */ + pti_finalize(); + system_state = SYSTEM_RUNNING; numa_default_policy();