Received: by 10.223.176.5 with SMTP id f5csp442798wra; Fri, 9 Feb 2018 01:29:16 -0800 (PST) X-Google-Smtp-Source: AH8x225JauzxEgi8ZV5Zvnrn5C3mCc/giLxA9LlNQv/k6eeK3ydOjgfAaRqmMZJEPOQPQw7RPtqm X-Received: by 10.98.128.13 with SMTP id j13mr2140274pfd.141.1518168556662; Fri, 09 Feb 2018 01:29:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518168556; cv=none; d=google.com; s=arc-20160816; b=lJlY9XSId/suVFM3B5HwbgNdarkWLz/0QCZjry0Nu3usMdLL+kh+TQNlO3T8/d5dTH dytJKBo/iGS1r3pq/c+GPHx+G5FPjZoRUatW6LZnZXgoG0TVhO+01Fq2p5NsPnS46M+s 2PCIDkYjgT8lp8CmaClYEjwRsR0OWWktQVYO9HLGtZjz+tZ/+bBeCJV/9w8EqCdL+LIz GbGlNkvA4wdqH0eMTiiBgCsvGsxstj5Hjrsch7QnNkDMV81ewjgrbqrdY6HiI7JR81ma E57rmSiNX5mN6JY67LwVU+zGHaHfLZBqfasAI5RGRvjH1kKpsHgXJSjTEaCpxnKpcv3S zBiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=5GVwPDKsD+1K6vG3mdefs4/myzOy2uBlRsuw23QPAt0=; b=vb3PWQJ8vQWyNizQya6hLVBDs6ptS4r5hKgX3CSKp4PmWOJicod3gBDttaOTRL2hmw TBC+qa9aRXXlLZ+VIGIRpXaNAN7w3IfCccAYHwQ6GhSer20G2lSN76KDokWpZM36dppi 5vSfZLKLU7QEDBDiyckXNi1duF2SIPDHBjqW++LT4BBEucPL6qwm4N8eOnJ+Mcx/zWNA lah96aAMP0B5MK19J+dNzHXOPAZNZkMWqTF46tX9setleOiEeXzi+Wc3KjBmZ4w9GuwY y2JlYlDrq4fyBaxK90GBBUKJ3FAq/5IntQeH6FkuhtN1Fn9AcVBEYocldkR5evX1Ydgg carg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=e+NuTq70; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s65si1456782pfe.45.2018.02.09.01.28.59; Fri, 09 Feb 2018 01:29:16 -0800 (PST) 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; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=e+NuTq70; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752560AbeBIJ1H (ORCPT + 99 others); Fri, 9 Feb 2018 04:27:07 -0500 Received: from 8bytes.org ([81.169.241.247]:43388 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752314AbeBIJ0J (ORCPT ); Fri, 9 Feb 2018 04:26:09 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id 2A6F1C99; Fri, 9 Feb 2018 10:25:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1518168356; bh=Qx/1HWYNv8AQFzQ0MiHmuTzC8G5VFEXVR8wXhzVdEyA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e+NuTq70ormBnMGNlI+bbbs8IRV0WeLbKIo8n/hYVI/oaVbvtg4gmGY78874a8QXm 6KLdzslRV2raL0XDHfmyxscPE6DIb3nyAYq+ioOabQ1JHizaqrkdV21aT9SOvSy8lC vmtV/kO/4Ao2uypbg798PVuu+gK9+5t9WjK/8udcJ8uYSuBsGgMw2zJcRg2Z8CYS2N R7DKz3bN8LlefH6EFLoccirxo9V3bm9a8CZbXtH6X7Oaz4tB1FhLCLWE1CkxeVkN99 vjDG+ylzhSghzlhI+0uCPvX7BqmQW/O/2jGz7ZPpaO4X/1ZbZgunbPFXoqM/3OttuQ PZkyoBa8oNTsw== 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 , jroedel@suse.de, joro@8bytes.org Subject: [PATCH 30/31] x86/ldt: Enable LDT user-mapping for PAE Date: Fri, 9 Feb 2018 10:25:39 +0100 Message-Id: <1518168340-9392-31-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518168340-9392-1-git-send-email-joro@8bytes.org> References: <1518168340-9392-1-git-send-email-joro@8bytes.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joerg Roedel 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 we don't have a full top-level PGD entry available for the LDT, but only PMD entry. Signed-off-by: Joerg Roedel --- arch/x86/include/asm/mmu_context.h | 4 --- arch/x86/kernel/ldt.c | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h index c931b88..af96cfb 100644 --- a/arch/x86/include/asm/mmu_context.h +++ b/arch/x86/include/asm/mmu_context.h @@ -70,11 +70,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(); -#endif } /* diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c index 8ab7df9..7787451 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. -- 2.7.4