Skip to contentSkip to conversation

x86/sgx: Add a basic NUMA allocation scheme to sgx_alloc_epc_page()

PATCH In review Jarkko Sakkinen 1 participant 2 messages Feb 23, 2021 – Feb 25, 2021

Subsystems (2)
lore
Share & tools
lore

Jarkko Sakkinen

author maintainer
#0 lore raw

PATCH v2 1/1 x86/sgx: Add a basic NUMA allocation scheme to sgx_alloc_epc_page()

Background
==========

EPC section is covered by one or more SRAT entries that are associated with one and only one PXM (NUMA node). The motivation behind this patch is to provide basic elements of building allocation scheme based on this premise.

It does not try to fully address NUMA. For instance, it does not provide integration to the mempolicy API, but neither does introduce any bottlenecks to address this later on. Memory allocation is a complex topic, and thus it's better to start with baby steps.

Solution
========

Use phys_to_target_node() to associate each NUMA node with the EPC sections contained within its range.

In sgx_alloc_epc_page(), first try to allocate from the NUMA node, where the CPU is executing. If that fails, fallback to the legacy allocation.

---

v2:
* s/section_list/numa_section_list/
* s/MAX_NUMNODES//num_possible_nodes()/
* Add more verbose inline comments that Dave provided.
* If NUMA mapping fails, print a warning and description of the fallbck. The physical address is alredy printed in pr_info(), just before the mapping happens.

 arch/x86/Kconfig               |  1 +
 arch/x86/kernel/cpu/sgx/main.c | 57 +++++++++++++++++++++++++++++++++-
 arch/x86/kernel/cpu/sgx/sgx.h  |  1 +
 3 files changed, 58 insertions(+), 1 deletion(-)
arch/x86/Kconfig +1 -0
index 21f851179ff0..dcb73a5edf63 100644
@@ -1941,6 +1941,7 @@ config X86_SGX
 	depends on CRYPTO_SHA256=y
 	select SRCU
 	select MMU_NOTIFIER
+	select NUMA_KEEP_MEMINFO if NUMA
 	help
 	  Intel(R) Software Guard eXtensions (SGX) is a set of CPU instructions
 	  that can be used by applications to set aside private regions of code
arch/x86/kernel/cpu/sgx/main.c +56 -1

95 lines not on this page · raw message

arch/x86/kernel/cpu/sgx/sgx.h +1 -0
index 5fa42d143feb..2e8a07cf92a6 100644
@@ -45,6 +45,7 @@ struct sgx_epc_section {
 	spinlock_t lock;
 	struct list_head page_list;
 	unsigned long free_cnt;
+	struct list_head numa_section_list;
 
 	/*
 	 * Pages which need EREMOVE run on them before they can be
Signature · 1 line
2.30.1
author maintainer
#1 lore raw
Quoted 15 lines · Jarkko Sakkinen

Background
==========

EPC section is covered by one or more SRAT entries that are associated with one and only one PXM (NUMA node). The motivation behind this patch is to provide basic elements of building allocation scheme based on this premise.

It does not try to fully address NUMA. For instance, it does not provide integration to the mempolicy API, but neither does introduce any bottlenecks to address this later on. Memory allocation is a complex topic, and thus it's better to start with baby steps.

Solution
========

Quoted 8 lines

Use phys_to_target_node() to associate each NUMA node with the EPC sections contained within its range.

In sgx_alloc_epc_page(), first try to allocate from the NUMA node, where the CPU is executing. If that fails, fallback to the legacy allocation.

In [1], 'numa' branch is tip/master with the patch set on top.

Haitao, Any chances that you might have time to give a shot at testing this, when the bandwidth allows?

[1] https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-sgx.git:

/Jarkko