From nobody Sat Nov 15 17:49:59 2025 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1748035093; cv=none; d=zohomail.com; s=zohoarc; b=T50V+aGTQO1RZEC5dfQFIfdKIG1b1Qn23TGRWiSn8RGfOR6585dbrw/2rPo9laxyjntWayXYWwzg59B5G/O9ihX1Mg9sIwxZW677g6yD29EKySqe9MFVcaEAwDgd7xJHykZIHGT3GLbJnJ4BBa6l47to6YGKGMI2k4lPCfC6mZU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748035093; 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=iWz0ReyH+SKNmPaGDhMX0bWIwvt8gZviHfnomndUJSc=; b=AyODNf8E9auXhbkKpS3ZrhzXCHS+425Sk9yQTFFzJ298dNL9MgTU/rFVCu+2YWcdW1nOOmAdZURvh3T72Wz8vZNr/Lrv8xnAgH79Ay/95KtMBaBBKpFEHPzNH+oz8m2b481PWsMdiw3KPfhQh8BoOR63F4tJKRXjP7sGZZMJr+4= 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 1748035093290752.2297827361621; Fri, 23 May 2025 14:18:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uIZlg-00039w-B7; Fri, 23 May 2025 17:17:28 -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 1uIUZk-0006HF-QK for qemu-devel@nongnu.org; Fri, 23 May 2025 11:44:48 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uIUZi-0000ZQ-A2 for qemu-devel@nongnu.org; Fri, 23 May 2025 11:44:48 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c15:2b89:0:640:9815:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 76F8D613C2; Fri, 23 May 2025 18:44:39 +0300 (MSK) Received: from dev-vm2-nested.ru-central1.internal (unknown [2a02:6b8:c0e:501:0:fca5:0:123]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ViSnaZ0FfqM0-SZi5ZzzK; Fri, 23 May 2025 18:44:38 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1748015079; bh=iWz0ReyH+SKNmPaGDhMX0bWIwvt8gZviHfnomndUJSc=; h=Message-ID:Date:Cc:Subject:To:From; b=sTwBEjn/dW8AhUwtn7NsK4RzATPJHv3WSr3H5GVjmvC/MODF/0Bz1h/iLmnazDeK8 Y2kc+UP/51MT6bzh0+RzNafWJmUBj4bRl1LeM0wggQ+UTN+r+6X9WOoDNdi0MP8iyr VYA4s8bvOg2sUfqs2renxfOb6tgqWXVa9aAqmx/Q= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Kirill Martynov To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Zhao Liu , Kirill Martynov Subject: [PATCH] x86/cpu: Handle SMM mode in x86_cpu_dump_state for softmmu Date: Fri, 23 May 2025 15:44:31 +0000 Message-ID: <20250523154431.506993-1-stdcalllevi@yandex-team.ru> X-Mailer: git-send-email 2.43.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=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=stdcalllevi@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 23 May 2025 17:17:23 -0400 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 @yandex-team.ru) X-ZM-MESSAGEID: 1748035095932116600 Content-Type: text/plain; charset="utf-8" Certain error conditions can trigger x86_cpu_dump_state() to output CPU sta= te debug information e.g. KVM emulation failure due to misbehaving guest. However, if the CPU is in System Management Mode (SMM) when the assertion in cpu_asidx_from_attrs failure happens because: 1. In SMM mode (smm=3D1), the CPU must use multiple address spaces with a dedicated SMM address space 2. On machine types with softmmu, address spaces are hardcoded to 1 (no multiple address spaces available) The assertion occurs in cpu_asidx_from_attrs() when trying to access memory in SMM mode with insufficient address spaces. Fix this by: 1. If number of address spaces is 1 always use index 0 2. In other cases use attr.secure for identified proper index This prevents the assertion while still providing useful debug output during VM shutdown errors. Stack trace of the original issue: #0 ... in raise () from /lib/x86_64-linux-gnu/libc.so.6 #1 ... in abort () from /lib/x86_64-linux-gnu/libc.so.6 #2 ... in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #3 ... in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6 #4 ... in cpu_asidx_from_attrs (cpu=3Dcpu@entry=3D0x5578ca2eb340, attrs=3D= ...) at ../hw/core/cpu-sysemu.c:76 #5 ... in cpu_memory_rw_debug (cpu=3Dcpu@entry=3D0x5578ca2eb340, addr=3Daddr@entry=3D2147258348, ptr=3Dptr@entry=3D0x7f5341ca373c, len=3D= len@entry=3D1, is_write=3Dis_write@entry=3Dfalse) at ../softmmu/physmem.c:3529 #6 ... in x86_cpu_dump_state (cs=3D0x5578ca2eb340, f=3D0x7f53434065c0 <_IO_2_1_stderr_>, flags=3D) at ../target/i386/cpu-dump.c:560 #7 ... in kvm_cpu_exec (cpu=3Dcpu@entry=3D0x5578ca2eb340) at ../accel/kvm/kvm-all.c:3000 #8 ... in kvm_vcpu_thread_fn (arg=3Darg@entry=3D0x5578ca2eb340) at ../accel/kvm/kvm-accel-ops.c:51 #9 ... in qemu_thread_start (args=3D) at ../util/qemu-thread-posix.c:505 #10 ... in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0 #11 ... in clone () from /lib/x86_64-linux-gnu/libc.so.6 Signed-off-by: Kirill Martynov Reviewed-by: Xiaoyao Li Reviewed-by: Zhao Liu --- target/i386/cpu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index c51e0a43d0..2616a61c87 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -2507,7 +2507,7 @@ void cpu_sync_avx_hflag(CPUX86State *env); #ifndef CONFIG_USER_ONLY static inline int x86_asidx_from_attrs(CPUState *cs, MemTxAttrs attrs) { - return !!attrs.secure; + return cs->num_ases =3D=3D 1 ? 0 : (!!attrs.secure); } =20 static inline AddressSpace *cpu_addressspace(CPUState *cs, MemTxAttrs attr= s) --=20 2.43.0