From nobody Sat May 18 23:44:27 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1696577530; cv=none; d=zohomail.com; s=zohoarc; b=fXGes6+LJXck+9/QN91RnYYL2omDairKcP2guhRMm86l4yn39Cdjl0OmkKX+HBJ8HESBXOiRx4zozhYLYsg6PJl09BYPNylD6wqeGn5E0/u6uYh0ca1QN5xgakqBBq1Fs93MbT/NLp1e6oXvXCVlLO/QFIb/FYRDgfYwGVNsl0Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1696577530; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=oIbD361Dq1XrdFMBm2ks5K17RPXWKenYwe5/7qyYG28=; b=guF2lOX0645iqzHhQnIgEdE80Qu0S1aaUroC6pCRcNXocfpJoQ+qz83/v7NkWArVRHQwL88+0JphuX2Ezb0yUCXrGS2yuqi24vbkcnxTAWDnrJ6S1Bj7jMhXjOVMprx9+c2Kgo7hmd27DxgFtwrCOjcw8r12vgE7dkfPp+04Q24= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1696577530841303.07848135061784; Fri, 6 Oct 2023 00:32:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qofJM-0006XP-Nj; Fri, 06 Oct 2023 03:31:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qofJB-0006TD-Su for qemu-devel@nongnu.org; Fri, 06 Oct 2023 03:31:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qofJ9-00031X-ON for qemu-devel@nongnu.org; Fri, 06 Oct 2023 03:31:37 -0400 Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-562-wUg6LeeaNeSxTOoq7XvOwA-1; Fri, 06 Oct 2023 03:31:22 -0400 Received: by mail-oi1-f197.google.com with SMTP id 5614622812f47-3ae65e9d394so2800657b6e.2 for ; Fri, 06 Oct 2023 00:31:22 -0700 (PDT) Received: from localhost.localdomain ([115.96.157.133]) by smtp.googlemail.com with ESMTPSA id m22-20020a637d56000000b00563590be25esm2670338pgn.29.2023.10.06.00.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 00:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696577494; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=oIbD361Dq1XrdFMBm2ks5K17RPXWKenYwe5/7qyYG28=; b=B7Sf91YanvaAwZbpDGUSFy5tzH75DDa0U7pcl1dN1oM/F/NfRy98c2D44NbLmlXNsgz7wg 6e1UbcERoc3H7wgwfJrhnMWaEgsRwM6A8l1HAaImrdE0Awb5p8zZ0HW9DT4lcHNpQZVQ3W q2CeEA3IQDydz3G0yHSUZdGNT7wj2f8= X-MC-Unique: wUg6LeeaNeSxTOoq7XvOwA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696577481; x=1697182281; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oIbD361Dq1XrdFMBm2ks5K17RPXWKenYwe5/7qyYG28=; b=QzP231Isgw6KUtdDYjD1/rGg2HEIBij+TD6dLI99DS8/Gia67i3HQST9YnuC4Ah2Hq 91QzF3HyYs1L6Q6xoC1CQV5YC6nObzj4aKOiIqO1SFsl+n8W2Fa15tJnd/kW7X/QOGaa zHniaZkstg+pgfuVEJiH+xzqH2qRCCg980RM2J9h8rpvhV1Jf1aGZ6qeDtN8jksLfhps G6hrZbLN6/vVcGwmPGcWKz8A5JsQ2YGOGBDKpHEaVM+Vmi1w8fGe2NTCFxtw5Y/isjBu tbG9NxLRFJCJr6KsthMYFAZaoKyzq8xgrTTicbvgECgDh1rzkDGpZiUte+cprVDfhvlv +kBA== X-Gm-Message-State: AOJu0YwmDME6LWkDzjPKl0p3jLZJHd+TfwUDrw4sWPUYyJBOHnR74FLI a0GWtLp0M4lYaLlW5IX/vdebY6gkrI/+ElWwYFJY4ZgTl7LHZr0ShbUqJH1+5W+HYm3+hNdURJk 1ADaa4q1HEqICaFw= X-Received: by 2002:a05:6358:339b:b0:143:9235:9f1f with SMTP id i27-20020a056358339b00b0014392359f1fmr6429637rwd.12.1696577481422; Fri, 06 Oct 2023 00:31:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEG+qnPy/0Lkqjsgq3XYccmaoWl+Oj4DZTYPIlt/+7tKb7NlHKbnXacGPlMicFHzL7+L0zzVQ== X-Received: by 2002:a05:6358:339b:b0:143:9235:9f1f with SMTP id i27-20020a056358339b00b0014392359f1fmr6429628rwd.12.1696577480922; Fri, 06 Oct 2023 00:31:20 -0700 (PDT) From: Ani Sinha To: Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Beraldo Leal Cc: Ani Sinha , imammedo@redhat.com, David Hildenbrand , qemu-devel@nongnu.org Subject: [PATCH] tests/avocado: add test to exercize processor address space memory bound checks Date: Fri, 6 Oct 2023 13:00:22 +0530 Message-ID: <20231006073022.120279-1-anisinha@redhat.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=anisinha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1696577531096100001 Content-Type: text/plain; charset="utf-8" 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 proces= sor is capable of addressing all memory. Boundary cases are tested. CC: imammedo@redhat.com CC: David Hildenbrand Signed-off-by: Ani Sinha --- tests/avocado/mem-addr-space-check.py | 113 ++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 tests/avocado/mem-addr-space-check.py diff --git a/tests/avocado/mem-addr-space-check.py b/tests/avocado/mem-addr= -space-check.py new file mode 100644 index 0000000000..6949f7567e --- /dev/null +++ b/tests/avocado/mem-addr-space-check.py @@ -0,0 +1,113 @@ +# Check for crash when using memory beyond the available guest processor +# address space. +# +# Copyright (c) 2023 Red Hat, Inc. +# +# Author: +# Ani Sinha +# +# 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 . + +from avocado_qemu import QemuSystemTest +import signal + +class MemAddrCheck(QemuSystemTest): + def test_phybits_low_pse36(self): + """ + :avocado: tags=3Dmachine:q35 + :avocado: tags=3Darch:x86_64 + + With pse36 feature ON, a processor has 36 bits of addressing. So i= t can + access up to a maximum of 64GiB of memory. Memory hotplug region b= egins + at 4 GiB boundary when "above_4g_mem_size" is 0 (this would be tru= e 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 l= eaves + total hotpluggable actual memory size of 59 GiB. If the VM is star= ted + 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 direc= tly. + If maxmem is set to 59.6G, QEMU should fail to start with a messag= e that + says "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=3D1,maxmem=3D59.6G', + '-cpu', 'pentium,pse36=3Don', '-display', 'none', + '-object', 'memory-backend-ram,id=3Dmem1,size=3D1= G', + '-device', 'virtio-mem-pci,id=3Dvm0,memdev=3Dmem1= ') + self.vm.set_qmp_monitor(enabled=3DFalse) + 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=3Dmachine:q35 + :avocado: tags=3Darch:x86_64 + + Setting maxmem to 59.5G and making sure that QEMU can start with t= he + same options as the failing case above. + """ + self.vm.add_args('-machine', 'q35', '-m', + '512,slots=3D1,maxmem=3D59.5G', + '-cpu', 'pentium,pse36=3Don', '-display', 'none', + '-object', 'memory-backend-ram,id=3Dmem1,size=3D1= G', + '-device', 'virtio-mem-pci,id=3Dvm0,memdev=3Dmem1= ') + self.vm.set_qmp_monitor(enabled=3DFalse) + self.vm.launch() + self.vm.shutdown() + self.assertEquals(self.vm.exitcode(), -signal.SIGTERM, + "QEMU did not terminate gracefully upon SIGTERM") + + def test_phybits_ok_pentium2(self): + """ + :avocado: tags=3Dmachine:q35 + :avocado: tags=3Darch:x86_64 + + Pentium2 has 36 bits of addressing, so its same as pentium + with pse36 ON. + """ + self.vm.add_args('-machine', 'q35', '-m', + '512,slots=3D1,maxmem=3D59.5G', + '-cpu', 'pentium2', '-display', 'none', + '-object', 'memory-backend-ram,id=3Dmem1,size=3D1= G', + '-device', 'virtio-mem-pci,id=3Dvm0,memdev=3Dmem1= ') + self.vm.set_qmp_monitor(enabled=3DFalse) + self.vm.launch() + self.vm.shutdown() + self.assertEquals(self.vm.exitcode(), -signal.SIGTERM, + "QEMU did not terminate gracefully upon SIGTERM") + + def test_phybits_low_nonpse36(self): + """ + :avocado: tags=3Dmachine:q35 + :avocado: tags=3Darch:x86_64 + + Pentium processor has 32 bits of addressing without pse36 or pae + so it can access up to 4 GiB of memory. Setting maxmem to 4GiB + should make QEMU fail to start with "phys-bits too low" message. + """ + self.vm.add_args('-S', '-machine', 'q35', '-m', + '512,slots=3D1,maxmem=3D4G', + '-cpu', 'pentium', '-display', 'none', + '-object', 'memory-backend-ram,id=3Dmem1,size=3D1= G', + '-device', 'virtio-mem-pci,id=3Dvm0,memdev=3Dmem1= ') + self.vm.set_qmp_monitor(enabled=3DFalse) + 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') --=20 2.42.0