On Fri, May 23, 2025 at 03:44:31PM +0000, Kirill Martynov wrote:
> Date: Fri, 23 May 2025 15:44:31 +0000
> From: Kirill Martynov <stdcalll...@yandex-team.ru>
> Subject: [PATCH] x86/cpu: Handle SMM mode in x86_cpu_dump_state for softmmu
> X-Mailer: git-send-email 2.43.0
> 
> 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 <stdcalll...@yandex-team.ru>
> ---
>  target/i386/cpu.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Sorry for delay. This fix looks good to me,

Reviewed-by: Zhao Liu <zhao1....@intel.com>


Reply via email to