qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Ani Sinha <anisinha@redhat.com>, Cleber Rosa <crosa@redhat.com>,
	Wainer dos Santos Moschetta <wainersm@redhat.com>,
	Beraldo Leal <bleal@redhat.com>
Cc: imammedo@redhat.com, David Hildenbrand <david@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [PATCH v5] tests/avocado: add test to exercize processor address space memory bound checks
Date: Wed, 8 Nov 2023 16:03:51 +0100	[thread overview]
Message-ID: <cabed062-bfb7-431d-b0fe-b38c159165e4@linaro.org> (raw)
In-Reply-To: <20231103110643.11664-1-anisinha@redhat.com>

Hi Ani,

On 3/11/23 12:06, Ani Sinha wrote:
> QEMU has validations to make sure that a VM is not started with more memory
> (static and hotpluggable memory) than what the guest processor can address
> directly with its addressing bits. This change adds a test to make sure QEMU
> fails to start with a specific error message when an attempt is made to
> start a VM with more memory than what the processor can directly address.
> The test also checks for passing cases when the address space of the processor
> is capable of addressing all memory. Boundary cases are tested.
> 
> CC: imammedo@redhat.com
> CC: David Hildenbrand <david@redhat.com>
> Acked-by: David Hildenbrand <david@redhat.com>
> Signed-off-by: Ani Sinha <anisinha@redhat.com>
> ---
>   tests/avocado/mem-addr-space-check.py | 361 ++++++++++++++++++++++++++
>   1 file changed, 361 insertions(+)
>   create mode 100644 tests/avocado/mem-addr-space-check.py
> 
> Changelog:
> v5:
>    - made the negative test cases (ones that do not result in QEMU crash)
>      more robust by checking the non-existence of the "phys-bits too low"
>      log.
>    - added a new test case for AMD HT window where QEMU starts fine.
>    - rebased.
>    - cosmetic typo/comment adjustments.
> 
> Tests all pass:
> $ ./pyvenv/bin/avocado run tests/avocado/mem-addr-space-check.py --tap -
> 1..15
> ok 1 tests/avocado/mem-addr-space-check.py:MemAddrCheck.test_phybits_low_pse36
> ok 2 tests/avocado/mem-addr-space-check.py:MemAddrCheck.test_phybits_low_pae
> ok 3 tests/avocado/mem-addr-space-check.py:MemAddrCheck.test_phybits_ok_pentium_pse36
> ok 4 tests/avocado/mem-addr-space-check.py:MemAddrCheck.test_phybits_ok_pentium_pae
> ok 5 tests/avocado/mem-addr-space-check.py:MemAddrCheck.test_phybits_ok_pentium2
> ok 6 tests/avocado/mem-addr-space-check.py:MemAddrCheck.test_phybits_low_nonpse36
> ok 7 tests/avocado/mem-addr-space-check.py:MemAddrCheck.test_phybits_low_tcg_q35_70_amd
> ok 8 tests/avocado/mem-addr-space-check.py:MemAddrCheck.test_phybits_low_tcg_q35_71_amd
> ok 9 tests/avocado/mem-addr-space-check.py:MemAddrCheck.test_phybits_ok_tcg_q35_70_amd
> ok 10 tests/avocado/mem-addr-space-check.py:MemAddrCheck.test_phybits_ok_tcg_q35_71_amd
> ok 11 tests/avocado/mem-addr-space-check.py:MemAddrCheck.test_phybits_ok_tcg_q35_71_intel
> ok 12 tests/avocado/mem-addr-space-check.py:MemAddrCheck.test_phybits_low_tcg_q35_71_amd_41bits
> ok 13 tests/avocado/mem-addr-space-check.py:MemAddrCheck.test_phybits_ok_tcg_q35_71_amd_41bits
> ok 14 tests/avocado/mem-addr-space-check.py:MemAddrCheck.test_phybits_low_tcg_q35_intel_cxl
> ok 15 tests/avocado/mem-addr-space-check.py:MemAddrCheck.test_phybits_ok_tcg_q35_intel_cxl
> 
> v4: incorporated changes related to suggestions from David.
> v3: added pae tests as well.
> v2: added 64-bit tests. Added cxl tests.
> 
> diff --git a/tests/avocado/mem-addr-space-check.py b/tests/avocado/mem-addr-space-check.py
> new file mode 100644
> index 0000000000..6b4ada5857
> --- /dev/null
> +++ b/tests/avocado/mem-addr-space-check.py
> @@ -0,0 +1,361 @@
> +# Check for crash when using memory beyond the available guest processor
> +# address space.
> +#
> +# Copyright (c) 2023 Red Hat, Inc.
> +#
> +# Author:
> +#  Ani Sinha <anisinha@redhat.com>
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program.  If not, see <http://www.gnu.org/licenses/>.
> +
> +from avocado_qemu import QemuSystemTest
> +import signal
> +import time
> +
> +class MemAddrCheck(QemuSystemTest):
> +    # first, lets test some 32-bit processors.
> +    # for all 32-bit cases, pci64_hole_size is 0.
> +    def test_phybits_low_pse36(self):
> +        """
> +        :avocado: tags=machine:q35
> +        :avocado: tags=arch:x86_64
> +
> +        With pse36 feature ON, a processor has 36 bits of addressing. So it can
> +        access up to a maximum of 64GiB of memory. Memory hotplug region begins
> +        at 4 GiB boundary when "above_4g_mem_size" is 0 (this would be true when
> +        we have 0.5 GiB of VM memory, see pc_q35_init()). This means total
> +        hotpluggable memory size is 60 GiB. Per slot, we reserve 1 GiB of memory
> +        for dimm alignment for all newer machines (see enforce_aligned_dimm
> +        property for pc machines and pc_get_device_memory_range()). That leaves
> +        total hotpluggable actual memory size of 59 GiB. If the VM is started
> +        with 0.5 GiB of memory, maxmem should be set to a maximum value of
> +        59.5 GiB to ensure that the processor can address all memory directly.
> +        Note that 64-bit pci hole size is 0 in this case. If maxmem is set to
> +        59.6G, QEMU should fail to start with a message "phy-bits are too low".
> +        If maxmem is set to 59.5G with all other QEMU parameters identical, QEMU
> +        should start fine.
> +        """
> +        self.vm.add_args('-S', '-machine', 'q35', '-m',
> +                         '512,slots=1,maxmem=59.6G',
> +                         '-cpu', 'pentium,pse36=on', '-display', 'none',
> +                         '-object', 'memory-backend-ram,id=mem1,size=1G',
> +                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
> +        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'phys-bits too low')
> +
> +    def test_phybits_low_pae(self):
> +        """
> +        :avocado: tags=machine:q35
> +        :avocado: tags=arch:x86_64
> +
> +        With pae feature ON, a processor has 36 bits of addressing. So it can
> +        access up to a maximum of 64GiB of memory. Rest is the same as the case
> +        with pse36 above.
> +        """
> +        self.vm.add_args('-S', '-machine', 'q35', '-m',
> +                         '512,slots=1,maxmem=59.6G',
> +                         '-cpu', 'pentium,pae=on', '-display', 'none',
> +                         '-object', 'memory-backend-ram,id=mem1,size=1G',
> +                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
> +        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'phys-bits too low')
> +
> +    def test_phybits_ok_pentium_pse36(self):
> +        """
> +        :avocado: tags=machine:q35
> +        :avocado: tags=arch:x86_64
> +
> +        Setting maxmem to 59.5G and making sure that QEMU can start with the
> +        same options as the failing case above with pse36 cpu feature.
> +        """
> +        self.vm.add_args('-machine', 'q35', '-m',
> +                         '512,slots=1,maxmem=59.5G',
> +                         '-cpu', 'pentium,pse36=on', '-display', 'none',
> +                         '-object', 'memory-backend-ram,id=mem1,size=1G',
> +                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
> +        self.vm.set_qmp_monitor(enabled=False)
> +        self.vm.launch()
> +        time.sleep(3)

Why do we need to wait 3s? Maybe add a definition, then:

            time.sleep(DELAY_Q35_BOOT_SEQUENCE)

here and in the other tests. Or a comment. So we can tune
that delay in a single place. Otherwise,

Acked-by: Philippe Mathieu-Daudé <philmd@linaro.org>

> +        self.vm.shutdown()
> +        self.assertNotRegex(self.vm.get_log(), r'phys-bits too low')



  reply	other threads:[~2023-11-08 15:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-03 11:06 [PATCH v5] tests/avocado: add test to exercize processor address space memory bound checks Ani Sinha
2023-11-08 15:03 ` Philippe Mathieu-Daudé [this message]
2023-11-09  2:46   ` Ani Sinha

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=cabed062-bfb7-431d-b0fe-b38c159165e4@linaro.org \
    --to=philmd@linaro.org \
    --cc=anisinha@redhat.com \
    --cc=bleal@redhat.com \
    --cc=crosa@redhat.com \
    --cc=david@redhat.com \
    --cc=imammedo@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --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).