From patchwork Wed Jul 11 11:29:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 10519511 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 3577D6032A for ; Wed, 11 Jul 2018 11:32:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39A3426861 for ; Wed, 11 Jul 2018 11:32:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C92928578; Wed, 11 Jul 2018 11:32:07 +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 B01B026861 for ; Wed, 11 Jul 2018 11:32:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F04356B028E; Wed, 11 Jul 2018 07:30:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E667A6B028F; Wed, 11 Jul 2018 07:30:20 -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 D28996B0290; Wed, 11 Jul 2018 07:30:20 -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 6F8506B028E for ; Wed, 11 Jul 2018 07:30:20 -0400 (EDT) Received: by mail-ed1-f72.google.com with SMTP id c2-v6so9864516edi.20 for ; Wed, 11 Jul 2018 04:30:20 -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=5RyuMf0JoQLxU50ftKKt3zum+cKILbraWmtXrPttPno=; b=WzuyHHWlGoyvKPVckZ6ZDDaFAPyla7IyDKI3pDgXvoBjkF2OsCqd//B38Tcv8tOpR2 h5NQ8uzMggGfMjZCZ7y9XXs4uBp9Il1uqZb1E9D0ceXW09prJ0vIbZWBWXSQvc2jwcfU lbykza0stmZf1nIObSvQR3YDNhdrBzAmmfuuO4gVtw9IBEnBjzWOtFcz8IGQ3TawmQlv XJBIkzT8ZCGPF6la/P9LbOYLoqOaxBB4FxMH6wd9rn3bADwyoFnImoiKukve9K8e96Hj c5KMK/kRTHWnax2Rs1N3MiEDJhoTJMfcaGvu8H1g49zxTaPWH5bxLUPbmkFgn3Y/ouKh zgww== X-Gm-Message-State: APt69E18lfcRWDeSoDL1f2reVBfMROnr0Z+6AlKk2iYdDtY2GgxjuhSn yTvZZUOEjNi6Iw033hjolyLR5SOT1dMeqEx780nsXDx09pAVNdknlKrfH85KG9fiQ9XI6SrfFhL 7GfU0TiLMUPh6sR7iKmUUattwJw5zOyDoYwUrPBsNMApJ1XbvDGbb4LIS7JbQsJRx1g== X-Received: by 2002:a50:ba3b:: with SMTP id g56-v6mr31462712edc.85.1531308620015; Wed, 11 Jul 2018 04:30:20 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcXzYlcWagBcDC/a1cXne7AfQuz6G+kGhf8uruLspw7hdIU9IJ3ZqqpYj88Mo4SavsIFJ6n X-Received: by 2002:a50:ba3b:: with SMTP id g56-v6mr31462673edc.85.1531308619328; Wed, 11 Jul 2018 04:30:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531308619; cv=none; d=google.com; s=arc-20160816; b=wzPb8XCUwVOWqRJ2TE3vXOyuufStB0i2Lq4LUJ6AKOZx1gQubS1wx7wn0lJ/Y7rBtY DV6Wn+FHDm3BlutQaIhxzA6Uc/7TC8swglnLwiJmCFXLAseKvobl32UuM6L/okd3iMZW b3DOArk08wmMaqqWEWi0qdP11oZrOjP6W0V1x9JTyFeJD0CUaib9KzLl6h53Yy0M+C3v Paxs3YtQdt/tBAtcyWfIDKvGA1DEBWt0UjKD5nOSjm+/kKuJDyCqfVZeo2TJlkL/6b9b ECq3g0rPcrx3LCyvPsIM1uMfZMlcGWcvas7pHV0J/H9Bc5jBTItbof83mPMm2sLd2wfC aWmA== 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=5RyuMf0JoQLxU50ftKKt3zum+cKILbraWmtXrPttPno=; b=l5d6fuCrOYMbZEUL6AzXBiw8vZ6CtyyYUXUQQvRh4aEtosQz//gNISzQxhUjTaj7rp vtecixAqkxJl7sfdu8ottJs4srGA8urTxyv5TwVSDnuNfa4DRrvNVkdX2F8CdoXzjNQB I0/tIQvSc0HQpGMa0UIn3PU3j8gCTExabjRe2lFE+xLeQm5KB8eI+C+i/OC/fRRJHwfJ D7BA5i23S3V+26wJ8I09t1hVorNiOJ+3TfUez2NJNXNjitu5k++iV18ZRsxecsEYfoGz eofzNtUVu7uOnmhZ28ldrau09kNIkDIqrkP0/Xfh75tqnB0rgYhn9Pk2daB3cdAQrmZ1 zHeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@8bytes.org header.s=mail-1 header.b=Gcz9K5kG; spf=pass (google.com: domain of joro@8bytes.org designates 2a01:238:4383:600:38bc:a715:4b6d:a889 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. [2a01:238:4383:600:38bc:a715:4b6d:a889]) by mx.google.com with ESMTPS id 29-v6si6010913edx.293.2018.07.11.04.30.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 04:30:19 -0700 (PDT) Received-SPF: pass (google.com: domain of joro@8bytes.org designates 2a01:238:4383:600:38bc:a715:4b6d:a889 as permitted sender) client-ip=2a01:238:4383:600:38bc:a715:4b6d:a889; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@8bytes.org header.s=mail-1 header.b=Gcz9K5kG; spf=pass (google.com: domain of joro@8bytes.org designates 2a01:238:4383:600:38bc:a715:4b6d:a889 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 61F681A0E; Wed, 11 Jul 2018 13:30:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1531308607; bh=w6IEnwiFb5igPoQcBU4Vm3UbctYunXcFUtJ3fSOqaF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gcz9K5kGh32sGspT/+8WCbrNJfL+D6XpwFrJe4o21jggLaMr/tN/wijxLoRy9trIB 34VTXu2ntqsYBIOWxovduwLigB1vyR1PwHq2R2dpoSaIWSVfo036ACo6lxg0suQ1Ps zx1r9R8B6KH06LDWsB6shoGvd+OXGdBtgWPep8ftxlokZZa+Cnie492teLwQGOaeHl l9pdJ75QbFcQQYKH0l4PwUbXKwBvqMnp7B1UDX5RGHaGVnTOTOPrzeMgMqMAQpfz/E MjCT8LeO1LD8p3edHOfOtxCOo/FnCLq7qkV/fPT9R6hQedtQE7IvVObMoCJWz+Zugi PNrYel4nopmcQ== 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 29/39] x86/mm/pti: Introduce pti_finalize() Date: Wed, 11 Jul 2018 13:29:36 +0200 Message-Id: <1531308586-29340-30-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531308586-29340-1-git-send-email-joro@8bytes.org> References: <1531308586-29340-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 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 --- 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 38a17f1..5df09a0 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 a688617..9b19f9a 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 fc77054..1825f30 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 0174883..1a941ef 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 3b4ada1..fcfef46 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();