tools/testing/selftests/riscv/hwprobe/cbo.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/riscv/hwprobe/cbo.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/riscv/hwprobe/cbo.c- Extension
.c- Size
- 9550 bytes
- Lines
- 378
- 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
stdbool.hstdint.hstring.hsched.hsignal.hassert.hlinux/compiler.hlinux/kernel.hasm/ucontext.hgetopt.hhwprobe.hkselftest.h
Detected Declarations
function fault_handlerfunction cbo_invalfunction cbo_cleanfunction cbo_flushfunction cbo_zerofunction prefetch_ifunction prefetch_rfunction prefetch_wfunction test_no_cbo_invalfunction test_no_zicbomfunction test_no_zicbozfunction is_power_of_2function test_zicbopfunction test_zicbomfunction test_zicbozfunction check_no_zicbo_cpusfunction main
Annotated Snippet
static void cbo_inval(char *base) { cbo_insn(base, 0); }
static void cbo_clean(char *base) { cbo_insn(base, 1); }
static void cbo_flush(char *base) { cbo_insn(base, 2); }
static void cbo_zero(char *base) { cbo_insn(base, 4); }
static void prefetch_i(char *base) { prefetch_insn(base, 0); }
static void prefetch_r(char *base) { prefetch_insn(base, 1); }
static void prefetch_w(char *base) { prefetch_insn(base, 3); }
static void test_no_cbo_inval(void *arg)
{
ksft_print_msg("Testing cbo.inval instruction remain privileged\n");
got_fault = false;
cbo_inval(&mem[0]);
ksft_test_result(got_fault, "No cbo.inval\n");
}
static void test_no_zicbom(void *arg)
{
ksft_print_msg("Testing Zicbom instructions remain privileged\n");
got_fault = false;
cbo_clean(&mem[0]);
ksft_test_result(got_fault, "No cbo.clean\n");
got_fault = false;
cbo_flush(&mem[0]);
ksft_test_result(got_fault, "No cbo.flush\n");
}
static void test_no_zicboz(void *arg)
{
ksft_print_msg("No Zicboz, testing cbo.zero remains privileged\n");
got_fault = false;
cbo_zero(&mem[0]);
ksft_test_result(got_fault, "No cbo.zero\n");
}
static bool is_power_of_2(__u64 n)
{
return n != 0 && (n & (n - 1)) == 0;
}
static void test_zicbop(void *arg)
{
struct riscv_hwprobe pair = {
.key = RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE,
};
struct sigaction act = {
.sa_sigaction = &fault_handler,
.sa_flags = SA_SIGINFO
};
struct sigaction dfl = {
.sa_handler = SIG_DFL
};
cpu_set_t *cpus = (cpu_set_t *)arg;
__u64 block_size;
long rc;
rc = sigaction(SIGSEGV, &act, NULL);
assert(rc == 0);
rc = sigaction(SIGBUS, &act, NULL);
assert(rc == 0);
rc = riscv_hwprobe(&pair, 1, sizeof(cpu_set_t), (unsigned long *)cpus, 0);
block_size = pair.value;
ksft_test_result(rc == 0 && pair.key == RISCV_HWPROBE_KEY_ZICBOP_BLOCK_SIZE &&
is_power_of_2(block_size), "Zicbop block size\n");
ksft_print_msg("Zicbop block size: %llu\n", block_size);
got_fault = false;
prefetch_i(&mem[0]);
prefetch_r(&mem[0]);
prefetch_w(&mem[0]);
ksft_test_result(!got_fault, "Zicbop prefetch.* on valid address\n");
got_fault = false;
prefetch_i(NULL);
prefetch_r(NULL);
prefetch_w(NULL);
ksft_test_result(!got_fault, "Zicbop prefetch.* on NULL\n");
rc = sigaction(SIGBUS, &dfl, NULL);
assert(rc == 0);
rc = sigaction(SIGSEGV, &dfl, NULL);
assert(rc == 0);
}
static void test_zicbom(void *arg)
{
Annotation
- Immediate include surface: `stdbool.h`, `stdint.h`, `string.h`, `sched.h`, `signal.h`, `assert.h`, `linux/compiler.h`, `linux/kernel.h`.
- Detected declarations: `function fault_handler`, `function cbo_inval`, `function cbo_clean`, `function cbo_flush`, `function cbo_zero`, `function prefetch_i`, `function prefetch_r`, `function prefetch_w`, `function test_no_cbo_inval`, `function test_no_zicbom`.
- 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.