Received: by 10.223.185.116 with SMTP id b49csp2773131wrg; Mon, 5 Mar 2018 08:27:59 -0800 (PST) X-Google-Smtp-Source: AG47ELsN7esBHmyD4VwUq9eUruykPXGI1YLChYm50nH85WLQMh7R73XRmgPDR5rF7pbG0ENsS6Yj X-Received: by 2002:a17:902:848e:: with SMTP id c14-v6mr13904913plo.139.1520267279653; Mon, 05 Mar 2018 08:27:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520267279; cv=none; d=google.com; s=arc-20160816; b=TH6RtSuNRPxlS3TZ+EZAiggBbwXCri3lLpzOK3slY+zDYaCcxX3b4pDfBkuVGM4ydB Q34zntDPwCfVZHZJYnHCIz1vYd86bzP9WIvrBIGxurLEH8ahbf2uLruR6Of17IPHmVaA CfNnk/2gnO5DNDwM0JG892RWUeQcJob2doXTTC7sve/MjNvmfIBPdTUHsbRKa02LYuUv 9LS5S3zSC5JGse2fkVihjq6fvpARd7kNRR7jfV2IAShBtY+M8DKywGR3MmL7rRtv5kRo N9ZaCwtSAe+SXQ8cq0xBeLokc+cdyIt5ZFgMx+c2cAvhAlILQSeStqwD8H3snCtWiLrA BhxQ== 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=sWBCCQ+OvSmJOpp6eeMOBODP1/IY3KHCUtLLnGE6OD8=; b=lgaboQbvKZu+iiF06Ylvns6ylqMQlI5CKjslJQUhJ3DVtd5Uyrpe0wSq6pryJ1Ga2K 5iOzSuCXOmxZ1V6hoU/Sgr59E237LrDe8Ck1iH5IFsGMKn8x4PX8RCErU/yLpqIKDRVC X7ujplINxviap9G+dlXXToYbCFbpB0xi2LOfWx2f/3QpT/cxWce6L9WVIdMf5P0BnBgz a7REAqKGRHRkzjvPZFieNdK8duOuhm1svbV2Ijb5MwEOBDz3t38gkppFsmneYcllGTnN 3hk9m6Wc5GwAnxApqC2TUfnt/ZcSrv2STMFcybrlH0ZFJpKPayNJ+Bf5muD/ZuiZ1uog hkYA== 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 k6-v6si9477596pla.333.2018.03.05.08.27.45; Mon, 05 Mar 2018 08:27:59 -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 S1752757AbeCEQ0k (ORCPT + 99 others); Mon, 5 Mar 2018 11:26:40 -0500 Received: from mga01.intel.com ([192.55.52.88]:49459 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751679AbeCEQ0e (ORCPT ); Mon, 5 Mar 2018 11:26:34 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.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="208994407" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga006.fm.intel.com with ESMTP; 05 Mar 2018 08:26:27 -0800 Received: by black.fi.intel.com (Postfix, from userid 1000) id D6F9E832; 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 21/22] x86/mm: Introduce page_keyid() and page_encrypted() Date: Mon, 5 Mar 2018 19:26:09 +0300 Message-Id: <20180305162610.37510-22-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 The new helpers checks if page is encrypted and with which keyid. They use anon_vma get the information. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/asm/mktme.h | 14 ++++++++++++++ arch/x86/mm/mktme.c | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/arch/x86/include/asm/mktme.h b/arch/x86/include/asm/mktme.h index 56c7e9b14ab6..dd81fe167e25 100644 --- a/arch/x86/include/asm/mktme.h +++ b/arch/x86/include/asm/mktme.h @@ -33,10 +33,24 @@ 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); + +int page_keyid(struct page *page); #else + #define mktme_keyid_mask ((phys_addr_t)0) #define mktme_nr_keyids 0 #define mktme_keyid_shift 0 + +static inline int page_keyid(struct page *page) +{ + return 0; +} #endif +static inline bool page_encrypted(struct page *page) +{ + /* All pages with non-zero KeyID are encrypted */ + return page_keyid(page) != 0; +} + #endif diff --git a/arch/x86/mm/mktme.c b/arch/x86/mm/mktme.c index 69172aabc07c..0ab795dfb1a4 100644 --- a/arch/x86/mm/mktme.c +++ b/arch/x86/mm/mktme.c @@ -39,6 +39,23 @@ int anon_vma_keyid(struct anon_vma *anon_vma) return anon_vma->arch_anon_vma.keyid; } +int page_keyid(struct page *page) +{ + struct anon_vma *anon_vma; + int keyid = 0; + + if (!PageAnon(page)) + return 0; + + anon_vma = page_get_anon_vma(page); + if (anon_vma) { + keyid = anon_vma_keyid(anon_vma); + put_anon_vma(anon_vma); + } + + return keyid; +} + void prep_encrypt_page(struct page *page, gfp_t gfp, unsigned int order) { void *v = page_to_virt(page); -- 2.16.1