From patchwork Tue Dec 4 07:39:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alison Schofield X-Patchwork-Id: 10711229 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3958D13BF for ; Tue, 4 Dec 2018 07:37:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2796C2A46B for ; Tue, 4 Dec 2018 07:37:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AEB82A544; Tue, 4 Dec 2018 07:37:43 +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=unavailable 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 BB9FB2A46B for ; Tue, 4 Dec 2018 07:37:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C8C356B6D8D; Tue, 4 Dec 2018 02:37:27 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 95D386B6D93; Tue, 4 Dec 2018 02:37:27 -0500 (EST) 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 5FE506B6D94; Tue, 4 Dec 2018 02:37:27 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f197.google.com (mail-pf1-f197.google.com [209.85.210.197]) by kanga.kvack.org (Postfix) with ESMTP id D6B2D6B6D90 for ; Tue, 4 Dec 2018 02:37:26 -0500 (EST) Received: by mail-pf1-f197.google.com with SMTP id i3so13366870pfj.4 for ; Mon, 03 Dec 2018 23:37:26 -0800 (PST) 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:in-reply-to :references; bh=VMi4JcyKXvHAwfNOWqwaIbkVM7b+Bbw86BRoAAgBw6M=; b=Okfynzis0c8/SL4czDaepmXkftkFE+1C5Mqxw+s6mKNhrA/E6VqacY6LJIAiLOVljP B2COrbrGBr06Rt86pDqqZbwC3pLJG3InsgIM56gzQFmzK2QvboH0O2E8YhFS8hIB0nTE d5E1RWqMnc0ekBV9mXEirbBZmMbRXoeQbbwh2prIKWuZjiJ19JJAZOIIG9K4unDeqnPM pjsxgbIF2sczkvb9tQMaf7cZVXLmQgeSMla9+o9KL9ueil8WlJmENPql4AkgiaAl4jxz iTbqjKzpH9jJBGDTq5/NBhq0qsMWrkNRpoAyKd7jjefTVVBVLsrNNcXqambpwulanKnn nhxg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of alison.schofield@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=alison.schofield@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: AA+aEWbSUt5U+6WzSFijAO1CQBXltE32w4pGLqPi6it1uKMfu3htcOEN FWh54gTwTPWvf7Ky3M4RIKDVrU3MVa5NjOiFIJrpyAOPuYVyVQZTOOzmkLm1zlSnJzL3kpczNOU oCzkRMnFOnVNMNovWPhsTHWxhmnKf53SVWzQvNuyysTF+XoK9ZxUVXX4iB6Ytlr7V/g== X-Received: by 2002:a63:f34b:: with SMTP id t11mr15994206pgj.341.1543909046527; Mon, 03 Dec 2018 23:37:26 -0800 (PST) X-Google-Smtp-Source: AFSGD/XZwOh7qdUxA7g8lfhrzQ+kXRCUSyM/nSf79nH5deNI2qqSmxgpFFbnL9kAR8RnZKfiu1uV X-Received: by 2002:a63:f34b:: with SMTP id t11mr15994185pgj.341.1543909045653; Mon, 03 Dec 2018 23:37:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543909045; cv=none; d=google.com; s=arc-20160816; b=Z81j5Ors9mRDLzQEFxGM7I2IWjU9s5TO5aMPq3QKFSz7D1UKVxdGK4+rbGlUPyARMB FOXpQ1KtAop2mYGMbcW9Cbq0qz6MvZQxvIZRlEtDazIQXVGihQ903KIpn74b2hFYxo3h OM/M82u8G61ppNTlPSDeeAi2XisAHq0mr+2aqUn5I4xyAVejUu2+Cuj2Xiqa0gjBfJ9K 6bEXVhkPbVzQ6834lOsZglE1IhZQjRXy0jFvM5JSvlkNZriS1x6nyjb6EBQqP2P3gGN9 rbP/rgB57zCnYaJb3BbnXckmp7L4rVugkMCUcfbZkqsr7/wGQJxkm2kayTWfBZ3usMFb 6iQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:cc:to:from; bh=VMi4JcyKXvHAwfNOWqwaIbkVM7b+Bbw86BRoAAgBw6M=; b=fQYxHiMXASzM6Vg48N5bW4n7QttnbrO603VZD/BNOJkL280ym/h5RqOAm7qbl4LisR sJmnYHgy01DcxT+fNxxd2u96TaICsDOWZ+0/0qhnWn3um8lmYGw106BR3aHseHF5q07O 5IxYPoSE7jZ4iDsFWEqB0BHcUBKVbU+vCxSj+64rvP8V74UPMGStLG723vW8wQcdfLxg UXRM1yrhRN1MCbNl6z4rAlO1bcFVgc6fn4VBmLqFBVgiLJGHDA0afRQxhvAxn7t3DKgf 7DcpNMKXxwAc6vU37fV09mHDvxh4NiKnXvXGdPN075QFYnFAyR0DX+jiOgNdfyFEnh/Q A3Rg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of alison.schofield@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=alison.schofield@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga01.intel.com (mga01.intel.com. [192.55.52.88]) by mx.google.com with ESMTPS id 28si21308808pfm.50.2018.12.03.23.37.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 23:37:25 -0800 (PST) Received-SPF: pass (google.com: domain of alison.schofield@intel.com designates 192.55.52.88 as permitted sender) client-ip=192.55.52.88; Authentication-Results: mx.google.com; spf=pass (google.com: domain of alison.schofield@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=alison.schofield@intel.com; dmarc=pass (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 fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Dec 2018 23:37:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,313,1539673200"; d="scan'208";a="115858977" Received: from alison-desk.jf.intel.com (HELO alison-desk) ([10.54.74.53]) by FMSMGA003.fm.intel.com with ESMTP; 03 Dec 2018 23:37:24 -0800 From: Alison Schofield To: dhowells@redhat.com, tglx@linutronix.de Cc: jmorris@namei.org, mingo@redhat.com, hpa@zytor.com, bp@alien8.de, luto@kernel.org, peterz@infradead.org, kirill.shutemov@linux.intel.com, dave.hansen@intel.com, kai.huang@intel.com, jun.nakajima@intel.com, dan.j.williams@intel.com, jarkko.sakkinen@intel.com, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org Subject: [RFC v2 08/13] mm: Use reference counting for encrypted VMAs Date: Mon, 3 Dec 2018 23:39:55 -0800 Message-Id: <985ba614d49986fdfc0397434fd1dd9eb5646c6f.1543903910.git.alison.schofield@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: 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 The MKTME (Multi-Key Total Memory Encryption) Key Service needs a reference count on encrypted VMAs. This reference count is used to determine when a hardware encryption keyid is in use, which in turn, tells the key service what operations can be safely performed with this keyid. The approach is: 1) Increment/decrement the reference count during encrypt_mprotect() system call for initial or updated encryption on a VMA. 2) Piggy back on the new vm_area_dup/free() helpers. If the VMAs being duplicated, or freed are encrypted, adjust the reference count. Signed-off-by: Alison Schofield Signed-off-by: Kirill A. Shutemov --- arch/x86/mm/mktme.c | 2 ++ kernel/fork.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/arch/x86/mm/mktme.c b/arch/x86/mm/mktme.c index facf08f9cb74..55d34beb9b81 100644 --- a/arch/x86/mm/mktme.c +++ b/arch/x86/mm/mktme.c @@ -145,10 +145,12 @@ void mprotect_set_encrypt(struct vm_area_struct *vma, int newkeyid, if (oldkeyid == newkeyid) return; + vma_put_encrypt_ref(vma); newprot = pgprot_val(vma->vm_page_prot); newprot &= ~mktme_keyid_mask; newprot |= (unsigned long)newkeyid << mktme_keyid_shift; vma->vm_page_prot = __pgprot(newprot); + vma_get_encrypt_ref(vma); /* * The VMA doesn't have any inherited pages. diff --git a/kernel/fork.c b/kernel/fork.c index 07cddff89c7b..d12d27b50966 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -341,12 +341,14 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) if (new) { *new = *orig; INIT_LIST_HEAD(&new->anon_vma_chain); + vma_get_encrypt_ref(new); } return new; } void vm_area_free(struct vm_area_struct *vma) { + vma_put_encrypt_ref(vma); kmem_cache_free(vm_area_cachep, vma); }