From patchwork Tue Jul 17 11:20:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A . Shutemov" X-Patchwork-Id: 10529031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1736D603ED for ; Tue, 17 Jul 2018 11:22:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04DFE28C20 for ; Tue, 17 Jul 2018 11:22:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED33528C0F; Tue, 17 Jul 2018 11:22:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65DE528C0F for ; Tue, 17 Jul 2018 11:22:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 585A76B0277; Tue, 17 Jul 2018 07:21:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3CAD36B0278; Tue, 17 Jul 2018 07:21:58 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 105226B027B; Tue, 17 Jul 2018 07:21:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by kanga.kvack.org (Postfix) with ESMTP id AFC116B0278 for ; Tue, 17 Jul 2018 07:21:57 -0400 (EDT) Received: by mail-pg1-f198.google.com with SMTP id 132-v6so323192pga.18 for ; Tue, 17 Jul 2018 04:21:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=rYMWfSoXuMb2oWqDHGe0r6iG6Cw+ogj7+GlnAOZFbRY=; b=mlGDjlJCFw6IBjb+2924vVoROp7lxnocI70rVS0r9v798Kx5Q5ct/omUNZaOSLFHAX OnkRSLka5hafOniPDdMDhzDCNzhLxcTMm7/OiVlc5aFrtprXoIbueQQP/VZmZ8Vrq3Nt 7KAt+xVixQS89RVVNfN6fYjkKkW+TQX9ws/hotY/rU1k3v1GR400Eg8+FriUPeml3eDc uB4YxR/v950MeNafwn54n3nHqpiHpTBcSNTg5XilZMkLOP+VooYimaN89Ib7+YYZsizD g+CSeS4ZZJVjBbMdcFLGyQks/fP4yKMH187Ia85A3lZmw4XEhez5c3h+YAKtkH0kiIaV g9sw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AOUpUlGHcPG9d+qi2By3zRfAlt/MyBgy+r/ZMLpaemCM/ot1EJe/5/sU 00/qYNa+S9VOsCc5vV1oWhxzSNUjhA+ayZCGlMutCopctcOgM3MmuFIsuoGamYVQTSsLm9vDBgx PbY/JSz7HPerOidrF5rjL9gIDyR9tikxN5bOZoFLttaO1fdSSEkv3mhnc5LolTLTMhw== X-Received: by 2002:a65:5c02:: with SMTP id u2-v6mr1195080pgr.304.1531826517388; Tue, 17 Jul 2018 04:21:57 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfkS6ByiXz65mHVTFMdtEJ9Vu77ePGfECe1i6vna+bxB6awJyQvWRKHExOeHXMXZKirNpva X-Received: by 2002:a65:5c02:: with SMTP id u2-v6mr1195040pgr.304.1531826516634; Tue, 17 Jul 2018 04:21:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531826516; cv=none; d=google.com; s=arc-20160816; b=RKxs8ILwLC1EC2gv3re4G+hrb8LlQquDsYaeRie6FnmNRQacloR6xNZXO0/a5uL5w0 d7tFZWJ5hKoopWn9tzwxf4XjmxQPoH+iCm1Rh+YBEkTt5G/r5sgscF5sMVTLAMuZEwkl Ilce5H6zHMmKXw65nUG1uFh2XY+I3m0k610rX1LK0npEeR8euZi9ACEVasEeYQsCqEND l2wJmCpZtsrk+xeudwyG16f5zG2tqQuSGsKAHRJTk+cpYw3509v1oE6DSoHr9+7oWfj5 moLFkxOXO0i7syk4w+laK65oqePSnm4ntpbeHybE3xxLYF8vYboRB5C2vEjYYtnC1dd2 YHTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=rYMWfSoXuMb2oWqDHGe0r6iG6Cw+ogj7+GlnAOZFbRY=; b=z9C2EGTillwH2ntwI35CXZ9fiPzL4nMhszo9qV6T2bu9RdfzpzsYtdAfXc2Bkt8A28 P/mmzXb4KVr7EY87Gs7P/nID/fAgCKd4E9/UzwrjxEbkUXt0q0DtxjA97lCB7Bl2EPGs oBmySwDtKITVuQmlN4cIQubppF8OCvNOqUBzfp7z0+YYdLApPekL5tq7nqj1dW0oLs21 677BQH7+OIRjvwwGCNCkuyW3O2q8mNZXaPl7rxFpXPTX99cLXPCzza5+p91DHekSMmBF HCawPn3HIagJYVSod5VhDHvSpa8b0igcRT7NhxNFooOpMTLeHDC531AApwtOKuvGVhi7 MuLQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga11.intel.com (mga11.intel.com. [192.55.52.93]) by mx.google.com with ESMTPS id b23-v6si597132pls.341.2018.07.17.04.21.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 04:21:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.93 as permitted sender) client-ip=192.55.52.93; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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;