From patchwork Wed Jun 14 17:37:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 9787105 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 D095C6038F for ; Wed, 14 Jun 2017 17:38:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B91C21FF13 for ; Wed, 14 Jun 2017 17:38:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADCEF26E3A; Wed, 14 Jun 2017 17:38:02 +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 0373327853 for ; Wed, 14 Jun 2017 17:38:02 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3107521A143E8; Wed, 14 Jun 2017 10:36:45 -0700 (PDT) X-Original-To: intel-sgx-kernel-dev@lists.01.org Delivered-To: intel-sgx-kernel-dev@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 75FF621A16EC6 for ; Wed, 14 Jun 2017 10:36:44 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jun 2017 10:37:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,341,1493708400"; d="scan'208";a="113210028" Received: from sjchrist-ts.jf.intel.com ([10.54.74.20]) by orsmga005.jf.intel.com with ESMTP; 14 Jun 2017 10:37:45 -0700 From: Sean Christopherson To: intel-sgx-kernel-dev@lists.01.org Date: Wed, 14 Jun 2017 10:37:32 -0700 Message-Id: <1497461858-20309-7-git-send-email-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497461858-20309-1-git-send-email-sean.j.christopherson@intel.com> References: <1497461858-20309-1-git-send-email-sean.j.christopherson@intel.com> Subject: [intel-sgx-kernel-dev] [RFC][PATCH 06/12] intel_sgx: return nr pages reclaimed by sgx_swap_pages 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 Return the number of EPC pages reclaimed by sgx_swap_pages and expose the function outside of sgx_page_cache.c. Signed-off-by: Sean Christopherson --- drivers/platform/x86/intel_sgx/sgx.h | 1 + drivers/platform/x86/intel_sgx/sgx_page_cache.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/intel_sgx/sgx.h b/drivers/platform/x86/intel_sgx/sgx.h index 98c75fb..0ec0b67 100644 --- a/drivers/platform/x86/intel_sgx/sgx.h +++ b/drivers/platform/x86/intel_sgx/sgx.h @@ -232,5 +232,6 @@ void sgx_eblock(struct sgx_encl *encl, struct sgx_epc_page *epc_page); void sgx_etrack(struct sgx_encl *encl); int sgx_init_page(struct sgx_encl *encl, struct sgx_encl_page *entry, unsigned long addr, unsigned int alloc_flags); +unsigned long sgx_swap_pages(unsigned long nr_to_scan); #endif /* __ARCH_X86_INTEL_SGX_H__ */ diff --git a/drivers/platform/x86/intel_sgx/sgx_page_cache.c b/drivers/platform/x86/intel_sgx/sgx_page_cache.c index 9a1981c..365ce05 100644 --- a/drivers/platform/x86/intel_sgx/sgx_page_cache.c +++ b/drivers/platform/x86/intel_sgx/sgx_page_cache.c @@ -251,14 +251,16 @@ static void sgx_evict_page(struct sgx_encl_page *entry, entry->flags &= ~SGX_ENCL_PAGE_RESERVED; } -static void sgx_write_pages(struct sgx_encl *encl, struct list_head *src) +static unsigned long sgx_write_pages(struct sgx_encl *encl, + struct list_head *src) { struct sgx_epc_page *entry; struct sgx_epc_page *tmp; struct vm_area_struct *vma; + unsigned long nr_reclaimed = 0; if (list_empty(src)) - return; + return nr_reclaimed; /* EBLOCK */ list_for_each_entry_safe(entry, tmp, src, list) { @@ -278,12 +280,16 @@ static void sgx_write_pages(struct sgx_encl *encl, struct list_head *src) list_del_init(&entry->list); sgx_evict_page(entry->encl_page, encl); encl->secs_child_cnt--; + nr_reclaimed++; } if (!encl->secs_child_cnt && (encl->flags & SGX_ENCL_INITIALIZED)) { sgx_evict_page(&encl->secs_page, encl); encl->flags |= SGX_ENCL_SECS_EVICTED; + nr_reclaimed++; } + + return nr_reclaimed; } static inline void sgx_age_pages(struct list_head *swap, struct list_head *skip) @@ -336,10 +342,11 @@ static inline void sgx_lru_putback(struct list_head *src) spin_unlock(&lru->lock); } -static void sgx_swap_pages(unsigned long nr_to_scan) +unsigned long sgx_swap_pages(unsigned long nr_to_scan) { struct sgx_epc_page *entry, *tmp; struct sgx_encl *encl; + unsigned long nr_reclaimed = 0; LIST_HEAD(iso); LIST_HEAD(swap); @@ -369,7 +376,7 @@ static void sgx_swap_pages(unsigned long nr_to_scan) sgx_del_if_dead(encl, &swap, &skip); sgx_reserve_pages(&swap, &skip); - sgx_write_pages(encl, &swap); + nr_reclaimed += sgx_write_pages(encl, &swap); mutex_unlock(&encl->lock); } @@ -380,6 +387,8 @@ static void sgx_swap_pages(unsigned long nr_to_scan) kref_put(&encl->refcount, sgx_encl_release); } + + return nr_reclaimed; } int ksgxswapd(void *p)