From patchwork Thu Jan 26 21:21:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 9540111 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 5BA80604A0 for ; Thu, 26 Jan 2017 21:21:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D9071FE6A for ; Thu, 26 Jan 2017 21:21:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 423FD2817F; Thu, 26 Jan 2017 21:21:20 +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 E8FA928329 for ; Thu, 26 Jan 2017 21:21:18 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E279681F7D for ; Thu, 26 Jan 2017 13:21:18 -0800 (PST) X-Original-To: intel-sgx-kernel-dev@lists.01.org Delivered-To: intel-sgx-kernel-dev@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 EC64881F82 for ; Thu, 26 Jan 2017 13:21:17 -0800 (PST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 26 Jan 2017 13:21:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,291,1477983600"; d="scan'208";a="927062813" Received: from gerardan-mobl.ger.corp.intel.com (HELO localhost) ([10.252.16.178]) by orsmga003.jf.intel.com with ESMTP; 26 Jan 2017 13:21:16 -0800 From: Jarkko Sakkinen To: intel-sgx-kernel-dev@lists.01.org Date: Thu, 26 Jan 2017 23:21:08 +0200 Message-Id: <20170126212109.12922-3-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170126212109.12922-1-jarkko.sakkinen@linux.intel.com> References: <20170126212109.12922-1-jarkko.sakkinen@linux.intel.com> Subject: [intel-sgx-kernel-dev] [PATCH 2/3] intel_sgx: remove flags parameter from sgx_free_page() 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 The flags parameter is unnecessary cruft as EREMOVE has a valid and successful code path for an unused page. Signed-off-by: Jarkko Sakkinen --- drivers/platform/x86/intel_sgx.h | 4 +-- drivers/platform/x86/intel_sgx_ioctl.c | 12 +++---- drivers/platform/x86/intel_sgx_page_cache.c | 50 +++++++++-------------------- drivers/platform/x86/intel_sgx_util.c | 6 ++-- drivers/platform/x86/intel_sgx_vma.c | 6 ++-- 5 files changed, 26 insertions(+), 52 deletions(-) diff --git a/drivers/platform/x86/intel_sgx.h b/drivers/platform/x86/intel_sgx.h index ed9e8e6..be08346 100644 --- a/drivers/platform/x86/intel_sgx.h +++ b/drivers/platform/x86/intel_sgx.h @@ -236,8 +236,6 @@ int sgx_page_cache_init(resource_size_t start, unsigned long size); void sgx_page_cache_teardown(void); struct sgx_epc_page *sgx_alloc_page(struct sgx_tgid_ctx *tgid_epc_cnt, unsigned int flags); -void sgx_free_page(struct sgx_epc_page *entry, - struct sgx_encl *encl, - unsigned int flags); +void sgx_free_page(struct sgx_epc_page *entry, struct sgx_encl *encl); #endif /* __ARCH_X86_INTEL_SGX_H__ */ diff --git a/drivers/platform/x86/intel_sgx_ioctl.c b/drivers/platform/x86/intel_sgx_ioctl.c index f2cc2c1..a1da92a 100644 --- a/drivers/platform/x86/intel_sgx_ioctl.c +++ b/drivers/platform/x86/intel_sgx_ioctl.c @@ -213,7 +213,6 @@ static bool sgx_process_add_page_req(struct sgx_add_page_req *req) struct sgx_epc_page *epc_page; struct sgx_encl_page *encl_page = req->encl_page; struct sgx_encl *encl = req->encl; - unsigned int free_flags = SGX_FREE_SKIP_EREMOVE; struct vm_area_struct *vma; int ret; @@ -222,7 +221,7 @@ static bool sgx_process_add_page_req(struct sgx_add_page_req *req) return false; if (!sgx_pin_mm(encl)) { - sgx_free_page(epc_page, encl, free_flags); + sgx_free_page(epc_page, encl); return false; } @@ -252,7 +251,6 @@ static bool sgx_process_add_page_req(struct sgx_add_page_req *req) encl_page->addr, &req->secinfo, backing); sgx_put_backing(backing, 0); - free_flags = 0; if (ret) { sgx_warn(encl, "EADD returned %d\n", ret); zap_vma_ptes(vma, encl_page->addr, PAGE_SIZE); @@ -276,7 +274,7 @@ static bool sgx_process_add_page_req(struct sgx_add_page_req *req) sgx_unpin_mm(encl); return true; out: - sgx_free_page(epc_page, encl, free_flags); + sgx_free_page(epc_page, encl); mutex_unlock(&encl->lock); sgx_unpin_mm(encl); return false; @@ -416,8 +414,7 @@ static int sgx_init_page(struct sgx_encl *encl, if (!vaddr) { sgx_warn(encl, "kmap of a new VA page failed %d\n", ret); - sgx_free_page(epc_page, encl, - SGX_FREE_SKIP_EREMOVE); + sgx_free_page(epc_page, encl); kfree(va_page); return -EFAULT; } @@ -427,8 +424,7 @@ static int sgx_init_page(struct sgx_encl *encl, if (ret) { sgx_warn(encl, "EPA returned %d\n", ret); - sgx_free_page(epc_page, encl, - SGX_FREE_SKIP_EREMOVE); + sgx_free_page(epc_page, encl); kfree(va_page); return -EFAULT; } diff --git a/drivers/platform/x86/intel_sgx_page_cache.c b/drivers/platform/x86/intel_sgx_page_cache.c index 7f73ac7..3fc8091 100644 --- a/drivers/platform/x86/intel_sgx_page_cache.c +++ b/drivers/platform/x86/intel_sgx_page_cache.c @@ -267,7 +267,7 @@ static int __sgx_ewb(struct sgx_encl *encl, return ret; } -static bool sgx_ewb(struct sgx_encl *encl, +static void sgx_ewb(struct sgx_encl *encl, struct sgx_encl_page *entry) { int ret = __sgx_ewb(encl, entry); @@ -284,17 +284,13 @@ static bool sgx_ewb(struct sgx_encl *encl, smp_call_function(sgx_ipi_cb, NULL, 1); if (ret > 0) sgx_err(encl, "EWB returned %d, enclave killed\n", ret); - return false; } - - return true; } -void sgx_free_encl_page(struct sgx_encl_page *entry, - struct sgx_encl *encl, - unsigned int flags) +static void sgx_free_encl_page(struct sgx_encl_page *entry, + struct sgx_encl *encl) { - sgx_free_page(entry->epc_page, encl, flags); + sgx_free_page(entry->epc_page, encl); entry->epc_page = NULL; entry->flags &= ~SGX_ENCL_PAGE_RESERVED; } @@ -304,7 +300,6 @@ static void sgx_write_pages(struct sgx_encl *encl, struct list_head *src) struct sgx_encl_page *entry; struct sgx_encl_page *tmp; struct vm_area_struct *evma; - unsigned int free_flags; if (list_empty(src)) return; @@ -318,7 +313,7 @@ static void sgx_write_pages(struct sgx_encl *encl, struct list_head *src) evma = sgx_find_vma(encl, entry->addr); if (!evma) { list_del(&entry->load_list); - sgx_free_encl_page(entry, encl, 0); + sgx_free_encl_page(entry, encl); continue; } @@ -335,25 +330,20 @@ static void sgx_write_pages(struct sgx_encl *encl, struct list_head *src) load_list); list_del(&entry->load_list); - free_flags = 0; evma = sgx_find_vma(encl, entry->addr); if (evma) { - if (sgx_ewb(encl, entry)) - free_flags = SGX_FREE_SKIP_EREMOVE; + sgx_ewb(encl, entry); encl->secs_child_cnt--; } - sgx_free_encl_page(entry, encl, free_flags); + sgx_free_encl_page(entry, encl); } if (!encl->secs_child_cnt && (encl->flags & SGX_ENCL_INITIALIZED)) { - free_flags = 0; - if (sgx_ewb(encl, &encl->secs_page)) - free_flags = SGX_FREE_SKIP_EREMOVE; - + sgx_ewb(encl, &encl->secs_page); encl->flags |= SGX_ENCL_SECS_EVICTED; - sgx_free_encl_page(&encl->secs_page, encl, free_flags); + sgx_free_encl_page(&encl->secs_page, encl); } mutex_unlock(&encl->lock); @@ -532,28 +522,20 @@ struct sgx_epc_page *sgx_alloc_page(struct sgx_tgid_ctx *ctx, * @encl: the enclave who owns the EPC page * @flags: free flags */ -void sgx_free_page(struct sgx_epc_page *entry, - struct sgx_encl *encl, - unsigned int flags) +void sgx_free_page(struct sgx_epc_page *entry, struct sgx_encl *encl) { void *epc; int ret; - if (encl) { + if (encl) atomic_dec(&encl->tgid_ctx->epc_cnt); - if (encl->flags & SGX_ENCL_SUSPEND) - flags |= SGX_FREE_SKIP_EREMOVE; - } - - if (!(flags & SGX_FREE_SKIP_EREMOVE)) { - epc = sgx_get_epc_page(entry); - ret = __eremove(epc); - sgx_put_epc_page(epc); + epc = sgx_get_epc_page(entry); + ret = __eremove(epc); + sgx_put_epc_page(epc); - if (ret) - sgx_err(encl, "EREMOVE returned %d\n", ret); - } + if (ret) + sgx_err(encl, "EREMOVE returned %d\n", ret); spin_lock(&sgx_free_list_lock); list_add(&entry->free_list, &sgx_free_list); diff --git a/drivers/platform/x86/intel_sgx_util.c b/drivers/platform/x86/intel_sgx_util.c index 2c390c5..99356f0 100644 --- a/drivers/platform/x86/intel_sgx_util.c +++ b/drivers/platform/x86/intel_sgx_util.c @@ -220,7 +220,7 @@ void sgx_encl_release(struct kref *ref) entry = *slot; if (entry->epc_page) { list_del(&entry->load_list); - sgx_free_page(entry->epc_page, encl, 0); + sgx_free_page(entry->epc_page, encl); } radix_tree_delete(&encl->page_tree, entry->addr >> PAGE_SHIFT); kfree(entry); @@ -230,12 +230,12 @@ void sgx_encl_release(struct kref *ref) va_page = list_first_entry(&encl->va_pages, struct sgx_va_page, list); list_del(&va_page->list); - sgx_free_page(va_page->epc_page, encl, 0); + sgx_free_page(va_page->epc_page, encl); kfree(va_page); } if (encl->secs_page.epc_page) - sgx_free_page(encl->secs_page.epc_page, encl, 0); + sgx_free_page(encl->secs_page.epc_page, encl); encl->secs_page.epc_page = NULL; diff --git a/drivers/platform/x86/intel_sgx_vma.c b/drivers/platform/x86/intel_sgx_vma.c index 6a23690..c339de3 100644 --- a/drivers/platform/x86/intel_sgx_vma.c +++ b/drivers/platform/x86/intel_sgx_vma.c @@ -143,7 +143,6 @@ static struct sgx_encl_page *sgx_vma_do_fault(struct vm_area_struct *vma, 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; /* If process was forked, VMA is still there but vm_private_data is set @@ -237,7 +236,6 @@ static struct sgx_encl_page *sgx_vma_do_fault(struct vm_area_struct *vma, sgx_put_backing(backing, 0); if (rc) { - free_flags = 0; entry = ERR_PTR(rc); goto out; } @@ -257,9 +255,9 @@ static struct sgx_encl_page *sgx_vma_do_fault(struct vm_area_struct *vma, out: mutex_unlock(&encl->lock); if (epc_page) - sgx_free_page(epc_page, encl, free_flags); + sgx_free_page(epc_page, encl); if (secs_epc_page) - sgx_free_page(secs_epc_page, encl, SGX_FREE_SKIP_EREMOVE); + sgx_free_page(secs_epc_page, encl); return entry; }