From patchwork Tue Jun 12 14:39:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A . Shutemov" X-Patchwork-Id: 10460507 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0616C602A0 for ; Tue, 12 Jun 2018 14:39:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0007287E2 for ; Tue, 12 Jun 2018 14:39:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3FA3287E6; Tue, 12 Jun 2018 14:39:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F9D3287E2 for ; Tue, 12 Jun 2018 14:39:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 44C0F6B000E; Tue, 12 Jun 2018 10:39:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 32DBA6B026B; Tue, 12 Jun 2018 10:39:29 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23EB96B026C; Tue, 12 Jun 2018 10:39:29 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f70.google.com (mail-pg0-f70.google.com [74.125.83.70]) by kanga.kvack.org (Postfix) with ESMTP id BF9A56B000E for ; Tue, 12 Jun 2018 10:39:28 -0400 (EDT) Received: by mail-pg0-f70.google.com with SMTP id d2-v6so3958820pgq.22 for ; Tue, 12 Jun 2018 07:39:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=kxW7VtK00rzRCitGj/zIxCfEBhtp7jHOw5kyqyXwaeE=; b=UH9bk1IJYiVoLL55ClUvM5aaLn4P1c5po7gS4klwq8Guyx1KUm6A80PAt9qeTY+uE8 chVSVIEVtz5zgCOpX1KfplszATShM/8ud7YeP9bHQDcqcj7hbdFvfyaZ4oyGbWzMDarj H+1O/z73UfclaU8qn/HojoMygT+/ZBM4Fou0wyP6hMqFN5Hh1Be9vajwXt4o+O5tMt8k 8h/nDBtA5OoLlg3yRdt7n+iPh6nIkii+NM8Wj6nQc6dSCmZ8HV7bo9MAR+BypC1tQ+if nMd8OKPuYkZeF6B8Y+sd6aoC4stYpmv9zaCpQhdScoz5+eO/QsYZEnrRbLom9iSPPLWX ghtA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: APt69E18dLJGnqp8wh6eJgKQ0qDKStE6GDczh6dmqnIQJs0HkoACyHcn OAYPtJU/PKhx61dImAJe68k6Re7rHOKxomWjLhNhzO65oK0QhA/nwcaGr8pp4Bst1ovVlIwQz8h n91UgnTBhr4T78zW5fTnF0Ig446YuIvuld1zT7k54l5oneFFAU3yfWDbpYxRQIeckpQ== X-Received: by 2002:a17:902:224:: with SMTP id 33-v6mr699209plc.309.1528814368492; Tue, 12 Jun 2018 07:39:28 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJvvjZ+Yg8LQVI4UaKF8EoRUo9Jrl5a1X+ghU3m48jXUwJKtfV31yO5e9Vi4fsOkxgSX2o9 X-Received: by 2002:a17:902:224:: with SMTP id 33-v6mr699156plc.309.1528814367590; Tue, 12 Jun 2018 07:39:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528814367; cv=none; d=google.com; s=arc-20160816; b=BoSnbqPcWkemYfdRpjQk41gDrDalDm6qgI7xkthbzBLQiw1d/TTQcH0ShE5TJ14Xy8 fJijYAEb5YLDDXI52fIKNKQiX60gjSoWCO1RXp1W/u+kKpbTm4kHGUmI1nmQ9crecGWX kuNa0PL79o8DyppAzVk6W+3G6CojTL4cTIlNghZS403wheQWeWWfA3ERVFJ03qfvKR9t FmKoVmOuMfLDivaWgUEcZWKj5uRQfINs49YizZzJMzuRC0zeWZyS3Cd2EoC3xIkp4d+k FQrrg8Hu89IVOgi/HXsJSOpw/zf6cTpNQxqRfIre/PjHQ72KNGJGuWvwH3f2f5wVZKP3 ukyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=kxW7VtK00rzRCitGj/zIxCfEBhtp7jHOw5kyqyXwaeE=; b=FcCnkI2W83QIfN63aEGiSWQNFCo5LJzvOmcUXslXv1cGt2Mv2PW4Wt7xK78gHTnCGc oiBzQsHm5prjFXtyuO5iTXjq0dKBB7X4aY06dzAUCPKk+cz8lrBEPNjBLo01j3rojvpY z63fxY44RycnU+R4No+U6p4/fN0d0XpRp+57bTPA9QPUTzOY66ZPJJLXtyOoRnEnEhht fLEDYzuMWtLmI0g1rSKPdoe20y0UWqMb9FWTd/R0ZbEXR0fSysNUmRhmpEWhUtUVyaQB XryKK4Z1Y/MD/5xSeTx3JqQ5p4aQOYgYVeMKxYllueM2nSbdw33daie23kyhExkQogex S/gg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga18.intel.com (mga18.intel.com. [134.134.136.126]) by mx.google.com with ESMTPS id w1-v6si242590pgp.10.2018.06.12.07.39.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jun 2018 07:39:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.126 as permitted sender) client-ip=134.134.136.126; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of kirill.shutemov@linux.intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=kirill.shutemov@linux.intel.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.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> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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; +}