From patchwork Fri Dec 30 16:19:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 9492319 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 F305C62AB9 for ; Fri, 30 Dec 2016 16:19:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF66C1FF15 for ; Fri, 30 Dec 2016 16:19:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D466222638; Fri, 30 Dec 2016 16:19:17 +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=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7E3311FF15 for ; Fri, 30 Dec 2016 16:19:17 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 7C48881864 for ; Fri, 30 Dec 2016 08:19:17 -0800 (PST) X-Original-To: intel-sgx-kernel-dev@lists.01.org Delivered-To: intel-sgx-kernel-dev@lists.01.org Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 4789D81864 for ; Fri, 30 Dec 2016 08:19:16 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 30 Dec 2016 08:19:15 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,432,1477983600"; d="scan'208";a="803626517" Received: from arsehgal-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.6.21]) by FMSMGA003.fm.intel.com with ESMTP; 30 Dec 2016 08:19:14 -0800 From: Jarkko Sakkinen To: intel-sgx-kernel-dev@lists.01.org Date: Fri, 30 Dec 2016 18:19:03 +0200 Message-Id: <20161230161904.20777-3-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161230161904.20777-1-jarkko.sakkinen@linux.intel.com> References: <20161230161904.20777-1-jarkko.sakkinen@linux.intel.com> Subject: [intel-sgx-kernel-dev] [PATCH 2/3] intel_sgx: pin the backing page inside sgx_eldu X-BeenThere: intel-sgx-kernel-dev@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Project: Intel® Software Guard Extensions for Linux*: https://01.org/intel-software-guard-extensions" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-sgx-kernel-dev-bounces@lists.01.org Sender: "intel-sgx-kernel-dev" X-Virus-Scanned: ClamAV using ClamSMTP Encapsulted pinning of the backing page into sgx_eldu in order to drop duplicate code. Signed-off-by: Jarkko Sakkinen --- drivers/platform/x86/intel_sgx_vma.c | 47 +++++++++++++++--------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/drivers/platform/x86/intel_sgx_vma.c b/drivers/platform/x86/intel_sgx_vma.c index e8a67b6..ff72e63 100644 --- a/drivers/platform/x86/intel_sgx_vma.c +++ b/drivers/platform/x86/intel_sgx_vma.c @@ -110,18 +110,26 @@ static void sgx_vma_close(struct vm_area_struct *vma) kref_put(&encl->refcount, sgx_encl_release); } -static int do_eldu(struct sgx_encl *encl, - struct sgx_encl_page *encl_page, - struct sgx_epc_page *epc_page, - struct page *backing, - bool is_secs) +static int sgx_eldu(struct sgx_encl *encl, + struct sgx_encl_page *encl_page, + struct sgx_epc_page *epc_page, + bool is_secs) { + struct page *backing; struct sgx_page_info pginfo; void *secs_ptr = NULL; void *epc_ptr; void *va_ptr; int ret; + backing = sgx_get_backing(encl, encl_page); + if (IS_ERR(backing)) { + ret = PTR_ERR(backing); + sgx_warn(encl, "pinning the backing page for ELDU failed with %d\n", + ret); + return ret; + } + pginfo.srcpge = (unsigned long)kmap_atomic(backing); if (!is_secs) secs_ptr = sgx_get_epc_page(encl->secs_page.epc_page); @@ -144,10 +152,13 @@ static int do_eldu(struct sgx_encl *encl, if (!is_secs) sgx_put_epc_page(secs_ptr); + sgx_put_backing(backing, 0); + kunmap_atomic((void *)(unsigned long)pginfo.srcpge); - WARN_ON(ret); - if (ret) + if (ret) { + sgx_err(encl, "ELDU returned %d\n", ret); return -EFAULT; + } return 0; } @@ -159,7 +170,6 @@ static struct sgx_encl_page *sgx_vma_do_fault(struct vm_area_struct *vma, struct sgx_encl_page *entry; struct sgx_epc_page *epc_page = NULL; struct sgx_epc_page *secs_epc_page = NULL; - struct page *backing; unsigned int free_flags = SGX_FREE_SKIP_EREMOVE; int rc; @@ -218,15 +228,7 @@ static struct sgx_encl_page *sgx_vma_do_fault(struct vm_area_struct *vma, goto out; } - backing = sgx_get_backing(encl, &encl->secs_page); - if (IS_ERR(backing)) { - entry = (void *)backing; - goto out; - } - - rc = do_eldu(encl, &encl->secs_page, secs_epc_page, - backing, true /* is_secs */); - sgx_put_backing(backing, 0); + rc = sgx_eldu(encl, &encl->secs_page, secs_epc_page, true); if (rc) goto out; @@ -237,22 +239,13 @@ static struct sgx_encl_page *sgx_vma_do_fault(struct vm_area_struct *vma, secs_epc_page = NULL; } - backing = sgx_get_backing(encl, entry); - if (IS_ERR(backing)) { - entry = (void *)backing; - goto out; - } - - rc = do_eldu(encl, entry, epc_page, backing, false /* is_secs */); + rc = sgx_eldu(encl, entry, epc_page, false /* is_secs */); if (rc) { - sgx_put_backing(backing, 0); entry = ERR_PTR(rc); goto out; } rc = vm_insert_pfn(vma, entry->addr, PFN_DOWN(epc_page->pa)); - sgx_put_backing(backing, 0); - if (rc) { free_flags = 0; goto out;