[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220922171057.1236139-13-kristen@linux.intel.com>
Date: Thu, 22 Sep 2022 10:10:49 -0700
From: Kristen Carlson Accardi <kristen@...ux.intel.com>
To: linux-kernel@...r.kernel.org, linux-sgx@...r.kernel.org,
cgroups@...r.kernel.org, Jarkko Sakkinen <jarkko@...nel.org>,
Dave Hansen <dave.hansen@...ux.intel.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
x86@...nel.org, "H. Peter Anvin" <hpa@...or.com>
Cc: Kristen Carlson Accardi <kristen@...ux.intel.com>,
Sean Christopherson <seanjc@...gle.com>
Subject: [RFC PATCH 12/20] x86/sgx: Add helper to retrieve SGX EPC LRU given an EPC page
From: Sean Christopherson <sean.j.christopherson@...el.com>
Introduce a function that will be used to retrieve an LRU
from an EPC page.
Signed-off-by: Sean Christopherson <sean.j.christopherson@...el.com>
Signed-off-by: Kristen Carlson Accardi <kristen@...ux.intel.com>
Cc: Sean Christopherson <seanjc@...gle.com>
---
arch/x86/kernel/cpu/sgx/main.c | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kernel/cpu/sgx/main.c b/arch/x86/kernel/cpu/sgx/main.c
index 98531f6fb448..9f2cb264a347 100644
--- a/arch/x86/kernel/cpu/sgx/main.c
+++ b/arch/x86/kernel/cpu/sgx/main.c
@@ -31,6 +31,10 @@ static DEFINE_XARRAY(sgx_epc_address_space);
* with sgx_global_lru.lock acquired.
*/
static struct sgx_epc_lru sgx_global_lru;
+static inline struct sgx_epc_lru *sgx_lru(struct sgx_epc_page *epc_page)
+{
+ return &sgx_global_lru;
+}
static atomic_long_t sgx_nr_free_pages = ATOMIC_LONG_INIT(0);
@@ -299,6 +303,7 @@ static int sgx_reclaim_pages(int nr_to_scan, bool ignore_age)
struct sgx_backing backing[SGX_MAX_NR_TO_RECLAIM];
struct sgx_encl_page *encl_page;
struct sgx_epc_page *epc_page, *tmp;
+ struct sgx_epc_lru *lru;
pgoff_t page_index;
LIST_HEAD(iso);
int ret;
@@ -354,10 +359,11 @@ static int sgx_reclaim_pages(int nr_to_scan, bool ignore_age)
continue;
skip:
- spin_lock(&sgx_global_lru.lock);
+ lru = sgx_lru(epc_page);
+ spin_lock(&lru->lock);
epc_page->flags &= ~SGX_EPC_PAGE_RECLAIM_IN_PROGRESS;
- list_move_tail(&epc_page->list, &sgx_global_lru.reclaimable);
- spin_unlock(&sgx_global_lru.lock);
+ list_move_tail(&epc_page->list, &lru->reclaimable);
+ spin_unlock(&lru->lock);
kref_put(&encl_page->encl->refcount, sgx_encl_release);
}
@@ -514,14 +520,16 @@ struct sgx_epc_page *__sgx_alloc_epc_page(void)
*/
void sgx_record_epc_page(struct sgx_epc_page *page, unsigned long flags)
{
- spin_lock(&sgx_global_lru.lock);
+ struct sgx_epc_lru *lru = sgx_lru(page);
+
+ spin_lock(&lru->lock);
WARN_ON(page->flags & SGX_EPC_PAGE_RECLAIM_FLAGS);
page->flags |= flags;
if (flags & SGX_EPC_PAGE_RECLAIMER_TRACKED)
- list_add_tail(&page->list, &sgx_global_lru.reclaimable);
+ list_add_tail(&page->list, &lru->reclaimable);
else
- list_add_tail(&page->list, &sgx_global_lru.unreclaimable);
- spin_unlock(&sgx_global_lru.lock);
+ list_add_tail(&page->list, &lru->unreclaimable);
+ spin_unlock(&lru->lock);
}
/**
@@ -536,14 +544,16 @@ void sgx_record_epc_page(struct sgx_epc_page *page, unsigned long flags)
*/
int sgx_drop_epc_page(struct sgx_epc_page *page)
{
- spin_lock(&sgx_global_lru.lock);
+ struct sgx_epc_lru *lru = sgx_lru(page);
+
+ spin_lock(&lru->lock);
if ((page->flags & SGX_EPC_PAGE_RECLAIMER_TRACKED) &&
(page->flags & SGX_EPC_PAGE_RECLAIM_IN_PROGRESS)) {
- spin_unlock(&sgx_global_lru.lock);
+ spin_unlock(&lru->lock);
return -EBUSY;
}
list_del(&page->list);
- spin_unlock(&sgx_global_lru.lock);
+ spin_unlock(&lru->lock);
page->flags &= ~SGX_EPC_PAGE_RECLAIM_FLAGS;
--
2.37.3
Powered by blists - more mailing lists