Received: by 10.223.185.116 with SMTP id b49csp2775307wrg; Mon, 5 Mar 2018 08:30:01 -0800 (PST) X-Google-Smtp-Source: AG47ELuhQNFiazaq7Z+L/4gFRPb13gaY3R0smNl1LY0mSFweXmfD+Nk0vB6uZr3uQ/rjBD7q5lO7 X-Received: by 10.99.115.73 with SMTP id d9mr13074251pgn.354.1520267401501; Mon, 05 Mar 2018 08:30:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520267401; cv=none; d=google.com; s=arc-20160816; b=JB2SHn6XKNf176OdZv27q4gIEu6uSjrYjwJ8lhDS/SAmztNs+INyE0bBOcOCY5p/hA c3+alyR+z0om4TsXl/5cNWYCcuUGwjU1vunI1kf+8sTKs7a6kAvLBoc7ch7HNTI6wpx+ V0bulbDkWyjdh92uaLk/FGieJvRBHnvh+eq9nSuWuS3Ly0Vwa/CuyFAgqSuKQsTjWLIw iAbKgghOo7QTJsA9B7odOdSoNUQA1sdWS9kLdpZi+duR2kB0AhxxcwErpE4V7F/rfS/o +1XcC4uwcNTrECIPbH74/y33h3aDtvFPLsiUQ/GW6uA+Iwx9OPomgNSfYgZXFAdMS8HT +m+g== 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=9DRcNJfEQA3/AVUlZSWAKtn60UD3mKHbIBsEO6Qmeds=; b=H7kV2vRarbt8Mgh1DY8FwOlUsy09RjextG4qpmOIhr9RvD4Lo2JCkfiwOYfhmOTk2T sIWDUzyOLoFgM/jQWeE+9sFYJQUfz9aVCjcXht7GDKQw3arADrbL0XNppJ5JBHotfsDQ E2L4kY1+jFyU7tQG5kuBTGbH4g4o6KHyhG3bkIu9wojShFV1YJ2pJIAgigxLpiYNhau3 EnInELSwVQ62OOzD5yxLSu3nB60JjSms7i8Td5I3eaVyBeerNwFnS7vB21vUpoQR77VU Yk9ou4b2GwP235YN3Liki0B+rQO9nEGtx5Xs2y1UwV/OctSxgqB6q750KFG/Zfvnx4J9 B0sw== 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 t18si10467360pfg.246.2018.03.05.08.29.47; Mon, 05 Mar 2018 08:30:01 -0800 (PST) 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 S1752957AbeCEQ2Y (ORCPT + 99 others); Mon, 5 Mar 2018 11:28:24 -0500 Received: from mga17.intel.com ([192.55.52.151]:37468 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752618AbeCEQ0a (ORCPT ); Mon, 5 Mar 2018 11:26:30 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2018 08:26:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,427,1515484800"; d="scan'208";a="35620828" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 05 Mar 2018 08:26:27 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id A1BCF683; Mon, 5 Mar 2018 18:26:20 +0200 (EET) 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: [RFC, PATCH 17/22] x86/mm: Implement vma_is_encrypted() and vma_keyid() Date: Mon, 5 Mar 2018 19:26:05 +0300 Message-Id: <20180305162610.37510-18-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180305162610.37510-1-kirill.shutemov@linux.intel.com> References: <20180305162610.37510-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.1