qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Willian Rampazzo <wrampazz@redhat.com>
To: Cleber Rosa <crosa@redhat.com>
Cc: "Thomas Huth" <thuth@redhat.com>,
	"Beraldo Leal" <bleal@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	qemu-devel <qemu-devel@nongnu.org>,
	"Wainer dos Santos Moschetta" <wainersm@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>,
	"Richard Henderson" <rth@twiddle.net>
Subject: Re: [PATCH 1/1] hw/i386: prevent crash when an invalid number of dies is given
Date: Mon, 19 Oct 2020 13:30:15 -0300	[thread overview]
Message-ID: <CAKJDGDZZLK6Sp0HtHA7roGuWMJYmcd6ytjf_rdn5N=oSuE9LEg@mail.gmail.com> (raw)
In-Reply-To: <20201012033507.906096-2-crosa@redhat.com>

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>



      reply	other threads:[~2020-10-19 16:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

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='CAKJDGDZZLK6Sp0HtHA7roGuWMJYmcd6ytjf_rdn5N=oSuE9LEg@mail.gmail.com' \
    --to=wrampazz@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=bleal@redhat.com \
    --cc=crosa@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=thuth@redhat.com \
    --cc=wainersm@redhat.com \
    /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).