Skip to content

Commit 8dab78b

Browse files
committed
fix(vmm): pass through cache information from host
4.14 KVM reports the supported leaf 0x80000006 as zeroes, so it needs to be passed through from the host CPUID so that the guest sees meaningful information about the caches. Signed-off-by: Nikita Kalyazin <[email protected]>
1 parent 41e786e commit 8dab78b

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Fixed
6+
7+
- Fixed passing through cache information from host in CPUID leaf 0x80000006.
8+
59
## [1.3.2]
610

711
### Fixed

src/cpuid/src/cpu_leaf.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,16 @@ pub mod leaf_0x80000001 {
313313
}
314314
}
315315

316+
pub mod leaf_0x80000006 {
317+
pub const LEAF_NUM: u32 = 0x8000_0006;
318+
319+
pub mod edx {
320+
use crate::bit_helper::BitRange;
321+
322+
pub const RESERVED_BITRANGE: BitRange = bit_range!(16, 17);
323+
}
324+
}
325+
316326
pub mod leaf_0x80000008 {
317327
pub const LEAF_NUM: u32 = 0x8000_0008;
318328

src/cpuid/src/transformer/amd.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl CpuidTransformer for AmdCpuidTransformer {
132132
// Some versions of kernel may return the 0xB leaf for AMD even if this is an
133133
// Intel-specific leaf. Remove it.
134134
cpuid.retain(|entry| entry.function != leaf_0xb::LEAF_NUM);
135+
use_host_cpuid_function(cpuid, leaf_0x80000006::LEAF_NUM, false)?;
135136
use_host_cpuid_function(cpuid, leaf_0x8000001e::LEAF_NUM, false)?;
136137
use_host_cpuid_function(cpuid, leaf_0x8000001d::LEAF_NUM, true)?;
137138
self.process_entries(cpuid, vm_spec)
@@ -143,6 +144,7 @@ impl CpuidTransformer for AmdCpuidTransformer {
143144
leaf_0x7::LEAF_NUM => Some(amd::update_structured_extended_entry),
144145
leaf_0x80000000::LEAF_NUM => Some(amd::update_largest_extended_fn_entry),
145146
leaf_0x80000001::LEAF_NUM => Some(amd::update_extended_feature_info_entry),
147+
leaf_0x80000006::LEAF_NUM => Some(common::update_extended_cache_features_entry),
146148
leaf_0x80000008::LEAF_NUM => Some(amd::update_amd_features_entry),
147149
leaf_0x8000001d::LEAF_NUM => Some(amd::update_extended_cache_topology_entry),
148150
leaf_0x8000001e::LEAF_NUM => Some(amd::update_extended_apic_id_entry),

src/cpuid/src/transformer/common.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ pub fn update_cache_parameters_entry(
9898
Ok(())
9999
}
100100

101+
pub fn update_extended_cache_features_entry(
102+
entry: &mut kvm_cpuid_entry2,
103+
_vm_spec: &VmSpec,
104+
) -> Result<(), Error> {
105+
use crate::cpu_leaf::leaf_0x80000006::*;
106+
107+
// This only zeroes reserved bits [17:16].
108+
// The actual pass through is done by the `use_host_cpuid_function()` call.
109+
entry.edx.write_bits_in_range(&edx::RESERVED_BITRANGE, 0);
110+
111+
Ok(())
112+
}
113+
101114
/// Replaces the `cpuid` entries corresponding to `function` with the entries from the host's cpuid.
102115
pub fn use_host_cpuid_function(
103116
cpuid: &mut CpuId,

src/cpuid/src/transformer/intel.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use super::*;
55
use crate::bit_helper::BitHelper;
66
use crate::cpu_leaf::*;
7+
use crate::transformer::common::use_host_cpuid_function;
78

89
// The APIC ID shift in leaf 0xBh specifies the number of bits to shit the x2APIC ID to get a
910
// unique topology of the next level. This allows 128 logical processors/package.
@@ -139,6 +140,8 @@ impl CpuidTransformer for IntelCpuidTransformer {
139140
.map_err(Error::Fam)?;
140141
}
141142

143+
use_host_cpuid_function(cpuid, leaf_0x80000006::LEAF_NUM, false)?;
144+
142145
self.process_entries(cpuid, vm_spec)
143146
}
144147

@@ -150,6 +153,7 @@ impl CpuidTransformer for IntelCpuidTransformer {
150153
leaf_0xa::LEAF_NUM => Some(intel::update_perf_mon_entry),
151154
leaf_0xb::LEAF_NUM => Some(intel::update_extended_topology_entry),
152155
0x8000_0002..=0x8000_0004 => Some(common::update_brand_string_entry),
156+
leaf_0x80000006::LEAF_NUM => Some(common::update_cache_parameters_entry),
153157
_ => None,
154158
}
155159
}

0 commit comments

Comments
 (0)