tools/testing/selftests/powerpc/security/spectre_v2.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/security/spectre_v2.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/powerpc/security/spectre_v2.c
Extension
.c
Size
6214 bytes
Lines
236
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (miss_percent > 15) {
			if (miss_percent > 95) {
				/*
				 * Such a mismatch may be caused by a system being unaware
				 * the count cache is disabled. This may be to enable
				 * guest migration between hosts with different settings.
				 * Return skip code to avoid detecting this as an error.
				 * We are not vulnerable and reporting otherwise, so
				 * missing such a mismatch is safe.
				 */
				printf("Branch misses > 95%% unexpected in this configuration.\n");
				printf("Count cache likely disabled without Linux knowing.\n");
				if (state == COUNT_CACHE_FLUSH_SW)
					printf("WARNING: Kernel performing unnecessary flushes.\n");
				return 4;
			}
			printf("Branch misses > 15%% unexpected in this configuration!\n");
			printf("Possible mismatch between reported & actual mitigation\n");

			return 1;
		}
		break;
	case BRANCH_SERIALISATION:
		// This seems to affect userspace branch prediction a bit?
		if (miss_percent > 25) {
			printf("Branch misses > 25%% unexpected in this configuration!\n");
			printf("Possible mismatch between reported & actual mitigation\n");
			return 1;
		}
		break;
	case COUNT_CACHE_DISABLED:
		if (miss_percent < 95) {
			printf("Branch misses < 95%% unexpected in this configuration!\n");
			printf("Possible mismatch between reported & actual mitigation\n");
			return 1;
		}
		break;
	case UNKNOWN:
	case BTB_FLUSH:
		printf("Not sure!\n");
		return 1;
	}

	printf("OK - Measured branch prediction rates match reported spectre v2 mitigation.\n");

	return 0;
}

int main(int argc, char *argv[])
{
	return test_harness(spectre_v2_test, "spectre_v2");
}

Annotation

Implementation Notes