Skip to content

Commit 091641e

Browse files
kalyazinalsrdn
authored andcommitted
snap/restore: add mtrr and mce to save by cpuid
Signed-off-by: Nikita Kalyazin <[email protected]>
1 parent 25f4fdc commit 091641e

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

src/cpuid/src/cpu_leaf.rs

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ pub mod leaf_0x1 {
6161
}
6262

6363
pub mod edx {
64+
pub const MCE_BITINDEX: u32 = 7; // Memory Check Exception
65+
pub const MTRR_BITINDEX: u32 = 12; // Memory Type Range Registers
6466
pub const PSN_BITINDEX: u32 = 18; // Processor Serial Number
6567
pub const SSE42_BITINDEX: u32 = 20; // SSE 4.2
6668
pub const DS_BITINDEX: u32 = 21; // Debug Store.

src/cpuid/src/template/intel/c3.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn update_feature_info_entry(entry: &mut kvm_cpuid_entry2, _vm_spec: &VmSpec) ->
2626
// Stepping = 4
2727
.write_bits_in_range(&eax::STEPPING_BITRANGE, 4);
2828

29-
// Disable Features
29+
// Enable/disable Features
3030
entry
3131
.ecx
3232
.write_bit(ecx::DTES64_BITINDEX, false)
@@ -44,6 +44,8 @@ fn update_feature_info_entry(entry: &mut kvm_cpuid_entry2, _vm_spec: &VmSpec) ->
4444

4545
entry
4646
.edx
47+
.write_bit(edx::MCE_BITINDEX, true)
48+
.write_bit(edx::MTRR_BITINDEX, true)
4749
.write_bit(edx::PSN_BITINDEX, false)
4850
.write_bit(edx::DS_BITINDEX, false)
4951
.write_bit(edx::ACPI_BITINDEX, false)

src/cpuid/src/template/intel/mod.rs

+34
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,40 @@ pub(crate) fn msrs_to_save_by_cpuid(cpuid: &CpuId) -> HashSet<u32> {
5050
leaf_0x7::index0::ebx::MPX_BITINDEX,
5151
[MSR_IA32_BNDCFGS]
5252
);
53+
54+
// IA32_MTRR_PHYSBASEn, IA32_MTRR_PHYSMASKn
55+
cpuid_msr_dep!(0x1, 0, edx, leaf_0x1::edx::MTRR_BITINDEX, 0x200..0x210);
56+
57+
// Other MTRR MSRs
58+
cpuid_msr_dep!(
59+
0x1,
60+
0,
61+
edx,
62+
leaf_0x1::edx::MTRR_BITINDEX,
63+
[
64+
0x250, // IA32_MTRR_FIX64K_00000
65+
0x258, // IA32_MTRR_FIX16K_80000
66+
0x259, // IA32_MTRR_FIX16K_A0000
67+
0x268, // IA32_MTRR_FIX4K_C0000
68+
0x269, // IA32_MTRR_FIX4K_C8000
69+
0x26a, // IA32_MTRR_FIX4K_D0000
70+
0x26b, // IA32_MTRR_FIX4K_D8000
71+
0x26c, // IA32_MTRR_FIX4K_E0000
72+
0x26d, // IA32_MTRR_FIX4K_E8000
73+
0x26e, // IA32_MTRR_FIX4K_F0000
74+
0x26f, // IA32_MTRR_FIX4K_F8000
75+
0x277, // IA32_PAT
76+
0x2ff // IA32_MTRR_DEF_TYPE
77+
]
78+
);
79+
80+
// MCE MSRs
81+
// We are saving 32 MCE banks here as this is the maximum number supported by KVM
82+
// and configured by default.
83+
// The physical number of the MCE banks depends on the CPU.
84+
// The number of emulated MCE banks can be configured via KVM_X86_SETUP_MCE.
85+
cpuid_msr_dep!(0x1, 0, edx, leaf_0x1::edx::MCE_BITINDEX, 0x400..0x480);
86+
5387
msrs
5488
}
5589

src/cpuid/src/template/intel/t2.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) fn update_feature_info_entry(
2929
// Stepping = 2
3030
.write_bits_in_range(&eax::STEPPING_BITRANGE, 2);
3131

32-
// Disable Features
32+
// Enable/disable Features
3333
entry
3434
.ecx
3535
.write_bit(ecx::DTES64_BITINDEX, false)
@@ -48,6 +48,8 @@ pub(crate) fn update_feature_info_entry(
4848

4949
entry
5050
.edx
51+
.write_bit(edx::MCE_BITINDEX, true)
52+
.write_bit(edx::MTRR_BITINDEX, true)
5153
.write_bit(edx::PSN_BITINDEX, false)
5254
.write_bit(edx::SSE42_BITINDEX, false)
5355
.write_bit(edx::DS_BITINDEX, false)

0 commit comments

Comments
 (0)