tools/testing/selftests/arm64/mte/check_user_mem.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/arm64/mte/check_user_mem.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/arm64/mte/check_user_mem.c- Extension
.c- Size
- 5729 bytes
- Lines
- 244
- 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
assert.herrno.hfcntl.hsignal.hstdlib.hstdio.hstring.hucontext.hunistd.hsys/uio.hsys/mman.hkselftest.hmte_common_util.hmte_def.h
Detected Declarations
enum test_typefunction check_usermem_access_faultfunction format_test_namefunction main
Annotated Snippet
switch (test_type) {
case READ_TEST:
syscall_len = read(fd, ptr + ptroff, size);
break;
case WRITE_TEST:
syscall_len = write(fd, ptr + ptroff, size);
break;
case READV_TEST: {
struct iovec iov[1];
iov[0].iov_base = ptr + ptroff;
iov[0].iov_len = size;
syscall_len = readv(fd, iov, 1);
break;
}
case WRITEV_TEST: {
struct iovec iov[1];
iov[0].iov_base = ptr + ptroff;
iov[0].iov_len = size;
syscall_len = writev(fd, iov, 1);
break;
}
case LAST_TEST:
goto usermem_acc_err;
}
mte_wait_after_trig();
/*
* Accessing user memory in kernel with invalid tag should fail in sync
* mode without fault but may not fail in async mode as per the
* implemented MTE userspace support in Arm64 kernel.
*/
if (cur_mte_cxt.fault_valid) {
goto usermem_acc_err;
}
if (mode == MTE_SYNC_ERR && syscall_len < len) {
/* test passed */
} else if (mode == MTE_ASYNC_ERR && syscall_len == size) {
/* test passed */
} else {
goto usermem_acc_err;
}
}
}
}
goto exit;
usermem_acc_err:
err = KSFT_FAIL;
exit:
mte_free_memory((void *)ptr, len, mem_type, true);
close(fd);
return err;
}
void format_test_name(char* name, int name_len, int type, int sync, int map, int len, int offset) {
const char* test_type;
const char* mte_type;
const char* map_type;
switch (type) {
case READ_TEST:
test_type = "read";
break;
case WRITE_TEST:
test_type = "write";
break;
case READV_TEST:
test_type = "readv";
break;
case WRITEV_TEST:
test_type = "writev";
break;
default:
assert(0);
break;
}
switch (sync) {
case MTE_SYNC_ERR:
mte_type = "MTE_SYNC_ERR";
break;
case MTE_ASYNC_ERR:
mte_type = "MTE_ASYNC_ERR";
break;
default:
assert(0);
break;
}
Annotation
- Immediate include surface: `assert.h`, `errno.h`, `fcntl.h`, `signal.h`, `stdlib.h`, `stdio.h`, `string.h`, `ucontext.h`.
- Detected declarations: `enum test_type`, `function check_usermem_access_fault`, `function format_test_name`, `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.