From patchwork Thu Dec 1 20:56:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 9456901 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 4507860585 for ; Thu, 1 Dec 2016 20:57:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38B162841E for ; Thu, 1 Dec 2016 20:57:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DA362852E; Thu, 1 Dec 2016 20:57:05 +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 D48C22841E for ; Thu, 1 Dec 2016 20:57:04 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EFCA281F1C for ; Thu, 1 Dec 2016 12:57:04 -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 9CE9D81F1C for ; Thu, 1 Dec 2016 12:57:03 -0800 (PST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 01 Dec 2016 12:57:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.33,726,1477983600"; d="scan'208"; a="1076283117" Received: from wmcsween-mobl.ger.corp.intel.com (HELO localhost) ([10.252.12.30]) by fmsmga001.fm.intel.com with ESMTP; 01 Dec 2016 12:57:02 -0800 From: Jarkko Sakkinen To: intel-sgx-kernel-dev@lists.01.org Date: Thu, 1 Dec 2016 22:56:30 +0200 Message-Id: <20161201205632.8593-7-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20161201205632.8593-1-jarkko.sakkinen@linux.intel.com> References: <20161201205632.8593-1-jarkko.sakkinen@linux.intel.com> Subject: [intel-sgx-kernel-dev] [PATCH v4 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);