-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generates illegal instructions #500
Comments
Thanks for reporting this! Do you have instructions to reproduce? Ideally, starting with installing From a first look To test for The 27-th bit of ECX is But... we unconditionally call |
https://software.intel.com/en-us/articles/introduction-to-intel-advanced-vector-extensions states:
So it seems that we can't call |
Reproducing the crash is straightforward: cargo install cargo-edit
cargo add --help |
Same problem on macOS 10.12.6 (16G1036) on the CPU Any call of Affected rustc versions:
|
@fzzr- I think the fix for this issue hasn't made its way into the nightly releases yet unfortunately |
And not today unfortunately. 😩 |
@alexcrichton do you think it is worth to expand the CI to cover this? We can choose which CPU qemu-user uses, so we could actually add two The ones on travis support AVX2 IIRC, so the normal build bots just catch that case. |
I meant to look into this more closely but I’m on holiday. Isn’t there a cpuid bit to test for From a quick google search, |
@stevecheckoway this should be fixed on master, stdsimd on rustc has been updated, but the update just hasn't landed on nightly yet.
Before this issue we just checked for We now check both It is hard to tell whether this is sufficient. There are multiple sources of truth from Intel, none of them focusing on general run-time feature detection in user-space (e.g. for language run-times), but rather focused only on detecting avx/avx512 support, and IIRC I didn't found one explaining the procedure in a step-by-step fashion, but more like, "you need to check all these things in no particular order". FWIW we were checking for |
When the patch lands on nightly I am going to ping you all here again so that you can please try it out and see if it really fixed the issue. Sadly it appears that we it only triggers with particular OS and particular CPUs that I don't have at hand to reproduce this =/ |
@gnzlbg if we could get qemu working for something like this I think that'd be awesome yeah, although I dunno how much testing infrastructure that'd take... |
@gnzlbg I spent a little while reading the Intel manual about this. In order to execute Here's some standalone Rust code to look at the supported XSAVE features. #![feature(asm)]
#[derive(Debug, Clone)]
struct CpuidResult {
pub eax: u32,
pub ebx: u32,
pub ecx: u32,
pub edx: u32,
}
fn cpuid(mut eax: u32, mut ecx: u32) -> CpuidResult {
let ebx: u32;
let edx: u32;
unsafe {
asm!("cpuid"
: "+{eax}"(eax),
"={ebx}"(ebx),
"+{ecx}"(ecx),
"={edx}"(edx)
::: "intel");
};
CpuidResult { eax, ebx, ecx, edx }
}
unsafe fn xgetbv(ecx: u32) -> u64 {
let eax: u32;
let edx: u32;
asm!("xgetbv"
: "={eax}"(eax),
"={edx}"(edx)
: "{ecx}"(ecx)
:: "intel");
((edx as u64) << 32) | (eax as u64)
}
// CPUID.1:ECX
const XSAVE: u32 = 1 << 26;
const OSXSAVE: u32 = 1 << 27;
// CPUID.(EAX=0DH,ECX=1):EAX
const XSAVEOPT: u32 = 1 << 0;
const XSAVEC: u32 = 1 << 1;
const XG1: u32 = 1 << 2;
const XSS: u32 = 1 << 3;
fn main() {
// Check for support.
let features = cpuid(1, 0).ecx;
if features & XSAVE != 0 {
println!("Processor supports XGETBV, XRSTOR, XSAVE, and XSETBV");
assert!(cpuid(0, 0).eax >= 0xd);
} else {
println!("Processor does not support XGETBV, XRSTOR, XRSTORS, XSAVE, XSAVEC, XSAVEOPT, XSAVES, or XSETBV");
return;
}
// Check if enabled.
let enabled = features & OSXSAVE != 0;
if enabled {
println!("XSAVE features enabled");
} else {
println!("XSAVE featuers disabled");
println!("Executing XGETBV, XRSTOR, XRSTORS, XSAVE, XSAVEC, XSAVEOPT, XSAVES, and XSETBV will cause #UD");
return;
}
// Check which features are supported.
let result = cpuid(0xd, 0);
println!("Bitmap of user state components that can be managed by the XSAVE feature set: 0x{:08x}{:08x}",
result.edx, result.eax);
println!("Size of XSAVE area for all user state components supported by the processor: 0x{:x} bytes",
result.ecx);
println!("Size of XSAVE area for all user state components enabled by XCR0: 0x{:x} bytes",
result.ebx);
let result = cpuid(0xd, 1);
if result.eax & XSAVEOPT != 0 {
println!("XSAVEOPT is supported");
} else {
println!("Executing XSAVEOPT will cause #UD");
}
if result.eax & XSAVEC != 0 {
println!("XSAVEC is supported");
} else {
println!("Executing XSAVEC will cause #UD");
}
let xgetbv_1 = result.eax & XG1 != 0;
if xgetbv_1 {
println!("XGETBV with ECX = 1 is supported");
} else {
println!("Executing XGETBV with ECX = 1 will #GP(0)");
}
if result.eax & XSS != 0 {
println!("XSAVES, XRSTORS, and IA32_XSS MSR are supported");
println!("Bitmap of all supervisor state components that can be managed by XSAVES and XRSTORS: 0x{:08x}{:08x}",
result.edx, result.ecx);
println!("Size of XSAVE area containing all state components corresponding to bits set in XCR0 | IA32_XSS");
} else {
println!("Executing XSAVES or XRSTORS will #UD; accessing IA32_XSS MSR will #GP");
}
println!("XCR0 = 0x{:016x}", unsafe { xgetbv(0) });
if xgetbv_1 {
println!("XCR0 & XINUSE = 0x{:016x}", unsafe { xgetbv(1) });
}
} On my laptop, I get this output.
And indeed, executing |
This would mean that the issue is fixed. We are only calling I'll ping you all once the next nightly arrives so that you can try it. And @stevecheckoway thank you for looking into this. |
In the I think this patch should be in the |
I confirm that the bug is fixed. I can no longer reproduce on 1.29.0-nightly (9fd3d7899 2018-07-07). |
This commit updates the `stdsimd` module on the beta branch to pull in a fix for rust-lang/stdarch#500, a bug which affects the stable 1.27.0 release which causes feature detection on x86 to cause an illegal instruction on some CPUs.
Thanks for confirming the fix @fzzr- and @baskerville! I've posted this for a backport to 1.28.0 at rust-lang/rust#52154. We're unlikely to release a patch release for 1.27 for this, but we're only three weeks away from the 1.28 release! |
[beta] Update stdsimd submodule This commit updates the `stdsimd` module on the beta branch to pull in a fix for rust-lang/stdarch#500, a bug which affects the stable 1.27.0 release which causes feature detection on x86 to cause an illegal instruction on some CPUs.
@alexcrichton, Then I think we should mention this issue in the "release notes" for 1.27 as "known issues" because it's really important issue, imho. |
This commit updates the `stdsimd` module on the beta branch to pull in a fix for rust-lang/stdarch#500, a bug which affects the stable 1.27.0 release which causes feature detection on x86 to cause an illegal instruction on some CPUs.
[beta] Update stdsimd submodule This commit updates the `stdsimd` module on the beta branch to pull in a fix for rust-lang/stdarch#500, a bug which affects the stable 1.27.0 release which causes feature detection on x86 to cause an illegal instruction on some CPUs.
I get a systematic crash when I run cargo-edit 0.3.0 on an Intel Core 2 Duo E7600 CPU.
The lldb backtrace seems to indicate that SIMD is involved:
I'm also going to ping @BurntSushi as advised in the related cargo-edit issue.
I remember that I once got the same crash while playing with rustc's optimisation flags to build one of my projects.
The text was updated successfully, but these errors were encountered: