Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2259729imm; Thu, 19 Jul 2018 16:40:00 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc8C8iI1P0OFCUjdAW6SVNsSAsjenpativl92MdF0k/DAIO28hyoqt0o/6itzcZ2+LjUvKp X-Received: by 2002:a17:902:9302:: with SMTP id bc2-v6mr11965873plb.280.1532043600671; Thu, 19 Jul 2018 16:40:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532043600; cv=none; d=google.com; s=arc-20160816; b=oPOzXnkj9S/OBcQDgLjmv+u5aopMBsqg/LnCmSWC5oOgoDevdvPcZ1p/XBoWx1YE57 tdBRuvujEjTqSE4R8BJR/h9oKb/3THEqs5eQZxRzGXMbXlqIbk1cjY5oEmfvhMZilkdy xJTEieHDpJHHi16TjI53TsiNwtxzxbmDW87IFoLTO9h6OpPn5gnBQgQ7Iy1C0HSZx/UP 2mKS4QXhLwM0C0ACHoKGwwz9ewDgsVWk/AuVeF9x2ZjFByCuUI9QCADVt1rnYTBYCw8z ijdnlAZ3OUEAMbpuWlnc5Pmj3zDYEShsst5PFP4qjtIVy5tNAqd3BAGxgesWBOrQdbyV GnZA== 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=pd/P3imz/CGlbjrN9qlO+4zqLzWfnXTh3rqU5dbHgoA=; b=D5RQR8UxElQyWrqjFui9oLjhYRQBOScdttYVXcafJYKul3yXgCQ7+03HX4OxBU2X+y geQZS3WpRueJZc1YRxi9Nvl+MLmJI74AYi0+dHx9h7DqD9tyeJC+MYEQTGBmX2ObsYah X3LaVihN4cNwnNAQY8iCLZVzfi5UZJcLcBIzJIjaxRXjEfbloy0S6xio6y4/dc51u6DZ gthA1lRFIWDahq1UW3j0qJ5VXv9kqWOeoCOaXg5wSPyNJS/TnsQKwVdkB9JJTKF/4LQL Pq8lKdW6/jTeYasnTGkG5FcGXbF6nfvmpOo96LDoPqjq7/bGa4x21H1gi8qQSgPv4hks /7xg== 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 d30-v6si389013pla.110.2018.07.19.16.39.45; Thu, 19 Jul 2018 16:40:00 -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 S1731193AbeGTAXl (ORCPT + 99 others); Thu, 19 Jul 2018 20:23:41 -0400 Received: from terminus.zytor.com ([198.137.202.136]:39715 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727650AbeGTAXl (ORCPT ); Thu, 19 Jul 2018 20:23:41 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id w6JNbIit2454546 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 19 Jul 2018 16:37:18 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w6JNbING2454542; Thu, 19 Jul 2018 16:37:18 -0700 Date: Thu, 19 Jul 2018 16:37:18 -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: luto@kernel.org, pavel@ucw.cz, aarcange@redhat.com, jkosina@suse.cz, dhgutteridge@sympatico.ca, torvalds@linux-foundation.org, bp@alien8.de, boris.ostrovsky@oracle.com, mingo@kernel.org, hpa@zytor.com, brgerst@gmail.com, jpoimboe@redhat.com, dvlasenk@redhat.com, peterz@infradead.org, dave.hansen@intel.com, jgross@suse.com, tglx@linutronix.de, gregkh@linuxfoundation.org, eduval@amazon.com, will.deacon@arm.com, jroedel@suse.de, llong@redhat.com, linux-kernel@vger.kernel.org, David.Laight@aculab.com Reply-To: pavel@ucw.cz, luto@kernel.org, jkosina@suse.cz, aarcange@redhat.com, torvalds@linux-foundation.org, dhgutteridge@sympatico.ca, boris.ostrovsky@oracle.com, bp@alien8.de, hpa@zytor.com, mingo@kernel.org, jpoimboe@redhat.com, brgerst@gmail.com, dave.hansen@intel.com, peterz@infradead.org, dvlasenk@redhat.com, jgross@suse.com, tglx@linutronix.de, will.deacon@arm.com, eduval@amazon.com, gregkh@linuxfoundation.org, jroedel@suse.de, llong@redhat.com, linux-kernel@vger.kernel.org, David.Laight@aculab.com In-Reply-To: <1531906876-13451-37-git-send-email-joro@8bytes.org> References: <1531906876-13451-37-git-send-email-joro@8bytes.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/pti] x86/ldt: Enable LDT user-mapping for PAE Git-Commit-ID: 6df934b92a549cb3badb6d576f71aeb133e2f110 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: 6df934b92a549cb3badb6d576f71aeb133e2f110 Gitweb: https://git.kernel.org/tip/6df934b92a549cb3badb6d576f71aeb133e2f110 Author: Joerg Roedel AuthorDate: Wed, 18 Jul 2018 11:41:13 +0200 Committer: Thomas Gleixner CommitDate: Fri, 20 Jul 2018 01:11:48 +0200 x86/ldt: Enable LDT user-mapping for PAE This adds the needed special case for PAE to get the LDT mapped into the user page-table when PTI is enabled. The big difference to the other paging modes is that on PAE there is no full top-level PGD entry available for the LDT, but only a PMD entry. 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-37-git-send-email-joro@8bytes.org --- arch/x86/include/asm/mmu_context.h | 5 ---- arch/x86/kernel/ldt.c | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h index bbc796eb0a3b..eeeb9289c764 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -71,12 +71,7 @@ struct ldt_struct { static inline void *ldt_slot_va(int slot) { -#ifdef CONFIG_X86_64 return (void *)(LDT_BASE_ADDR + LDT_SLOT_STRIDE * slot); -#else - BUG(); - return (void *)fix_to_virt(FIX_HOLE); -#endif } /* diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c index 69af9a0d57b7..733e6ace0fa4 100644 --- a/arch/x86/kernel/ldt.c +++ b/arch/x86/kernel/ldt.c @@ -126,6 +126,57 @@ static void do_sanity_check(struct mm_struct *mm, } } +#ifdef CONFIG_X86_PAE + +static pmd_t *pgd_to_pmd_walk(pgd_t *pgd, unsigned long va) +{ + p4d_t *p4d; + pud_t *pud; + + if (pgd->pgd == 0) + return NULL; + + p4d = p4d_offset(pgd, va); + if (p4d_none(*p4d)) + return NULL; + + pud = pud_offset(p4d, va); + if (pud_none(*pud)) + return NULL; + + return pmd_offset(pud, va); +} + +static void map_ldt_struct_to_user(struct mm_struct *mm) +{ + pgd_t *k_pgd = pgd_offset(mm, LDT_BASE_ADDR); + pgd_t *u_pgd = kernel_to_user_pgdp(k_pgd); + pmd_t *k_pmd, *u_pmd; + + k_pmd = pgd_to_pmd_walk(k_pgd, LDT_BASE_ADDR); + u_pmd = pgd_to_pmd_walk(u_pgd, LDT_BASE_ADDR); + + if (static_cpu_has(X86_FEATURE_PTI) && !mm->context.ldt) + set_pmd(u_pmd, *k_pmd); +} + +static void sanity_check_ldt_mapping(struct mm_struct *mm) +{ + pgd_t *k_pgd = pgd_offset(mm, LDT_BASE_ADDR); + pgd_t *u_pgd = kernel_to_user_pgdp(k_pgd); + bool had_kernel, had_user; + pmd_t *k_pmd, *u_pmd; + + k_pmd = pgd_to_pmd_walk(k_pgd, LDT_BASE_ADDR); + u_pmd = pgd_to_pmd_walk(u_pgd, LDT_BASE_ADDR); + had_kernel = (k_pmd->pmd != 0); + had_user = (u_pmd->pmd != 0); + + do_sanity_check(mm, had_kernel, had_user); +} + +#else /* !CONFIG_X86_PAE */ + static void map_ldt_struct_to_user(struct mm_struct *mm) { pgd_t *pgd = pgd_offset(mm, LDT_BASE_ADDR); @@ -143,6 +194,8 @@ static void sanity_check_ldt_mapping(struct mm_struct *mm) do_sanity_check(mm, had_kernel, had_user); } +#endif /* CONFIG_X86_PAE */ + /* * If PTI is enabled, this maps the LDT into the kernelmode and * usermode tables for the given mm.