From patchwork Wed Jul 18 09:40:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 10531855 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 08AA8602CA for ; Wed, 18 Jul 2018 09:42:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE0BE28FBC for ; Wed, 18 Jul 2018 09:42:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E109A28FC6; Wed, 18 Jul 2018 09:42:23 +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 8167C28FBC for ; Wed, 18 Jul 2018 09:42:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 10F7D6B027F; Wed, 18 Jul 2018 05:41:34 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0C7536B0280; Wed, 18 Jul 2018 05:41:33 -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 E07826B0281; Wed, 18 Jul 2018 05:41:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 7C6986B027F for ; Wed, 18 Jul 2018 05:41:33 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id d5-v6so1699689edq.3 for ; Wed, 18 Jul 2018 02:41:33 -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=NbdKIJPV96otTTsK+7fSwd+ewV0164F3rd38sK3xCqQ=; b=dyHcdCfJj/4MUtSK+4At3aylZS7NWswB9tKa6gjBSSnNj66Vy+6nnUOLlv62PqWKRA 0HCiMOEsV9edgUDeT0CF9lZAEkiN3fVhnwCb3mtslx2BdU5OyPLmuz+H/QWZ8VliWV4b R0oDXjQeWuxDIJyc4IbUpiMA3c/7KbdQKYwN3YwIAFsB3bbLcmJA0Pj5KAQf4TYqgt5m yLiYNsUHpidPlZipWrJj6GDmT7EvElp89XSDXGzf3XWfUSZDPkrp0/VFNu/qZD8gKo/t piioZCKniL297bH+474yrvv4LDtXIwV3Ih6LQNRCz3e4xWIu+nGvjuXV0MR45RTnIyGZ a9rA== X-Gm-Message-State: AOUpUlGwlJ83ezwgBcw3/UgDWX2dQC5Mq7AMMikjH8SdIkBOPM3qp6eE WepOqmgLpWv+JP325i/RzwLPovzJolyPYU1iYvdoVpt/QViIQCTUvqYCmb7Jfj+g3vA32DBMedn zCXhScqmWDf9d42LBV0gF1IpNouVrXYT0LnOFv4gheJxtnOcmC+nrmGgKEvGol921fw== X-Received: by 2002:a50:be49:: with SMTP id b9-v6mr6041874edi.46.1531906893059; Wed, 18 Jul 2018 02:41:33 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcAr3z7RF6dvCjXK+XHkBecjUORMcyJbTDQrsSi4IvzYTZpNVRjM1oXQQMzav0lLgdkT71q X-Received: by 2002:a50:be49:: with SMTP id b9-v6mr6041836edi.46.1531906892426; Wed, 18 Jul 2018 02:41:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531906892; cv=none; d=google.com; s=arc-20160816; b=oMW9leEtmLhHFYyRfYntI744X0XIbMebu8S74hLTPIBdxbhND4ihHq8h17RGWYkN5B mXlfGXTPXff48LWJCJktMO00oPx6a+lBQ26mP89rp+2T3w47OQznGWJ40ckACFfoTiAG FifhDD8mrE2HubKXQ+yyPy2eomD1ecn742E3zlPVLePwCdMBHLyukBRyOsvsUeBfyHlr hjPE08yY85d+VJQg6xshfLEQecdgPgamh3EIoaN3uwyJC8f5Aw9EsHVgTtkpoiatEbpr 0QXyRj/YasxCWUt+B4jbW6hVyLT6sPkOgKCbnX5rDHmRvnJdMXpOagQygERo73wTQjLA wmYw== 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=NbdKIJPV96otTTsK+7fSwd+ewV0164F3rd38sK3xCqQ=; b=zk8G3mzfFfViC+6aeKwD0KcrX02+WHC5YrhfBfpvYW4XW988sMbReAQF8XCkKndsac ziuthprVvdAZh8RtlXoSQsCivVJMUHa6g5rU2s65yr7mE+nk2ihdbuO+m5Ofx/W2mO3a d0RG/vWkd2j5usyiETcWekr4Fn/z9Y4ADaDocOwj69X2y0NX5zO2pndaWD1OjFxxNwHW xLOE61KNtXmgACFEVy5cswhvDVAOT6nM43uqaC9t/9ttQakfR2A5KH/Zzze9eLFnIz5o 28vHKNk+DlXnNj4THznFKVFjyeqgiMyDZwzztuqdnC7T7lJM+Wd3yalXy7aPH/pnvQFv cUUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@8bytes.org header.s=mail-1 header.b=rAWiD1Uc; 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 r11-v6si1171220edp.9.2018.07.18.02.41.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 02:41:32 -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=rAWiD1Uc; 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 202FD889; Wed, 18 Jul 2018 11:41:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1531906882; bh=rgVeffvhNFRkOo6nEkJpgtDI1kRbfcMiZvXjhHYSbFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rAWiD1UcvtefUlQpKgaW3kkKYX95WVFcog+UnOuaWGKRrZtqX6cCHb/NVtRgi6/2y vJ8pta0W/mMSqv2vv8JpHLPIughd3vcg7NCpp+RDfm6VR+EecGHGBdMyahhDLJoUnT QGciV83KLef6+1WYPx0Znsdh95z+rFGY8LX5+vZECnrAKkvqjO/lNMw1ryuvg05ZUp G8Ky/xApvVjB6E/euhORZNM9gVi02Tj5w34NijI2X18PITjxOw0wB7wcpjNyaKt9V3 UbFNLlV2a37GOHpxhy8IOuveSBtl8572uh0/ykLSGPuoI0TBzmYIkVLwxpeUAtKc9x TNcl8xLMOk3oA== 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 17/39] x86/pgtable/32: Allocate 8k page-tables when PTI is enabled Date: Wed, 18 Jul 2018 11:40:54 +0200 Message-Id: <1531906876-13451-18-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531906876-13451-1-git-send-email-joro@8bytes.org> References: <1531906876-13451-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 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 abe6df1..30f9cb2 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 47b5951..db6fb77 100644 --- a/arch/x86/mm/pgtable.c +++ b/arch/x86/mm/pgtable.c @@ -343,7 +343,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 @@ -355,7 +356,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); }