Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5427303imm; Tue, 12 Jun 2018 07:43:10 -0700 (PDT) X-Google-Smtp-Source: ADUXVKI6uY6nbEjfPM31hwF+nT3pAFVHHaHJ4op5iWn+M9oGErgAhOa+n6B9ps19Ju0lCK4XE9u/ X-Received: by 2002:a17:902:784d:: with SMTP id e13-v6mr711284pln.197.1528814590613; Tue, 12 Jun 2018 07:43:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528814590; cv=none; d=google.com; s=arc-20160816; b=jWYYcVF049CTR96iS2J26rjq1c7JtO9G7DuX6tyRuKHmpPr+eC3QYsDz3nMVk2F5cD gphfOihKyd60nlBiz0+rrcPUsJ+69fFBIpzLvpzbxYGcVAfxMza03J1LilsLBtY597jJ eu+n9wMuxIYLXIDcYkr332Lus4F8w5NvqY1KK6AXX0cF8xGrZ51Hug91Ri5SQG+nRrpE THkgICci4wWmbc99qUlqofvQ3Bv7/ptarPXzd1vs2HJT8kO9fvHt+x2ZmTAL6z4v5lbC peiVeUlL1N/EB3Gj5v4Ls8PsrqnqrRyuPNaPZ9ZZQ8PPTMlkcIRzadsEX7eeYZaLhgOi kneg== 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=kxW7VtK00rzRCitGj/zIxCfEBhtp7jHOw5kyqyXwaeE=; b=MXTZv6lwSfAa2j56AgI/Xliu7XWHnMbj94+8IEd+kiS5heQH/KNKuDxqNewOeYtqVN rzWO7v2d9KhvhNonXrJSV79LU4OVBkJfFEMllRzL8UV26aItz6G8p60G2XKMejeQt5KU RQ+G1hGFVQBScTzSFfs7fguF6XWs1QWno8yTSXpNa9nm8z3cZtDQN8o+HugkP7akYfyD 31618AyQsi7urNzsqez3FiGYBS0aEuJTMK6oJ3BO+MJDC+0mNhuKjqURN3OjXUfRPLPS SF9yaG7k4nIKaomuC1BUrgSm7cD7WhWwDyCqw3uFnirMdaLftXog1yIo6tO3bJmxUkzR ltMw== 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 i69-v6si223360pge.674.2018.06.12.07.42.56; Tue, 12 Jun 2018 07:43:10 -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 S934414AbeFLOkf (ORCPT + 99 others); Tue, 12 Jun 2018 10:40:35 -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 S934284AbeFLOj3 (ORCPT ); Tue, 12 Jun 2018 10:39:29 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) 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="48732446" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga008.jf.intel.com with ESMTP; 12 Jun 2018 07:39:24 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id F140E440; Tue, 12 Jun 2018 17:39:20 +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 08/17] x86/mm: Implement vma_is_encrypted() and vma_keyid() Date: Tue, 12 Jun 2018 17:39:06 +0300 Message-Id: <20180612143915.68065-9-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 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. VMA is encrypted if KeyID is non-zero. vma_is_encrypted() checks that. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/mktme.h | 9 +++++++++ arch/x86/mm/mktme.c | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/arch/x86/include/asm/mktme.h b/arch/x86/include/asm/mktme.h index df31876ec48c..08f613953207 100644 --- a/arch/x86/include/asm/mktme.h +++ b/arch/x86/include/asm/mktme.h @@ -3,10 +3,19 @@ #include +struct vm_area_struct; + #ifdef CONFIG_X86_INTEL_MKTME extern phys_addr_t mktme_keyid_mask; extern int mktme_nr_keyids; extern int mktme_keyid_shift; + +#define vma_is_encrypted vma_is_encrypted +bool vma_is_encrypted(struct vm_area_struct *vma); + +#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 467f1b26c737..3b2f28a21d99 100644 --- a/arch/x86/mm/mktme.c +++ b/arch/x86/mm/mktme.c @@ -1,5 +1,22 @@ +#include #include phys_addr_t mktme_keyid_mask; int mktme_nr_keyids; int mktme_keyid_shift; + +bool vma_is_encrypted(struct vm_area_struct *vma) +{ + return pgprot_val(vma->vm_page_prot) & mktme_keyid_mask; +} + +int vma_keyid(struct vm_area_struct *vma) +{ + pgprotval_t prot; + + if (!vma_is_anonymous(vma)) + return 0; + + prot = pgprot_val(vma->vm_page_prot); + return (prot & mktme_keyid_mask) >> mktme_keyid_shift; +} -- 2.17.1