Received: by 10.223.185.116 with SMTP id b49csp2777905wrg; Mon, 5 Mar 2018 08:32:03 -0800 (PST) X-Google-Smtp-Source: AG47ELsvXIcy1J+VyN/FpnHi9JZfB7GdcJz/ruavd0MTlz4bzXhKxnKkHWP1/0ZFNZaXk3u097LF X-Received: by 2002:a17:902:684a:: with SMTP id f10-v6mr13996009pln.129.1520267523621; Mon, 05 Mar 2018 08:32:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520267523; cv=none; d=google.com; s=arc-20160816; b=VVlt5Ng8O+an5ocMcQsYwWPt09Dvs731VbAQHPJ4zdX4N3l/ADvwyrtRmusRnlv52T ttcGBJxHP1Widozi08CDBP2T/xrZokGCF17kms3i2/t3eOPlYAi2CyujTjOUReL1UeVv gJZEbIquhDAfm/EhanlFxwUKxoC0R0KspdHfEBxkkI5tAUmjrFafL+PsNz/SZ0WScIjV 8AN5xJzH7WlTHNROVCgO5D0T+q0+8jnnvdZCfFlqaNTvnZljIDINzWKGP2ybLkKmRd6y p1bAcuK8U7E8UGGUReYVjYTBLiFuhipCSM+Sb77FZkmWMJw9Ci6tH8ZYZGz+CMBLDU8L z3ug== 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=FVnmJY/F5Q1EiLj8T7cvtgTgITGJm5lV3USSXZzeJ8Q=; b=OPVEwRLAvf+EsIrN4UCohCMrwjtwuLfwO6QSb6wBRTj0u4eNNFJlcw1gaOFTxnQf+T lAJo25E7/cg/z7rBbAv3mXyE2fJ6mxCvIif5J3xdLPoojPbZNb0xZPCHR5LQdG7eyNTk J9MjmVVrWcptSmEUVRnziWCBTbBsgIs6tlttKSDJB+GaV5kw4HBnzZiQkZPC4XBq4A0v azMqnHxPSUmFyZrtzXFQMSRK0OFEkxEZz+NC4iM0xTZqdQal78cos0Bv1pNPeipZnzQs bzi6iVg6LTuz896QpYWbkEjgM1qDBkTo3FUdRJNOcjeDqh8xQbOXRsX7R0I0Nhwaovaz hZ1Q== 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 r15-v6si9434339pls.127.2018.03.05.08.31.48; Mon, 05 Mar 2018 08:32:03 -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 S1752878AbeCEQ2M (ORCPT + 99 others); Mon, 5 Mar 2018 11:28:12 -0500 Received: from mga17.intel.com ([192.55.52.151]:37471 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752630AbeCEQ0a (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:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.47,427,1515484800"; d="scan'208";a="35620830" 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 D04CC888; 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 20/22] x86/mm: Implement anon_vma_encrypted() and anon_vma_keyid() Date: Mon, 5 Mar 2018 19:26:08 +0300 Message-Id: <20180305162610.37510-21-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 This patch implements helpers to check if given VMA is encrypted and with which KeyID. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/mktme.h | 14 ++++++++++++++ arch/x86/mm/mktme.c | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/arch/x86/include/asm/mktme.h b/arch/x86/include/asm/mktme.h index c8f41837351a..56c7e9b14ab6 100644 --- a/arch/x86/include/asm/mktme.h +++ b/arch/x86/include/asm/mktme.h @@ -4,11 +4,20 @@ #include struct vm_area_struct; +struct anon_vma; struct page *__alloc_zeroed_encrypted_user_highpage(gfp_t gfp, struct vm_area_struct *vma, unsigned long vaddr); #ifdef CONFIG_X86_INTEL_MKTME +#define arch_anon_vma arch_anon_vma +struct arch_anon_vma { + int keyid; +}; + +#define arch_anon_vma_init(anon_vma, vma) \ + anon_vma->arch_anon_vma.keyid = vma_keyid(vma); + extern phys_addr_t mktme_keyid_mask; extern int mktme_nr_keyids; extern int mktme_keyid_shift; @@ -19,6 +28,11 @@ bool vma_is_encrypted(struct vm_area_struct *vma); #define vma_keyid vma_keyid int vma_keyid(struct vm_area_struct *vma); +#define anon_vma_encrypted anon_vma_encrypted +bool anon_vma_encrypted(struct anon_vma *anon_vma); + +#define anon_vma_keyid anon_vma_keyid +int anon_vma_keyid(struct anon_vma *anon_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 ef0eb1eb8d6e..69172aabc07c 100644 --- a/arch/x86/mm/mktme.c +++ b/arch/x86/mm/mktme.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -28,6 +29,16 @@ int vma_keyid(struct vm_area_struct *vma) return (prot & mktme_keyid_mask) >> mktme_keyid_shift; } +bool anon_vma_encrypted(struct anon_vma *anon_vma) +{ + return anon_vma_keyid(anon_vma); +} + +int anon_vma_keyid(struct anon_vma *anon_vma) +{ + return anon_vma->arch_anon_vma.keyid; +} + void prep_encrypt_page(struct page *page, gfp_t gfp, unsigned int order) { void *v = page_to_virt(page); -- 2.16.1