From nobody Sat Nov 23 22:28:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728233429038864.3234179936808; Sun, 6 Oct 2024 09:50:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxURh-000608-B7; Sun, 06 Oct 2024 12:49:25 -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 1sxURe-0005zS-QP for qemu-devel@nongnu.org; Sun, 06 Oct 2024 12:49:23 -0400 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sxURc-0008At-DM for qemu-devel@nongnu.org; Sun, 06 Oct 2024 12:49:22 -0400 Received: from zero.eik.bme.hu (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id 6B46D4E6001; Sun, 06 Oct 2024 18:49:15 +0200 (CEST) Received: from zero.eik.bme.hu ([127.0.0.1]) by zero.eik.bme.hu (zero.eik.bme.hu [127.0.0.1]) (amavisd-new, port 10028) with ESMTP id YdPnJhRLz9Ie; Sun, 6 Oct 2024 18:49:13 +0200 (CEST) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 75D804E6004; Sun, 06 Oct 2024 18:49:13 +0200 (CEST) X-Virus-Scanned: amavisd-new at eik.bme.hu Message-Id: <59dd3361ca8ede93122e87752c7d66a304b05c0f.1728232526.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH 1/2] log: Add separate debug option for logging invalid memory accesses To: qemu-devel@nongnu.org Cc: philmd@linaro.org Date: Sun, 06 Oct 2024 18:49:13 +0200 (CEST) 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=2001:738:2001:2001::2001; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, 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-ZM-MESSAGEID: 1728233431249116600 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently -d guest_errors enables logging of different invalid actions by the guest such as misusing hardware, accessing missing features or invalid memory areas. The memory access logging can be quite verbose which obscures the other messages enabled by this debug switch so separate it by adding a new -d memaccess option to make it possible to control it independently of other guest error logs. Signed-off-by: BALATON Zoltan --- include/qemu/log.h | 1 + system/memory.c | 6 +++--- system/physmem.c | 2 +- util/log.c | 2 ++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/qemu/log.h b/include/qemu/log.h index e10e24cd4f..6122e34bdd 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -37,6 +37,7 @@ bool qemu_log_separate(void); #define LOG_PER_THREAD (1 << 20) #define CPU_LOG_TB_VPU (1 << 21) #define LOG_TB_OP_PLUGIN (1 << 22) +#define LOG_MEM_ACCESS (1 << 23) =20 /* Lock/unlock output. */ =20 diff --git a/system/memory.c b/system/memory.c index f6f6fee6d8..e35a473248 100644 --- a/system/memory.c +++ b/system/memory.c @@ -1380,7 +1380,7 @@ bool memory_region_access_valid(MemoryRegion *mr, { if (mr->ops->valid.accepts && !mr->ops->valid.accepts(mr->opaque, addr, size, is_write, attrs= )) { - qemu_log_mask(LOG_GUEST_ERROR, "Invalid %s at addr 0x%" HWADDR_PRIX + qemu_log_mask(LOG_MEM_ACCESS, "Invalid %s at addr 0x%" HWADDR_PRIX ", size %u, region '%s', reason: rejected\n", is_write ? "write" : "read", addr, size, memory_region_name(mr)); @@ -1388,7 +1388,7 @@ bool memory_region_access_valid(MemoryRegion *mr, } =20 if (!mr->ops->valid.unaligned && (addr & (size - 1))) { - qemu_log_mask(LOG_GUEST_ERROR, "Invalid %s at addr 0x%" HWADDR_PRIX + qemu_log_mask(LOG_MEM_ACCESS, "Invalid %s at addr 0x%" HWADDR_PRIX ", size %u, region '%s', reason: unaligned\n", is_write ? "write" : "read", addr, size, memory_region_name(mr)); @@ -1402,7 +1402,7 @@ bool memory_region_access_valid(MemoryRegion *mr, =20 if (size > mr->ops->valid.max_access_size || size < mr->ops->valid.min_access_size) { - qemu_log_mask(LOG_GUEST_ERROR, "Invalid %s at addr 0x%" HWADDR_PRIX + qemu_log_mask(LOG_MEM_ACCESS, "Invalid %s at addr 0x%" HWADDR_PRIX ", size %u, region '%s', reason: invalid size " "(min:%u max:%u)\n", is_write ? "write" : "read", diff --git a/system/physmem.c b/system/physmem.c index dc1db3a384..0f0e8f3bed 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -2745,7 +2745,7 @@ static bool flatview_access_allowed(MemoryRegion *mr,= MemTxAttrs attrs, if (memory_region_is_ram(mr)) { return true; } - qemu_log_mask(LOG_GUEST_ERROR, + qemu_log_mask(LOG_MEM_ACCESS, "Invalid access to non-RAM device at " "addr 0x%" HWADDR_PRIX ", size %" HWADDR_PRIu ", " "region '%s'\n", addr, len, memory_region_name(mr)); diff --git a/util/log.c b/util/log.c index 6219819855..1aa7396277 100644 --- a/util/log.c +++ b/util/log.c @@ -503,6 +503,8 @@ const QEMULogItem qemu_log_items[] =3D { "open a separate log file per thread; filename must contain '%d'" }, { CPU_LOG_TB_VPU, "vpu", "include VPU registers in the 'cpu' logging" }, + { LOG_MEM_ACCESS, "memaccess", + "log invalid memory accesses" }, { 0, NULL, NULL }, }; =20 --=20 2.30.9 From nobody Sat Nov 23 22:28:43 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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=fail(p=none dis=none) header.from=eik.bme.hu Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728233396971259.09032044178855; Sun, 6 Oct 2024 09:49:56 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sxURi-00060i-1u; Sun, 06 Oct 2024 12:49:26 -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 1sxURe-0005zU-Ua for qemu-devel@nongnu.org; Sun, 06 Oct 2024 12:49:23 -0400 Received: from zero.eik.bme.hu ([2001:738:2001:2001::2001]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sxURc-0008Au-Dy for qemu-devel@nongnu.org; Sun, 06 Oct 2024 12:49:22 -0400 Received: from zero.eik.bme.hu (localhost [127.0.0.1]) by zero.eik.bme.hu (Postfix) with ESMTP id 6D0C94E6039; Sun, 06 Oct 2024 18:49:16 +0200 (CEST) Received: from zero.eik.bme.hu ([127.0.0.1]) by zero.eik.bme.hu (zero.eik.bme.hu [127.0.0.1]) (amavisd-new, port 10028) with ESMTP id TXdJrdIPRymz; Sun, 6 Oct 2024 18:49:14 +0200 (CEST) Received: by zero.eik.bme.hu (Postfix, from userid 432) id 7E3F54E6031; Sun, 06 Oct 2024 18:49:14 +0200 (CEST) X-Virus-Scanned: amavisd-new at eik.bme.hu Message-Id: <0f5949d8ece522e30f990d25981f79965bf05bbf.1728232526.git.balaton@eik.bme.hu> In-Reply-To: References: From: BALATON Zoltan Subject: [PATCH 2/2] log: Suggest using -d guest_error,memaccess instead of guest_errors To: qemu-devel@nongnu.org Cc: philmd@linaro.org Date: Sun, 06 Oct 2024 18:49:14 +0200 (CEST) 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=2001:738:2001:2001::2001; envelope-from=balaton@eik.bme.hu; helo=zero.eik.bme.hu X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, 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-ZM-MESSAGEID: 1728233400680116600 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Rename guest_errors to guest_error to match the log constant and print a warning for -d guest_errors to remind using guest_error,memaccess instead but preserve previous behaviour for convenience. Signed-off-by: BALATON Zoltan --- As this is a debug switch I think no formal deprecation is needed but this is to allow people to change their commands and scripts then it may be removed eventually. docs/devel/secure-coding-practices.rst | 2 +- tests/avocado/smmu.py | 2 +- tests/qtest/pnv-host-i2c-test.c | 2 +- util/log.c | 6 +++++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/devel/secure-coding-practices.rst b/docs/devel/secure-cod= ing-practices.rst index 0454cc527e..b330b01956 100644 --- a/docs/devel/secure-coding-practices.rst +++ b/docs/devel/secure-coding-practices.rst @@ -85,7 +85,7 @@ request completes. Unexpected accesses must not cause me= mory corruption or leaks in QEMU. =20 Invalid device register accesses can be reported with -``qemu_log_mask(LOG_GUEST_ERROR, ...)``. The ``-d guest_errors`` command-= line +``qemu_log_mask(LOG_GUEST_ERROR, ...)``. The ``-d guest_error`` command-l= ine option enables these log messages. =20 Live Migration diff --git a/tests/avocado/smmu.py b/tests/avocado/smmu.py index 83fd79e922..7ed836c12d 100644 --- a/tests/avocado/smmu.py +++ b/tests/avocado/smmu.py @@ -46,7 +46,7 @@ def common_vm_setup(self, custom_kernel=3DFalse): self.vm.add_args("-accel", "kvm") self.vm.add_args("-cpu", "host") self.vm.add_args("-machine", "iommu=3Dsmmuv3") - self.vm.add_args("-d", "guest_errors") + self.vm.add_args("-d", "guest_error,memaccess") self.vm.add_args('-bios', os.path.join(BUILD_DIR, 'pc-bios', 'edk2-aarch64-code.fd')) self.vm.add_args('-device', 'virtio-rng-pci,rng=3Drng0') diff --git a/tests/qtest/pnv-host-i2c-test.c b/tests/qtest/pnv-host-i2c-tes= t.c index 7f64d597ac..63a2acf9de 100644 --- a/tests/qtest/pnv-host-i2c-test.c +++ b/tests/qtest/pnv-host-i2c-test.c @@ -418,7 +418,7 @@ static void test_host_i2c(const void *data) =20 qts =3D qtest_initf("-M %s -smp %d,cores=3D1,threads=3D%d -nographic " "-nodefaults -serial mon:stdio -S " - "-d guest_errors", + "-d guest_error,memaccess", machine, SMT, SMT); =20 /* Check the I2C master status registers after POR */ diff --git a/util/log.c b/util/log.c index 1aa7396277..279c2b5cfb 100644 --- a/util/log.c +++ b/util/log.c @@ -486,7 +486,7 @@ const QEMULogItem qemu_log_items[] =3D { "show CPU state before CPU resets" }, { LOG_UNIMP, "unimp", "log unimplemented functionality" }, - { LOG_GUEST_ERROR, "guest_errors", + { LOG_GUEST_ERROR, "guest_error", "log when the guest OS does something invalid (eg accessing a\n" "non-existent register)" }, { CPU_LOG_PAGE, "page", @@ -521,6 +521,10 @@ int qemu_str_to_log_mask(const char *str) for (item =3D qemu_log_items; item->mask !=3D 0; item++) { mask |=3D item->mask; } + } else if (g_str_equal(*tmp, "guest_errors")) { + warn_report("Log option guest_errors is deprecated. " + "Use guest_error,memaccess instead."); + mask |=3D LOG_GUEST_ERROR | LOG_MEM_ACCESS; #ifdef CONFIG_TRACE_LOG } else if (g_str_has_prefix(*tmp, "trace:") && (*tmp)[6] !=3D '\0'= ) { trace_enable_events((*tmp) + 6); --=20 2.30.9