Skip to content

Commit

Permalink
cpus-common: ensure auto-assigned cpu_indexes don't clash
Browse files Browse the repository at this point in the history
Basing the cpu_index on the number of currently allocated vCPUs fails
when vCPUs aren't removed in a LIFO manner. This is especially true
when we are allocating a cpu_index for each guest thread in
linux-user where there is no ordering constraint on their allocation
and de-allocation.

[I've dropped the assert which is there to guard against out-of-order
removal as this should probably be caught higher up the stack. Maybe
we could just ifdef CONFIG_SOFTTMU it?]

Signed-off-by: Alex Bennée <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Acked-by: Igor Mammedow <[email protected]>
Cc: Nikolay Igotti <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
stsquad committed May 27, 2020
1 parent c729a99 commit 716386e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cpus-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ static bool cpu_index_auto_assigned;
static int cpu_get_free_index(void)
{
CPUState *some_cpu;
int cpu_index = 0;
int max_cpu_index = 0;

cpu_index_auto_assigned = true;
CPU_FOREACH(some_cpu) {
cpu_index++;
if (some_cpu->cpu_index >= max_cpu_index) {
max_cpu_index = some_cpu->cpu_index + 1;
}
}
return cpu_index;
return max_cpu_index;
}

void cpu_list_add(CPUState *cpu)
Expand All @@ -90,8 +92,6 @@ void cpu_list_remove(CPUState *cpu)
return;
}

assert(!(cpu_index_auto_assigned && cpu != QTAILQ_LAST(&cpus)));

QTAILQ_REMOVE_RCU(&cpus, cpu, node);
cpu->cpu_index = UNASSIGNED_CPU_INDEX;
}
Expand Down

0 comments on commit 716386e

Please sign in to comment.