Skip to content

Commit f4f7536

Browse files
committed
tests: move host vs guest cpu features into a single test
This is the same test spread over two files. Putting it together in a new file so they don't drift over time. Signed-off-by: Pablo Barbáchano <pablob@amazon.com>
1 parent 409877a commit f4f7536

File tree

3 files changed

+272
-276
lines changed

3 files changed

+272
-276
lines changed

tests/integration_tests/functional/test_cpu_features_aarch64.py

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
# SPDX-License-Identifier: Apache-2.0
33
"""Tests for the CPU features for aarch64."""
44

5-
import os
6-
75
import pytest
86

9-
from framework import utils
107
from framework.properties import global_props
118
from framework.utils_cpuid import CPU_FEATURES_CMD, CpuModel
129

@@ -49,78 +46,3 @@ def test_guest_cpu_features(uvm_any):
4946

5047
guest_feats = set(vm.ssh.check_output(CPU_FEATURES_CMD).stdout.split())
5148
assert guest_feats == expected_cpu_features
52-
53-
54-
def test_host_vs_guest_cpu_features(uvm_nano):
55-
"""Check CPU features host vs guest"""
56-
57-
vm = uvm_nano
58-
vm.add_net_iface()
59-
vm.start()
60-
host_feats = set(utils.check_output(CPU_FEATURES_CMD).stdout.split())
61-
guest_feats = set(vm.ssh.check_output(CPU_FEATURES_CMD).stdout.split())
62-
cpu_model = global_props.cpu_model
63-
match cpu_model:
64-
case CpuModel.ARM_NEOVERSE_N1:
65-
expected_guest_minus_host = set()
66-
expected_host_minus_guest = set()
67-
68-
# Upstream kernel v6.11+ hides "ssbs" from "lscpu" on Neoverse-N1 and Neoverse-V1 since
69-
# they have an errata whereby an MSR to the SSBS special-purpose register does not
70-
# affect subsequent speculative instructions, permitting speculative store bypassing for
71-
# a window of time.
72-
# https://github.com/torvalds/linux/commit/adeec61a4723fd3e39da68db4cc4d924e6d7f641
73-
#
74-
# While Amazon Linux kernels (v5.10 and v6.1) backported the above commit, our test
75-
# ubuntu kernel (v6.8) and our guest kernels (v5.10 and v6.1) don't pick it.
76-
host_has_ssbs = global_props.host_os not in {
77-
"amzn2",
78-
"amzn2023",
79-
} and global_props.host_linux_version_tpl < (6, 11)
80-
guest_has_ssbs = vm.guest_kernel_version < (6, 11)
81-
82-
if host_has_ssbs and not guest_has_ssbs:
83-
expected_host_minus_guest |= {"ssbs"}
84-
if not host_has_ssbs and guest_has_ssbs:
85-
expected_guest_minus_host |= {"ssbs"}
86-
87-
assert host_feats - guest_feats == expected_host_minus_guest
88-
assert guest_feats - host_feats == expected_guest_minus_host
89-
case CpuModel.ARM_NEOVERSE_V1:
90-
expected_guest_minus_host = set()
91-
# KVM does not enable PAC or SVE features by default
92-
# and Firecracker does not enable them either.
93-
expected_host_minus_guest = {
94-
"paca",
95-
"pacg",
96-
"sve",
97-
"svebf16",
98-
"svei8mm",
99-
}
100-
101-
# Upstream kernel v6.11+ hides "ssbs" from "lscpu" on Neoverse-N1 and Neoverse-V1 since
102-
# they have an errata whereby an MSR to the SSBS special-purpose register does not
103-
# affect subsequent speculative instructions, permitting speculative store bypassing for
104-
# a window of time.
105-
# https://github.com/torvalds/linux/commit/adeec61a4723fd3e39da68db4cc4d924e6d7f641
106-
#
107-
# While Amazon Linux kernels (v5.10 and v6.1) backported the above commit, our test
108-
# ubuntu kernel (v6.8) and our guest kernels (v5.10 and v6.1) don't pick it.
109-
host_has_ssbs = global_props.host_os not in {
110-
"amzn2",
111-
"amzn2023",
112-
} and global_props.host_linux_version_tpl < (6, 11)
113-
guest_has_ssbs = vm.guest_kernel_version < (6, 11)
114-
115-
if host_has_ssbs and not guest_has_ssbs:
116-
expected_host_minus_guest |= {"ssbs"}
117-
if not host_has_ssbs and guest_has_ssbs:
118-
expected_guest_minus_host |= {"ssbs"}
119-
120-
assert host_feats - guest_feats == expected_host_minus_guest
121-
assert guest_feats - host_feats == expected_guest_minus_host
122-
case _:
123-
if os.environ.get("BUILDKITE") is not None:
124-
assert (
125-
False
126-
), f"Cpu model {cpu_model} is not supported, please onboard it."
Lines changed: 272 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,272 @@
1+
# Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# pylint: disable=too-many-statements
5+
6+
"""
7+
Check CPU features in the host vs the guest.
8+
9+
This test can highlight differences between the host and what the guest sees.
10+
11+
No CPU templates as we are interested only on what is passed through to the guest by default.
12+
For that, check test_feat_parity.py
13+
"""
14+
15+
import os
16+
17+
from framework import utils
18+
from framework.properties import global_props
19+
from framework.utils_cpuid import CPU_FEATURES_CMD, CpuModel
20+
21+
CPU_MODEL = global_props.cpu_codename
22+
23+
INTEL_HOST_ONLY_FEATS = {
24+
"acpi",
25+
"aperfmperf",
26+
"arch_perfmon",
27+
"art",
28+
"bts",
29+
"cat_l3",
30+
"cdp_l3",
31+
"cqm",
32+
"cqm_llc",
33+
"cqm_mbm_local",
34+
"cqm_mbm_total",
35+
"cqm_occup_llc",
36+
"dca",
37+
"ds_cpl",
38+
"dtes64",
39+
"dtherm",
40+
"dts",
41+
"epb",
42+
"ept",
43+
"ept_ad",
44+
"est",
45+
"flexpriority",
46+
"flush_l1d",
47+
"hwp",
48+
"hwp_act_window",
49+
"hwp_epp",
50+
"hwp_pkg_req",
51+
"ida",
52+
"intel_ppin",
53+
"intel_pt",
54+
"mba",
55+
"monitor",
56+
"pbe",
57+
"pdcm",
58+
"pebs",
59+
"pln",
60+
"pts",
61+
"rdt_a",
62+
"sdbg",
63+
"smx",
64+
"tm",
65+
"tm2",
66+
"tpr_shadow",
67+
"vmx",
68+
"vnmi",
69+
"vpid",
70+
"xtpr",
71+
}
72+
73+
74+
def test_host_vs_guest_cpu_features(uvm_nano):
75+
"""Check CPU features host vs guest"""
76+
77+
vm = uvm_nano
78+
vm.add_net_iface()
79+
vm.start()
80+
host_feats = set(utils.check_output(CPU_FEATURES_CMD).stdout.split())
81+
guest_feats = set(vm.ssh.check_output(CPU_FEATURES_CMD).stdout.split())
82+
83+
match CPU_MODEL:
84+
case CpuModel.AMD_MILAN:
85+
host_guest_diff_5_10 = {
86+
"amd_ppin",
87+
"aperfmperf",
88+
"bpext",
89+
"cat_l3",
90+
"cdp_l3",
91+
"cpb",
92+
"cqm",
93+
"cqm_llc",
94+
"cqm_mbm_local",
95+
"cqm_mbm_total",
96+
"cqm_occup_llc",
97+
"decodeassists",
98+
"extapic",
99+
"extd_apicid",
100+
"flushbyasid",
101+
"hw_pstate",
102+
"ibs",
103+
"irperf",
104+
"lbrv",
105+
"mba",
106+
"monitor",
107+
"mwaitx",
108+
"overflow_recov",
109+
"pausefilter",
110+
"perfctr_llc",
111+
"perfctr_nb",
112+
"pfthreshold",
113+
"rdpru",
114+
"rdt_a",
115+
"sev",
116+
"sev_es",
117+
"skinit",
118+
"smca",
119+
"sme",
120+
"succor",
121+
"svm_lock",
122+
"tce",
123+
"tsc_scale",
124+
"v_vmsave_vmload",
125+
"vgif",
126+
"vmcb_clean",
127+
"wdt",
128+
}
129+
130+
host_guest_diff_6_1 = host_guest_diff_5_10 - {
131+
"lbrv",
132+
"pausefilter",
133+
"pfthreshold",
134+
"sme",
135+
"tsc_scale",
136+
"v_vmsave_vmload",
137+
"vgif",
138+
"vmcb_clean",
139+
} | {"brs", "rapl", "v_spec_ctrl"}
140+
141+
if global_props.host_linux_version_tpl < (6, 1):
142+
assert host_feats - guest_feats == host_guest_diff_5_10
143+
else:
144+
assert host_feats - guest_feats == host_guest_diff_6_1
145+
146+
assert guest_feats - host_feats == {
147+
"hypervisor",
148+
"tsc_adjust",
149+
"tsc_deadline_timer",
150+
"tsc_known_freq",
151+
}
152+
153+
case CpuModel.INTEL_SKYLAKE:
154+
assert host_feats - guest_feats == INTEL_HOST_ONLY_FEATS
155+
assert guest_feats - host_feats == {
156+
"hypervisor",
157+
"tsc_known_freq",
158+
"umip",
159+
}
160+
161+
case CpuModel.INTEL_CASCADELAKE:
162+
expected_host_minus_guest = INTEL_HOST_ONLY_FEATS
163+
expected_guest_minus_host = {
164+
"hypervisor",
165+
"tsc_known_freq",
166+
"umip",
167+
}
168+
169+
# Linux kernel v6.4+ passes through the CPUID bit for "flush_l1d" to guests.
170+
# https://github.com/torvalds/linux/commit/45cf86f26148e549c5ba4a8ab32a390e4bde216e
171+
#
172+
# Our test ubuntu host kernel is v6.8 and has the commit.
173+
if global_props.host_linux_version_tpl >= (6, 4):
174+
expected_host_minus_guest -= {"flush_l1d"}
175+
176+
# Linux kernel v6.6+ drops the "invpcid_single" synthetic feature bit.
177+
# https://github.com/torvalds/linux/commit/54e3d9434ef61b97fd3263c141b928dc5635e50d
178+
#
179+
# Our test ubuntu host kernel is v6.8 and has the commit.
180+
host_has_invpcid_single = global_props.host_linux_version_tpl < (6, 6)
181+
guest_has_invpcid_single = vm.guest_kernel_version < (6, 6)
182+
if host_has_invpcid_single and not guest_has_invpcid_single:
183+
expected_host_minus_guest |= {"invpcid_single"}
184+
if not host_has_invpcid_single and guest_has_invpcid_single:
185+
expected_guest_minus_host |= {"invpcid_single"}
186+
187+
assert host_feats - guest_feats == expected_host_minus_guest
188+
assert guest_feats - host_feats == expected_guest_minus_host
189+
190+
case CpuModel.INTEL_ICELAKE:
191+
host_guest_diff_5_10 = INTEL_HOST_ONLY_FEATS - {"cdp_l3"} | {
192+
"pconfig",
193+
"tme",
194+
"split_lock_detect",
195+
}
196+
host_guest_diff_6_1 = host_guest_diff_5_10 - {
197+
"bts",
198+
"dtes64",
199+
"dts",
200+
"pebs",
201+
}
202+
203+
if global_props.host_linux_version_tpl < (6, 1):
204+
assert host_feats - guest_feats == host_guest_diff_5_10
205+
else:
206+
assert host_feats - guest_feats == host_guest_diff_6_1
207+
208+
assert guest_feats - host_feats == {
209+
"hypervisor",
210+
"tsc_known_freq",
211+
}
212+
213+
case CpuModel.ARM_NEOVERSE_N1:
214+
expected_guest_minus_host = set()
215+
expected_host_minus_guest = set()
216+
217+
# Upstream kernel v6.11+ hides "ssbs" from "lscpu" on Neoverse-N1 and Neoverse-V1 since
218+
# they have an errata whereby an MSR to the SSBS special-purpose register does not
219+
# affect subsequent speculative instructions, permitting speculative store bypassing for
220+
# a window of time.
221+
# https://github.com/torvalds/linux/commit/adeec61a4723fd3e39da68db4cc4d924e6d7f641
222+
#
223+
# While Amazon Linux kernels (v5.10 and v6.1) backported the above commit, our test
224+
# ubuntu kernel (v6.8) and our guest kernels (v5.10 and v6.1) don't pick it.
225+
host_has_ssbs = global_props.host_os not in {
226+
"amzn2",
227+
"amzn2023",
228+
} and global_props.host_linux_version_tpl < (6, 11)
229+
guest_has_ssbs = vm.guest_kernel_version < (6, 11)
230+
231+
if host_has_ssbs and not guest_has_ssbs:
232+
expected_host_minus_guest |= {"ssbs"}
233+
if not host_has_ssbs and guest_has_ssbs:
234+
expected_guest_minus_host |= {"ssbs"}
235+
236+
assert host_feats - guest_feats == expected_host_minus_guest
237+
assert guest_feats - host_feats == expected_guest_minus_host
238+
239+
case CpuModel.ARM_NEOVERSE_V1:
240+
expected_guest_minus_host = set()
241+
# KVM does not enable PAC or SVE features by default
242+
# and Firecracker does not enable them either.
243+
expected_host_minus_guest = {"paca", "pacg", "sve", "svebf16", "svei8mm"}
244+
245+
# Upstream kernel v6.11+ hides "ssbs" from "lscpu" on Neoverse-N1 and Neoverse-V1 since
246+
# they have an errata whereby an MSR to the SSBS special-purpose register does not
247+
# affect subsequent speculative instructions, permitting speculative store bypassing for
248+
# a window of time.
249+
# https://github.com/torvalds/linux/commit/adeec61a4723fd3e39da68db4cc4d924e6d7f641
250+
#
251+
# While Amazon Linux kernels (v5.10 and v6.1) backported the above commit, our test
252+
# ubuntu kernel (v6.8) and our guest kernels (v5.10 and v6.1) don't pick it.
253+
host_has_ssbs = global_props.host_os not in {
254+
"amzn2",
255+
"amzn2023",
256+
} and global_props.host_linux_version_tpl < (6, 11)
257+
guest_has_ssbs = vm.guest_kernel_version < (6, 11)
258+
259+
if host_has_ssbs and not guest_has_ssbs:
260+
expected_host_minus_guest |= {"ssbs"}
261+
if not host_has_ssbs and guest_has_ssbs:
262+
expected_guest_minus_host |= {"ssbs"}
263+
264+
assert host_feats - guest_feats == expected_host_minus_guest
265+
assert guest_feats - host_feats == expected_guest_minus_host
266+
267+
case _:
268+
# only fail if running in CI
269+
if os.environ.get("BUILDKITE") is not None:
270+
assert (
271+
guest_feats == host_feats
272+
), f"Cpu model {CPU_MODEL} is not supported"

0 commit comments

Comments
 (0)