diff mbox

[intel-sgx-kernel-dev,RFC,06/12] intel_sgx: return nr pages reclaimed by sgx_swap_pages

Message ID 1497461858-20309-7-git-send-email-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sean Christopherson June 14, 2017, 5:37 p.m. UTC
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 <sean.j.christopherson@intel.com>
---
 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 mbox

Patch

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)