Received: by 10.223.185.116 with SMTP id b49csp2474781wrg; Mon, 5 Mar 2018 03:37:37 -0800 (PST) X-Google-Smtp-Source: AG47ELvlg5RtfxJ5moUU/M71lhoyqJOte9Gp8hN7SVZqXB3Lc19W6OKZu4t5SLUSt9Rba/7ooAnz X-Received: by 2002:a17:902:c81:: with SMTP id 1-v6mr12904605plt.205.1520249857444; Mon, 05 Mar 2018 03:37:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520249857; cv=none; d=google.com; s=arc-20160816; b=CXue3ZaFoyeXXsvdc0gYIPpwnK4oN9FNThS23H2n7JIqmVGr9Ec+0bV628oove2PaW fA3opJyhfD63RK6CztPg4he/dygi/OfQO9RjJqVXJb8U82l7i+tVHoa4xFdfx48yg4TH styuRLkr4JWUfp63dvXkF30xDZS+06GPUE1OxLL7Dq24NuXk6Aii+jhdcgnnHGOLGsF4 O8OLCuVlGFtG6ZiMLB5AB1HjQFV9EVKP72FbQMSirsgcn41Kal0gkooyHaQ+7YF9IRZO Ro8aOSqFMrC6a875STm8dImcUJ4Cpd6/8pZBC/1x8mzinZ+Oj3DsGc2FxghFV3SiqeQk YSuQ== 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=WYCZpTPO/b3ZfM2nM3gy2kd5U2LYtiArQm71CJUsWVn4As4UROekYPjkQ8SRRN6hDw eHcqIUv4j9cAKXzivUty7w3Lv7KWeLvW4tsQxDV4leL8zQKLjVyJLgMv4aYZUWdPV+X+ UkBrQojuAU+Xy3cqzhFWePOBl9WZeTRuCuDU2LjY3q5CBs/3feM+2TLlpn+jrDnknnd0 f2qCWyeLlmi7V7YrpzPt7CTr1AMcjZSQ/qEY513xu4y7LSzGXpHcheaNQcsPbVjgUyzd 0Fu8Yi2kG5NnBBgePEn3n5uzMXhQkBe/IKqJnZCrZhH7KhMMHIWGQxX8e7Is01xYDeJj kprw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=FaqYp7us; 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 q87si10024610pfa.385.2018.03.05.03.37.23; Mon, 05 Mar 2018 03:37:37 -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=FaqYp7us; 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 S933871AbeCEKbZ (ORCPT + 99 others); Mon, 5 Mar 2018 05:31:25 -0500 Received: from 8bytes.org ([81.169.241.247]:54420 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933271AbeCEK0Q (ORCPT ); Mon, 5 Mar 2018 05:26:16 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id F327BC8E; Mon, 5 Mar 2018 11:26:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1520245568; bh=V1SDpIc/DQ43udsqE0jhavavlRFOFPKOv6DqPLWbmas=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FaqYp7us8eePqMIHevBERzG3pAF7cLRGzrZ1n4MsQ6dHkvqpBypM2EP9s3xsemjL5 0usNFrtNDt7iUvwE8XT++ay1Qv9Nubpka9VHwOJdKgOyr9/8pRCBHvuqMSFgeETQpi jG9IQMhi10bRlE2hytaUpapxTzz6e6mU0NYucodUgcVrFUHZU5V0lEFZOL+XlbhPh1 vwiqza/0SVFDwhK1dEKvi8iatPl7bmzBbreOWs44Dkzja/j5pfuOTsN7+tNt35sKGE LtFee0HBB0APuEiXHQYSFkFd9juRNSBc8cVFxHBBchBnzX+5HbFkZuB6A3Y5R7hSzS 7pD6a4a/8AmJw== 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 17/34] x86/pgtable/32: Allocate 8k page-tables when PTI is enabled Date: Mon, 5 Mar 2018 11:25:46 +0100 Message-Id: <1520245563-8444-18-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520245563-8444-1-git-send-email-joro@8bytes.org> References: <1520245563-8444-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