tools/testing/selftests/arm64/mte/check_hugetlb_options.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/arm64/mte/check_hugetlb_options.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/arm64/mte/check_hugetlb_options.c- Extension
.c- Size
- 8931 bytes
- Lines
- 297
- 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.
Dependency Surface
errno.hfcntl.hsignal.hstdio.hstdlib.hstring.hucontext.hsys/mman.hsys/stat.hsys/types.hsys/wait.hkselftest.hmte_common_util.hmte_def.h
Detected Declarations
function default_huge_page_sizefunction is_hugetlb_allocatedfunction write_sysfsfunction allocate_hugetlbfunction free_hugetlbfunction check_child_tag_inheritancefunction check_mte_memoryfunction check_hugetlb_memory_mappingfunction check_clear_prot_mte_flagfunction check_child_hugetlb_memory_mappingfunction main
Annotated Snippet
if (sscanf(line, "Hugepagesize: %lu kB", &hps) == 1) {
hps <<= 10;
break;
}
}
free(line);
fclose(f);
return hps;
}
static bool is_hugetlb_allocated(void)
{
unsigned long hps = 0;
char *line = NULL;
size_t linelen = 0;
FILE *f = fopen("/proc/meminfo", "r");
if (!f)
return false;
while (getline(&line, &linelen, f) > 0) {
if (sscanf(line, "Hugetlb: %lu kB", &hps) == 1) {
hps <<= 10;
break;
}
}
free(line);
fclose(f);
if (hps > 0)
return true;
return false;
}
static void write_sysfs(char *str, unsigned long val)
{
FILE *f;
f = fopen(str, "w");
if (!f) {
ksft_print_msg("ERR: missing %s\n", str);
return;
}
fprintf(f, "%lu", val);
fclose(f);
}
static void allocate_hugetlb()
{
write_sysfs("/proc/sys/vm/nr_hugepages", 2);
}
static void free_hugetlb()
{
write_sysfs("/proc/sys/vm/nr_hugepages", 0);
}
static int check_child_tag_inheritance(char *ptr, int size, int mode)
{
int i, parent_tag, child_tag, fault, child_status;
pid_t child;
parent_tag = MT_FETCH_TAG((uintptr_t)ptr);
fault = 0;
child = fork();
if (child == -1) {
ksft_print_msg("FAIL: child process creation\n");
return KSFT_FAIL;
} else if (child == 0) {
mte_initialize_current_context(mode, (uintptr_t)ptr, size);
/* Do copy on write */
memset(ptr, '1', size);
mte_wait_after_trig();
if (cur_mte_cxt.fault_valid == true) {
fault = 1;
goto check_child_tag_inheritance_err;
}
for (i = 0; i < size; i += MT_GRANULE_SIZE) {
child_tag = MT_FETCH_TAG((uintptr_t)(mte_get_tag_address(ptr + i)));
if (parent_tag != child_tag) {
ksft_print_msg("FAIL: child mte tag (%d) mismatch\n", i);
fault = 1;
goto check_child_tag_inheritance_err;
}
}
check_child_tag_inheritance_err:
_exit(fault);
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `signal.h`, `stdio.h`, `stdlib.h`, `string.h`, `ucontext.h`, `sys/mman.h`.
- Detected declarations: `function default_huge_page_size`, `function is_hugetlb_allocated`, `function write_sysfs`, `function allocate_hugetlb`, `function free_hugetlb`, `function check_child_tag_inheritance`, `function check_mte_memory`, `function check_hugetlb_memory_mapping`, `function check_clear_prot_mte_flag`, `function check_child_hugetlb_memory_mapping`.
- 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.