Signal SIGILL (Illegal instruction) code ILL_ILLOPN (Illegal operand) after migrate to .net9
Description
We are currently migrating to .net9 and after some the our application crashes without any exception.
At first i found this message in the journal of our ubuntu 22.04:
kernel: traps: .NET Server GC[1867769] trap invalid opcode ip:7f2eb7bdc9d1 sp:7f2eb0de1e90 error:0 in libcoreclr.so[7f2eb7784000+4ed000]
Then, after some digging, i was able to generate a dump with the binary of this bug
I used WinDbg to open it and saw the following error:
Signal SIGILL (Illegal instruction) code ILL_ILLOPN (Illegal operand) at 0x7fcae8ee19d1
Locking at the address is saw this:
The crash did not happen at the same timings. It's arround 20-40 seconds until this happens.
The application is running on a small kubenetes system with only one node. If i host everything on my local machine everything works fine.
Reproduction Steps
Sadly i don't now how to provide a reproduction step without giving access to the server. I can provide a dump if needed.
Expected behavior
No crash
Actual behavior
As written in the description. If needed i can provide a dump (~730MB uncompressed, ~65MB compressed)
Regression?
No response
Known Workarounds
Going back to .net8
Configuration
dotnet info of the kubernetes pod:
.NET SDK:
Version: 9.0.200
Commit: 90e8b202f2
Workload version: 9.0.200-manifests.b4a8049f
MSBuild version: 17.13.8+cbc39bea8
Runtime Environment:
OS Name: ubuntu
OS Version: 22.04
OS Platform: Linux
RID: linux-x64
Base Path: /usr/share/dotnet/sdk/9.0.200/
.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.
Host:
Version: 9.0.2
Architecture: x64
Commit: 80aa709f5d
.NET SDKs installed:
9.0.200 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 9.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 9.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
Host CPU info:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 79
model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
stepping : 1
microcode : 0xb000036
cpu MHz : 2199.998
cache size : 16384 KB
physical id : 0
siblings : 6
core id : 0
cpu cores : 6
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 20
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap xsaveopt arat umip md_clear arch_capabilities
vmx flags : vnmi preemption_timer posted_intr invvpid ept_x_only ept_ad ept_1gb flexpriority apicv tsc_offset vtpr mtf vapic ept vpid unrestricted_guest vapic_reg vid shadow_vmcs pml
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa mmio_stale_data bhi
bogomips : 4399.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
CPU info of the Pod:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 79
model name : Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
stepping : 1
microcode : 0xb000036
cpu MHz : 2199.998
cache size : 16384 KB
physical id : 0
siblings : 6
core id : 0
cpu cores : 6
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 20
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm rdseed adx smap xsaveopt arat umip md_clear arch_capabilities
vmx flags : vnmi preemption_timer posted_intr invvpid ept_x_only ept_ad ept_1gb flexpriority apicv tsc_offset vtpr mtf vapic ept vpid unrestricted_guest vapic_reg vid shadow_vmcs pml
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs taa mmio_stale_data bhi
bogomips : 4399.99
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management:
Other information
No response
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch See info in area-owners.md if you want to be subscribed.
@tannergooding @dotnet/jit-contrib any idea how vpbroadcastq could appear in a non-avx512 environment?
kernel: traps: .NET Server GC[1867769] trap invalid opcode ip:7f2eb7bdc9d1 sp:7f2eb0de1e90 error:0 in libcoreclr.so[7f2eb7784000+4ed000]
ah, maybe it's actually VXSort in GC?
I can provide a dump if needed.
@Typhon226 could you please upload it to https://developercommunity.visualstudio.com/ (you can configure privacy level for attachments there if needed)
vpbroadcastq isn't AVX512 specific, it also exists on AVX2. The issue here looks to be specific to it using ZMM, which is AVX512F only.
I'm not aware of anything that would cause this JIT side, as we should be guarding and even asserting that AVX512 specific instructions/nodes aren't being introduced if compSupports reports false. So it could be GC or something else instead.
vpbroadcastqisn't AVX512 specific, it also exists on AVX2. The issue here looks to be specific to it usingZMM, which is AVX512F only.I'm not aware of anything that would cause this JIT side, as we should be guarding and even asserting that AVX512 specific instructions/nodes aren't being introduced if
compSupportsreportsfalse. So it could be GC or something else instead.
CC @mangod9 @Maoni0.
@EgorBo Dump is attached here: https://developercommunity.visualstudio.com/t/Dump-for-Issue-112897-Signal-SIGILL-Il/10858257
@EgorBo Dump is attached here: https://developercommunity.visualstudio.com/t/Dump-for-Issue-112897-Signal-SIGILL-Il/10858257
@jkotas as someone who often views dumps uploaded by the community - do I need a special permission to view them from there? Because I get Error 403
You do not need special permissions. It looks like that the link with restricted permissions was copy&pasted into description from somewhere.
@Typhon226 Could you please attach the dump to the developercommunity issue via the paper clip icon so that we are able to access it?
@EgorBo I reupload the file. Error was i closed the upload popup after the progress bar was at 100%. So i waited a little bit and it closed by it self, now i also was able to download.
@Typhon226 Thanks! Looks like it's definitely inside the GC (VXSort). GC uses AVX512 to accelerate the sort, but it's expected to be under some run-time check..
[0x5] libcoreclr!vxsort::vxsort_machine_traits<long, (vxsort::vector_machine)2>::shift_n_sub<3>+0xd (Inline Function) (Inline Function)
[0x6] libcoreclr!vxsort::packer<long, int, (vxsort::vector_machine)2, 3, 2, 128, false>::pack+0xd (Inline Function) (Inline Function)
[0x7] libcoreclr!vxsort::vxsort<long, (vxsort::vector_machine)2, 8, 3>::sort+0x111 0x7fcae20e1e90 0x7fcae8ee18b9
[0x8] libcoreclr!vxsort::vxsort<long, (vxsort::vector_machine)2, 8, 3>::sort+0x59 0x7fcae20e2460 0x7fcae8ee1838
[0x9] libcoreclr!do_vxsort_avx512+0x58 0x7fcae20e2480 0x7fcae8cdbcc2
[0xa] libcoreclr!SVR::do_vxsort+0x97 (Inline Function) (Inline Function)
[0xb] libcoreclr!SVR::gc_heap::sort_mark_list+0x252 0x7fcae20e2a20 0x7fcae8cf687c
[0xc] libcoreclr!SVR::gc_heap::mark_phase+0x1b5c 0x7fcae20e2a70 0x7fcae8cefc8a
[0xd] libcoreclr!SVR::gc_heap::gc1+0x2ca 0x7fcae20e2b50 0x7fcae8cd7181
[0xe] libcoreclr!SVR::gc_heap::garbage_collect+0xbb1 0x7fcae20e2c20 0x7fcae8cd381d
[0xf] libcoreclr!SVR::gc_heap::gc_thread_function+0x1abd 0x7fcae20e2cd0 0x7fcae8cd1d56
[0x10] libcoreclr!SVR::gc_heap::gc_thread_stub+0x31 0x7fcae20e2d60 0x7fcae8bf752e
Tagging subscribers to this area: @dotnet/gc See info in area-owners.md if you want to be subscribed.
adding @cshung, since linux support for vxsort was added in 9. If it was using avx512 specific registers it probably would have failed in other environments. Is this specific to the CPU specification listed the OP?
The code that is responsible for detecting AVX512 in run-time in GC: https://github.com/dotnet/runtime/blob/main/src/coreclr/gc/vxsort/isa_detection.cpp#L85-L121
I have no clue if __builtin_cpu_supports is doing the "right stuff"
My "guess" is that it's only checking the CPUID bit
and not also checking xsave, xgetbv, or other necessary bits like the OS requires
The Linux support should really be nearly identical to what Windows is doing there but we already have an xplat helper in PAL (used by the VM and NAOT/Crossgen), so lets just not duplicate it and reuse that instead
maybe we can even just use the GC/EE interface and mirror the jit flags like the JIT/EE interface has even and rely on the VM reporting rather than querying it independently in the GC?
The information used by __builtin_cpu_supports is populated here: https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/builtins/cpu_model/x86.c#L867-L918 . It does check xsave, xgetbv and other necessary bits.
It would be useful to check what the __cpu_model static got populated to, and what the code that run to populate it was. The process may have old or buggy version of these checks.
Per https://github.com/dotnet/runtime/blob/main/docs/project/linux-build-methodology.md#security-related-servicing, we are statically linking low-level C library helpers from Ubuntu 16. The low-level C library includes the helper to initialize __cpu_model.
The copy of the helper that we are linking in seems to be missing this fix to handle AVX512 correctly: https://github.com/gcc-mirror/gcc/commit/059cc8aca774e50555bc116436348d2898404685
We either need to patch the low-level C library in our build containers (cc @sbomer) or to switch to our copy of the AVX512 detection logic as @tannergooding suggested.
switching to using the PAL helper would be good, assuming it works for standalone GC too.
switching to using the PAL helper would be good, assuming it works for standalone GC too.
It can be made to work. I assume that we would link the PAL helper statically. We tend to avoid communicating these types of details over GC/EE interface.
Note that this bug is likely .NET 9 specific. It should be fixed in .NET 10 as a side-effect of updating our dependencies (https://github.com/dotnet/runtime/issues/109939).
I have the same issue after migrating from dotnet8 to dotnet9 in some backend services in Debian 12 It is a random issue, sometimes it happens after hours of execution.
The systemd log has these entries:
kernel: traps: .NET Server GC[1957508] trap invalid opcode ip:7fcba04281ea sp:7fcb203c7360 error:0 in libcoreclr.so[7fcb9ffd3000+4ec000]
Main process exited, code=killed, status=4/ILL
CPU Info:
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 85
model name : Intel(R) Xeon(R) Gold 6240R CPU @ 2.40GHz
stepping : 7
microcode : 0x5003302
cpu MHz : 2400.082
cache size : 36608 KB
physical id : 0
siblings : 4
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc rep_good nopl cpuid tsc_known_freq pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 movbe popcnt aes f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault intel_ppin ssbd ibrs ibpb stibp fsgsbase bmi1 bmi2 erms rdseed adx clflushopt clwb md_clear
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit mmio_stale_data retbleed gds bhi ibpb_no_ret
bogomips : 4800.16
clflush size : 64
cache_alignment : 64
address sizes : 46 bits physical, 48 bits virtual
power management: