Skip to content

Commit 9c93684

Browse files
Aaron Luhansendc
authored andcommitted
x86/sgx: Fix deadlock in SGX NUMA node search
When the current node doesn't have an EPC section configured by firmware and all other EPC sections are used up, CPU can get stuck inside the while loop that looks for an available EPC page from remote nodes indefinitely, leading to a soft lockup. Note how nid_of_current will never be equal to nid in that while loop because nid_of_current is not set in sgx_numa_mask. Also worth mentioning is that it's perfectly fine for the firmware not to setup an EPC section on a node. While setting up an EPC section on each node can enhance performance, it is not a requirement for functionality. Rework the loop to start and end on *a* node that has SGX memory. This avoids the deadlock looking for the current SGX-lacking node to show up in the loop when it never will. Fixes: 901ddbb ("x86/sgx: Add a basic NUMA allocation scheme to sgx_alloc_epc_page()") Reported-by: "Molina Sabido, Gerardo" <[email protected]> Signed-off-by: Aaron Lu <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Reviewed-by: Kai Huang <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Acked-by: Dave Hansen <[email protected]> Tested-by: Zhimin Luo <[email protected]> Link: https://lore.kernel.org/all/20240905080855.1699814-2-aaron.lu%40intel.com
1 parent 431c164 commit 9c93684

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

arch/x86/kernel/cpu/sgx/main.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -475,24 +475,25 @@ struct sgx_epc_page *__sgx_alloc_epc_page(void)
475475
{
476476
struct sgx_epc_page *page;
477477
int nid_of_current = numa_node_id();
478-
int nid = nid_of_current;
478+
int nid_start, nid;
479479

480-
if (node_isset(nid_of_current, sgx_numa_mask)) {
481-
page = __sgx_alloc_epc_page_from_node(nid_of_current);
482-
if (page)
483-
return page;
484-
}
485-
486-
/* Fall back to the non-local NUMA nodes: */
487-
while (true) {
488-
nid = next_node_in(nid, sgx_numa_mask);
489-
if (nid == nid_of_current)
490-
break;
480+
/*
481+
* Try local node first. If it doesn't have an EPC section,
482+
* fall back to the non-local NUMA nodes.
483+
*/
484+
if (node_isset(nid_of_current, sgx_numa_mask))
485+
nid_start = nid_of_current;
486+
else
487+
nid_start = next_node_in(nid_of_current, sgx_numa_mask);
491488

489+
nid = nid_start;
490+
do {
492491
page = __sgx_alloc_epc_page_from_node(nid);
493492
if (page)
494493
return page;
495-
}
494+
495+
nid = next_node_in(nid, sgx_numa_mask);
496+
} while (nid != nid_start);
496497

497498
return ERR_PTR(-ENOMEM);
498499
}

0 commit comments

Comments
 (0)