From patchwork Wed Jul 18 09:40:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 10531875 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 31B0D602CA for ; Wed, 18 Jul 2018 09:42:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 21EEE28FBC for ; Wed, 18 Jul 2018 09:42:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15B0728FCD; Wed, 18 Jul 2018 09:42:47 +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 B055328FBC for ; Wed, 18 Jul 2018 09:42:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DC246B0288; Wed, 18 Jul 2018 05:41:37 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 83A676B029D; Wed, 18 Jul 2018 05:41:37 -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 700456B029E; Wed, 18 Jul 2018 05:41:37 -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 D3C5E6B0288 for ; Wed, 18 Jul 2018 05:41:36 -0400 (EDT) Received: by mail-ed1-f71.google.com with SMTP id n2-v6so1704913edr.5 for ; Wed, 18 Jul 2018 02:41:36 -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=khCT7LJUjJmrEIZZGnZP39lIk888f8Tzft2KEA/oS5bciUEaKpYr2UZ0ZdqblN7IDq DkD/BPch9vh7tWaDN2tQ44R4ifyXndePzkxn3/fSDWhr/Xe5EwRpxPUvPlWRtN2mAlyq yzUwaxXBLVso3dbulyDs0TKJqeRXMePcSmJImTuXxnH25Se/JOpOZ0pKqx6fl9nxeST+ X9G0Z+RaWB+RAGdKxwT6PbfjPkAGxiEE4mnnu8gg2HdJek0xPjKiIg30WyUITbdPL8Er cg0H/D2Qg8DNRjhO9Br3ioKCOVCc5hR4MwCa7whyJtdcPlJnkBE/4X5WEZQjW6UJQ1AS PmYg== X-Gm-Message-State: AOUpUlGpPXKDS3vrx6aRdxnLzHMiknnOpSzCZ78LStSYMaNr7GDm3hes 9PkvmaIFahWuv1F9Q0EjCZNhvARp6mhGPfTUnGle8KGNAdnBADyk4crUOYdfNpfkU7DDp9hRYkL UVaDT2JYbsP7+Bh/feOuTDovprHuHZIWGzpj61TBo1KRpYgi9ZlryQY+DdeMyjB+dIw== X-Received: by 2002:a50:a7a2:: with SMTP id i31-v6mr6571885edc.296.1531906896436; Wed, 18 Jul 2018 02:41:36 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfXMmiKgBuJSN9N3cBarMsF/ZNzHFzGXMCSGWsIuh9dMsljgkwHaFLTkRDj/1mCPyKw0/Pc X-Received: by 2002:a50:a7a2:: with SMTP id i31-v6mr6571850edc.296.1531906895800; Wed, 18 Jul 2018 02:41:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531906895; cv=none; d=google.com; s=arc-20160816; b=d/cH77FZBAGSzCen+lgAgUVS1wX3Pw6bCxxiq0lr9C2tF8mTwwk/Y7vwrClp97U0Bc qGrL83nz6sMDpcJRE4wQ8gPQ4q2khPZDcL8R8aEHwt8T9gsBPoIFavkzblyxb+xgdKFu /iVCnm8D5uTHcd1HYSOyWTT9zTI53bhkUrrKLpEtsK262SXaDjrL7O4OhqXrioIK6ijZ zmbLhSKohNiCu2n0+vnF6hoxP11AuxlqJgIje389mdBnKiJ8vMN1vvNAsiZ+d2ZjG8pv 5ZQgUbCrOW7OiVN7VnCxlB6M3Bmg1uXyfOdIfUcVJzpGlRW/j40X3L7TuVvQqV/oll1S p9Ew== 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=JJK9CF07QlW6ihzAf94/MXcdigEtmY0LJdcrFhflzWov7AeMUoVVtjBM1EyodS5jrE 7M+zdlYwgNIhBwJn0VTrfJMpGN7vxh3ZzWcmFR7oVM747Uu/2sKJbmZhQbwM8CzjLdTV G/YdwdQGa3ju8eZTA0SrUoEn+5lS4hoynFGmy0uPZOYf4wgl2WM2WjsopYGgJ0o3vOnQ /CWoJ/rMXqz/xnXtwyPNUZwBikAgNItWjI0AB7PUI2tuc+BL6r8PYRzx6KxRtjvSEWLY 9K8gNmeT7z71QeqLAT40rrGU53zS6Lk4unKSjUZV31Hhhf51UUcdHlIz6iiqIPjiKJqc NotQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@8bytes.org header.s=mail-1 header.b=Qu51K4O8; 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 l11-v6si2343173edc.382.2018.07.18.02.41.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jul 2018 02:41:35 -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=Qu51K4O8; 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 B5B3FAA3; 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=1531906883; bh=PFTcFHATf/euI89FyiCX6ghifaBmqhDD9QfrXtzXoJY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qu51K4O8Sborqb/86q2MTFZgWs+I5VF/mXWK++dxnkR5qpKzY/fvzzAf8DNRrZVK6 0dN+xmEPB9LoEmY1LDW2ObjWiP946aAtBaWMZhvWbyO9rAU3RWrR2HIRoECGlTZ/UU Dn4uagMlAwO5mb1I7ccHS9IQBPw908aP5mnZy0WXFdWdlea4xRs/QdGY7gGuBR5jGU okFBYff/sNSkBycZr4XIlNjndO5I1W8/xQqONbGmjKSJiaV983dmNOkAbkdrbZpPFt KzhboHhWcdiOL+H1YkVTedIwND4WAoY01yT6S3tOMeglOdGX2JM4qG85s1v6pWTmaI MZoIfOyMc5Zhw== 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, 18 Jul 2018 11:40:58 +0200 Message-Id: <1531906876-13451-22-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 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)