Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3404427imm; Tue, 17 Jul 2018 04:24:46 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe4d9KPAm2zQBX5xwB2vtULVE4otr+TYFeaIC5kIdlBqxg5cXcrqJ8PF7PUqECJKINA6V7B X-Received: by 2002:a17:902:3081:: with SMTP id v1-v6mr1278700plb.266.1531826686908; Tue, 17 Jul 2018 04:24:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531826686; cv=none; d=google.com; s=arc-20160816; b=nvr1t7OcSwZ3IjUnSA7dY2swZuM8qGwgVtzCn1YuJlLtRVcd1Sy52ZfYilUYI3IGQH 8NITBNif6T1AemfaMStSM2aRlBJ//Ykf2TRhoTbMR/0s0bi52huAwBdBWRlAHPlT6Dlf 93dZ+zx+fOfHnmQbLfOdZ/u/zqyccGckTp8RTbpZ+nfbPSsjboY1vIaD9YSRe21fdiPu xyZPKgfp/IkoFQVlJ2vwbYXHfT5b9LNAvROCIF839WbBHizUqHRDKncElK2fSgT53PUh deB1hoi+XQxg3gEpdfKVWpNOqVrrLln2m54UrOCd9RliXYSvzV3pffIWgIO+F8l+XnaP Pafw== 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=+iL4oijNKpTNW3lrWT/HfOVJIAiXHqKSeh8gVOe0sxU=; b=0vnVc2IjGTniRdjyOR30KZzjCl19QmSiLAdFUF53nFC16hONMZE78/cJpVMbW2dJn0 24GQD6IK2qImlqXCinHq9Bsh0djblK00kFUGxOBp+cZBPkHslscylfAYZRLN7zUej169 ssDGE8Rej48Ta2d7T8DbCgCP7gIN+raiAObQExUypU87yo35XxBDCSUMVpq7b4wcU4X4 LO1FS4uQwoVx4G/Er/5rPfJ9wZHZTA7EfM5MTv0W9hs5P02P9l1QuG9NHCmzs6bTHVS4 zIZR3p3Tf1ItQDGaX7bvOrkkGLx2cqBjcKpyrA2YLarY0mzIX7usKvNzKdEJZtxLJvAc LcJg== 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 k23-v6si659539pgl.633.2018.07.17.04.24.31; Tue, 17 Jul 2018 04:24:46 -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 S1731479AbeGQLx7 (ORCPT + 99 others); Tue, 17 Jul 2018 07:53:59 -0400 Received: from mga01.intel.com ([192.55.52.88]:16951 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731458AbeGQLx7 (ORCPT ); Tue, 17 Jul 2018 07:53:59 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Jul 2018 04:21:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,365,1526367600"; d="scan'208";a="58320644" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 17 Jul 2018 04:21:45 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 293D270F; 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 11/19] x86/mm: Implement vma_keyid() Date: Tue, 17 Jul 2018 14:20:21 +0300 Message-Id: <20180717112029.42378-12-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 We store KeyID in upper bits for vm_page_prot that match position of KeyID in PTE. vma_keyid() extracts KeyID from vm_page_prot. With KeyID in vm_page_prot we don't need to modify any page table helper to propagate the KeyID to page table entires. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/mktme.h | 5 +++++ arch/x86/mm/mktme.c | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/arch/x86/include/asm/mktme.h b/arch/x86/include/asm/mktme.h index 7266494b4f0a..f0b7844e36a4 100644 --- a/arch/x86/include/asm/mktme.h +++ b/arch/x86/include/asm/mktme.h @@ -4,6 +4,8 @@ #include #include +struct vm_area_struct; + #ifdef CONFIG_X86_INTEL_MKTME extern phys_addr_t mktme_keyid_mask; extern int mktme_nr_keyids; @@ -14,6 +16,9 @@ extern struct page_ext_operations page_mktme_ops; #define page_keyid page_keyid int page_keyid(const struct page *page); +#define vma_keyid vma_keyid +int vma_keyid(struct vm_area_struct *vma); + #else #define mktme_keyid_mask ((phys_addr_t)0) #define mktme_nr_keyids 0 diff --git a/arch/x86/mm/mktme.c b/arch/x86/mm/mktme.c index 09cbff678b9f..a1f40ee61b25 100644 --- a/arch/x86/mm/mktme.c +++ b/arch/x86/mm/mktme.c @@ -1,3 +1,4 @@ +#include #include phys_addr_t mktme_keyid_mask; @@ -37,3 +38,14 @@ struct page_ext_operations page_mktme_ops = { .need = need_page_mktme, .init = init_page_mktme, }; + +int vma_keyid(struct vm_area_struct *vma) +{ + pgprotval_t prot; + + if (!mktme_enabled()) + return 0; + + prot = pgprot_val(vma->vm_page_prot); + return (prot & mktme_keyid_mask) >> mktme_keyid_shift; +} -- 2.18.0