From: "Alex Bennée" <alex.bennee@linaro.org>
To: peter.maydell@linaro.org
Cc: "Eduardo Habkost" <ehabkost@redhat.com>,
"Nikolay Igotti" <igotti@gmail.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
qemu-devel@nongnu.org, "Igor Mammedow" <imammedo@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Richard Henderson" <rth@twiddle.net>
Subject: [PULL 10/12] cpus-common: ensure auto-assigned cpu_indexes don't clash
Date: Wed, 27 May 2020 15:54:53 +0100 [thread overview]
Message-ID: <20200527145455.2550-11-alex.bennee@linaro.org> (raw)
In-Reply-To: <20200527145455.2550-1-alex.bennee@linaro.org>
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 <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Acked-by: Igor Mammedow <imammedo@redhat.com>
Cc: Nikolay Igotti <igotti@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Eduardo Habkost <ehabkost@redhat.com>
Message-Id: <20200520140541.30256-13-alex.bennee@linaro.org>
diff --git a/cpus-common.c b/cpus-common.c
index 55d5df89237..70a9d12981a 100644
--- a/cpus-common.c
+++ b/cpus-common.c
@@ -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)
@@ -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;
}
--
2.20.1
next prev parent reply other threads:[~2020-05-27 14:59 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-27 14:54 [PULL 00/12] testing and plugin fixes Alex Bennée
2020-05-27 14:54 ` [PULL 01/12] configure: add alternate binary for genisoimage Alex Bennée
2020-05-27 14:54 ` [PULL 02/12] tests/vm: pass --genisoimage to basevm script Alex Bennée
2020-05-27 14:54 ` [PULL 03/12] travis.yml: Use clang++ in the Clang tests Alex Bennée
2020-05-27 14:54 ` [PULL 04/12] tests/tcg: fix invocation of the memory record/replay tests Alex Bennée
2020-05-27 14:54 ` [PULL 05/12] tests/fp: enable extf80_le_quite tests Alex Bennée
2020-05-27 14:54 ` [PULL 06/12] tests/fp: split and audit the conversion tests Alex Bennée
2020-05-27 14:54 ` [PULL 07/12] tests/tcg: better detect confused gdb which can't connect Alex Bennée
2020-05-27 14:54 ` [PULL 08/12] tests/docker: add debian11 base image Alex Bennée
2020-05-27 14:54 ` [PULL 09/12] tests/docker: use a gcc-10 based image for arm64 tests Alex Bennée
2020-05-27 14:54 ` Alex Bennée [this message]
2020-05-27 14:54 ` [PULL 11/12] linux-user: properly "unrealize" vCPU object Alex Bennée
2020-05-27 14:54 ` [PULL 12/12] tests/tcg: add new threadcount test Alex Bennée
2020-05-28 13:54 ` [PULL 00/12] testing and plugin fixes Peter Maydell
2020-05-28 14:16 ` Alex Bennée
2020-05-28 14:57 ` Alex Bennée
2020-05-28 15:09 ` Peter Maydell
2020-05-28 15:18 ` Philippe Mathieu-Daudé
2020-05-28 15:20 ` Peter Maydell
2020-05-28 15:26 ` Philippe Mathieu-Daudé
2020-05-28 16:07 ` Peter Maydell
2020-05-28 17:19 ` Alex Bennée
2020-05-28 15:38 ` Gerd Hoffmann
2020-05-29 18:25 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200527145455.2550-11-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=ehabkost@redhat.com \
--cc=igotti@gmail.com \
--cc=imammedo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=rth@twiddle.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).