Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3402894imm; Tue, 17 Jul 2018 04:23:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd87seaCOjzQVCv9ZolkF7IloDMDn/t7p/G99wv+53KynZg++XxxV502KtkVSWX818jpbyP X-Received: by 2002:a17:902:3181:: with SMTP id x1-v6mr1238634plb.198.1531826584892; Tue, 17 Jul 2018 04:23:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531826584; cv=none; d=google.com; s=arc-20160816; b=cIwTQ1RGs7MxY6CmWRAAKExws5hA1B+JM4mWgacSg4ueT2G8IgbYB3my1LoA2amLmu W099guxOgNxiAnhfDEJhDDGXXiZr3xFIqAXsWFBNvXS2pPlU+kYYW6pBeguORaTdjHid DASb4WV6ADWI/AqaUDcdiS8OCw12OSagbS+DMToarEYNs/ensf+3dmBsEWna1JGT3zUz MOptuFvv2EYC96IDdkrZ4AehSPeZQAqd8+9P9FesgCQ0RcRjL8UiLu+UZTtXTD3Z0nqZ qf8l1h20r993GHOZP7cGm6nHbr1mcdq6T0Sxks/KFAYr3ENtzkHvnuYx05CUOaKjggCi BdtQ== 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=eX4hOL6mdxo8wovE4LKiTmPsdPR3/h2k6AOvEOcUYBA=; b=Xcyko7WkVCYguZ/3y26o+guBvsnpNjX9ZuTo0q6WfE11U/W+OsU5cG1z06ZtMi6ldb JrbntynRpkrb7O/YFZl+OFDysR1qYIWr0/raIa5AyFveItwbGBymzT64Po+ii8ex86vM xOl6UTjekaaWV4R6vvVvVlwy3QfvQcFoPZ+x0T1JMEz3KJLsjrwjXqIXgpg9faMObmB1 mAIw/vVmD5/MbeBYo+DJBks4RssCqd0Xj/yZm/HI0OywZsO9IfUVkyreJm9tax20036C zufMnvOLrtCrBh2BGWagddugQFrNZrwc5kIWnqhUsrq4Ri5DjcpB/AHs19je1KtRRpfD 00jw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j4-v6si637701plt.126.2018.07.17.04.22.49; Tue, 17 Jul 2018 04:23:04 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731642AbeGQLyN (ORCPT + 99 others); Tue, 17 Jul 2018 07:54:13 -0400 Received: from mga07.intel.com ([134.134.136.100]:40796 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731570AbeGQLyN (ORCPT ); Tue, 17 Jul 2018 07:54:13 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2018 04:22:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,365,1526367600"; d="scan'208";a="67665022" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 17 Jul 2018 04:21:45 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 188D351B; Tue, 17 Jul 2018 14:21:49 +0300 (EEST) From: "Kirill A. Shutemov" To: Ingo Molnar , x86@kernel.org, Thomas Gleixner , "H. Peter Anvin" , Tom Lendacky Cc: Dave Hansen , Kai Huang , Jacob Pan , linux-kernel@vger.kernel.org, linux-mm@kvack.org, "Kirill A. Shutemov" Subject: [PATCHv5 09/19] x86/mm: Preserve KeyID on pte_modify() and pgprot_modify() Date: Tue, 17 Jul 2018 14:20:19 +0300 Message-Id: <20180717112029.42378-10-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180717112029.42378-1-kirill.shutemov@linux.intel.com> References: <20180717112029.42378-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 An 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 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index 99fff853c944..3731f7e08757 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -120,8 +120,21 @@ * protection key is treated like _PAGE_RW, for * instance, and is *not* included in this mask since * pte_modify() does modify it. + * + * They include the physical address and the memory encryption keyID. + * The paddr and the keyID never occupy the same bits at the same time. + * But, a given bit might be used for the keyID on one system and used for + * the physical address on another. As an optimization, we manage them in + * one unit here since their combination always occupies the same hardware + * bits. PTE_PFN_MASK_MAX stores combined mask. + * + * Cast PAGE_MASK to a signed type so that it is sign-extended if + * virtual addresses are 32-bits but physical addresses are larger + * (ie, 32-bit PAE). */ -#define _PAGE_CHG_MASK (PTE_PFN_MASK | _PAGE_PCD | _PAGE_PWT | \ +#define PTE_PFN_MASK_MAX \ + (((signed long)PAGE_MASK) & ((1ULL << __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.18.0