Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on topology_core_id for splitting cpu pool #560

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions drivers/virt/nitro_enclaves/ne_misc_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,11 @@ static bool ne_check_enclaves_created(void)
*/
static int ne_setup_cpu_pool(const char *ne_cpu_list)
{
int core_id = -1;
int core_id = 0;
unsigned int cpu = 0;
unsigned int sibling = 0;
cpumask_var_t cpu_pool;
cpumask_var_t cpu_added;
unsigned int cpu_sibling = 0;
unsigned int i = 0;
int numa_node = -1;
Expand All @@ -274,6 +276,9 @@ static int ne_setup_cpu_pool(const char *ne_cpu_list)
if (!zalloc_cpumask_var(&cpu_pool, GFP_KERNEL))
return -ENOMEM;

if (!zalloc_cpumask_var(&cpu_added, GFP_KERNEL))
return -ENOMEM;

mutex_lock(&ne_cpu_pool.mutex);

rc = cpulist_parse(ne_cpu_list, cpu_pool);
Expand Down Expand Up @@ -399,20 +404,15 @@ static int ne_setup_cpu_pool(const char *ne_cpu_list)
* Split the NE CPU pool in threads per core to keep the CPU topology
* after offlining the CPUs.
*/
for_each_cpu(cpu, cpu_pool) {
core_id = topology_core_id(cpu);
if (core_id < 0 || core_id >= ne_cpu_pool.nr_parent_vm_cores) {
pr_err("%s: Invalid core id %d for CPU %d\n",
ne_misc_dev.name, core_id, cpu);

rc = -EINVAL;

goto clear_cpumask;
for_each_cpu(cpu, cpu_pool)
if (!cpumask_test_cpu(cpu, cpu_added)) {
for_each_cpu(sibling, topology_sibling_cpumask(cpu)) {
cpumask_set_cpu(sibling, cpu_added);
cpumask_set_cpu(sibling, ne_cpu_pool.avail_threads_per_core[core_id]);
}
core_id++;
}

cpumask_set_cpu(cpu, ne_cpu_pool.avail_threads_per_core[core_id]);
}

/*
* CPUs that are given to enclave(s) should not be considered online
* by Linux anymore, as the hypervisor will degrade them to floating.
Expand Down Expand Up @@ -444,7 +444,6 @@ static int ne_setup_cpu_pool(const char *ne_cpu_list)
online_cpus:
for_each_cpu(cpu, cpu_pool)
add_cpu(cpu);
clear_cpumask:
for (i = 0; i < ne_cpu_pool.nr_parent_vm_cores; i++)
cpumask_clear(ne_cpu_pool.avail_threads_per_core[i]);
free_cores_cpumask:
Expand Down