22# SPDX-License-Identifier: Apache-2.0
33
44# pylint: disable=too-many-statements
5+ # pylint: disable=too-many-branches
56
67"""
78Check CPU features in the host vs the guest.
7071 "xtpr" ,
7172}
7273
74+ INTEL_GUEST_ONLY_FEATS = {
75+ "hypervisor" ,
76+ "tsc_known_freq" ,
77+ "umip" ,
78+ }
79+
80+ AMD_MILAN_HOST_ONLY_FEATS = {
81+ "amd_ppin" ,
82+ "aperfmperf" ,
83+ "bpext" ,
84+ "cat_l3" ,
85+ "cdp_l3" ,
86+ "cpb" ,
87+ "cqm" ,
88+ "cqm_llc" ,
89+ "cqm_mbm_local" ,
90+ "cqm_mbm_total" ,
91+ "cqm_occup_llc" ,
92+ "decodeassists" ,
93+ "extapic" ,
94+ "extd_apicid" ,
95+ "flushbyasid" ,
96+ "hw_pstate" ,
97+ "ibs" ,
98+ "irperf" ,
99+ "lbrv" ,
100+ "mba" ,
101+ "monitor" ,
102+ "mwaitx" ,
103+ "overflow_recov" ,
104+ "pausefilter" ,
105+ "perfctr_llc" ,
106+ "perfctr_nb" ,
107+ "pfthreshold" ,
108+ "rdpru" ,
109+ "rdt_a" ,
110+ "sev" ,
111+ "sev_es" ,
112+ "skinit" ,
113+ "smca" ,
114+ "sme" ,
115+ "succor" ,
116+ "svm_lock" ,
117+ "tce" ,
118+ "tsc_scale" ,
119+ "v_vmsave_vmload" ,
120+ "vgif" ,
121+ "vmcb_clean" ,
122+ "wdt" ,
123+ }
124+
125+ AMD_GUEST_ONLY_FEATS = {
126+ "hypervisor" ,
127+ "tsc_adjust" ,
128+ "tsc_deadline_timer" ,
129+ "tsc_known_freq" ,
130+ }
131+
132+ AMD_MILAN_HOST_ONLY_FEATS_6_1 = AMD_MILAN_HOST_ONLY_FEATS - {
133+ "lbrv" ,
134+ "pausefilter" ,
135+ "pfthreshold" ,
136+ "sme" ,
137+ "tsc_scale" ,
138+ "v_vmsave_vmload" ,
139+ "vgif" ,
140+ "vmcb_clean" ,
141+ } | {"brs" , "rapl" , "v_spec_ctrl" }
142+
143+ AMD_GENOA_HOST_ONLY_FEATS = AMD_MILAN_HOST_ONLY_FEATS | {
144+ "avic" ,
145+ "flush_l1d" ,
146+ "ibrs_enhanced" ,
147+ }
148+
149+ AMD_GENOA_HOST_ONLY_FEATS_6_1 = AMD_MILAN_HOST_ONLY_FEATS_6_1 - {"brs" } | {
150+ "avic" ,
151+ "amd_lbr_v2" ,
152+ "cppc" ,
153+ "flush_l1d" ,
154+ "ibrs_enhanced" ,
155+ "perfmon_v2" ,
156+ "x2avic" ,
157+ }
158+
73159
74160def test_host_vs_guest_cpu_features (uvm_nano ):
75161 """Check CPU features host vs guest"""
@@ -82,93 +168,28 @@ def test_host_vs_guest_cpu_features(uvm_nano):
82168
83169 match CPU_MODEL :
84170 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-
141171 if global_props .host_linux_version_tpl < (6 , 1 ):
142- assert host_feats - guest_feats == host_guest_diff_5_10
172+ assert host_feats - guest_feats == AMD_MILAN_HOST_ONLY_FEATS
143173 else :
144- assert host_feats - guest_feats == host_guest_diff_6_1
174+ assert host_feats - guest_feats == AMD_MILAN_HOST_ONLY_FEATS_6_1
145175
146- assert guest_feats - host_feats == {
147- "hypervisor" ,
148- "tsc_adjust" ,
149- "tsc_deadline_timer" ,
150- "tsc_known_freq" ,
151- }
176+ assert guest_feats - host_feats == AMD_GUEST_ONLY_FEATS
152177
153178 case CpuModel .AMD_GENOA :
154- # Return here to allow the test to pass until CPU features to enable are confirmed
155- return
179+ if global_props .host_linux_version_tpl < (6 , 1 ):
180+ assert host_feats - guest_feats == AMD_GENOA_HOST_ONLY_FEATS
181+ else :
182+ assert host_feats - guest_feats == AMD_GENOA_HOST_ONLY_FEATS_6_1
183+
184+ assert guest_feats - host_feats == AMD_GUEST_ONLY_FEATS
156185
157186 case CpuModel .INTEL_SKYLAKE :
158187 assert host_feats - guest_feats == INTEL_HOST_ONLY_FEATS
159- assert guest_feats - host_feats == {
160- "hypervisor" ,
161- "tsc_known_freq" ,
162- "umip" ,
163- }
188+ assert guest_feats - host_feats == INTEL_GUEST_ONLY_FEATS
164189
165190 case CpuModel .INTEL_CASCADELAKE :
166191 expected_host_minus_guest = INTEL_HOST_ONLY_FEATS
167- expected_guest_minus_host = {
168- "hypervisor" ,
169- "tsc_known_freq" ,
170- "umip" ,
171- }
192+ expected_guest_minus_host = INTEL_GUEST_ONLY_FEATS
172193
173194 # Linux kernel v6.4+ passes through the CPUID bit for "flush_l1d" to guests.
174195 # https://github.com/torvalds/linux/commit/45cf86f26148e549c5ba4a8ab32a390e4bde216e
@@ -208,11 +229,7 @@ def test_host_vs_guest_cpu_features(uvm_nano):
208229 assert host_feats - guest_feats == host_guest_diff_5_10
209230 else :
210231 assert host_feats - guest_feats == host_guest_diff_6_1
211-
212- assert guest_feats - host_feats == {
213- "hypervisor" ,
214- "tsc_known_freq" ,
215- }
232+ assert guest_feats - host_feats == INTEL_GUEST_ONLY_FEATS - {"umip" }
216233
217234 case CpuModel .ARM_NEOVERSE_N1 :
218235 expected_guest_minus_host = set ()
0 commit comments