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.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sys/types.hstdint.hmalloc.hunistd.hstdlib.hstring.hstdio.hsys/prctl.hutils.h../pmu/event.h
Detected Declarations
enum spectre_v2_statefunction do_count_loopfunction setup_eventfunction get_sysfs_statefunction spectre_v2_testfunction main
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
- Immediate include surface: `sys/types.h`, `stdint.h`, `malloc.h`, `unistd.h`, `stdlib.h`, `string.h`, `stdio.h`, `sys/prctl.h`.
- Detected declarations: `enum spectre_v2_state`, `function do_count_loop`, `function setup_event`, `function get_sysfs_state`, `function spectre_v2_test`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.