Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3404169imm; Tue, 17 Jul 2018 04:24:30 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeCR4MPdg5wGoCWbqyNlu5xmlmpQHy8yWEuTDs65cP4sEfQtWFrqKhdA4uK3REg5WiW33QI X-Received: by 2002:a62:8917:: with SMTP id v23-v6mr257874pfd.127.1531826670377; Tue, 17 Jul 2018 04:24:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531826670; cv=none; d=google.com; s=arc-20160816; b=wK5QnENPyF8zLhamafrWefYtWDahzGDROZUpLmr6ISlh+bmNvLHSnUe+4HaPCmmskr 0GO5A4Xmqq9r6p4jg5vv4yA/X2P8bmvFmcwOjhkp8R4YhLAMVurgDjmLhLExqUivWEF8 9nFBZl/LjLzhmwfNH5SvYe4SqHNYXLqgz0uo24rc0SD69eFOgf+z75aL8UMwfyJK+YC5 MYOYpNhUjs4t+Rd5hMJMhsuBQS2EedY9Ipf9xvXu7xgHTqBdKDcal/uUqcI/17sjc0cH 8FjipjJWSfWgYMe1FaTnxbSOI5fRs1lw7G7ZQRxMtclO5nEPMQpuG8lr8kFBzCfeSuXr GTpg== 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=rYMWfSoXuMb2oWqDHGe0r6iG6Cw+ogj7+GlnAOZFbRY=; b=Qz5TJSa+y0fGIVrcsJN66HgRSWm4HTfYGtfxQTCGUlHLyQQ34MOrOj7K3x5qF14Hw8 Z9T6LD/DdDt1MQoAaCXu1rW4ayYj/eNxvlKLcE3tqMe4Wr2hFEUWxfYT0oXsbClhkmIG EkmmoiImmwAFfyEVhNCGFIRirJCvRmePRmVWmCfFqyyUR9Zqn/IMtneyjH3hqZ2CYbjW 9JH3mpxmENODdzNqLzGNFa/x+BpDQNdCR+XvFywmX6gs3l3xB1KqdUQ3d9oGQBY1dk6J uyKoLZDVqUvaoFvJ/7mrPfRwGKn9Prnq9GwTqrYqm4v+XasjeXKtJiBem1FCuisItBOD tYaA== 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 p1-v6si665285plb.204.2018.07.17.04.24.15; Tue, 17 Jul 2018 04:24:30 -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 S1731602AbeGQLyL (ORCPT + 99 others); Tue, 17 Jul 2018 07:54:11 -0400 Received: from mga18.intel.com ([134.134.136.126]:40529 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731086AbeGQLyF (ORCPT ); Tue, 17 Jul 2018 07:54:05 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2018 04:21:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,365,1526367600"; d="scan'208";a="245908269" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 17 Jul 2018 04:21:46 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 2170D669; 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 10/19] x86/mm: Implement page_keyid() using page_ext Date: Tue, 17 Jul 2018 14:20:20 +0300 Message-Id: <20180717112029.42378-11-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 Store KeyID in bits 31:16 of extended page flags. These bits are unused. page_keyid() returns zero until page_ext is ready. page_ext initializer enables static branch to indicate that page_keyid() can use page_ext. The same static branch will gate MKTME readiness in general. 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 | 7 +++++++ arch/x86/include/asm/page.h | 1 + arch/x86/mm/mktme.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/page_ext.h | 11 ++++++++++- mm/page_ext.c | 3 +++ 5 files changed, 55 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/mktme.h b/arch/x86/include/asm/mktme.h index df31876ec48c..7266494b4f0a 100644 --- a/arch/x86/include/asm/mktme.h +++ b/arch/x86/include/asm/mktme.h @@ -2,11 +2,18 @@ #define _ASM_X86_MKTME_H #include +#include #ifdef CONFIG_X86_INTEL_MKTME extern phys_addr_t mktme_keyid_mask; extern int mktme_nr_keyids; extern int mktme_keyid_shift; + +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 467f1b26c737..09cbff678b9f 100644 --- a/arch/x86/mm/mktme.c +++ b/arch/x86/mm/mktme.c @@ -3,3 +3,37 @@ phys_addr_t mktme_keyid_mask; int mktme_nr_keyids; int mktme_keyid_shift; + +static DEFINE_STATIC_KEY_FALSE(mktme_enabled_key); + +static inline bool mktme_enabled(void) +{ + return static_branch_unlikely(&mktme_enabled_key); +} + +int page_keyid(const struct page *page) +{ + if (!mktme_enabled()) + return 0; + + return lookup_page_ext(page)->keyid; +} +EXPORT_SYMBOL(page_keyid); + +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 !!mktme_nr_keyids; +} + +static void init_page_mktme(void) +{ + static_branch_enable(&mktme_enabled_key); +} + +struct page_ext_operations page_mktme_ops = { + .need = need_page_mktme, + .init = init_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.18.0