From patchwork Fri Dec 2 20:00:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 9459113 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 C8CD76074E for ; Fri, 2 Dec 2016 20:00:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5EAC285AE for ; Fri, 2 Dec 2016 20:00:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB046285B2; Fri, 2 Dec 2016 20:00: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=-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 6BEE4285AE for ; Fri, 2 Dec 2016 20:00:43 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8B05B81C77 for ; Fri, 2 Dec 2016 12:00:43 -0800 (PST) X-Original-To: intel-sgx-kernel-dev@lists.01.org Delivered-To: intel-sgx-kernel-dev@lists.01.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 15E1281C77 for ; Fri, 2 Dec 2016 12:00:42 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga102.fm.intel.com with ESMTP; 02 Dec 2016 12:00:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,288,1477983600"; d="scan'208";a="198391122" Received: from rmullen-mobl.amr.corp.intel.com (HELO localhost) ([10.252.2.199]) by fmsmga004.fm.intel.com with ESMTP; 02 Dec 2016 12:00:39 -0800 From: Jarkko Sakkinen To: intel-sgx-kernel-dev@lists.01.org Date: Fri, 2 Dec 2016 22:00:16 +0200 Message-Id: <20161202200018.25552-7-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161202200018.25552-1-jarkko.sakkinen@linux.intel.com> References: <20161202200018.25552-1-jarkko.sakkinen@linux.intel.com> Subject: [intel-sgx-kernel-dev] [PATCH v5 6/8] intel_sgx: reduce the use of SGX_ENCL_SUSPEND 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 Reduced the use of SGX_ENCL_SUSPEND only to three situations: - sgx_free_epc_page() checks this flags in order not to call ENCLS(EREMOVE) to an uninitialized EPC page. - sgx_find_encl() must be able to return SGX_POWER_LOST_ENCLAVE error code. In other cases SGX_ENCL_INVALIDATED will fully cover it. Signed-off-by: Jarkko Sakkinen --- drivers/platform/x86/intel_sgx_ioctl.c | 2 +- drivers/platform/x86/intel_sgx_util.c | 9 +++------ drivers/platform/x86/intel_sgx_vma.c | 5 +---- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/platform/x86/intel_sgx_ioctl.c b/drivers/platform/x86/intel_sgx_ioctl.c index 5a68dbe..0c3fd29 100644 --- a/drivers/platform/x86/intel_sgx_ioctl.c +++ b/drivers/platform/x86/intel_sgx_ioctl.c @@ -320,7 +320,7 @@ static void sgx_add_page_worker(struct work_struct *work) do { schedule(); - if (encl->flags & SGX_ENCL_SUSPEND) + if (encl->flags & SGX_ENCL_INVALIDATED) skip_rest = true; mutex_lock(&encl->lock); diff --git a/drivers/platform/x86/intel_sgx_util.c b/drivers/platform/x86/intel_sgx_util.c index 8ba2abd..41ccc18 100644 --- a/drivers/platform/x86/intel_sgx_util.c +++ b/drivers/platform/x86/intel_sgx_util.c @@ -135,16 +135,13 @@ void sgx_zap_tcs_ptes(struct sgx_encl *encl, struct vm_area_struct *vma) bool sgx_pin_mm(struct sgx_encl *encl) { - if (encl->flags & SGX_ENCL_SUSPEND) - return false; - mutex_lock(&encl->lock); - if (!(encl->flags & SGX_ENCL_INVALIDATED)) { - atomic_inc(&encl->mm->mm_count); - } else { + if (encl->flags & SGX_ENCL_INVALIDATED) { mutex_unlock(&encl->lock); return false; } + + atomic_inc(&encl->mm->mm_count); mutex_unlock(&encl->lock); down_read(&encl->mm->mmap_sem); diff --git a/drivers/platform/x86/intel_sgx_vma.c b/drivers/platform/x86/intel_sgx_vma.c index 88a316a..3ea200c 100644 --- a/drivers/platform/x86/intel_sgx_vma.c +++ b/drivers/platform/x86/intel_sgx_vma.c @@ -259,8 +259,6 @@ static struct sgx_encl_page *sgx_vma_do_fault(struct vm_area_struct *vma, list_add_tail(&entry->load_list, &encl->load_list); out: mutex_unlock(&encl->lock); - if (encl->flags & SGX_ENCL_SUSPEND) - free_flags |= SGX_FREE_SKIP_EREMOVE; if (epc_page) sgx_free_page(epc_page, encl, free_flags); if (secs_epc_page) @@ -361,8 +359,7 @@ static int sgx_vma_access(struct vm_area_struct *vma, unsigned long addr, if (!(encl->flags & SGX_ENCL_DEBUG) || !(encl->flags & SGX_ENCL_INITIALIZED) || - (encl->flags & SGX_ENCL_INVALIDATED) || - (encl->flags & SGX_ENCL_SUSPEND)) + (encl->flags & SGX_ENCL_INVALIDATED)) return -EFAULT; sgx_dbg(encl, "%s addr=0x%lx, len=%d\n", op_str, addr, len);