Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/powerpc: Return skip code for spectre_v2

When running under older versions of qemu of under newer versions with
old machine types, some security features will not be reported to the
guest. This will lead the guest OS to consider itself Vulnerable to
spectre_v2.

So, spectre_v2 test fails in such cases when the host is mitigated and
miss predictions cannot be detected as expected by the test.

Make it return the skip code instead, for this particular case. We
don't want to miss the case when the test fails and the system reports
as mitigated or not affected. But it is not a problem to miss failures
when the system reports as Vulnerable.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200728155039.401445-1-cascardo@canonical.com

authored by

Thadeu Lima de Souza Cascardo and committed by
Michael Ellerman
f3054ffd b859c95c

+10
+10
tools/testing/selftests/powerpc/security/spectre_v2.c
··· 183 183 if (miss_percent > 15) { 184 184 printf("Branch misses > 15%% unexpected in this configuration!\n"); 185 185 printf("Possible mis-match between reported & actual mitigation\n"); 186 + /* 187 + * Such a mismatch may be caused by a guest system 188 + * reporting as vulnerable when the host is mitigated. 189 + * Return skip code to avoid detecting this as an error. 190 + * We are not vulnerable and reporting otherwise, so 191 + * missing such a mismatch is safe. 192 + */ 193 + if (state == VULNERABLE) 194 + return 4; 195 + 186 196 return 1; 187 197 } 188 198 break;