qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/cpu: Handle SMM mode in x86_cpu_dump_state for softmmu
@ 2025-05-23 15:44 Kirill Martynov
  2025-06-17  6:50 ` Kirill Martynov
                   ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Kirill Martynov @ 2025-05-23 15:44 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Zhao Liu, Kirill Martynov

Certain error conditions can trigger x86_cpu_dump_state() to output CPU state
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=1), 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=cpu@entry=0x5578ca2eb340, attrs=...)
   at ../hw/core/cpu-sysemu.c:76
#5  ... in cpu_memory_rw_debug (cpu=cpu@entry=0x5578ca2eb340,
   addr=addr@entry=2147258348, ptr=ptr@entry=0x7f5341ca373c, len=len@entry=1,
    is_write=is_write@entry=false) at ../softmmu/physmem.c:3529
#6  ... in x86_cpu_dump_state (cs=0x5578ca2eb340,
   f=0x7f53434065c0 <_IO_2_1_stderr_>, flags=<optimized out>)
   at ../target/i386/cpu-dump.c:560
#7  ... in kvm_cpu_exec (cpu=cpu@entry=0x5578ca2eb340)
   at ../accel/kvm/kvm-all.c:3000
#8  ... in kvm_vcpu_thread_fn (arg=arg@entry=0x5578ca2eb340)
   at ../accel/kvm/kvm-accel-ops.c:51
#9  ... in qemu_thread_start (args=<optimized out>)
   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 <stdcalllevi@yandex-team.ru>
---
 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 == 1 ? 0 : (!!attrs.secure);
 }
 
 static inline AddressSpace *cpu_addressspace(CPUState *cs, MemTxAttrs attrs)
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-07-29  8:37 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-23 15:44 [PATCH] x86/cpu: Handle SMM mode in x86_cpu_dump_state for softmmu Kirill Martynov
2025-06-17  6:50 ` Kirill Martynov
2025-07-02  3:17 ` Zhao Liu
2025-07-02 14:16 ` Xiaoyao Li
2025-07-02 15:10   ` Xiaoyao Li
2025-07-02 16:24     ` Xiaoyao Li
2025-07-03  9:25       ` Kirill Martynov
2025-07-03 12:53         ` Xiaoyao Li
2025-07-04  8:20           ` Zhao Liu
2025-07-04 13:50             ` Xiaoyao Li
2025-07-28 14:44               ` Kirill Martynov
2025-07-28 16:19                 ` Zhao Liu
2025-07-29  6:01                   ` Xiaoyao Li
2025-07-29  8:36                     ` Kirill Martynov

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).