From patchwork Wed Jun 14 17:37:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 9787115 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 03E8A6038E for ; Wed, 14 Jun 2017 17:38:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE8C91FF13 for ; Wed, 14 Jun 2017 17:38:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D07CD268AE; Wed, 14 Jun 2017 17:38:03 +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 115C326E4A 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 3837121A143CE; 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 A4F6821A16ECB 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="113210031" 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:33 -0700 Message-Id: <1497461858-20309-8-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 07/12] intel_sgx: add swap flag to allow caller to ignore LRU 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 Add a flag, SGX_SWAP_IGNORE_LRU, that when passed to sgx_swap_pages causes the EPC swap flow to skip LRU checks that might result in an EPC page not being selected for swapping. Signed-off-by: Sean Christopherson --- drivers/platform/x86/intel_sgx/sgx.h | 7 ++++++- drivers/platform/x86/intel_sgx/sgx_page_cache.c | 10 ++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/platform/x86/intel_sgx/sgx.h b/drivers/platform/x86/intel_sgx/sgx.h index 0ec0b67..cfd22e4 100644 --- a/drivers/platform/x86/intel_sgx/sgx.h +++ b/drivers/platform/x86/intel_sgx/sgx.h @@ -232,6 +232,11 @@ 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); + +enum sgx_swap_flags { + SGX_SWAP_IGNORE_LRU = BIT(0), +}; +unsigned long sgx_swap_pages(unsigned long nr_to_scan, + unsigned int flags); #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 365ce05..6c899cd 100644 --- a/drivers/platform/x86/intel_sgx/sgx_page_cache.c +++ b/drivers/platform/x86/intel_sgx/sgx_page_cache.c @@ -342,7 +342,8 @@ static inline void sgx_lru_putback(struct list_head *src) spin_unlock(&lru->lock); } -unsigned long sgx_swap_pages(unsigned long nr_to_scan) +unsigned long sgx_swap_pages(unsigned long nr_to_scan, + unsigned int flags) { struct sgx_epc_page *entry, *tmp; struct sgx_encl *encl; @@ -369,7 +370,8 @@ unsigned long sgx_swap_pages(unsigned long nr_to_scan) down_read(&encl->mm->mmap_sem); sgx_del_if_dead(encl, &swap, &skip); - sgx_age_pages(&swap, &skip); + if (!(flags & SGX_SWAP_IGNORE_LRU)) + sgx_age_pages(&swap, &skip); if (!list_empty(&swap)) { mutex_lock(&encl->lock); @@ -399,7 +401,7 @@ int ksgxswapd(void *p) sgx_nr_free_pages < sgx_nr_high_pages); if (sgx_nr_free_pages < sgx_nr_high_pages) - sgx_swap_pages(SGX_NR_SWAP_CLUSTER_MAX); + sgx_swap_pages(SGX_NR_SWAP_CLUSTER_MAX, 0); } pr_info("%s: done\n", __func__); @@ -512,7 +514,7 @@ struct sgx_epc_page *sgx_alloc_page(unsigned int flags) break; } - sgx_swap_pages(SGX_NR_SWAP_CLUSTER_MAX); + sgx_swap_pages(SGX_NR_SWAP_CLUSTER_MAX, 0); schedule(); }