Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5427249imm; Tue, 12 Jun 2018 07:43:07 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIzYpN7WlWVveKGSSee+hvUOBlrsClyf5wOaU4G1YnmH0ynoImVqpXEuf5cm035ghdWtxTJ X-Received: by 2002:a63:b812:: with SMTP id p18-v6mr592257pge.11.1528814587413; Tue, 12 Jun 2018 07:43:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528814587; cv=none; d=google.com; s=arc-20160816; b=qpRq8MI2HggN9StzbrS10Z3m30G2c5XDwV4vm8GgZ4dOXSB6X4r+CO3qj/vp5/lNKj ws32xKS5ercDDFwj4Uxqz+O/xDE1rlVi5evqIqZ68nC8XbjpT+1CgxpmAHsS4T4WEyYn u9RhEIayfbBaIApGgtL1OQDh+HFg+rZvCrIjz0PBG8hMA7yvL2TMfJKnoqru8vmMoXCd jRmsyCmnnCfT7LxsUvtzP1IG3Tpj2sM8rzoRBN60GJ9CdIE7wx0z32Er+LyZsxUWzavG msRKRWtw/A1V8+YO0jalKAE5HEX6TsCGHiwLLuS8SZ3MjUuBrxWHBioSQEgL/tUt9CF/ fDXw== 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=X4NncAZsfLVXVh81JmLvpu2zI6KspJKOFQy+9eebDbQ=; b=FnU1fQgSKeeDJRhp3zNLTHJPN/KhEWd5nB/NK7ZTUXQiONTS+e8dtl2iPNpoCPzwYp nNadqFmxb/iOQtghlG7OOicKLpNcolcLiuIKiLb0SRlO/6VgsuSvxM/6I5zBnWpxTBw3 AGK8dF5nLOOxwFtTSvaIWV4730iN7cNobB+CSXexh8BmW9xySojzEJ2sY7fcdJyEPwJq 6NKcyjB3jn1+JK+8kNkM+SUazBI548AaS+kIXzRCd9IcBBfIfMZ/jcyxObs0SZDmM8bi ltbFg9mLcAth7l6OGyaxUKzWdBo+/8+mfWYhBMJCIdy6ArcDp4xjZfl5YiCjAmLwaXZy 9ZwA== 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 1-v6si282814plv.16.2018.06.12.07.42.53; Tue, 12 Jun 2018 07:43:07 -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 S934176AbeFLOkc (ORCPT + 99 others); Tue, 12 Jun 2018 10:40:32 -0400 Received: from mga07.intel.com ([134.134.136.100]:48199 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934290AbeFLOj3 (ORCPT ); Tue, 12 Jun 2018 10:39:29 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 12 Jun 2018 07:39:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,215,1526367600"; d="scan'208";a="207428844" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 12 Jun 2018 07:39:24 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 0631946D; Tue, 12 Jun 2018 17:39:21 +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: [PATCHv3 09/17] x86/mm: Implement page_keyid() using page_ext Date: Tue, 12 Jun 2018 17:39:07 +0300 Message-Id: <20180612143915.68065-10-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180612143915.68065-1-kirill.shutemov@linux.intel.com> References: <20180612143915.68065-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 Store KeyID in bits 31:16 of extended page flags. These bits are unused. We don't yet set KeyID for the page. It will come in the following patch that implements prep_encrypted_page(). All pages have KeyID-0 for now. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/mktme.h | 6 ++++++ arch/x86/include/asm/page.h | 1 + arch/x86/mm/mktme.c | 21 +++++++++++++++++++++ include/linux/page_ext.h | 11 ++++++++++- mm/page_ext.c | 3 +++ 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/mktme.h b/arch/x86/include/asm/mktme.h index 08f613953207..0fe0db424e48 100644 --- a/arch/x86/include/asm/mktme.h +++ b/arch/x86/include/asm/mktme.h @@ -2,6 +2,7 @@ #define _ASM_X86_MKTME_H #include +#include struct vm_area_struct; @@ -16,6 +17,11 @@ bool vma_is_encrypted(struct vm_area_struct *vma); #define vma_keyid vma_keyid int vma_keyid(struct vm_area_struct *vma); +extern struct page_ext_operations page_mktme_ops; + +#define page_keyid page_keyid +int page_keyid(const struct page *page); + #else #define mktme_keyid_mask ((phys_addr_t)0) #define mktme_nr_keyids 0 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h index 7555b48803a8..39af59487d5f 100644 --- a/arch/x86/include/asm/page.h +++ b/arch/x86/include/asm/page.h @@ -19,6 +19,7 @@ struct page; #include +#include extern struct range pfn_mapped[]; extern int nr_pfn_mapped; diff --git a/arch/x86/mm/mktme.c b/arch/x86/mm/mktme.c index 3b2f28a21d99..b02d5b9d4339 100644 --- a/arch/x86/mm/mktme.c +++ b/arch/x86/mm/mktme.c @@ -5,6 +5,15 @@ phys_addr_t mktme_keyid_mask; int mktme_nr_keyids; int mktme_keyid_shift; +int page_keyid(const struct page *page) +{ + if (mktme_status != MKTME_ENABLED) + return 0; + + return lookup_page_ext(page)->keyid; +} +EXPORT_SYMBOL(page_keyid); + bool vma_is_encrypted(struct vm_area_struct *vma) { return pgprot_val(vma->vm_page_prot) & mktme_keyid_mask; @@ -20,3 +29,15 @@ int vma_keyid(struct vm_area_struct *vma) prot = pgprot_val(vma->vm_page_prot); return (prot & mktme_keyid_mask) >> mktme_keyid_shift; } + +static bool need_page_mktme(void) +{ + /* Make sure keyid doesn't collide with extended page flags */ + BUILD_BUG_ON(__NR_PAGE_EXT_FLAGS > 16); + + return true; +} + +struct page_ext_operations page_mktme_ops = { + .need = need_page_mktme, +}; diff --git a/include/linux/page_ext.h b/include/linux/page_ext.h index f84f167ec04c..d9c5aae9523f 100644 --- a/include/linux/page_ext.h +++ b/include/linux/page_ext.h @@ -23,6 +23,7 @@ enum page_ext_flags { PAGE_EXT_YOUNG, PAGE_EXT_IDLE, #endif + __NR_PAGE_EXT_FLAGS }; /* @@ -33,7 +34,15 @@ enum page_ext_flags { * then the page_ext for pfn always exists. */ struct page_ext { - unsigned long flags; + union { + unsigned long flags; +#ifdef CONFIG_X86_INTEL_MKTME + struct { + unsigned short __pad; + unsigned short keyid; + }; +#endif + }; }; extern void pgdat_page_ext_init(struct pglist_data *pgdat); diff --git a/mm/page_ext.c b/mm/page_ext.c index a9826da84ccb..036658229842 100644 --- a/mm/page_ext.c +++ b/mm/page_ext.c @@ -68,6 +68,9 @@ static struct page_ext_operations *page_ext_ops[] = { #if defined(CONFIG_IDLE_PAGE_TRACKING) && !defined(CONFIG_64BIT) &page_idle_ops, #endif +#ifdef CONFIG_X86_INTEL_MKTME + &page_mktme_ops, +#endif }; static unsigned long total_usage; -- 2.17.1