Received: by 10.213.65.68 with SMTP id h4csp638654imn; Wed, 28 Mar 2018 09:59:07 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/iC+z/1NlumLmQ1ugS8UANNbNuYm0nFnWi2XD7H5dUEGvSLXMeqZbQATvYrzDvb73yUFFW X-Received: by 2002:a17:902:6a81:: with SMTP id n1-v6mr34027plk.342.1522256347427; Wed, 28 Mar 2018 09:59:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522256347; cv=none; d=google.com; s=arc-20160816; b=rfh9ZfVQfkTD3WQIQPs9bcalHMQaJxM9i9VCCnOHS8Jt9UsYzmfUtTDKhUM/poqeWH zsUQYNwMFJp50cTFhueTbKkVVOYgdHlT6xe/IxD/lIP20DzHR90+nkDo6HKGLGK+vpGF BSzdRLGelEtAF+pVpdKK3gZKq6vg5Hc4c/qpieVX4uMevWHsgCyj/PjVtc4OyJ1XXA65 Bgaf0ocm5MTQ3jLDmgQFgQlDJvX/khn+9E/RDw2SQrNEbnhGvROfGaN/d70XZhIjXv2V b3GqEy3kGRRSx3pLDfgJNDS6qN5hL1QT3B+Nvv0CjgI/tfl/TS3xM/epQI5L7nF0K0CL Ly6A== 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=2aQBu+X+ObG7ZJEDcWO3gI43VYo6djIyY23sa2BaJXw=; b=NFidLJ1sZJblKSBC0DN1ATytFRyWLlIFD5WtAhOqZ10AKG/ZjG77mM/Kq1n7Qxsc4A EDvXlU3KiZ8JdjVzJu6LRpF3WVmqHJvNYsTkSpP/4/VvRp1kLCmc+fC5EA4MSDa8+X8T v3v6Hw9M+ZtpP4ipj1sBD+FRukYSbY+JYFhezzVCwomA6OVIP6mrIyl2sVUEDCvV2ntu rSWuWFXJLWwpeImect4RUtiIlIyAPAlurTiO6JbCwvrR8dtRl6tdfNTONGQqB5uRukHq g+ZbTtdWKAUODRg1lOdwk2UtbqblVOkDYw7zWWWbIuFylxVn7+oqtts+qbLtEhp7LRjg QNMg== 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 c22-v6si4125686plz.279.2018.03.28.09.58.53; Wed, 28 Mar 2018 09:59: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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753221AbeC1Q5O (ORCPT + 99 others); Wed, 28 Mar 2018 12:57:14 -0400 Received: from mga02.intel.com ([134.134.136.20]:53107 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752547AbeC1Qzv (ORCPT ); Wed, 28 Mar 2018 12:55:51 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Mar 2018 09:55:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,372,1517904000"; d="scan'208";a="42043588" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 28 Mar 2018 09:55:47 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id AA4F5744; 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 12/14] x86/mm: Implement page_keyid() using page_ext Date: Wed, 28 Mar 2018 19:55:38 +0300 Message-Id: <20180328165540.648-13-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 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 | 12 ++++++++++++ arch/x86/include/asm/page.h | 1 + arch/x86/mm/mktme.c | 12 ++++++++++++ include/linux/page_ext.h | 11 ++++++++++- mm/page_ext.c | 3 +++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/mktme.h b/arch/x86/include/asm/mktme.h index 08f613953207..5f440d57aa47 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,17 @@ 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 +static inline int page_keyid(struct page *page) +{ + if (!mktme_nr_keyids) + return 0; + + return lookup_page_ext(page)->keyid; +} + #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..3da25212a372 100644 --- a/arch/x86/mm/mktme.c +++ b/arch/x86/mm/mktme.c @@ -20,3 +20,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 bbec618a614b..5b9cb41ec1ca 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 5295ef331165..be0d7da8f5ea 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.16.2