forked from firecracker-microvm/firecracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(vmm): Set FDP_EXCPTN_ONLY and ZERO_FCS_FDS
Sets FDP_EXCPTN_ONLY bit (CPUID.7h.0:EBX[6]) and ZERO_FCS_FDS bit (CPUID.7h.0:EBX[13]) in Intel's CPUID normalization as recommended in kernel doc. For more details, please refer to https://lore.kernel.org/all/[email protected]/ Signed-off-by: Takahiro Itazuri <[email protected]>
- Loading branch information
Showing
20 changed files
with
67 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ pub enum NormalizeCpuidError { | |
/// Leaf 0x6 is missing from CPUID. | ||
#[error("Leaf 0x6 is missing from CPUID.")] | ||
MissingLeaf6, | ||
/// Leaf 0x7 / subleaf 0 is missing from CPUID. | ||
#[error("Leaf 0x7 / subleaf 0 is missing from CPUID.")] | ||
MissingLeaf7, | ||
/// Leaf 0xA is missing from CPUID. | ||
#[error("Leaf 0xA is missing from CPUID.")] | ||
MissingLeafA, | ||
|
@@ -85,6 +88,7 @@ impl super::IntelCpuid { | |
) -> Result<(), NormalizeCpuidError> { | ||
self.update_deterministic_cache_entry(cpu_count, cpus_per_core)?; | ||
self.update_power_management_entry()?; | ||
self.update_extended_feature_flags_entry()?; | ||
self.update_performance_monitoring_entry()?; | ||
self.update_brand_string_entry()?; | ||
|
||
|
@@ -197,6 +201,22 @@ impl super::IntelCpuid { | |
Ok(()) | ||
} | ||
|
||
/// Update structured extended feature flags enumeration leaf | ||
fn update_extended_feature_flags_entry(&mut self) -> Result<(), NormalizeCpuidError> { | ||
let leaf_7_0 = self | ||
.get_mut(&CpuidKey::subleaf(0x7, 0)) | ||
.ok_or(NormalizeCpuidError::MissingLeaf7)?; | ||
|
||
// Set FDP_EXCPTN_ONLY bit (bit 6) and ZERO_FCS_FDS bit (bit 13) as recommended in kernel | ||
// doc. These bits are reserved in AMD. | ||
// https://lore.kernel.org/all/[email protected]/ | ||
// https://github.com/torvalds/linux/commit/45016721de3c714902c6f475b705e10ae0bdd801 | ||
set_bit(&mut leaf_7_0.result.ebx, 6, true); | ||
set_bit(&mut leaf_7_0.result.ebx, 13, true); | ||
|
||
Ok(()) | ||
} | ||
|
||
/// Update performance monitoring entry | ||
fn update_performance_monitoring_entry(&mut self) -> Result<(), NormalizeCpuidError> { | ||
let leaf_a = self | ||
|
@@ -422,4 +442,30 @@ mod tests { | |
}), | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_update_extended_feature_flags_entry() { | ||
let mut cpuid = | ||
crate::cpu_config::x86_64::cpuid::IntelCpuid(std::collections::BTreeMap::from([( | ||
crate::cpu_config::x86_64::cpuid::CpuidKey { | ||
leaf: 0x7, | ||
subleaf: 0, | ||
}, | ||
crate::cpu_config::x86_64::cpuid::CpuidEntry { | ||
flags: crate::cpu_config::x86_64::cpuid::KvmCpuidFlags::SIGNIFICANT_INDEX, | ||
..Default::default() | ||
}, | ||
)])); | ||
|
||
cpuid.update_extended_feature_flags_entry().unwrap(); | ||
|
||
let leaf_7_0 = cpuid | ||
.get(&crate::cpu_config::x86_64::cpuid::CpuidKey { | ||
leaf: 0x7, | ||
subleaf: 0, | ||
}) | ||
.unwrap(); | ||
assert!((leaf_7_0.result.ebx & (1 << 6)) > 0); | ||
assert!((leaf_7_0.result.ebx & (1 << 13)) > 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters