From patchwork Thu Apr 20 16:16:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 9690889 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 3E07A60383 for ; Thu, 20 Apr 2017 16:16:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2003D2849C for ; Thu, 20 Apr 2017 16:16:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1491E2849F; Thu, 20 Apr 2017 16:16:26 +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 BB60628499 for ; Thu, 20 Apr 2017 16:16:25 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 691DF21954084; Thu, 20 Apr 2017 09:16:25 -0700 (PDT) X-Original-To: intel-sgx-kernel-dev@lists.01.org Delivered-To: intel-sgx-kernel-dev@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 C7F6F21954079 for ; Thu, 20 Apr 2017 09:16:23 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP; 20 Apr 2017 09:16:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,225,1488873600"; d="scan'208";a="251515781" Received: from sjchrist-ts.jf.intel.com ([10.54.74.20]) by fmsmga004.fm.intel.com with ESMTP; 20 Apr 2017 09:16:22 -0700 From: Sean Christopherson To: intel-sgx-kernel-dev@lists.01.org Date: Thu, 20 Apr 2017 09:16:13 -0700 Message-Id: <1492704977-26510-2-git-send-email-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1492704977-26510-1-git-send-email-sean.j.christopherson@intel.com> References: <1492704977-26510-1-git-send-email-sean.j.christopherson@intel.com> Subject: [intel-sgx-kernel-dev] [PATCH v2 1/4] intel_sgx: track SECS eviction using its epc_page X-BeenThere: intel-sgx-kernel-dev@lists.01.org X-Mailman-Version: 2.1.22 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 Track whether or not the SECS is resident in the EPC based on its epc_page pointer and remove the flag SGX_ENCL_SECS_EVICTED. Signed-off-by: Sean Christopherson --- drivers/platform/x86/intel_sgx/sgx.h | 5 ++--- drivers/platform/x86/intel_sgx/sgx_page_cache.c | 4 +--- drivers/platform/x86/intel_sgx/sgx_util.c | 3 +-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/drivers/platform/x86/intel_sgx/sgx.h b/drivers/platform/x86/intel_sgx/sgx.h index e59ff01..3451a56 100644 --- a/drivers/platform/x86/intel_sgx/sgx.h +++ b/drivers/platform/x86/intel_sgx/sgx.h @@ -122,9 +122,8 @@ struct sgx_tgid_ctx { enum sgx_encl_flags { SGX_ENCL_INITIALIZED = BIT(0), SGX_ENCL_DEBUG = BIT(1), - SGX_ENCL_SECS_EVICTED = BIT(2), - SGX_ENCL_SUSPEND = BIT(3), - SGX_ENCL_DEAD = BIT(4), + SGX_ENCL_SUSPEND = BIT(2), + SGX_ENCL_DEAD = BIT(3), }; struct sgx_encl { diff --git a/drivers/platform/x86/intel_sgx/sgx_page_cache.c b/drivers/platform/x86/intel_sgx/sgx_page_cache.c index 59a67cb..85276db 100644 --- a/drivers/platform/x86/intel_sgx/sgx_page_cache.c +++ b/drivers/platform/x86/intel_sgx/sgx_page_cache.c @@ -369,10 +369,8 @@ static void sgx_write_pages(struct sgx_encl *encl, struct list_head *src) encl->secs_child_cnt--; } - if (!encl->secs_child_cnt && (encl->flags & SGX_ENCL_INITIALIZED)) { + if (!encl->secs_child_cnt && (encl->flags & SGX_ENCL_INITIALIZED)) sgx_evict_page(&encl->secs_page, encl); - encl->flags |= SGX_ENCL_SECS_EVICTED; - } mutex_unlock(&encl->lock); } diff --git a/drivers/platform/x86/intel_sgx/sgx_util.c b/drivers/platform/x86/intel_sgx/sgx_util.c index 1e9fa18..716c1dd 100644 --- a/drivers/platform/x86/intel_sgx/sgx_util.c +++ b/drivers/platform/x86/intel_sgx/sgx_util.c @@ -304,7 +304,7 @@ static struct sgx_encl_page *sgx_do_fault(struct vm_area_struct *vma, } /* If SECS is evicted then reload it first */ - if (encl->flags & SGX_ENCL_SECS_EVICTED) { + if (!encl->secs_page.epc_page) { secs_epc_page = sgx_alloc_page(SGX_ALLOC_ATOMIC); if (IS_ERR(secs_epc_page)) { rc = PTR_ERR(secs_epc_page); @@ -317,7 +317,6 @@ static struct sgx_encl_page *sgx_do_fault(struct vm_area_struct *vma, goto out; encl->secs_page.epc_page = secs_epc_page; - encl->flags &= ~SGX_ENCL_SECS_EVICTED; /* Do not free */ secs_epc_page = NULL;