Skip to content
This repository was archived by the owner on Mar 24, 2022. It is now read-only.

Commit 25eff66

Browse files
authored
Check extended CPU features only when necessary (#426)
When checking for CPU features, we support some features under `get_extended_feature_info`, CPUID leaf `eax=7`. Unlike the other leaves we check (`eax=1` and `eax=80000001`), this leaf is not ubiquitous and a rough estimate from feature flags (specifically, `smep`, which Intel added in Ivy Bridge) suggests this leaf may not exist on processors from before 2012. Only check this leaf if the module we would load requires features reported by it, for compatibility with such processors. See https://bugzilla.mozilla.org/show_bug.cgi?id=1615786, wherein the machine's processor is an AMD Phenom II, a series that shipped in 2010.
1 parent ec8d6ff commit 25eff66

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

  • lucet-runtime/lucet-runtime-internals/src/module

lucet-runtime/lucet-runtime-internals/src/module/dl.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,28 @@ fn check_feature_support(module_features: &ModuleFeatures) -> Result<(), Error>
4848
return Err(missing_feature("POPCNT"));
4949
}
5050

51-
let info = cpuid.get_extended_feature_info().ok_or_else(|| {
52-
Error::Unsupported("Unable to obtain host CPU extended feature info!".to_string())
53-
})?;
51+
if module_features.bmi1 || module_features.bmi2 {
52+
let info = cpuid.get_extended_feature_info().ok_or_else(|| {
53+
Error::Unsupported("Unable to obtain host CPU extended feature info!".to_string())
54+
})?;
5455

55-
if module_features.bmi1 && !info.has_bmi1() {
56-
return Err(missing_feature("BMI1"));
57-
}
56+
if module_features.bmi1 && !info.has_bmi1() {
57+
return Err(missing_feature("BMI1"));
58+
}
5859

59-
if module_features.bmi2 && !info.has_bmi2() {
60-
return Err(missing_feature("BMI2"));
60+
if module_features.bmi2 && !info.has_bmi2() {
61+
return Err(missing_feature("BMI2"));
62+
}
6163
}
6264

63-
let info = cpuid.get_extended_function_info().ok_or_else(|| {
64-
Error::Unsupported("Unable to obtain host CPU extended function info!".to_string())
65-
})?;
65+
if module_features.lzcnt {
66+
let info = cpuid.get_extended_function_info().ok_or_else(|| {
67+
Error::Unsupported("Unable to obtain host CPU extended function info!".to_string())
68+
})?;
6669

67-
if module_features.lzcnt && !info.has_lzcnt() {
68-
return Err(missing_feature("LZCNT"));
70+
if module_features.lzcnt && !info.has_lzcnt() {
71+
return Err(missing_feature("LZCNT"));
72+
}
6973
}
7074

7175
// Features are fine, we're compatible!

0 commit comments

Comments
 (0)