Received: by 10.223.176.5 with SMTP id f5csp447302wra; Fri, 9 Feb 2018 01:34:28 -0800 (PST) X-Google-Smtp-Source: AH8x226pnimqaqx4wWCjx80hWj7BRfdFF2Ubq02sK0g2SM1m12QlxrA3At/v9PyeYtoiB4xjWC// X-Received: by 2002:a17:902:bf0a:: with SMTP id bi10-v6mr1973263plb.181.1518168868637; Fri, 09 Feb 2018 01:34:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518168868; cv=none; d=google.com; s=arc-20160816; b=GUMCgOS+g+CDfdOEpN3JRKlBax+TPHNiw2VkD2UhMJD21YKKRCnq94Q8qTvpQqWzm5 L+qsqZEvoV8y0P166tiPkxhxWP920Hag0xSRvOmftmwiRgxSankhLh2Yv8k6g9n0LnIt ogqUfWS4KgUelFNGEJo8tFQvHCN39ZTsMEBMugveQqAhjfQMEnUy9ux2euNj295Rym2G qFDofnPI4iWJoxdZCzp9ZkKSGwaZQZUs9kAok5q4h/fQzm9MTj2b45BrodXZmM6yRMA0 M/BTdpwpR7Ll1vBl7yjx4yL7Y8s28Mww/UfG+L0WLjAIXlM621JdJriP6m8GfwUZBCL4 Wa5w== 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=JkRqSgi4/+KSltBc4UZcNnsJotRDCBQ6c9iKVNw312Y=; b=jAw8UPlpNrQHmhMUTli3fia40v34+yi65M6DknhoRjRWnfaOIM6J4cr43dZyB6j2P7 amJP9Yuw46c8kBA3l3yrir2ZpOH9e/pVbJ8xyphMWYOb5rioKpzs+lbj2szVI0/PRZdC Zis2RJoSdNBtylUjUjbiDVQMw/LPf652zS83/+d65+8OdwXjCsMRvALb0NLfZTCo+CIQ 1KqEAGeBsTEvYJk/iLM5I4Doeep1ncWXaXbxAv5Ki2D8MNY++/wfTJLKDqGr5mgNCLEr HwnOa35ykgkHQm0XPDE8U952VUrIidEysahqzFM9Sp3TvHR9ohLIJm8GUPh76Hvq+8Dh XRmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=D0RMJWxX; 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 m3si1178554pgs.54.2018.02.09.01.34.11; Fri, 09 Feb 2018 01:34:28 -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=D0RMJWxX; 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 S1752854AbeBIJcI (ORCPT + 99 others); Fri, 9 Feb 2018 04:32:08 -0500 Received: from 8bytes.org ([81.169.241.247]:43486 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751124AbeBIJ0B (ORCPT ); Fri, 9 Feb 2018 04:26:01 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id 72417692; Fri, 9 Feb 2018 10:25:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1518168353; bh=V1SDpIc/DQ43udsqE0jhavavlRFOFPKOv6DqPLWbmas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D0RMJWxXUOYNarcRXRBu+oQHvtBAPrbnzOUjX0GKK3hHmmGmjy/WIGI77P6nQfr00 VcMG4jhl+mnFhTmSypgA6X8+hwivJZw5WcTsq5c2CYL7bZWoruFWQJFJJCQUb690n2 2Zu6qzfyNf8KGYy4AZyOGz0I8HWFo2FlhhZdNQE3CPsdLATuj1DOfFoAqWf+1yOeh8 y7PiLXQTsttAZ2Skq9nCBm/zjZWDoUoxOPC6PEI/GDFOj4tR/oBVvNZTl/fDwXyWXV N/Mhk5N3KcYwYRzm5JSFdi8UxHi0IiclZZyBvR+QVTadsQLgp5CfTQPzP7NIOjW1Ai myFXfmak2in2A== 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 15/31] x86/pgtable/32: Allocate 8k page-tables when PTI is enabled Date: Fri, 9 Feb 2018 10:25:24 +0100 Message-Id: <1518168340-9392-16-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 Allocate a kernel and a user page-table root when PTI is enabled. Also allocate a full page per root for PAE because otherwise the bit to flip in cr3 to switch between them would be non-constant, which creates a lot of hassle. Keep that for a later optimization. Signed-off-by: Joerg Roedel --- arch/x86/kernel/head_32.S | 20 +++++++++++++++----- arch/x86/mm/pgtable.c | 5 +++-- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S index c290209..1f35d60 100644 --- a/arch/x86/kernel/head_32.S +++ b/arch/x86/kernel/head_32.S @@ -512,11 +512,18 @@ ENTRY(initial_code) ENTRY(setup_once_ref) .long setup_once +#ifdef CONFIG_PAGE_TABLE_ISOLATION +#define PGD_ALIGN (2 * PAGE_SIZE) +#define PTI_USER_PGD_FILL 1024 +#else +#define PGD_ALIGN (PAGE_SIZE) +#define PTI_USER_PGD_FILL 0 +#endif /* * BSS section */ __PAGE_ALIGNED_BSS - .align PAGE_SIZE + .align PGD_ALIGN #ifdef CONFIG_X86_PAE .globl initial_pg_pmd initial_pg_pmd: @@ -526,14 +533,17 @@ initial_pg_pmd: initial_page_table: .fill 1024,4,0 #endif + .align PGD_ALIGN initial_pg_fixmap: .fill 1024,4,0 -.globl empty_zero_page -empty_zero_page: - .fill 4096,1,0 .globl swapper_pg_dir + .align PGD_ALIGN swapper_pg_dir: .fill 1024,4,0 + .fill PTI_USER_PGD_FILL,4,0 +.globl empty_zero_page +empty_zero_page: + .fill 4096,1,0 EXPORT_SYMBOL(empty_zero_page) /* @@ -542,7 +552,7 @@ EXPORT_SYMBOL(empty_zero_page) #ifdef CONFIG_X86_PAE __PAGE_ALIGNED_DATA /* Page-aligned for the benefit of paravirt? */ - .align PAGE_SIZE + .align PGD_ALIGN ENTRY(initial_page_table) .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */ # if KPMDS == 3 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c index 004abf9..a81d42e 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -338,7 +338,8 @@ static inline pgd_t *_pgd_alloc(void) * We allocate one page for pgd. */ if (!SHARED_KERNEL_PMD) - return (pgd_t *)__get_free_page(PGALLOC_GFP); + return (pgd_t *)__get_free_pages(PGALLOC_GFP, + PGD_ALLOCATION_ORDER); /* * Now PAE kernel is not running as a Xen domain. We can allocate @@ -350,7 +351,7 @@ static inline pgd_t *_pgd_alloc(void) static inline void _pgd_free(pgd_t *pgd) { if (!SHARED_KERNEL_PMD) - free_page((unsigned long)pgd); + free_pages((unsigned long)pgd, PGD_ALLOCATION_ORDER); else kmem_cache_free(pgd_cache, pgd); } -- 2.7.4