Received: by 10.223.185.116 with SMTP id b49csp2469716wrg; Mon, 5 Mar 2018 03:32:05 -0800 (PST) X-Google-Smtp-Source: AG47ELsmqTp/OHemkuKkYh8H87aCStTtoXOWeQBV23iJwS4FWfOp/MBDjbBfkqjN7mv39LDy6W7A X-Received: by 10.98.139.18 with SMTP id j18mr15144041pfe.179.1520249525611; Mon, 05 Mar 2018 03:32:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520249525; cv=none; d=google.com; s=arc-20160816; b=PnWhAFkYhi93HCMeuttHvYkt378iBVSgiEuklZ3aL28e/jrY3wN8VP5ZgG/ACdUNzo VZdzGXTKzjPvUUEicrw6y1t96irkH4WNCaj0XQctqhlsf+4RFgcEV0LlN42+chaT9S9X yOVoUp0fqjFGACo1Sk6eAA5D1SEnp/5YeYkDf8VpGjdmTNnSwdLYahrWhj+kXtEzO+/r LSMbXSK18MsP6cqIaLYPqS8seR+mqxPGOf7lb7YwmOZhcHrl1UoyUB5ki52As9k6DV4Q r09u9hS3w7ZDex0dGQxRs4K58zmlVhN8X5aYAQt4ul82xW7mERszl6/q+/ZUjlQ1Qzsx oaSA== 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=OtmgrQzGNTF1dKS8rsrXdj2gmkkzEVOS8D3O/x8SeY0=; b=APwB2vUTW2GEpGUVrf8F7d6JPOFFWemmySMIUXj1zWErQ7TrM6uYeXnidTwEslzz7K fSnGjebKQW6RrlrKKTdsCBNtx/FUP37itqu+Ty5I0qgaQTKlmdMOrY0IWcb/nsHDrh7q iaMMDuaFXhKhT8ZyqDNi38lIdQvjG4pXp2ak0zAIlGcPwMFFHroUxzPBjvopKVrTckkc /oNSV1AIKYpGdSmyJe0pUs4nuTm1ZXbrnrGV9yP3ITOfNmiRYK7qHgoXmshMdJWy39o+ lsVje0n4n8I47bfmUMHuUlC21VvHO8fEsD+ZsOvnXc0CooV1k7FfCfueXXC8wU1SRFFY unqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@8bytes.org header.s=mail-1 header.b=pKB12yeu; 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 g1si1071046pgo.257.2018.03.05.03.31.50; Mon, 05 Mar 2018 03:32:05 -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=pKB12yeu; 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 S933907AbeCEK0i (ORCPT + 99 others); Mon, 5 Mar 2018 05:26:38 -0500 Received: from 8bytes.org ([81.169.241.247]:54458 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933728AbeCEK0R (ORCPT ); Mon, 5 Mar 2018 05:26:17 -0500 Received: by theia.8bytes.org (Postfix, from userid 1000) id 64115949; Mon, 5 Mar 2018 11:26:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1520245568; bh=s9CAfuRFmkLetJEfLXhvoueZHgcpMNk9aFSLl7VcuXA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pKB12yeuoNCQyT1uLB5+aEmNC0uERsFDFBz5t7S+PaDs1QqbhYnkunWv6PC/m1s+N iTncCVebpATcmbcVcGpA0pfqkqYbPr+8T88g/Z8+vejiIp1ziVUlEtAl1QP18zBoPm 9LOq9j4bhzhJ6BokIIYpbVKFCm1Eq2+FFwyqu5DjMtJf9j7jUwVT7W0AqwAkoJt5sE O5sGF/M8P/8WnlOXrbRy6AePPiQBmMGHIsY94ZAHBYdyzmzzyuSc2GSRyVReldep6v SsgkETHtfVrQt7V/rugjrPVzhZjS1Q0W6Iqd9A7lb9dtv/YWdL+n7F9t1qr+WF+ilV fnNLQTYE6LgvQ== 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 21/34] x86/mm/pae: Populate valid user PGD entries Date: Mon, 5 Mar 2018 11:25:50 +0100 Message-Id: <1520245563-8444-22-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 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 3696398..48fc70b 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) @@ -267,14 +268,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) -- 2.7.4