RFC: linux-user-i386: crash on cpuid
PATCH 1/1 RFC: linux-user-i386: crash on cpuid
Running cpuid instructions with a simple run like:
i386-linux-user/qemu-i386 tests/tcg/sha1-i386
Results in the following assert:
#0 0x00007ffff64246f5 in raise () from /lib64/libc.so.6 #1 0x00007ffff64262fa in abort () from /lib64/libc.so.6 #2 0x00007ffff7937ec5 in g_assertion_message () from /lib64/libglib-2.0.so.0 #3 0x00007ffff7937f5a in g_assertion_message_expr () from /lib64/libglib-2.0.so.0 #4 0x000055555561b54c in apicid_bitwidth_for_count (count=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:58 #5 0x000055555561b58a in apicid_smt_width (nr_cores=0, nr_threads=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:67 #6 0x000055555561b5c3 in apicid_core_offset (nr_cores=0, nr_threads=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:82 #7 0x000055555561b5e3 in apicid_pkg_offset (nr_cores=0, nr_threads=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:89 #8 0x000055555561dd86 in cpu_x86_cpuid (env=0x555557999550, index=4, count=3, eax=0x7fffffffcae8, ebx=0x7fffffffcaec, ecx=0x7fffffffcaf0, edx=0x7fffffffcaf4) at /home/elmarco/src/qemu/target-i386/cpu.c:2405 #9 0x0000555555638e8e in helper_cpuid (env=0x555557999550) at /home/elmarco/src/qemu/target-i386/misc_helper.c:106
#10 0x000055555599dc5e in static_code_gen_buffer ()
#11 0x00005555555952f8 in cpu_tb_exec (cpu=0x5555579912d0, itb=0x7ffff4371ab0) at /home/elmarco/src/qemu/cpu-exec.c:166
#12 0x0000555555595c8e in cpu_loop_exec_tb (cpu=0x5555579912d0, tb=0x7ffff4371ab0, last_tb=0x7fffffffd088, tb_exit=0x7fffffffd084, sc=0x7fffffffd0a0) at /home/elmarco/src/qemu/cpu-exec.c:517 #13 0x0000555555595e50 in cpu_exec (cpu=0x5555579912d0) at /home/elmarco/src/qemu/cpu-exec.c:612
#14 0x00005555555c065b in cpu_loop (env=0x555557999550) at /home/elmarco/src/qemu/linux-user/main.c:297
#15 0x00005555555c25b2 in main (argc=2, argv=0x7fffffffd848, envp=0x7fffffffd860) at /home/elmarco/src/qemu/linux-user/main.c:4803
The fields are set in qemu_init_vcpu() with softmmu, but it's a stub with linux-user.
--- target-i386/cpu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
target-i386/cpu.c +4 -1
@@ -3097,7 +3097,10 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)mce_init (cpu); -#ifndef CONFIG_USER_ONLY +#ifdef CONFIG_USER_ONLY + cs->nr_cores = smp_cores; + cs->nr_threads = smp_threads; +#else if (tcg_enabled ()) {AddressSpace *newas =g_new (AddressSpace,1 );
Signature · 1 line
2.10.0
Quoted 34 lines · Marc-André Lureau
Running cpuid instructions with a simple run like:
i386-linux-user/qemu-i386 tests/tcg/sha1-i386Results in the following assert:
#0 0x00007ffff64246f5 in raise () from /lib64/libc.so.6 #1 0x00007ffff64262fa in abort () from /lib64/libc.so.6 #2 0x00007ffff7937ec5 in g_assertion_message () from /lib64/libglib-2.0.so.0 #3 0x00007ffff7937f5a in g_assertion_message_expr () from /lib64/libglib-2.0.so.0 #4 0x000055555561b54c in apicid_bitwidth_for_count (count=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:58 #5 0x000055555561b58a in apicid_smt_width (nr_cores=0, nr_threads=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:67 #6 0x000055555561b5c3 in apicid_core_offset (nr_cores=0, nr_threads=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:82 #7 0x000055555561b5e3 in apicid_pkg_offset (nr_cores=0, nr_threads=0) at /home/elmarco/src/qemu/include/hw/i386/topology.h:89 #8 0x000055555561dd86 in cpu_x86_cpuid (env=0x555557999550, index=4, count=3, eax=0x7fffffffcae8, ebx=0x7fffffffcaec, ecx=0x7fffffffcaf0, edx=0x7fffffffcaf4) at /home/elmarco/src/qemu/target-i386/cpu.c:2405 #9 0x0000555555638e8e in helper_cpuid (env=0x555557999550) at /home/elmarco/src/qemu/target-i386/misc_helper.c:106#10
0x000055555599dc5einstatic_code_gen_buffer()
#110x00005555555952f8incpu_tb_exec(cpu=0x5555579912d0, itb=0x7ffff4371ab0) at/home/elmarco/src/qemu/cpu-exec.c:166
#120x0000555555595c8eincpu_loop_exec_tb(cpu=0x5555579912d0, tb=0x7ffff4371ab0, last_tb=0x7fffffffd088, tb_exit=0x7fffffffd084, sc=0x7fffffffd0a0) at/home/elmarco/src/qemu/cpu-exec.c:517#130x0000555555595e50incpu_exec(cpu=0x5555579912d0) at/home/elmarco/src/qemu/cpu-exec.c:612
#140x00005555555c065bincpu_loop(env=0x555557999550) at/home/elmarco/src/qemu/linux-user/main.c:297
#150x00005555555c25b2in main (argc=2, argv=0x7fffffffd848, envp=0x7fffffffd860) at/home/elmarco/src/qemu/linux-user/main.c:4803The fields are set in
qemu_init_vcpu()with softmmu, but it's a stub with linux-user.Signed-off-by Marc-André Lureau <[email protected]>--- target-i386/cpu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)target-i386/cpu.c +0
-0
target-i386/cpu.c static void x86_cpu_realizefn(DeviceState *dev, Error **errp) · line 3103
Quoted 8 lines
target-i386/cpu.c +4
-1@@ -3097,7 +3097,10 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)mce_init (cpu); -#ifndef CONFIG_USER_ONLY +#ifdef CONFIG_USER_ONLY + cs->nr_cores = smp_cores; + cs->nr_threads = smp_threads; +#else
On CONFIG_USER_ONLY, smp_cores and smp_threads are defined as:
/* *-user doesn't have configurable SMP topology */ #define smp_cores 1 #define smp_threads 1
It sounds simpler to just set nr_cores and nr_threads to 1 by default in cpu_common_initfn(). (Preferably with a comment noting that the default value is changed by qemu_init_vcpu() for softmmu).
Signature · 1 line
Eduardo
Hi
----- Original Message -----
Quoted 62 lines · Marc-André Lureau
Quoted 49 lines
Running cpuid instructions with a simple run like:
i386-linux-user/qemu-i386 tests/tcg/sha1-i386Results in the following assert:
#0 0x00007ffff64246f5 in raise () from /lib64/libc.so.6 #1 0x00007ffff64262fa in abort () from /lib64/libc.so.6 #2 0x00007ffff7937ec5 in g_assertion_message () from
/lib64/libglib-2.0.so.0
#30x00007ffff7937f5aing_assertion_message_expr() from/lib64/libglib-2.0.so.0
#40x000055555561b54cinapicid_bitwidth_for_count(count=0) at/home/elmarco/src/qemu/include/hw/i386/topology.h:58
#50x000055555561b58ainapicid_smt_width(nr_cores=0, nr_threads=0) at/home/elmarco/src/qemu/include/hw/i386/topology.h:67
#60x000055555561b5c3inapicid_core_offset(nr_cores=0, nr_threads=0) at/home/elmarco/src/qemu/include/hw/i386/topology.h:82
#70x000055555561b5e3inapicid_pkg_offset(nr_cores=0, nr_threads=0) at/home/elmarco/src/qemu/include/hw/i386/topology.h:89
#80x000055555561dd86incpu_x86_cpuid(env=0x555557999550, index=4, count=3, eax=0x7fffffffcae8, ebx=0x7fffffffcaec, ecx=0x7fffffffcaf0, edx=0x7fffffffcaf4) at/home/elmarco/src/qemu/target-i386/cpu.c:2405#90x0000555555638e8einhelper_cpuid(env=0x555557999550) at/home/elmarco/src/qemu/target-i386/misc_helper.c:106
#100x000055555599dc5einstatic_code_gen_buffer()
#110x00005555555952f8incpu_tb_exec(cpu=0x5555579912d0, itb=0x7ffff4371ab0) at/home/elmarco/src/qemu/cpu-exec.c:166#120x0000555555595c8eincpu_loop_exec_tb(cpu=0x5555579912d0, tb=0x7ffff4371ab0, last_tb=0x7fffffffd088, tb_exit=0x7fffffffd084, sc=0x7fffffffd0a0) at/home/elmarco/src/qemu/cpu-exec.c:517#130x0000555555595e50incpu_exec(cpu=0x5555579912d0) at/home/elmarco/src/qemu/cpu-exec.c:612
#140x00005555555c065bincpu_loop(env=0x555557999550) at/home/elmarco/src/qemu/linux-user/main.c:297
#150x00005555555c25b2in main (argc=2, argv=0x7fffffffd848, envp=0x7fffffffd860) at/home/elmarco/src/qemu/linux-user/main.c:4803The fields are set in
qemu_init_vcpu()with softmmu, but it's a stub with linux-user.Signed-off-by Marc-André Lureau <[email protected]>--- target-i386/cpu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)target-i386/cpu.c +0
-0target-i386/cpu.c static void x86_cpu_realizefn(DeviceState *dev, · line 3104
Quoted 9 lines
target-i386/cpu.c +4
-1@@ -3097,7 +3097,10 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)mce_init (cpu ); -#ifndef CONFIG_USER_ONLY +#ifdef CONFIG_USER_ONLY + cs->nr_cores = smp_cores; + cs->nr_threads = smp_threads; +#else On
CONFIG_USER_ONLY,smp_coresandsmp_threadsare defined as:
Quoted 8 lines
/* *-user doesn't have configurable SMP topology */ #define smp_cores 1 #define smp_threads 1It sounds simpler to just set
nr_coresandnr_threadsto 1 by default incpu_common_initfn(). (Preferably with a comment noting that the default value is changed byqemu_init_vcpu()for softmmu).
Ok, I'll resend a patch
thanks
Hi
----- Original Message -----
Quoted 9 lines
Review
Quoted 6 lines
(quoted diff) +4
-1-#ifndef CONFIG_USER_ONLY +#ifdef CONFIG_USER_ONLY + cs->nr_cores = smp_cores; + cs->nr_threads = smp_threads; +#elseOn
CONFIG_USER_ONLY,smp_coresandsmp_threadsare defined as:
Quoted 8 lines
/* *-user doesn't have configurable SMP topology */ #define smp_cores 1 #define smp_threads 1It sounds simpler to just set
nr_coresandnr_threadsto 1 by default incpu_common_initfn(). (Preferably with a comment noting that the default value is changed byqemu_init_vcpu()for softmmu).
Any reason those define exists? It seems we could use cpu state values instead, ex:
target-i386/cpu.c +4 -4
@@ -2490,13 +2490,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,switch (count) {case 0 : - *eax =apicid_core_offset (smp_cores, smp_threads); - *ebx = smp_threads; + *eax =apicid_core_offset (cs->nr_cores, cs->nr_threads); + *ebx = cs->nr_threads; *ecx |=CPUID_TOPOLOGY_LEVEL_SMT ;break ;case 1 : - *eax =apicid_pkg_offset (smp_cores, smp_threads); - *ebx = smp_cores * smp_threads; + *eax =apicid_pkg_offset (cs->nr_cores, cs->nr_threads); + *ebx = cs->nr_cores * cs->nr_threads; *ecx |=CPUID_TOPOLOGY_LEVEL_CORE ;break ;
Quoted 16 lines · Marc-André Lureau
Hi
----- Original Message -----
Quoted 13 lines
Review
Quoted 6 lines
(quoted diff) +4
-1-#ifndef CONFIG_USER_ONLY +#ifdef CONFIG_USER_ONLY + cs->nr_cores = smp_cores; + cs->nr_threads = smp_threads; +#elseOn
CONFIG_USER_ONLY,smp_coresandsmp_threadsare defined as:/* *-user doesn't have configurable SMP topology */ #define smp_cores 1 #define smp_threads 1
Quoted 6 lines
Quoted 4 lines
It sounds simpler to just set
nr_coresandnr_threadsto 1 by default incpu_common_initfn(). (Preferably with a comment noting that the default value is changed byqemu_init_vcpu()for softmmu).Any reason those define exists? It seems we could use cpu state values instead, ex:
Just because there was existing non-softmmu-specific code that used those variables. If we eliminate their usage (are the ones below the only cases?), we can remove the macros.
Quoted 21 lines
target-i386/cpu.c +4
-4@@ -2490,13 +2490,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,switch (count) {case 0 : - *eax =apicid_core_offset (smp_cores, smp_threads); - *ebx = smp_threads; + *eax =apicid_core_offset (cs->nr_cores, cs->nr_threads); + *ebx = cs->nr_threads; *ecx |=CPUID_TOPOLOGY_LEVEL_SMT ;break ;case 1 : - *eax =apicid_pkg_offset (smp_cores, smp_threads); - *ebx = smp_cores * smp_threads; + *eax =apicid_pkg_offset (cs->nr_cores, cs->nr_threads); + *ebx = cs->nr_cores * cs->nr_threads; *ecx |=CPUID_TOPOLOGY_LEVEL_CORE ;break ;
Signature · 1 line
Eduardo