qemu-system-i386 and general protection

2023-01-12 Thread He Zhe
Hi All,

We are experiencing a general protection fault with qemu-system-i386 as follow.
This can be reproduced with kernel v5.15 and latest v6.2-rc3 as we found so far.

It would work well if we reverted the commit
2f8a21d8ff3af484a37edc8ea61d127ec1529ab5 ("target/i386: Enable AVX cpuid bits 
when using TCG")
introduced since qemu 7.2.

We also tried setting cpu to Broadwell and Icelake-Server and got the same 
error.

./qemu-system-i386 -object rng-random,filename=/dev/urandom,id=rng0 -device 
virtio-rng-pci,rng=rng0 -drive file=/tmp/rootfs.ext4,if=virtio,format=raw -usb 
-device usb-tablet -usb -device usb-kbd   -cpu Haswell -machine q35,i8042=off 
-smp 4 -m 8192  -m 8192 -smp cpus=8 -serial mon:stdio -serial null -nographic  
-kernel /tmp/bzImage -append 'root=/dev/vda rw  ip=dhcp console=ttyS0 
console=ttyS1 oprofile.timer=1 tsc=reliable no_timer_check 
rcupdate.rcu_expedited=1 '

[  OK  ] Started System Logging Service.
[  204.194033] traps: named[280] general protection fault ip:b7ef8545 
sp:bf8d5a1c error:0
[  204.198913] audit: type=1701 audit(1673507379.204:2): auid=4294967295 
uid=997 gid=996 ses=4294967295 subj=kernel pid=280 comm="named" ex1
[  204.219923] [ cut here ]
[  204.220455] Bad FPU state detected at restore_fpregs_from_fpstate+0x3a/0x78, 
reinitializing FPU registers.   
[  204.221442] WARNING: CPU: 4 PID: 274 at ../arch/x86/mm/extable.c:127 
fixup_exception+0x3f0/0x41c
[  204.223147] Modules linked in:
[  204.223945] CPU: 4 PID: 274 Comm: rs:main Q:Reg Not tainted 6.2.0-rc3 #1
[  204.224769] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 
rel-1.16.1-0-g3208b098f51a-prebuilt.qemu.org 04/01/2014
[  204.226061] EIP: fixup_exception+0x3f0/0x41c
[  204.226533] Code: ff ff 8d 74 26 00 0f 0b ba 4c c9 dc d1 e9 10 fd ff ff b1 
01 89 44 24 04 c7 04 24 e0 44 98 d1 88 0d 69 87 cc d1 e8 8c bf
[  204.228038] EAX: 005e EBX: d1aee764 ECX: 0027 EDX: 0001
[  204.228498] ESI: c18efee4 EDI: 000d EBP: c18efe58 ESP: c18efddc
[  204.229102] DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068 EFLAGS: 0086
[  204.229662] CR0: 80050033 CR2: bf8d5d54 CR3: 02aaf000 CR4: 001506d0
[  204.230408] Call Trace:
[  204.232101]  ? restore_fpregs_from_fpstate+0x3a/0x78
[  204.232733]  ? __switch_to_asm+0x1c/0xe4
[  204.233028]  ? __schedule+0x28c/0x844
[  204.233362]  ? _raw_spin_lock+0x10/0x34
[  204.233829]  exc_general_protection+0x81/0x340
[  204.234403]  ? futex_wait+0xb4/0x190
[  204.234818]  ? exc_bounds+0xa4/0xa4
[  204.235054]  handle_exception+0x133/0x133
[  204.235629] EIP: restore_fpregs_from_fpstate+0x3a/0x78
[  204.236113] Code: 0a 8d 76 00 db e2 0f 77 db 45 f4 3e 8d 74 26 00 a1 e8 51 
a7 d1 8b 5d f4 21 d0 8b 15 ec 51 a7 d1 8d 7b 40 21 d1 89 ca 04
[  204.236152] EAX: 0007 EBX: c2047200 ECX:  EDX: 
[  204.236171] ESI: c20471c0 EDI: c2047240 EBP: c18eff4c ESP: c18eff40
[  204.236191] DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068 EFLAGS: 0046
[  204.236309]  ? exc_bounds+0xa4/0xa4
[  204.236475]  ? exc_bounds+0xa4/0xa4
[  204.240268]  ? restore_fpregs_from_fpstate+0x37/0x78
[FAILED[  204.240752]  switch_fpu_return+0x49/0xe0
[  204.241422]  exit_to_user_mode_prepare+0x189/0x1a0
] Failed to start Berkeley Internet Name Domain (DNS).
[  204.241910]  ? syscall_exit_work+0x10b/0x138
[  204.243209]  syscall_exit_to_user_mode+0x1c/0x38
[  204.243707]  __do_fast_syscall_32+0x56/0xac
[  204.243947]  do_fast_syscall_32+0x32/0x74
[  204.244158]  do_SYSENTER_32+0x15/0x24
[  204.244333]  entry_SYSENTER_32+0x98/0xf1
[  204.244759] EIP: 0xb7f59549
[  204.245200] Code: 03 74 c0 01 10 05 03 74 b8 01 10 06 03 74 b4 01 10 07 03 
74 b0 01 10 08 03 74 d8 01 00 00 00 00 00 51 52 55 89 e5 0f 36
[  204.246900] EAX:  EBX: 012b373c ECX: 0189 EDX: 
[  204.247352] ESI:  EDI:  EBP:  ESP: b69feff0
[  204.247873] DS: 007b ES: 007b FS:  GS: 0033 SS: 007b EFLAGS: 0282
See 'systemctl status named.service' for details.
[  204.248870] ---[ end trace  ]---
[  204.251318] general protection fault, maybe for address 0x0:  [#1] 
PREEMPT SMP
[  204.252076] CPU: 4 PID: 274 Comm: rs:main Q:Reg Tainted: G    W  
6.2.0-rc3 #1
[  204.252685] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 
rel-1.16.1-0-g3208b098f51a-prebuilt.qemu.org 04/01/2014
[  204.253207] EIP: entry_SYSENTER_32+0xe0/0xf1
[  204.253537] Code: 8b 54 24 30 8b 4c 24 3c 8e 64 24 24 5b 83 c4 08 5e 5f 5d 
89 c4 eb 0b 0f 20 d8 0d 00 10 00 00 0f 22 d8 0f ba 34 24 09 96
[  204.254956] EAX:  EBX: 012b373c ECX: b69feff0 EDX: b7f59549
[  204.255282] ESI:  EDI:  EBP:  ESP: ff8b
[  204.255774] DS: 007b ES: 007b FS:  GS: 0033 SS: 0068 EFLAGS: 0282
[  204.256136] CR0: 80050033 CR2: bf8d5d54 CR3: 02aaf000 CR4: 001506d0
[  204.256435] Call Trace:
[  204.257004] Modules linked in:
[  204.257824] ---[ end trace  ]---
[  204.258197] EIP: 

Re: [PATCH 0/2] target/arm: Fix issue 1078

2022-06-20 Thread He Zhe



On 6/19/22 08:15, Richard Henderson wrote:
> Nicely summarized by the reporter, but I thought it would be
> nicer to pull all of the logic into arm_pamax, rather than
> leave it separated.

Reported-by: He Zhe 

I ran a quick test. qemu still hangs with these two commits applied.

One fact that might help, qemu can boot up successfully if the change of the
following commit is reverted.
https://gitlab.com/qemu-project/qemu/-/commit/39a1fd25287f5dece59fdf4752491faf59310296
The change had been moved to target/arm/ptw.c.

Zhe

>
>
> r~
>
>
> Richard Henderson (2):
>   target/arm: Extend arm_pamax to more than aarch64
>   target/arm: Check V7VE as well as LPAE in arm_pamax
>
>  hw/arm/virt.c| 10 +-
>  target/arm/ptw.c | 26 --
>  2 files changed, 21 insertions(+), 15 deletions(-)
>




Re: [Qemu-devel] [PATCH] configure: Add pkg-config handling for libgcrypt

2019-08-29 Thread He Zhe



On 8/29/19 5:15 PM, Daniel P. Berrangé wrote:
> On Thu, Aug 29, 2019 at 04:53:02PM +0800, zhe...@windriver.com wrote:
>> From: He Zhe 
>>
>> libgcrypt may also be controlled by pkg-config, this patch adds pkg-config
>> handling for libgcrypt.
> Where are you seeing pkg-config files for libgcrypt ?
>
> The upstream project has (frustratingly) been hostile to any proposal to
> add pkg-config support saying people should stick with their custom 
> libgcrypt-config tool
>
>https://dev.gnupg.org/T2037
>
> Even if this is something added by some distro downstream, what is the
> benefit in using it, compared with libgcrypt-confg which should already
> work & is portable.

IMHO, it could be easy for people to use pkg-config as a center to control
configurations for many different packages.

This is just an addition for qemu to be able to work in both cases. It does not
remove libgcrypt-confg and can fall back to libgcrypt-confg when pkg-config does
not work.

Zhe

>
>> Signed-off-by: He Zhe 
>> ---
>>  configure | 48 
>>  1 file changed, 40 insertions(+), 8 deletions(-)
>>
>> diff --git a/configure b/configure
>> index e44e454..0f362a7 100755
>> --- a/configure
>> +++ b/configure
>> @@ -2875,6 +2875,30 @@ has_libgcrypt() {
>>  return 0
>>  }
>>  
>> +has_libgcrypt_pkgconfig() {
>> +if ! has $pkg_config ; then
>> +return 1
>> +fi
>> +
>> +if ! $pkg_config --list-all | grep libgcrypt > /dev/null 2>&1 ; then
>> +return 1
>> +fi
>> +
>> +if test -n "$cross_prefix" ; then
>> +host=$($pkg_config --variable=host libgcrypt)
>> +if test "${host%-gnu}-" != "${cross_prefix%-gnu}" ; then
>> +print_error "host($host) does not match 
>> cross_prefix($cross_prefix)"
>> +return 1
>> +fi
>> +fi
>> +
>> +if ! $pkg_config --atleast-version=1.5.0 libgcrypt ; then
>> +print_error "libgcrypt version is $($pkg_config --modversion 
>> libgcrypt)"
>> +return 1
>> +fi
>> +
>> +return 0
>> +}
>>  
>>  if test "$nettle" != "no"; then
>>  pass="no"
>> @@ -2902,7 +2926,14 @@ fi
>>  
>>  if test "$gcrypt" != "no"; then
>>  pass="no"
>> -if has_libgcrypt; then
>> +if has_libgcrypt_pkgconfig; then
>> +gcrypt_cflags=$($pkg_config --cflags libgcrypt)
>> +if test "$static" = "yes" ; then
>> +gcrypt_libs=$($pkg_config --libs --static libgcrypt)
>> +else
>> +gcrypt_libs=$($pkg_config --libs libgcrypt)
>> +fi
>> +elif has_libgcrypt; then
>>  gcrypt_cflags=$(libgcrypt-config --cflags)
>>  gcrypt_libs=$(libgcrypt-config --libs)
>>  # Debian has removed -lgpg-error from libgcrypt-config
>> @@ -2912,15 +2943,16 @@ if test "$gcrypt" != "no"; then
>>  then
>>  gcrypt_libs="$gcrypt_libs -lgpg-error"
>>  fi
>> +fi
>>  
>> -# Link test to make sure the given libraries work (e.g for static).
>> -write_c_skeleton
>> -if compile_prog "" "$gcrypt_libs" ; then
>> -LIBS="$gcrypt_libs $LIBS"
>> -QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags"
>> -pass="yes"
>> -fi
>> +# Link test to make sure the given libraries work (e.g for static).
>> +write_c_skeleton
>> +if compile_prog "" "$gcrypt_libs" ; then
>> +LIBS="$gcrypt_libs $LIBS"
>> +QEMU_CFLAGS="$QEMU_CFLAGS $gcrypt_cflags"
>> +pass="yes"
>>  fi
>> +
>>  if test "$pass" = "yes"; then
>>  gcrypt="yes"
>>  cat > $TMPC << EOF
>> -- 
>> 2.7.4
>>
> Regards,
> Daniel