[libos] Update cpuid leaf table

This commit is contained in:
Qi Zheng 2023-11-16 13:05:33 +08:00 committed by volcano
parent cb1ee85605
commit 3fb86f96c4

@ -57,6 +57,7 @@ impl CpuIdCache {
fn generate_cpuid_cache(&mut self, max_basic_leaf: u32, max_extend_leaf: u32) {
let mut sgx_support: bool = false;
let mut pconfig_support: bool = false;
// Generate basic leaf cpuid cache
for leaf in CPUID_MIN_BASIC_LEAF..=max_basic_leaf {
// Intel SGX Capability Enumeration Leaf,
@ -64,6 +65,11 @@ impl CpuIdCache {
if leaf == 0x12 && !sgx_support {
continue;
}
// Intel PCONFIG Enumeration Leaf,
// Leaf 1BH is supported if CPUID.(EAX=07H, ECX=0H):EDX[18] = 1.
if leaf == 0x1B && !pconfig_support {
continue;
}
let mut max_subleaf = 0;
for subleaf in (0..) {
let cpuid_input = CpuIdInput { leaf, subleaf };
@ -96,13 +102,15 @@ impl CpuIdCache {
0xD => 63,
// (Sub-leaf == 0) can not decide max_subleaf for these leaf,
// later match expression will decide the max_subleaf.
0x4 | 0xB | 0x12 | 0x1F => CPUID_MAX_SUBLEAF,
0x4 | 0xB | 0x12 | 0x1B | 0x1F => CPUID_MAX_SUBLEAF,
// Default max_subleaf is 0.
_ => 0,
};
if leaf == 0x7 {
// EBX Bit 02: Supports Intel® SGX Extensions if 1.
sgx_support = (cpuid_result.ebx & 0x0000_0004) != 0;
// EDX Bit 18: Supports PCONFIG if 1.
pconfig_support = (cpuid_result.edx & 0x40000) != 0;
}
}
// These leafs determine the maximum supported sub-leaf according to
@ -120,6 +128,9 @@ impl CpuIdCache {
// EAX Bit 03 - 00: Sub-leaf Type.
// 0000b: Indicates this sub-leaf is invalid.
0x12 if subleaf >= 2 && (cpuid_result.eax & 0x0000000F) == 0 => subleaf,
// If a sub-leaf type (EAX) is 0, the sub-leaf is invalid and zero is returned
// in EBX, ECX, and EDX.
0x1B if (cpuid_result.eax == 0) => subleaf,
// V2 Extended Topology Enumeration Leaf
// CPUID leaf 0x1F is a preferred superset to leaf 0xB.
0x1F if (cpuid_result.ecx & 0x0000_FF00) == 0 => subleaf,
@ -214,8 +225,9 @@ lazy_static! {
}
fn is_cpuid_leaf_has_subleaves(leaf: u32) -> bool {
const CPUID_LEAF_WITH_SUBLEAF: [u32; 11] =
[0x4, 0x7, 0xB, 0xD, 0xF, 0x10, 0x12, 0x14, 0x17, 0x18, 0x1F];
const CPUID_LEAF_WITH_SUBLEAF: [u32; 12] = [
0x4, 0x7, 0xB, 0xD, 0xF, 0x10, 0x12, 0x14, 0x17, 0x18, 0x1B, 0x1F,
];
CPUID_LEAF_WITH_SUBLEAF.contains(&leaf)
}