* [PATCH 0/1] hw/i386: prevent crash when an invalid number of dies is given @ 2020-10-12 3:35 Cleber Rosa 2020-10-12 3:35 ` [PATCH 1/1] " Cleber Rosa 0 siblings, 1 reply; 3+ messages in thread From: Cleber Rosa @ 2020-10-12 3:35 UTC (permalink / raw) To: qemu-devel Cc: Thomas Huth, Beraldo Leal, Michael S. Tsirkin, Alex Bennée, Wainer dos Santos Moschetta, Willian Rampazzo, Cleber Rosa, Paolo Bonzini, Eduardo Habkost, Philippe Mathieu-Daudé, Richard Henderson Simple patch (and test) to avoid crashes when and invalid number of dies is given. Cleber Rosa (1): hw/i386: prevent crash when an invalid number of dies is given hw/i386/pc.c | 5 +++++ tests/acceptance/cpu_topology_dies.py | 31 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/acceptance/cpu_topology_dies.py -- 2.25.4 ^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/1] hw/i386: prevent crash when an invalid number of dies is given 2020-10-12 3:35 [PATCH 0/1] hw/i386: prevent crash when an invalid number of dies is given Cleber Rosa @ 2020-10-12 3:35 ` Cleber Rosa 2020-10-19 16:30 ` Willian Rampazzo 0 siblings, 1 reply; 3+ messages in thread From: Cleber Rosa @ 2020-10-12 3:35 UTC (permalink / raw) To: qemu-devel Cc: Thomas Huth, Beraldo Leal, Michael S. Tsirkin, Alex Bennée, Wainer dos Santos Moschetta, Willian Rampazzo, Cleber Rosa, Paolo Bonzini, Eduardo Habkost, Philippe Mathieu-Daudé, Richard Henderson When parsing the topology, the right default value of 1 is given to dies, but if an invalid number such as 0 is given, QEMU will crash with a floating point exception. The alternative approach is to silently set dies to a valid value, as it's done with cores and threads. Signed-off-by: Cleber Rosa <crosa@redhat.com> --- hw/i386/pc.c | 5 +++++ tests/acceptance/cpu_topology_dies.py | 31 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/acceptance/cpu_topology_dies.py diff --git a/hw/i386/pc.c b/hw/i386/pc.c index e87be5d29a..209e44663d 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -713,6 +713,11 @@ void pc_smp_parse(MachineState *ms, QemuOpts *opts) unsigned cores = qemu_opt_get_number(opts, "cores", 0); unsigned threads = qemu_opt_get_number(opts, "threads", 0); + if (dies <= 0) { + error_report("Invalid CPU topology: dies must be 1 or greater"); + exit(1); + } + /* compute missing values, prefer sockets over cores over threads */ if (cpus == 0 || sockets == 0) { cores = cores > 0 ? cores : 1; diff --git a/tests/acceptance/cpu_topology_dies.py b/tests/acceptance/cpu_topology_dies.py new file mode 100644 index 0000000000..d73b7b30a2 --- /dev/null +++ b/tests/acceptance/cpu_topology_dies.py @@ -0,0 +1,31 @@ +# Check for crash when using invalid dies value for -smp +# +# Copyright (c) 2020 Red Hat, Inc. +# +# Author: +# Cleber Rosa <crosa@redhat.com> +# +# This work is licensed under the terms of the GNU GPL, version 2 or +# later. See the COPYING file in the top-level directory. +from avocado_qemu import Test + +class CPUTolopogyDies(Test): + """ + :avocado: tags=arch:x86_64 + :avocado: tags=machine:pc + """ + def test_invalid(self): + self.vm.add_args('-S', '-display', 'none', '-smp', '1,dies=0') + self.vm.set_qmp_monitor(enabled=False) + self.vm.launch() + self.vm.wait() + self.assertEquals(self.vm.exitcode(), 1, "QEMU exit code should be 1") + self.assertRegex(self.vm.get_log(), + r'Invalid CPU topology: dies must be 1 or greater') + + def test_valid(self): + self.vm.add_args('-S', '-display', 'none', '-smp', '1,dies=1') + self.vm.launch() + self.vm.command('quit') + self.vm.wait() + self.assertEquals(self.vm.exitcode(), 0, "QEMU exit code should be 0") -- 2.25.4 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] hw/i386: prevent crash when an invalid number of dies is given 2020-10-12 3:35 ` [PATCH 1/1] " Cleber Rosa @ 2020-10-19 16:30 ` Willian Rampazzo 0 siblings, 0 replies; 3+ messages in thread From: Willian Rampazzo @ 2020-10-19 16:30 UTC (permalink / raw) To: Cleber Rosa Cc: Thomas Huth, Beraldo Leal, Michael S. Tsirkin, Alex Bennée, qemu-devel, Wainer dos Santos Moschetta, Paolo Bonzini, Eduardo Habkost, Philippe Mathieu-Daudé, Richard Henderson On Mon, Oct 12, 2020 at 12:35 AM Cleber Rosa <crosa@redhat.com> wrote: > > When parsing the topology, the right default value of 1 is given to > dies, but if an invalid number such as 0 is given, QEMU will crash > with a floating point exception. > > The alternative approach is to silently set dies to a valid value, > as it's done with cores and threads. > > Signed-off-by: Cleber Rosa <crosa@redhat.com> > --- > hw/i386/pc.c | 5 +++++ > tests/acceptance/cpu_topology_dies.py | 31 +++++++++++++++++++++++++++ > 2 files changed, 36 insertions(+) > create mode 100644 tests/acceptance/cpu_topology_dies.py > > diff --git a/hw/i386/pc.c b/hw/i386/pc.c > index e87be5d29a..209e44663d 100644 > --- a/hw/i386/pc.c > +++ b/hw/i386/pc.c > @@ -713,6 +713,11 @@ void pc_smp_parse(MachineState *ms, QemuOpts *opts) > unsigned cores = qemu_opt_get_number(opts, "cores", 0); > unsigned threads = qemu_opt_get_number(opts, "threads", 0); > > + if (dies <= 0) { > + error_report("Invalid CPU topology: dies must be 1 or greater"); > + exit(1); > + } > + > /* compute missing values, prefer sockets over cores over threads */ > if (cpus == 0 || sockets == 0) { > cores = cores > 0 ? cores : 1; > diff --git a/tests/acceptance/cpu_topology_dies.py b/tests/acceptance/cpu_topology_dies.py > new file mode 100644 > index 0000000000..d73b7b30a2 > --- /dev/null > +++ b/tests/acceptance/cpu_topology_dies.py > @@ -0,0 +1,31 @@ > +# Check for crash when using invalid dies value for -smp > +# > +# Copyright (c) 2020 Red Hat, Inc. > +# > +# Author: > +# Cleber Rosa <crosa@redhat.com> > +# > +# This work is licensed under the terms of the GNU GPL, version 2 or > +# later. See the COPYING file in the top-level directory. > +from avocado_qemu import Test > + > +class CPUTolopogyDies(Test): > + """ > + :avocado: tags=arch:x86_64 > + :avocado: tags=machine:pc > + """ > + def test_invalid(self): > + self.vm.add_args('-S', '-display', 'none', '-smp', '1,dies=0') > + self.vm.set_qmp_monitor(enabled=False) > + self.vm.launch() > + self.vm.wait() > + self.assertEquals(self.vm.exitcode(), 1, "QEMU exit code should be 1") > + self.assertRegex(self.vm.get_log(), > + r'Invalid CPU topology: dies must be 1 or greater') > + > + def test_valid(self): > + self.vm.add_args('-S', '-display', 'none', '-smp', '1,dies=1') > + self.vm.launch() > + self.vm.command('quit') > + self.vm.wait() > + self.assertEquals(self.vm.exitcode(), 0, "QEMU exit code should be 0") > -- > 2.25.4 > Reviewed-by: Willian Rampazzo <willianr@redhat.com> ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-10-19 16:32 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-10-12 3:35 [PATCH 0/1] hw/i386: prevent crash when an invalid number of dies is given Cleber Rosa 2020-10-12 3:35 ` [PATCH 1/1] " Cleber Rosa 2020-10-19 16:30 ` Willian Rampazzo
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).