From patchwork Mon Jan 30 19:57:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 9546067 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 E5A5160417 for ; Mon, 30 Jan 2017 19:57:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA4BC2818B for ; Mon, 30 Jan 2017 19:57:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE182281C3; Mon, 30 Jan 2017 19:57:38 +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 81EF32818B for ; Mon, 30 Jan 2017 19:57:38 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3DBEB81F77 for ; Mon, 30 Jan 2017 11:57:38 -0800 (PST) X-Original-To: intel-sgx-kernel-dev@lists.01.org Delivered-To: intel-sgx-kernel-dev@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 316C481F77 for ; Mon, 30 Jan 2017 11:57:37 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga104.fm.intel.com with ESMTP; 30 Jan 2017 11:57:36 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,312,1477983600"; d="scan'208";a="815147126" Received: from mbrennan-mobl3.ger.corp.intel.com (HELO localhost) ([10.252.3.129]) by FMSMGA003.fm.intel.com with ESMTP; 30 Jan 2017 11:57:35 -0800 From: Jarkko Sakkinen To: intel-sgx-kernel-dev@lists.01.org Date: Mon, 30 Jan 2017 21:57:29 +0200 Message-Id: <20170130195730.14975-2-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170130195730.14975-1-jarkko.sakkinen@linux.intel.com> References: <20170130195730.14975-1-jarkko.sakkinen@linux.intel.com> Subject: [intel-sgx-kernel-dev] [PATCH v3 1/2] 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 | 53 ++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/drivers/platform/x86/intel_sgx_vma.c b/drivers/platform/x86/intel_sgx_vma.c index 6a23690..9cc8e83 100644 --- a/drivers/platform/x86/intel_sgx_vma.c +++ b/drivers/platform/x86/intel_sgx_vma.c @@ -93,25 +93,33 @@ 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; - pginfo.srcpge = (unsigned long)kmap_atomic(backing); + 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; + } + if (!is_secs) secs_ptr = sgx_get_epc_page(encl->secs_page.epc_page); pginfo.secs = (unsigned long)secs_ptr; epc_ptr = sgx_get_epc_page(epc_page); va_ptr = sgx_get_epc_page(encl_page->va_page->epc_page); + pginfo.srcpge = (unsigned long)kmap_atomic(backing); pginfo.linaddr = is_secs ? 0 : encl_page->addr; pginfo.pcmd = (unsigned long)&encl_page->pcmd; @@ -121,16 +129,19 @@ static int do_eldu(struct sgx_encl *encl, (unsigned long)va_ptr + encl_page->va_offset); + kunmap_atomic((void *)(unsigned long)pginfo.srcpge); sgx_put_epc_page(va_ptr); sgx_put_epc_page(epc_ptr); if (!is_secs) sgx_put_epc_page(secs_ptr); - kunmap_atomic((void *)(unsigned long)pginfo.srcpge); - WARN_ON(ret); - if (ret) + sgx_put_backing(backing, false); + + if (ret) { + sgx_err(encl, "ELDU returned %d\n", ret); return -EFAULT; + } return 0; } @@ -142,7 +153,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; @@ -201,15 +211,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; @@ -220,24 +222,15 @@ 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; } + free_flags = 0; rc = vm_insert_pfn(vma, entry->addr, PFN_DOWN(epc_page->pa)); - sgx_put_backing(backing, 0); - if (rc) { - free_flags = 0; entry = ERR_PTR(rc); goto out; }