From patchwork Tue Feb 7 17:05:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 9560697 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 5524D602B1 for ; Tue, 7 Feb 2017 17:05:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47867269A3 for ; Tue, 7 Feb 2017 17:05:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3CA612842B; Tue, 7 Feb 2017 17:05:28 +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 4BE2C269A3 for ; Tue, 7 Feb 2017 17:05:26 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 38A7681FF3 for ; Tue, 7 Feb 2017 09:05:26 -0800 (PST) X-Original-To: intel-sgx-kernel-dev@lists.01.org Delivered-To: intel-sgx-kernel-dev@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 0FAC381FEC for ; Tue, 7 Feb 2017 09:05:25 -0800 (PST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP; 07 Feb 2017 09:05:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.33,346,1477983600"; d="scan'208"; a="1123328962" Received: from sjchrist-ts.jf.intel.com ([10.54.74.20]) by fmsmga002.fm.intel.com with ESMTP; 07 Feb 2017 09:05:24 -0800 From: Sean Christopherson To: intel-sgx-kernel-dev@lists.01.org Date: Tue, 7 Feb 2017 09:05:14 -0800 Message-Id: <1486487114-2785-2-git-send-email-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486487114-2785-1-git-send-email-sean.j.christopherson@intel.com> References: <20170131230308.7561-1-jarkko.sakkinen@linux.intel.com> <1486487114-2785-1-git-send-email-sean.j.christopherson@intel.com> Subject: [intel-sgx-kernel-dev] [PATCH 6/?] intel_sgx: move sgx_ewb call into sgx_evict_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 Move the call to sgx_ewb() into sgx_evict_page(), and always perform EBLOCK->ETRACK-EWB for pages that are being evicted even if the VMA for the page cannot be found. Killing an enclave due to VMA closure is a lazy operation, i.e. an enclave may contain active threads even after a VMA is closed. Signed-off-by: Sean Christopherson Reviewed-by: Jarkko Sakkinen --- drivers/platform/x86/intel_sgx_page_cache.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/drivers/platform/x86/intel_sgx_page_cache.c b/drivers/platform/x86/intel_sgx_page_cache.c index 72f8ef1..8224729 100644 --- a/drivers/platform/x86/intel_sgx_page_cache.c +++ b/drivers/platform/x86/intel_sgx_page_cache.c @@ -310,6 +310,7 @@ static void sgx_ewb(struct sgx_encl *encl, static void sgx_evict_page(struct sgx_encl_page *entry, struct sgx_encl *encl) { + sgx_ewb(encl, entry); sgx_free_page(entry->epc_page, encl); entry->epc_page = NULL; entry->flags &= ~SGX_ENCL_PAGE_RESERVED; @@ -319,7 +320,7 @@ 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; + struct vm_area_struct *vma; if (list_empty(src)) return; @@ -330,14 +331,11 @@ static void sgx_write_pages(struct sgx_encl *encl, struct list_head *src) /* EBLOCK */ list_for_each_entry_safe(entry, tmp, src, load_list) { - evma = sgx_find_vma(encl, entry->addr); - if (!evma) { - list_del(&entry->load_list); - sgx_evict_page(entry, encl); - continue; + vma = sgx_find_vma(encl, entry->addr); + if (vma) { + zap_vma_ptes(vma, entry->addr, PAGE_SIZE); } - zap_vma_ptes(evma, entry->addr, PAGE_SIZE); sgx_eblock(encl, entry->epc_page); } @@ -350,20 +348,14 @@ static void sgx_write_pages(struct sgx_encl *encl, struct list_head *src) load_list); list_del(&entry->load_list); - - evma = sgx_find_vma(encl, entry->addr); - if (evma) { - sgx_ewb(encl, entry); - encl->secs_child_cnt--; - } - sgx_evict_page(entry, encl); + + encl->secs_child_cnt--; } if (!encl->secs_child_cnt && (encl->flags & SGX_ENCL_INITIALIZED)) { - sgx_ewb(encl, &encl->secs_page); - encl->flags |= SGX_ENCL_SECS_EVICTED; sgx_evict_page(&encl->secs_page, encl); + encl->flags |= SGX_ENCL_SECS_EVICTED; } mutex_unlock(&encl->lock);