* [PATCH] cpus: verify that number of created cpus do not exceed smp params
@ 2020-10-23 7:34 Pavel Dovgalyuk
2020-10-23 8:10 ` Philippe Mathieu-Daudé
2020-10-23 17:06 ` Igor Mammedov
0 siblings, 2 replies; 4+ messages in thread
From: Pavel Dovgalyuk @ 2020-10-23 7:34 UTC (permalink / raw)
To: qemu-devel; +Cc: pbonzini, pavel.dovgalyuk, rth
Machine definitions may miss some vCPU-related parameters.
E.g., xlnx-versal-virt missed min_cpus and it was set to 1 by default.
This allowed using -smp 1 command line argument. But the machine
still created 2 vCPUs and passed all checks.
This patch adds one more check that does not allow creating
extra cpus that exceed the values specified in machine/smp.
Signed-off-by: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
---
0 files changed
diff --git a/softmmu/cpus.c b/softmmu/cpus.c
index 47cceddd80..da74794e09 100644
--- a/softmmu/cpus.c
+++ b/softmmu/cpus.c
@@ -603,6 +603,11 @@ void qemu_init_vcpu(CPUState *cpu)
{
MachineState *ms = MACHINE(qdev_get_machine());
+ if (cpu->cpu_index >= ms->smp.cpus) {
+ fprintf(stderr, "Machine definition error: trying to create too many CPUs\n");
+ exit(1);
+ }
+
cpu->nr_cores = ms->smp.cores;
cpu->nr_threads = ms->smp.threads;
cpu->stopped = true;
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] cpus: verify that number of created cpus do not exceed smp params
2020-10-23 7:34 [PATCH] cpus: verify that number of created cpus do not exceed smp params Pavel Dovgalyuk
@ 2020-10-23 8:10 ` Philippe Mathieu-Daudé
2020-10-23 8:16 ` Pavel Dovgalyuk
2020-10-23 17:06 ` Igor Mammedov
1 sibling, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-10-23 8:10 UTC (permalink / raw)
To: Pavel Dovgalyuk, qemu-devel, Markus Armbruster; +Cc: pbonzini, rth
On 10/23/20 9:34 AM, Pavel Dovgalyuk wrote:
> Machine definitions may miss some vCPU-related parameters.
> E.g., xlnx-versal-virt missed min_cpus and it was set to 1 by default.
> This allowed using -smp 1 command line argument. But the machine
> still created 2 vCPUs and passed all checks.
> This patch adds one more check that does not allow creating
> extra cpus that exceed the values specified in machine/smp.
>
> Signed-off-by: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
> ---
> 0 files changed
>
> diff --git a/softmmu/cpus.c b/softmmu/cpus.c
> index 47cceddd80..da74794e09 100644
> --- a/softmmu/cpus.c
> +++ b/softmmu/cpus.c
> @@ -603,6 +603,11 @@ void qemu_init_vcpu(CPUState *cpu)
> {
> MachineState *ms = MACHINE(qdev_get_machine());
>
> + if (cpu->cpu_index >= ms->smp.cpus) {
> + fprintf(stderr, "Machine definition error: trying to create too many CPUs\n");
> + exit(1);
Shouldn't this be an assert()?
> + }
> +
> cpu->nr_cores = ms->smp.cores;
> cpu->nr_threads = ms->smp.threads;
> cpu->stopped = true;
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cpus: verify that number of created cpus do not exceed smp params
2020-10-23 8:10 ` Philippe Mathieu-Daudé
@ 2020-10-23 8:16 ` Pavel Dovgalyuk
0 siblings, 0 replies; 4+ messages in thread
From: Pavel Dovgalyuk @ 2020-10-23 8:16 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel, Markus Armbruster; +Cc: pbonzini, rth
On 23.10.2020 11:10, Philippe Mathieu-Daudé wrote:
> On 10/23/20 9:34 AM, Pavel Dovgalyuk wrote:
>> Machine definitions may miss some vCPU-related parameters.
>> E.g., xlnx-versal-virt missed min_cpus and it was set to 1 by default.
>> This allowed using -smp 1 command line argument. But the machine
>> still created 2 vCPUs and passed all checks.
>> This patch adds one more check that does not allow creating
>> extra cpus that exceed the values specified in machine/smp.
>>
>> Signed-off-by: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
>> ---
>> 0 files changed
>>
>> diff --git a/softmmu/cpus.c b/softmmu/cpus.c
>> index 47cceddd80..da74794e09 100644
>> --- a/softmmu/cpus.c
>> +++ b/softmmu/cpus.c
>> @@ -603,6 +603,11 @@ void qemu_init_vcpu(CPUState *cpu)
>> {
>> MachineState *ms = MACHINE(qdev_get_machine());
>> + if (cpu->cpu_index >= ms->smp.cpus) {
>> + fprintf(stderr, "Machine definition error: trying to create
>> too many CPUs\n");
>> + exit(1);
>
> Shouldn't this be an assert()?
I thought about this.
Bugs could be unnoticed and reveal in release. Therefore user should
know the details and shouldn't see an assert.
>
>> + }
>> +
>> cpu->nr_cores = ms->smp.cores;
>> cpu->nr_threads = ms->smp.threads;
>> cpu->stopped = true;
>>
>>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] cpus: verify that number of created cpus do not exceed smp params
2020-10-23 7:34 [PATCH] cpus: verify that number of created cpus do not exceed smp params Pavel Dovgalyuk
2020-10-23 8:10 ` Philippe Mathieu-Daudé
@ 2020-10-23 17:06 ` Igor Mammedov
1 sibling, 0 replies; 4+ messages in thread
From: Igor Mammedov @ 2020-10-23 17:06 UTC (permalink / raw)
To: Pavel Dovgalyuk; +Cc: pbonzini, David Gibson, qemu-devel, rth
On Fri, 23 Oct 2020 10:34:41 +0300
Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru> wrote:
> Machine definitions may miss some vCPU-related parameters.
> E.g., xlnx-versal-virt missed min_cpus and it was set to 1 by default.
> This allowed using -smp 1 command line argument. But the machine
> still created 2 vCPUs and passed all checks.
> This patch adds one more check that does not allow creating
> extra cpus that exceed the values specified in machine/smp.
>
> Signed-off-by: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
> ---
> 0 files changed
>
> diff --git a/softmmu/cpus.c b/softmmu/cpus.c
> index 47cceddd80..da74794e09 100644
> --- a/softmmu/cpus.c
> +++ b/softmmu/cpus.c
> @@ -603,6 +603,11 @@ void qemu_init_vcpu(CPUState *cpu)
> {
> MachineState *ms = MACHINE(qdev_get_machine());
>
> + if (cpu->cpu_index >= ms->smp.cpus) {
looks like for such machines we need MachineClass:min_cpus + setting it in affected machines
and corresponding check in smp_parse(), instead of terminating from qemu_init_vcpu();
> + fprintf(stderr, "Machine definition error: trying to create too many CPUs\n");
> + exit(1);
> + }
> +
> cpu->nr_cores = ms->smp.cores;
> cpu->nr_threads = ms->smp.threads;
> cpu->stopped = true;
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-10-23 17:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-10-23 7:34 [PATCH] cpus: verify that number of created cpus do not exceed smp params Pavel Dovgalyuk
2020-10-23 8:10 ` Philippe Mathieu-Daudé
2020-10-23 8:16 ` Pavel Dovgalyuk
2020-10-23 17:06 ` Igor Mammedov
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).