Skip to content

Commit f2ddc04

Browse files
committed
fix(test): Handle ssbs correctly in host/guest feature comparison
Linux kernel should hide "ssbs" since Neoverse-N1 and Neoverse-V1 have an errata whereby an MSR to the SSBS special-purpose register does not affect subsequent speculative instructions, permitting speculative store bypassing for a window of time. Although Amazon Linux host kernels (v5.10 and v6.1) backported it, the guest kernels (v5.10 and v6.1) and the ubuntu host kernel (currently v6.8) lack the change. Fixes: 2babc80 ("test(aarch64): add host vs guest cpu feature test") Signed-off-by: Takahiro Itazuri <[email protected]>
1 parent 2e994b5 commit f2ddc04

File tree

1 file changed

+49
-10
lines changed

1 file changed

+49
-10
lines changed

tests/integration_tests/functional/test_cpu_features_aarch64.py

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import framework.utils_cpuid as cpuid_utils
1212
from framework import utils
13+
from framework.properties import global_props
1314
from framework.utils_cpuid import CPU_FEATURES_CMD, CpuModel
1415

1516
PLATFORM = platform.machine()
@@ -81,25 +82,63 @@ def test_host_vs_guest_cpu_features_aarch64(uvm_nano):
8182
cpu_model = cpuid_utils.get_cpu_model_name()
8283
match cpu_model:
8384
case CpuModel.ARM_NEOVERSE_N1:
84-
assert host_feats - guest_feats == set()
85-
# Kernel should hide this feature, but our guest kernel
86-
# currently lacks the commit with this change.
87-
# The commit that introduces the change:
88-
# https://github.com/torvalds/linux/commit/7187bb7d0b5c7dfa18ca82e9e5c75e13861b1d88
89-
assert guest_feats - host_feats == {"ssbs"}
85+
expected_guest_minus_host = set()
86+
expected_host_minus_guest = set()
87+
88+
# Upstream kernel v6.11+ hides "ssbs" from "lscpu" on Neoverse-N1 and Neoverse-V1 since
89+
# they have an errata whereby an MSR to the SSBS special-purpose register does not
90+
# affect subsequent speculative instructions, permitting speculative store bypassing for
91+
# a window of time.
92+
# https://github.com/torvalds/linux/commit/adeec61a4723fd3e39da68db4cc4d924e6d7f641
93+
#
94+
# While Amazon Linux kernels (v5.10 and v6.1) backported the above commit, our test
95+
# ubuntu kernel (v6.8) and our guest kernels (v5.10 and v6.1) don't pick it.
96+
host_has_ssbs = global_props.host_os not in {
97+
"amzn2",
98+
"amzn2023",
99+
} and global_props.host_linux_version_tpl < (6, 11)
100+
guest_has_ssbs = vm.guest_kernel_version < (6, 11)
101+
102+
if host_has_ssbs and not guest_has_ssbs:
103+
expected_host_minus_guest |= {"ssbs"}
104+
if not host_has_ssbs and guest_has_ssbs:
105+
expected_guest_minus_host |= {"ssbs"}
106+
107+
assert host_feats - guest_feats == expected_host_minus_guest
108+
assert guest_feats - host_feats == expected_guest_minus_host
90109
case CpuModel.ARM_NEOVERSE_V1:
110+
expected_guest_minus_host = set()
91111
# KVM does not enable PAC or SVE features by default
92112
# and Firecracker does not enable them either.
93-
assert host_feats - guest_feats == {
113+
expected_host_minus_guest = {
94114
"paca",
95115
"pacg",
96116
"sve",
97117
"svebf16",
98118
"svei8mm",
99119
}
100-
# kernel should hide this feature, but our guest kernel
101-
# is not recent enough for this.
102-
assert guest_feats - host_feats == {"ssbs"}
120+
121+
# Upstream kernel v6.11+ hides "ssbs" from "lscpu" on Neoverse-N1 and Neoverse-V1 since
122+
# they have an errata whereby an MSR to the SSBS special-purpose register does not
123+
# affect subsequent speculative instructions, permitting speculative store bypassing for
124+
# a window of time.
125+
# https://github.com/torvalds/linux/commit/adeec61a4723fd3e39da68db4cc4d924e6d7f641
126+
#
127+
# While Amazon Linux kernels (v5.10 and v6.1) backported the above commit, our test
128+
# ubuntu kernel (v6.8) and our guest kernels (v5.10 and v6.1) don't pick it.
129+
host_has_ssbs = global_props.host_os not in {
130+
"amzn2",
131+
"amzn2023",
132+
} and global_props.host_linux_version_tpl < (6, 11)
133+
guest_has_ssbs = vm.guest_kernel_version < (6, 11)
134+
135+
if host_has_ssbs and not guest_has_ssbs:
136+
expected_host_minus_guest |= {"ssbs"}
137+
if not host_has_ssbs and guest_has_ssbs:
138+
expected_guest_minus_host |= {"ssbs"}
139+
140+
assert host_feats - guest_feats == expected_host_minus_guest
141+
assert guest_feats - host_feats == expected_guest_minus_host
103142
case _:
104143
if os.environ.get("BUILDKITE") is not None:
105144
assert False, f"Cpu model {cpu_model} is not supported"

0 commit comments

Comments
 (0)