Received: by 10.213.65.68 with SMTP id h4csp641946imn; Wed, 28 Mar 2018 10:01:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+9pHrAkc45+h4cbja/GCJCZ8H/XPtF5Jhu7PpZqzgqK8/iNjPw8RBBvYfbnutEwTsFrmPa X-Received: by 10.99.97.203 with SMTP id v194mr3059592pgb.373.1522256515819; Wed, 28 Mar 2018 10:01:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522256515; cv=none; d=google.com; s=arc-20160816; b=Vh+3i6KRVC+vil61w4hYRKJ+PtNDGBPdd+uxKsojpGor87O5M6CujZLYW9LkZqMZ33 aMVjUCbC8piblZI0rv/D2wNoaogfG5ye6S6vDYkQGUouX1JbR2SqUjKE2/uL65xAk6nm gkR/0HKaiIDHu3VnkJ4urAPPaz2PKAkqd788CZeFseXMUNrfvZCeD+Olel2LlhP9vppk dH2G5k1RVU7jS1tSFke7PCOEM7tBMZpmZmV+hXvTmjOC6jnvgNfHwsUFPnkeSEN/6ZvF dwZ/FxPqQAzfxu7M7rcaY54OJbvW6Kc5rCfkB99RrtTjvbnARarSqqqbtTYuS0D3jHnJ LyRA== 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=3occEk9RfMYcS1SGvWxhJ735WIKgOQE2Xf11O/4Vtfo=; b=z3Hava8xX/xyxrN7ZqgmXGDbYYbbYKS0XkSplN2vgkQhLa6qlzjlpXoMYjNgLp2PA7 1YuSzuPA53YoyAfPeTG8oUiqo4H7tXIenXpHlkzBnuY6qM6lVrYu1/tsChNMoqW2ryIP sKtH+HYhx0lD5tgyDspYcqd5pJow72r2Et/dWw1QNVts3wO3RJ5okQX9W33JMkmqFyRj /lu0bmsTAETYs9YN0eNj/milslpDN6czIHQZ3pZ7t0dwuXu54iATLkQaMHMuBjlmXPrr PKYuLH9NmL/OetYtqnidsohJ/L/EVHMZGNciUU1So+Qp1P3ewvg/J+eWQYc+8ENxSeY8 yR+Q== 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 l186si2722435pge.224.2018.03.28.10.01.35; Wed, 28 Mar 2018 10:01:55 -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 S1753296AbeC1Q6t (ORCPT + 99 others); Wed, 28 Mar 2018 12:58:49 -0400 Received: from mga04.intel.com ([192.55.52.120]:25299 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752318AbeC1Qzu (ORCPT ); Wed, 28 Mar 2018 12:55:50 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.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="41487324" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga004.fm.intel.com with ESMTP; 28 Mar 2018 09:55:47 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 9F1C8589; 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 11/14] x86/mm: Implement vma_is_encrypted() and vma_keyid() Date: Wed, 28 Mar 2018 19:55:37 +0300 Message-Id: <20180328165540.648-12-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 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.16.2