From patchwork Wed Jul 11 11:29:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 10519475 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 4AA20603D7 for ; Wed, 11 Jul 2018 11:31:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D2DB26861 for ; Wed, 11 Jul 2018 11:31:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4012328837; Wed, 11 Jul 2018 11:31:25 +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=ham 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 CA1E726861 for ; Wed, 11 Jul 2018 11:31:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C44856B0281; Wed, 11 Jul 2018 07:30:14 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id BCA2B6B0284; Wed, 11 Jul 2018 07:30:14 -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 AB83D6B0285; Wed, 11 Jul 2018 07:30:14 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id 23E5B6B0281 for ; Wed, 11 Jul 2018 07:30:14 -0400 (EDT) Received: by mail-ed1-f69.google.com with SMTP id a22-v6so9880568eds.13 for ; Wed, 11 Jul 2018 04:30:14 -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=+ANkec/qOV8O7R4W7k9Hg882TYBVp21R4fwlww4KLPQ=; b=UPNcocPdphNxV+2DnV5OQTcO57EDNPgUYmwat4PcNRM1cIuWtjNj6VGymixQAVMZHo U5GOhvVfn+Sy0djPhlUevPIB1Mi96JIwOBq7cvTNtN6DVF34RmTbNW0lmEZu1ieO6+CX Vxb1s1hQoDDzwb57qcBWiYGveXitqVTHO7RImcrBBGmAZHT1Lk3pvQQJkNE6miwSPp31 M6s4rPONS9rfl0D+R+ldAEjDnGpTJNvEIkI4e3CzJvUx1WXQC0edelTlYlLIs9xdp+nq PgjTrET3JB8yK8oLssVdq0DDOAbiIyGEeApNUDsriBJuVj927fl1oPLufO7ffGoFJMv/ U4VA== X-Gm-Message-State: APt69E3OjkZz/De2IA4lYSAhsTLRFokZKDNIlA0KymU58Ap36lWTBZ5d nubKKZB2gCitg5MqcmoOtpBHOZ4g5AR2O1Jf89fa3w3+GeseAd1GBarLCoXu/ncPGxSjESS/bmJ YqkHC/lj4C86ybYF6q+o+0TIxCZCymFH5o9gFN+5/vyV5GzApWJP1mMg4xNkfGZQWNw== X-Received: by 2002:a50:b5e6:: with SMTP id a93-v6mr29977024ede.94.1531308613712; Wed, 11 Jul 2018 04:30:13 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeN2k/KdkTQ3VFdYRHGHzu4eB7M2Xc3mD8t6v2J64+t2SJN7kzPe3tWEjWkMayz+Stn/D38 X-Received: by 2002:a50:b5e6:: with SMTP id a93-v6mr29976989ede.94.1531308613102; Wed, 11 Jul 2018 04:30:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531308613; cv=none; d=google.com; s=arc-20160816; b=uxoU9b4SEjfcXYb51VNcHNVNAJGm32mikiyFx1beKA6bzRTLSeOeeI4xqtgPvCXAFq mbyEiIJOn4rczAP5BhAI2iHl5gCGmfwo55TW6lZq6gHNXrTISe+BfGWizFiDQfHjXPcY 5uI358nXrTaS6GtnlT0ePZh5vxgsv+C6qyD/K9mPE08I/dd2xQh19La6OXE92t59RrRz pgKraTFN6tJ4yXdoBwwstlniwSk+3tR9nOmxoAZesyOo+vuh4Mef/cEUyxtpkYLOYc/F 5nPe3JcYnA7VtzL/O5oxx8sRf1HQWN8el3WwW8Ym2nBHqn1cx9PF2yOqp9zYBAj7L/5n zsuA== 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=+ANkec/qOV8O7R4W7k9Hg882TYBVp21R4fwlww4KLPQ=; b=Uhv77qDHEItdysSrdwCVUq1bK+5dGaMNRVH7jgshuB2vkaGKqfznskWJT6uxhg13cJ 7AqXuNnIt05d90TgR9jyxq6FY1TaF+r/yJnXIbbTyzT8i0p7KIgw3UHLIuzbi1TuruM/ /23tILAFdu2eKlRWh/z+GcM3pIhOIeyKd555iRkqZaytYz8YFvJfEyqRKvMr5zG1Mzcg WQMPS94FLILY3kWcHYewN4A0f3VuZoMAI07AQLBLeLcGyBcm5dV8I7VUWp4SSWfJZ/Ec WDmw3uMPr794Pg5Y1DM95qW7/u6gL4hCm16xlkibyeR+U/u648Je1UgkkKCSfBQIugDj H0MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@8bytes.org header.s=mail-1 header.b=en9hSk4h; spf=pass (google.com: domain of joro@8bytes.org designates 81.169.241.247 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. [81.169.241.247]) by mx.google.com with ESMTPS id y2-v6si4097548eda.263.2018.07.11.04.30.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 04:30:13 -0700 (PDT) Received-SPF: pass (google.com: domain of joro@8bytes.org designates 81.169.241.247 as permitted sender) client-ip=81.169.241.247; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@8bytes.org header.s=mail-1 header.b=en9hSk4h; spf=pass (google.com: domain of joro@8bytes.org designates 81.169.241.247 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 659538F7; Wed, 11 Jul 2018 13:30:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1531308604; bh=PFTcFHATf/euI89FyiCX6ghifaBmqhDD9QfrXtzXoJY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=en9hSk4hYOsD++3w38gifiwWkGDk58uaqFDcZxi8Ua3e6KXFE+CHpqX054Afg3Pfq qUaCARjgPsJvNMzcLa9R72QqlW6WiU5CP78c1nIpOKjiLHpc4rZEfW1TiNrn4g+rvM IDHFjDRblXNu2Ce+svqvkDfe4196OFpb5TmyymV2fV28okORCElj4411F5kuAmDYyv dnY94nfDuubDt0L3wWdVWJkqKM9t/FKK3A4i+C7jNiuK7Xyb1FO51kQQCluDBxgZMV kyCwFGC/WALY4M89mG3dPw1LU4IN5mKDtHc6BlsCoRxq2qOjAp4TqTP3kJqKT/7Rfg 4dPrJn2YfFR6g== 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 21/39] x86/mm/pae: Populate valid user PGD entries Date: Wed, 11 Jul 2018 13:29:28 +0200 Message-Id: <1531308586-29340-22-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531308586-29340-1-git-send-email-joro@8bytes.org> References: <1531308586-29340-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 Generic page-table code populates all non-leaf entries with _KERNPG_TABLE bits set. This is fine for all paging modes except PAE. In PAE mode only a subset of the bits is allowed to be set. Make sure we only set allowed bits by masking out the reserved bits. Signed-off-by: Joerg Roedel --- arch/x86/include/asm/pgtable_types.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index 99fff85..b64acb0 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -50,6 +50,7 @@ #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL) #define _PAGE_SOFTW1 (_AT(pteval_t, 1) << _PAGE_BIT_SOFTW1) #define _PAGE_SOFTW2 (_AT(pteval_t, 1) << _PAGE_BIT_SOFTW2) +#define _PAGE_SOFTW3 (_AT(pteval_t, 1) << _PAGE_BIT_SOFTW3) #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT) #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE) #define _PAGE_SPECIAL (_AT(pteval_t, 1) << _PAGE_BIT_SPECIAL) @@ -266,14 +267,37 @@ typedef struct pgprot { pgprotval_t pgprot; } pgprot_t; typedef struct { pgdval_t pgd; } pgd_t; +#ifdef CONFIG_X86_PAE + +/* + * PHYSICAL_PAGE_MASK might be non-constant when SME is compiled in, so we can't + * use it here. + */ + +#define PGD_PAE_PAGE_MASK ((signed long)PAGE_MASK) +#define PGD_PAE_PHYS_MASK (((1ULL << __PHYSICAL_MASK_SHIFT)-1) & PGD_PAE_PAGE_MASK) + +/* + * PAE allows Base Address, P, PWT, PCD and AVL bits to be set in PGD entries. + * All other bits are Reserved MBZ + */ +#define PGD_ALLOWED_BITS (PGD_PAE_PHYS_MASK | _PAGE_PRESENT | \ + _PAGE_PWT | _PAGE_PCD | \ + _PAGE_SOFTW1 | _PAGE_SOFTW2 | _PAGE_SOFTW3) + +#else +/* No need to mask any bits for !PAE */ +#define PGD_ALLOWED_BITS (~0ULL) +#endif + static inline pgd_t native_make_pgd(pgdval_t val) { - return (pgd_t) { val }; + return (pgd_t) { val & PGD_ALLOWED_BITS }; } static inline pgdval_t native_pgd_val(pgd_t pgd) { - return pgd.pgd; + return pgd.pgd & PGD_ALLOWED_BITS; } static inline pgdval_t pgd_flags(pgd_t pgd)