Received: by 10.213.65.68 with SMTP id h4csp664805imn; Wed, 28 Mar 2018 10:26:19 -0700 (PDT) X-Google-Smtp-Source: AIpwx48nfh/OBrYG0xbXIcU5sZn9HUZCGkyyZ5YZT8wtROxQ/XnyDLwY5N+n/FkuFbBU7i10UxY2 X-Received: by 10.98.33.154 with SMTP id o26mr3706770pfj.54.1522257979664; Wed, 28 Mar 2018 10:26:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522257979; cv=none; d=google.com; s=arc-20160816; b=BtTT48seP6iNt1BqbrUTCvgYHck4es1YKjc5tDyZl615CLsUQRNI7psDasCGDEuMov ZiGGGdn9YVtPDo8IYxboiCP99vyCt+8IadZYF9ZJIbluhT3laPQM4ZTen0Lg37bBKbk+ d+/B3NV65ruYeTR4HuUrAxTCYHYKy244aDgu1DIsbd4wBtfSUGV34zTKuOc48BN7WHQa QXEDG1krDhDHdKhESyylYk2LWCFrunCJwhail9LT6oKdvfHAbjllh5mBWeNoBc29sqBd j7iqI6NL2e4d4ZrBpykE1gl1fowB9OmlDmsdXnpDA9xJ5s+RHys3zQssgvgMpFCmXBtP a60Q== 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:arc-authentication-results; bh=FVLjNgtYsIKMjPlS1qvXFLlJeHw4gDAEbkvTFuc5WXw=; b=LWxwPMa8R9Jf1fn2FaS6cNKqL7IPewP4uy0iogw7Tmjx+q2XNw8jcBq5U/hKw7a8tB BhHWOGgw6/OcL0ojqKLd0/UbzeXxmP4zsNahfBD9qqPoluV7W2gBoPtXJRO0FYvUk2rp 73Rnh7yO0AIduXQVXSafCpqszp/jLH1m5lxtoT/FajhqMfgNdwYY/2mE6zy9CJ4TZVUL jlHtTo2JOxzfuqX1vtCktcxv/F6hgOiQD2nliWwrMwLIyIOQ+M/gCYXS8hB/MrGJMmuH gsS1zDPcVOrN99oIMvomyVGb4R+ihScysDRcnvti+T5KTY2W1zurTxnXVNtHqgZzyKVH SAXQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1-v6si3936173plb.101.2018.03.28.10.26.03; Wed, 28 Mar 2018 10:26:19 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753259AbeC1Q6M (ORCPT + 99 others); Wed, 28 Mar 2018 12:58:12 -0400 Received: from mga12.intel.com ([192.55.52.136]:20183 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752447AbeC1Qzu (ORCPT ); Wed, 28 Mar 2018 12:55:50 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Mar 2018 09:55:49 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,372,1517904000"; d="scan'208";a="37608760" Received: from black.fi.intel.com ([10.237.72.28]) by FMSMGA003.fm.intel.com with ESMTP; 28 Mar 2018 09:55:47 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 952E153A; Wed, 28 Mar 2018 19:55:43 +0300 (EEST) From: "Kirill A. Shutemov" To: Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" , Tom Lendacky Cc: Dave Hansen , Kai Huang , linux-kernel@vger.kernel.org, linux-mm@kvack.org, "Kirill A. Shutemov" Subject: [PATCHv2 10/14] x86/mm: Preserve KeyID on pte_modify() and pgprot_modify() Date: Wed, 28 Mar 2018 19:55:36 +0300 Message-Id: <20180328165540.648-11-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180328165540.648-1-kirill.shutemov@linux.intel.com> References: <20180328165540.648-1-kirill.shutemov@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Encrypted VMA will have KeyID stored in vma->vm_page_prot. This way we don't need to do anything special to setup encrypted page table entries and don't need to reserve space for KeyID in a VMA. This patch changes _PAGE_CHG_MASK to include KeyID bits. Otherwise they are going to be stripped from vm_page_prot on the first pgprot_modify(). Define PTE_PFN_MASK_MAX similar to PTE_PFN_MASK but based on __PHYSICAL_MASK_SHIFT. This way we include whole range of bits architecturally available for PFN without referencing physical_mask and mktme_keyid_mask variables. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/pgtable_types.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index acfe755562a6..9ea5ba83fc0b 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -121,8 +121,13 @@ * protection key is treated like _PAGE_RW, for * instance, and is *not* included in this mask since * pte_modify() does modify it. + * + * It includes full range of PFN bits regardless if they were claimed for KeyID + * or not: we want to preserve KeyID on pte_modify() and pgprot_modify(). */ -#define _PAGE_CHG_MASK (PTE_PFN_MASK | _PAGE_PCD | _PAGE_PWT | \ +#define PTE_PFN_MASK_MAX \ + (((signed long)PAGE_MASK) & ((1UL << __PHYSICAL_MASK_SHIFT) - 1)) +#define _PAGE_CHG_MASK (PTE_PFN_MASK_MAX | _PAGE_PCD | _PAGE_PWT | \ _PAGE_SPECIAL | _PAGE_ACCESSED | _PAGE_DIRTY | \ _PAGE_SOFT_DIRTY) #define _HPAGE_CHG_MASK (_PAGE_CHG_MASK | _PAGE_PSE) -- 2.16.2