Repository navigation
Open
rust-lang/rust
#166335Description
I tried this command:
TARGET=x86_64-unknown-linux-gnu RUSTFLAGS="-C target-feature=-sse3 -Cforce-frame-pointers=on" cargo test --manifest-path crates/core_arch/Cargo.toml
It aborts with SIGILL. The coredump has the following backtrace for the failing thread:
Stack trace of thread 793861:
#0 0x000056211512f8ad _RNvNtNtNtCsf7HRiN87Bge_9core_arch9core_arch3x862kl20__mm_encodekey256_u32B7_ (core_arch-a950f9464a0014cc + 0x8198ad)
#1 0x00005621150b39b0 _RNvNtNtNtNtCsf7HRiN87Bge_9core_arch9core_arch3x862kl5tests12encodekey256 (core_arch-a950f9464a0014cc + 0x79d9b0)
#2 0x00005621150b4cbf _RNvNvNtNtNtNtCsf7HRiN87Bge_9core_arch9core_arch3x862kl5testss_26test_mm_aesdecwide256kl_u826test_mm_aesdecwide256kl_u8 (core_arch-a950f9464a0014cc + 0x79ecbf)
#3 0x00005621150b4080 _RNvNtNtNtNtCsf7HRiN87Bge_9core_arch9core_arch3x862kl5testss_26test_mm_aesdecwide256kl_u8 (core_arch-a950f9464a0014cc + 0x79e080)
#4 0x00005621150e81f9 _RNCNvNtNtNtNtCsf7HRiN87Bge_9core_arch9core_arch3x862kl5tests26test_mm_aesdecwide256kl_u80Bb_ (core_arch-a950f9464a0014cc + 0x7d21f9)
#5 0x0000562114f02608 _RNvYNCNvNtNtNtNtCsf7HRiN87Bge_9core_arch9core_arch3x862kl5tests26test_mm_aesdecwide256kl_u80INtNtNtCs9xW7P2vDFDD_4core3ops8function6FnOnceuE9call_onceBe_ (core_arch-a950f9464a0014cc + 0x5ec608)
#6 0x000056211517a7fb _RINvCsfPaTRGSX743_4test28___rust_begin_short_backtraceINtNtCs9xW7P2vDFDD_4core6result6ResultuNtNtCshvaLlscjhsv_5alloc6string6StringEFEBQ_EB2_ (core_arch-a950f9464a0014cc + 0x8647fb)
#7 0x0000562115187fb5 _RNCNvCsfPaTRGSX743_4test8run_test0B3_ (core_arch-a950f9464a0014cc + 0x871fb5)
#8 0x0000562115182504 _RINvNtNtCsadZFJLPwbP2_3std3sys9backtrace28___rust_begin_short_backtraceNCNvCsfPaTRGSX743_4test8run_tests_0uEB1b_ (core_arch-a950f9464a0014cc + 0x86c504)
#9 0x000056211518af42 _RNSNvYNCINvNtNtCsadZFJLPwbP2_3std6thread9lifecycle15spawn_uncheckedNCNvCsfPaTRGSX743_4test8run_tests_0uEs_0INtNtNtCs9xW7P2vDFDD_4core3ops8function6FnOnceuE9call_once6vtableB17_ (core_arch-a950f9464a0014cc + 0x874f42)
#10 0x00005621151f6faf _RNvNvMs0_NtNtNtCsadZFJLPwbP2_3std3sys6thread4unixNtB7_6Thread3new12thread_start (core_arch-a950f9464a0014cc + 0x8e0faf)
#11 0x00007f60e44c6db8 start_thread (libc.so.6 + 0x94db8)
#12 0x00007f60e4544f98 __clone3 (libc.so.6 + 0x112f98)
So this seems to be inside test_mm_aesdecwide256kl_u8:
Activity
RalfJung commentedon Nov 19, 2026
It looks like my CPU has
wideklbut notkl:The test
test_mm_aesdecwide256kl_u8checks forwidekland then invokesencodekey256which needkl.Looks like a buggy test? Cc @sayantn (test added in #1706)
RalfJung commentedon Nov 19, 2026
The Rust compiler information thinks that "widekl" implies "kl".
That would make sense but seems to be wrong? Or the "widekl" feature detection is broken and my CPU doesn't actually have "widekl".
bjorn3 commentedon Nov 19, 2026
LLVM also has widekl imply kl: https://github.com/llvm/llvm-project/blob/1d73203488050b947d7fab760f76de8990a4d937/llvm/lib/Target/X86/X86.td#L328-L330 Your CPU should be Alderlake, which according to GCC has both kl and widekl. According to LLVM both widekl and by feature implication kl is supported. AFAICT it doesn't make sense to support widekl without kl given that all those instructions need a wrapping key set, which can only be set by the privileged loadiwkey instruction, which is part of the kl feature.
According to https://lore.kernel.org/all/[email protected]/ userspace isn't supposed to use Keylocker instructions though "because there is no ABI provided to communicate and coordinate wrapping-key restore failures to userspace". It looks like that patchset hasn't landed yet, so I suspect keylocker is entirely unsupported on Linux right now. @sayantn how did it work for you? Did you test on another OS?
sayantn commentedon Nov 21, 2026
I have not tested on anything other than Linux (I couldn't test it natively since my cpu doesn't support keylocker). I don't really get the point in that post about communicating key wrapping failures. The instructions are not privileged except for
loadiwkey.sayantn commentedon Nov 21, 2026
upon looking at the std_detect code again, there might be a bug. It queries
cpuid(0x19), and setsklif bit 0 ofEBXis on, andwideklif bit 2 ofEBXis active. Looking at the gcc code, I think the actual flow has to be check bit 0 ofEBX(this signifies OS permission to USE keylocker), and then query bit 2 ofEBXforwidekl, and query bit 23 ofECXfromcpuid(0x07)forklbjorn3 commentedon Nov 21, 2026
If you hybernate and resume or use something like CRUI to create a snapshot of a process and restore it after a reboot (as is common for applying updates on supercomputers), all the wrapped keys would be invalidated. As I understand it the problem is how would the kernel communicate this to programs to avoid them crashing next time they try to use a keylocker instruction? There is currently no defined way for that.
sayantn commentedon Nov 21, 2026
ok that makes sense. I put up a pr fixing this behavior (checking os support before enabling
widekl, currently onlyklchecked for that, which was the reason for that bug), and some other bugs rust-lang/rust#166335rustbot commentedon Nov 22, 2026
Error: Label bug can only be set by Rust team members
Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.
bardiharborow commentedon Nov 22, 2026
@rustbot label +A-x86 +A-runtime-detection +A-testing