xref: /qemu/tests/functional/test_mem_addr_space.py (revision 9f7cf938efc6016f7ce323b064c2f3f46360c751)
1cce85725SThomas Huth#!/usr/bin/env python3
2cce85725SThomas Huth#
30034d039SAni Sinha# Check for crash when using memory beyond the available guest processor
40034d039SAni Sinha# address space.
50034d039SAni Sinha#
60034d039SAni Sinha# Copyright (c) 2023 Red Hat, Inc.
70034d039SAni Sinha#
80034d039SAni Sinha# Author:
90034d039SAni Sinha#  Ani Sinha <anisinha@redhat.com>
100034d039SAni Sinha#
110034d039SAni Sinha# SPDX-License-Identifier: GPL-2.0-or-later
120034d039SAni Sinha
13cce85725SThomas Huthfrom qemu_test import QemuSystemTest
140034d039SAni Sinhaimport time
150034d039SAni Sinha
160034d039SAni Sinhaclass MemAddrCheck(QemuSystemTest):
170034d039SAni Sinha    # after launch, in order to generate the logs from QEMU we need to
180034d039SAni Sinha    # wait for some time. Launching and then immediately shutting down
190034d039SAni Sinha    # the VM generates empty logs. A delay of 1 second is added for
200034d039SAni Sinha    # this reason.
210034d039SAni Sinha    DELAY_Q35_BOOT_SEQUENCE = 1
220034d039SAni Sinha
2342ea7f78SDaniel P. Berrangé    # This helper can go away when the 32-bit host deprecation
2442ea7f78SDaniel P. Berrangé    # turns into full & final removal of support.
2542ea7f78SDaniel P. Berrangé    def ensure_64bit_binary(self):
2642ea7f78SDaniel P. Berrangé        with open(self.qemu_bin, "rb") as fh:
2742ea7f78SDaniel P. Berrangé            ident = fh.read(4)
2842ea7f78SDaniel P. Berrangé
2942ea7f78SDaniel P. Berrangé            # "\x7fELF"
3042ea7f78SDaniel P. Berrangé            if ident != bytes([0x7f, 0x45, 0x4C, 0x46]):
3142ea7f78SDaniel P. Berrangé                # Non-ELF file implies macOS or Windows which
3242ea7f78SDaniel P. Berrangé                # we already assume to be 64-bit only
3342ea7f78SDaniel P. Berrangé                return
3442ea7f78SDaniel P. Berrangé
3542ea7f78SDaniel P. Berrangé            # bits == 1 -> 32-bit; bits == 2 -> 64-bit
3642ea7f78SDaniel P. Berrangé            bits = int.from_bytes(fh.read(1), byteorder='little')
3742ea7f78SDaniel P. Berrangé            if bits != 2:
3842ea7f78SDaniel P. Berrangé                # 32-bit ELF builds won't be able to address sufficient
3942ea7f78SDaniel P. Berrangé                # RAM to run the tests
4042ea7f78SDaniel P. Berrangé                self.skipTest("64-bit build host is required")
4142ea7f78SDaniel P. Berrangé
420034d039SAni Sinha    # first, lets test some 32-bit processors.
430034d039SAni Sinha    # for all 32-bit cases, pci64_hole_size is 0.
440034d039SAni Sinha    def test_phybits_low_pse36(self):
450034d039SAni Sinha        """
460034d039SAni Sinha        With pse36 feature ON, a processor has 36 bits of addressing. So it can
470034d039SAni Sinha        access up to a maximum of 64GiB of memory. Memory hotplug region begins
480034d039SAni Sinha        at 4 GiB boundary when "above_4g_mem_size" is 0 (this would be true when
490034d039SAni Sinha        we have 0.5 GiB of VM memory, see pc_q35_init()). This means total
500034d039SAni Sinha        hotpluggable memory size is 60 GiB. Per slot, we reserve 1 GiB of memory
51516871f0SPhilippe Mathieu-Daudé        for dimm alignment for all machines. That leaves total hotpluggable
52516871f0SPhilippe Mathieu-Daudé        actual memory size of 59 GiB. If the VM is started with 0.5 GiB of
53516871f0SPhilippe Mathieu-Daudé        memory, maxmem should be set to a maximum value of 59.5 GiB to ensure
54516871f0SPhilippe Mathieu-Daudé        that the processor can address all memory directly.
550034d039SAni Sinha        Note that 64-bit pci hole size is 0 in this case. If maxmem is set to
560034d039SAni Sinha        59.6G, QEMU should fail to start with a message "phy-bits are too low".
570034d039SAni Sinha        If maxmem is set to 59.5G with all other QEMU parameters identical, QEMU
580034d039SAni Sinha        should start fine.
590034d039SAni Sinha        """
6042ea7f78SDaniel P. Berrangé        self.ensure_64bit_binary()
61*9f7cf938SThomas Huth        self.set_machine('q35')
62*9f7cf938SThomas Huth        self.vm.add_args('-S', '-m', '512,slots=1,maxmem=59.6G',
630034d039SAni Sinha                         '-cpu', 'pentium,pse36=on', '-display', 'none',
640034d039SAni Sinha                         '-object', 'memory-backend-ram,id=mem1,size=1G',
650034d039SAni Sinha                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
660034d039SAni Sinha        self.vm.set_qmp_monitor(enabled=False)
670034d039SAni Sinha        self.vm.launch()
680034d039SAni Sinha        self.vm.wait()
69572960cbSThomas Huth        self.assertEqual(self.vm.exitcode(), 1, "QEMU exit code should be 1")
700034d039SAni Sinha        self.assertRegex(self.vm.get_log(), r'phys-bits too low')
710034d039SAni Sinha
720034d039SAni Sinha    def test_phybits_low_pae(self):
730034d039SAni Sinha        """
740034d039SAni Sinha        With pae feature ON, a processor has 36 bits of addressing. So it can
750034d039SAni Sinha        access up to a maximum of 64GiB of memory. Rest is the same as the case
760034d039SAni Sinha        with pse36 above.
770034d039SAni Sinha        """
7842ea7f78SDaniel P. Berrangé        self.ensure_64bit_binary()
79*9f7cf938SThomas Huth        self.set_machine('q35')
80*9f7cf938SThomas Huth        self.vm.add_args('-S', '-m', '512,slots=1,maxmem=59.6G',
810034d039SAni Sinha                         '-cpu', 'pentium,pae=on', '-display', 'none',
820034d039SAni Sinha                         '-object', 'memory-backend-ram,id=mem1,size=1G',
830034d039SAni Sinha                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
840034d039SAni Sinha        self.vm.set_qmp_monitor(enabled=False)
850034d039SAni Sinha        self.vm.launch()
860034d039SAni Sinha        self.vm.wait()
87572960cbSThomas Huth        self.assertEqual(self.vm.exitcode(), 1, "QEMU exit code should be 1")
880034d039SAni Sinha        self.assertRegex(self.vm.get_log(), r'phys-bits too low')
890034d039SAni Sinha
900034d039SAni Sinha    def test_phybits_ok_pentium_pse36(self):
910034d039SAni Sinha        """
920034d039SAni Sinha        Setting maxmem to 59.5G and making sure that QEMU can start with the
930034d039SAni Sinha        same options as the failing case above with pse36 cpu feature.
940034d039SAni Sinha        """
9542ea7f78SDaniel P. Berrangé        self.ensure_64bit_binary()
96*9f7cf938SThomas Huth        self.set_machine('q35')
97*9f7cf938SThomas Huth        self.vm.add_args('-m', '512,slots=1,maxmem=59.5G',
980034d039SAni Sinha                         '-cpu', 'pentium,pse36=on', '-display', 'none',
990034d039SAni Sinha                         '-object', 'memory-backend-ram,id=mem1,size=1G',
1000034d039SAni Sinha                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
1010034d039SAni Sinha        self.vm.set_qmp_monitor(enabled=False)
1020034d039SAni Sinha        self.vm.launch()
1030034d039SAni Sinha        time.sleep(self.DELAY_Q35_BOOT_SEQUENCE)
1040034d039SAni Sinha        self.vm.shutdown()
1050034d039SAni Sinha        self.assertNotRegex(self.vm.get_log(), r'phys-bits too low')
1060034d039SAni Sinha
1070034d039SAni Sinha    def test_phybits_ok_pentium_pae(self):
1080034d039SAni Sinha        """
1090034d039SAni Sinha        Test is same as above but now with pae cpu feature turned on.
1100034d039SAni Sinha        Setting maxmem to 59.5G and making sure that QEMU can start fine
1110034d039SAni Sinha        with the same options as the case above.
1120034d039SAni Sinha        """
11342ea7f78SDaniel P. Berrangé        self.ensure_64bit_binary()
114*9f7cf938SThomas Huth        self.set_machine('q35')
115*9f7cf938SThomas Huth        self.vm.add_args('-m', '512,slots=1,maxmem=59.5G',
1160034d039SAni Sinha                         '-cpu', 'pentium,pae=on', '-display', 'none',
1170034d039SAni Sinha                         '-object', 'memory-backend-ram,id=mem1,size=1G',
1180034d039SAni Sinha                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
1190034d039SAni Sinha        self.vm.set_qmp_monitor(enabled=False)
1200034d039SAni Sinha        self.vm.launch()
1210034d039SAni Sinha        time.sleep(self.DELAY_Q35_BOOT_SEQUENCE)
1220034d039SAni Sinha        self.vm.shutdown()
1230034d039SAni Sinha        self.assertNotRegex(self.vm.get_log(), r'phys-bits too low')
1240034d039SAni Sinha
1250034d039SAni Sinha    def test_phybits_ok_pentium2(self):
1260034d039SAni Sinha        """
1270034d039SAni Sinha        Pentium2 has 36 bits of addressing, so its same as pentium
1280034d039SAni Sinha        with pse36 ON.
1290034d039SAni Sinha        """
13042ea7f78SDaniel P. Berrangé        self.ensure_64bit_binary()
131*9f7cf938SThomas Huth        self.set_machine('q35')
132*9f7cf938SThomas Huth        self.vm.add_args('-m', '512,slots=1,maxmem=59.5G',
1330034d039SAni Sinha                         '-cpu', 'pentium2', '-display', 'none',
1340034d039SAni Sinha                         '-object', 'memory-backend-ram,id=mem1,size=1G',
1350034d039SAni Sinha                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
1360034d039SAni Sinha        self.vm.set_qmp_monitor(enabled=False)
1370034d039SAni Sinha        self.vm.launch()
1380034d039SAni Sinha        time.sleep(self.DELAY_Q35_BOOT_SEQUENCE)
1390034d039SAni Sinha        self.vm.shutdown()
1400034d039SAni Sinha        self.assertNotRegex(self.vm.get_log(), r'phys-bits too low')
1410034d039SAni Sinha
1420034d039SAni Sinha    def test_phybits_low_nonpse36(self):
1430034d039SAni Sinha        """
1440034d039SAni Sinha        Pentium processor has 32 bits of addressing without pse36 or pae
1450034d039SAni Sinha        so it can access physical address up to 4 GiB. Setting maxmem to
1460034d039SAni Sinha        4 GiB should make QEMU fail to start with "phys-bits too low"
1470034d039SAni Sinha        message because the region for memory hotplug is always placed
1480034d039SAni Sinha        above 4 GiB due to the PCI hole and simplicity.
1490034d039SAni Sinha        """
15042ea7f78SDaniel P. Berrangé        self.ensure_64bit_binary()
151*9f7cf938SThomas Huth        self.set_machine('q35')
152*9f7cf938SThomas Huth        self.vm.add_args('-S', '-m', '512,slots=1,maxmem=4G',
1530034d039SAni Sinha                         '-cpu', 'pentium', '-display', 'none',
1540034d039SAni Sinha                         '-object', 'memory-backend-ram,id=mem1,size=1G',
1550034d039SAni Sinha                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
1560034d039SAni Sinha        self.vm.set_qmp_monitor(enabled=False)
1570034d039SAni Sinha        self.vm.launch()
1580034d039SAni Sinha        self.vm.wait()
159572960cbSThomas Huth        self.assertEqual(self.vm.exitcode(), 1, "QEMU exit code should be 1")
1600034d039SAni Sinha        self.assertRegex(self.vm.get_log(), r'phys-bits too low')
1610034d039SAni Sinha
1620034d039SAni Sinha    # now lets test some 64-bit CPU cases.
1630034d039SAni Sinha    def test_phybits_low_tcg_q35_70_amd(self):
1640034d039SAni Sinha        """
1650034d039SAni Sinha        For q35 7.1 machines and above, there is a HT window that starts at
1660034d039SAni Sinha        1024 GiB and ends at 1 TiB - 1. If the max GPA falls in this range,
1670034d039SAni Sinha        "above_4G" memory is adjusted to start at 1 TiB boundary for AMD cpus
1680034d039SAni Sinha        in the default case. Lets test without that case for machines 7.0.
1690034d039SAni Sinha        For q35-7.0 machines, "above 4G" memory starts are 4G.
1700034d039SAni Sinha        pci64_hole size is 32 GiB. Since TCG_PHYS_ADDR_BITS is defined to
1710034d039SAni Sinha        be 40, TCG emulated CPUs have maximum of 1 TiB (1024 GiB) of
17235a5a331SManos Pitsidianakis        directly addressable memory.
1730034d039SAni Sinha        Hence, maxmem value at most can be
1740034d039SAni Sinha        1024 GiB - 4 GiB - 1 GiB per slot for alignment - 32 GiB + 0.5 GiB
1750034d039SAni Sinha        which is equal to 987.5 GiB. Setting the value to 988 GiB should
1760034d039SAni Sinha        make QEMU fail with the error message.
1770034d039SAni Sinha        """
17842ea7f78SDaniel P. Berrangé        self.ensure_64bit_binary()
179*9f7cf938SThomas Huth        self.set_machine('pc-q35-7.0')
180*9f7cf938SThomas Huth        self.vm.add_args('-S', '-m', '512,slots=1,maxmem=988G',
1810034d039SAni Sinha                         '-display', 'none',
1820034d039SAni Sinha                         '-object', 'memory-backend-ram,id=mem1,size=1G',
1830034d039SAni Sinha                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
1840034d039SAni Sinha        self.vm.set_qmp_monitor(enabled=False)
1850034d039SAni Sinha        self.vm.launch()
1860034d039SAni Sinha        self.vm.wait()
187572960cbSThomas Huth        self.assertEqual(self.vm.exitcode(), 1, "QEMU exit code should be 1")
1880034d039SAni Sinha        self.assertRegex(self.vm.get_log(), r'phys-bits too low')
1890034d039SAni Sinha
1900034d039SAni Sinha    def test_phybits_low_tcg_q35_71_amd(self):
1910034d039SAni Sinha        """
1920034d039SAni Sinha        AMD_HT_START is defined to be at 1012 GiB. So for q35 machines
1930034d039SAni Sinha        version > 7.0 and AMD cpus, instead of 1024 GiB limit for 40 bit
1940034d039SAni Sinha        processor address space, it has to be 1012 GiB , that is 12 GiB
19535a5a331SManos Pitsidianakis        less than the case above in order to accommodate HT hole.
1960034d039SAni Sinha        Make sure QEMU fails when maxmem size is 976 GiB (12 GiB less
1970034d039SAni Sinha        than 988 GiB).
1980034d039SAni Sinha        """
19942ea7f78SDaniel P. Berrangé        self.ensure_64bit_binary()
200*9f7cf938SThomas Huth        self.set_machine('pc-q35-7.1')
201*9f7cf938SThomas Huth        self.vm.add_args('-S', '-m', '512,slots=1,maxmem=976G',
2020034d039SAni Sinha                         '-display', 'none',
2030034d039SAni Sinha                         '-object', 'memory-backend-ram,id=mem1,size=1G',
2040034d039SAni Sinha                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
2050034d039SAni Sinha        self.vm.set_qmp_monitor(enabled=False)
2060034d039SAni Sinha        self.vm.launch()
2070034d039SAni Sinha        self.vm.wait()
208572960cbSThomas Huth        self.assertEqual(self.vm.exitcode(), 1, "QEMU exit code should be 1")
2090034d039SAni Sinha        self.assertRegex(self.vm.get_log(), r'phys-bits too low')
2100034d039SAni Sinha
2110034d039SAni Sinha    def test_phybits_ok_tcg_q35_70_amd(self):
2120034d039SAni Sinha        """
2130034d039SAni Sinha        Same as q35-7.0 AMD case except that here we check that QEMU can
2140034d039SAni Sinha        successfully start when maxmem is < 988G.
2150034d039SAni Sinha        """
21642ea7f78SDaniel P. Berrangé        self.ensure_64bit_binary()
217*9f7cf938SThomas Huth        self.set_machine('pc-q35-7.0')
218*9f7cf938SThomas Huth        self.vm.add_args('-S', '-m', '512,slots=1,maxmem=987.5G',
2190034d039SAni Sinha                         '-display', 'none',
2200034d039SAni Sinha                         '-object', 'memory-backend-ram,id=mem1,size=1G',
2210034d039SAni Sinha                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
2220034d039SAni Sinha        self.vm.set_qmp_monitor(enabled=False)
2230034d039SAni Sinha        self.vm.launch()
2240034d039SAni Sinha        time.sleep(self.DELAY_Q35_BOOT_SEQUENCE)
2250034d039SAni Sinha        self.vm.shutdown()
2260034d039SAni Sinha        self.assertNotRegex(self.vm.get_log(), r'phys-bits too low')
2270034d039SAni Sinha
2280034d039SAni Sinha    def test_phybits_ok_tcg_q35_71_amd(self):
2290034d039SAni Sinha        """
2300034d039SAni Sinha        Same as q35-7.1 AMD case except that here we check that QEMU can
2310034d039SAni Sinha        successfully start when maxmem is < 976G.
2320034d039SAni Sinha        """
23342ea7f78SDaniel P. Berrangé        self.ensure_64bit_binary()
234*9f7cf938SThomas Huth        self.set_machine('pc-q35-7.1')
235*9f7cf938SThomas Huth        self.vm.add_args('-S', '-m', '512,slots=1,maxmem=975.5G',
2360034d039SAni Sinha                         '-display', 'none',
2370034d039SAni Sinha                         '-object', 'memory-backend-ram,id=mem1,size=1G',
2380034d039SAni Sinha                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
2390034d039SAni Sinha        self.vm.set_qmp_monitor(enabled=False)
2400034d039SAni Sinha        self.vm.launch()
2410034d039SAni Sinha        time.sleep(self.DELAY_Q35_BOOT_SEQUENCE)
2420034d039SAni Sinha        self.vm.shutdown()
2430034d039SAni Sinha        self.assertNotRegex(self.vm.get_log(), r'phys-bits too low')
2440034d039SAni Sinha
2450034d039SAni Sinha    def test_phybits_ok_tcg_q35_71_intel(self):
2460034d039SAni Sinha        """
2470034d039SAni Sinha        Same parameters as test_phybits_low_tcg_q35_71_amd() but use
2480034d039SAni Sinha        Intel cpu instead. QEMU should start fine in this case as
2490034d039SAni Sinha        "above_4G" memory starts at 4G.
2500034d039SAni Sinha        """
25142ea7f78SDaniel P. Berrangé        self.ensure_64bit_binary()
252*9f7cf938SThomas Huth        self.set_machine('pc-q35-7.1')
2530034d039SAni Sinha        self.vm.add_args('-S', '-cpu', 'Skylake-Server',
254*9f7cf938SThomas Huth                         '-m', '512,slots=1,maxmem=976G',
2550034d039SAni Sinha                         '-display', 'none',
2560034d039SAni Sinha                         '-object', 'memory-backend-ram,id=mem1,size=1G',
2570034d039SAni Sinha                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
2580034d039SAni Sinha        self.vm.set_qmp_monitor(enabled=False)
2590034d039SAni Sinha        self.vm.launch()
2600034d039SAni Sinha        time.sleep(self.DELAY_Q35_BOOT_SEQUENCE)
2610034d039SAni Sinha        self.vm.shutdown()
2620034d039SAni Sinha        self.assertNotRegex(self.vm.get_log(), r'phys-bits too low')
2630034d039SAni Sinha
2640034d039SAni Sinha    def test_phybits_low_tcg_q35_71_amd_41bits(self):
2650034d039SAni Sinha        """
2660034d039SAni Sinha        AMD processor with 41 bits. Max cpu hw address = 2 TiB.
2670034d039SAni Sinha        By setting maxram above 1012 GiB  - 32 GiB - 4 GiB = 976 GiB, we can
2680034d039SAni Sinha        force "above_4G" memory to start at 1 TiB for q35-7.1 machines
2690034d039SAni Sinha        (max GPA will be above AMD_HT_START which is defined as 1012 GiB).
2700034d039SAni Sinha
2710034d039SAni Sinha        With pci_64_hole size at 32 GiB, in this case, maxmem should be 991.5
2720034d039SAni Sinha        GiB with 1 GiB per slot for alignment and 0.5 GiB as non-hotplug
2730034d039SAni Sinha        memory for the VM (1024 - 32 - 1 + 0.5). With 992 GiB, QEMU should
2740034d039SAni Sinha        fail to start.
2750034d039SAni Sinha        """
27642ea7f78SDaniel P. Berrangé        self.ensure_64bit_binary()
277*9f7cf938SThomas Huth        self.set_machine('pc-q35-7.1')
2780034d039SAni Sinha        self.vm.add_args('-S', '-cpu', 'EPYC-v4,phys-bits=41',
279*9f7cf938SThomas Huth                         '-m', '512,slots=1,maxmem=992G',
2800034d039SAni Sinha                         '-display', 'none',
2810034d039SAni Sinha                         '-object', 'memory-backend-ram,id=mem1,size=1G',
2820034d039SAni Sinha                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
2830034d039SAni Sinha        self.vm.set_qmp_monitor(enabled=False)
2840034d039SAni Sinha        self.vm.launch()
2850034d039SAni Sinha        self.vm.wait()
286572960cbSThomas Huth        self.assertEqual(self.vm.exitcode(), 1, "QEMU exit code should be 1")
2870034d039SAni Sinha        self.assertRegex(self.vm.get_log(), r'phys-bits too low')
2880034d039SAni Sinha
2890034d039SAni Sinha    def test_phybits_ok_tcg_q35_71_amd_41bits(self):
2900034d039SAni Sinha        """
2910034d039SAni Sinha        AMD processor with 41 bits. Max cpu hw address = 2 TiB.
29235a5a331SManos Pitsidianakis        Same as above but by setting maxram between 976 GiB and 992 Gib,
2930034d039SAni Sinha        QEMU should start fine.
2940034d039SAni Sinha        """
29542ea7f78SDaniel P. Berrangé        self.ensure_64bit_binary()
296*9f7cf938SThomas Huth        self.set_machine('pc-q35-7.1')
2970034d039SAni Sinha        self.vm.add_args('-S', '-cpu', 'EPYC-v4,phys-bits=41',
298*9f7cf938SThomas Huth                         '-m', '512,slots=1,maxmem=990G',
2990034d039SAni Sinha                         '-display', 'none',
3000034d039SAni Sinha                         '-object', 'memory-backend-ram,id=mem1,size=1G',
3010034d039SAni Sinha                         '-device', 'pc-dimm,id=vm0,memdev=mem1')
3020034d039SAni Sinha        self.vm.set_qmp_monitor(enabled=False)
3030034d039SAni Sinha        self.vm.launch()
3040034d039SAni Sinha        time.sleep(self.DELAY_Q35_BOOT_SEQUENCE)
3050034d039SAni Sinha        self.vm.shutdown()
3060034d039SAni Sinha        self.assertNotRegex(self.vm.get_log(), r'phys-bits too low')
3070034d039SAni Sinha
3080034d039SAni Sinha    def test_phybits_low_tcg_q35_intel_cxl(self):
3090034d039SAni Sinha        """
3100034d039SAni Sinha        cxl memory window starts after memory device range. Here, we use 1 GiB
3110034d039SAni Sinha        of cxl window memory. 4G_mem end aligns at 4G. pci64_hole is 32 GiB and
3120034d039SAni Sinha        starts after the cxl memory window.
3130034d039SAni Sinha        So maxmem here should be at most 986 GiB considering all memory boundary
3140034d039SAni Sinha        alignment constraints with 40 bits (1 TiB) of processor physical bits.
3150034d039SAni Sinha        """
31642ea7f78SDaniel P. Berrangé        self.ensure_64bit_binary()
317*9f7cf938SThomas Huth        self.set_machine('q35')
3180034d039SAni Sinha        self.vm.add_args('-S', '-cpu', 'Skylake-Server,phys-bits=40',
319*9f7cf938SThomas Huth                         '-m', '512,slots=1,maxmem=987G',
3200034d039SAni Sinha                         '-display', 'none',
3210034d039SAni Sinha                         '-device', 'pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1',
322*9f7cf938SThomas Huth                         '-M', 'cxl=on,cxl-fmw.0.targets.0=cxl.1,cxl-fmw.0.size=1G')
3230034d039SAni Sinha        self.vm.set_qmp_monitor(enabled=False)
3240034d039SAni Sinha        self.vm.launch()
3250034d039SAni Sinha        self.vm.wait()
326572960cbSThomas Huth        self.assertEqual(self.vm.exitcode(), 1, "QEMU exit code should be 1")
3270034d039SAni Sinha        self.assertRegex(self.vm.get_log(), r'phys-bits too low')
3280034d039SAni Sinha
3290034d039SAni Sinha    def test_phybits_ok_tcg_q35_intel_cxl(self):
3300034d039SAni Sinha        """
3310034d039SAni Sinha        Same as above but here we do not reserve any cxl memory window. Hence,
3320034d039SAni Sinha        with the exact same parameters as above, QEMU should start fine even
3330034d039SAni Sinha        with cxl enabled.
3340034d039SAni Sinha        """
33542ea7f78SDaniel P. Berrangé        self.ensure_64bit_binary()
336*9f7cf938SThomas Huth        self.set_machine('q35')
3370034d039SAni Sinha        self.vm.add_args('-S', '-cpu', 'Skylake-Server,phys-bits=40',
338*9f7cf938SThomas Huth                         '-machine', 'cxl=on',
339*9f7cf938SThomas Huth                         '-m', '512,slots=1,maxmem=987G',
3400034d039SAni Sinha                         '-display', 'none',
3410034d039SAni Sinha                         '-device', 'pxb-cxl,bus_nr=12,bus=pcie.0,id=cxl.1')
3420034d039SAni Sinha        self.vm.set_qmp_monitor(enabled=False)
3430034d039SAni Sinha        self.vm.launch()
3440034d039SAni Sinha        time.sleep(self.DELAY_Q35_BOOT_SEQUENCE)
3450034d039SAni Sinha        self.vm.shutdown()
3460034d039SAni Sinha        self.assertNotRegex(self.vm.get_log(), r'phys-bits too low')
347cce85725SThomas Huth
348cce85725SThomas Huthif __name__ == '__main__':
349cce85725SThomas Huth    QemuSystemTest.main()
350