Skip to content

Commit 20bacd3

Browse files
committed
test: add test for cache features for amd
The test verifies that we pass the 0x80000006 leaf through from the host on AMD, so that the guest has access to the information about cache properties. Signed-off-by: Nikita Kalyazin <[email protected]>
1 parent 8dab78b commit 20bacd3

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/cpuid/src/cpu_leaf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ pub mod leaf_0x80000006 {
319319
pub mod edx {
320320
use crate::bit_helper::BitRange;
321321

322-
pub const RESERVED_BITRANGE: BitRange = bit_range!(16, 17);
322+
pub const RESERVED_BITRANGE: BitRange = bit_range!(17, 16);
323323
}
324324
}
325325

src/cpuid/src/transformer/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub fn update_extended_cache_features_entry(
105105
use crate::cpu_leaf::leaf_0x80000006::*;
106106

107107
// This only zeroes reserved bits [17:16].
108-
// The actual pass through is done by the `use_host_cpuid_function()` call.
108+
// The actual passthrough is done by the `use_host_cpuid_function()` call.
109109
entry.edx.write_bits_in_range(&edx::RESERVED_BITRANGE, 0);
110110

111111
Ok(())

tests/integration_tests/functional/test_cpu_features.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@ def _check_cpuid_x86(test_microvm, expected_cpu_count, expected_htt):
4040
)
4141

4242

43+
def _check_extended_cache_features(vm):
44+
l3_params = cpuid_utils.get_guest_cpuid(vm)[(0x80000006, 0, "edx")]
45+
46+
# fmt: off
47+
line_size = (l3_params >> 0) & 0xFF
48+
lines_per_tag = (l3_params >> 8) & 0xF
49+
assoc = (l3_params >> 12) & 0xF
50+
cache_size = (l3_params >> 18) & 0x3FFF
51+
# fmt: on
52+
53+
assert line_size > 0
54+
assert lines_per_tag == 0x1 # This is hardcoded in the AMD spec
55+
assert assoc == 0x9 # This is hardcoded in the AMD spec
56+
assert cache_size > 0
57+
58+
4359
def _check_cpu_features_arm(test_microvm):
4460
if cpuid_utils.get_instance_type() == "m6g.metal":
4561
expected_cpu_features = {
@@ -112,6 +128,25 @@ def test_cpuid(test_microvm_with_api, network_config, num_vcpus, htt):
112128
_check_cpuid_x86(vm, num_vcpus, "true" if num_vcpus > 1 else "false")
113129

114130

131+
@pytest.mark.skipif(PLATFORM != "x86_64", reason="CPUID is only supported on x86_64.")
132+
@pytest.mark.skipif(
133+
cpuid_utils.get_cpu_vendor() != cpuid_utils.CpuVendor.AMD,
134+
reason="L3 cache info is only present in 0x80000006 for AMD",
135+
)
136+
def test_extended_cache_features(test_microvm_with_api, network_config):
137+
"""
138+
Check extended cache features (leaf 0x80000006).
139+
140+
@type: functional
141+
"""
142+
vm = test_microvm_with_api
143+
vm.spawn()
144+
vm.basic_config()
145+
_tap, _, _ = vm.ssh_network_config(network_config, "1")
146+
vm.start()
147+
_check_extended_cache_features(vm)
148+
149+
115150
@pytest.mark.skipif(
116151
PLATFORM != "aarch64",
117152
reason="The CPU features on x86 are tested as part of the CPU templates.",

0 commit comments

Comments
 (0)