tools/testing/selftests/x86/lam.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/x86/lam.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/x86/lam.c- Extension
.c- Size
- 29285 bytes
- Lines
- 1372
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.hstring.hsys/syscall.hsys/ioctl.htime.hsignal.hsetjmp.hsys/mman.hsys/utsname.hsys/wait.hsys/stat.hfcntl.hinttypes.hsched.hsys/uio.hlinux/io_uring.hkselftest.h
Detected Declarations
struct testcasesstruct file_iostruct io_uring_queuestruct io_ringfunction segv_handlerfunction lam_is_availablefunction la57_enabledfunction set_lamfunction get_default_tag_bitsfunction get_lamfunction set_metadatafunction handle_lam_testfunction handle_max_bitsfunction handle_mallocfunction handle_mmapfunction handle_syscallfunction get_user_syscallfunction sys_uring_setupfunction sys_uring_enterfunction mmap_io_uringfunction setup_io_uringfunction handle_uring_cqfunction handle_uring_sqfunction do_uringfunction handle_uringfunction fork_testfunction handle_execvefunction handle_inheritancefunction thread_fn_get_lamfunction thread_fn_set_lamfunction handle_threadfunction handle_thread_enablefunction run_testfunction cmd_helpfunction file_Existsfunction pasid_enabledfunction Dsa_Init_Sysfsfunction set_force_svmfunction handle_pasidfunction main
Annotated Snippet
struct testcases {
unsigned int later;
int expected; /* 2: SIGSEGV Error; 1: other errors */
unsigned long lam;
uint64_t addr;
uint64_t cmd;
int (*test_func)(struct testcases *test);
const char *msg;
};
/* Used by CQ of uring, source file handler and file's size */
struct file_io {
int file_fd;
off_t file_sz;
struct iovec iovecs[];
};
struct io_uring_queue {
unsigned int *head;
unsigned int *tail;
unsigned int *ring_mask;
unsigned int *ring_entries;
unsigned int *flags;
unsigned int *array;
union {
struct io_uring_cqe *cqes;
struct io_uring_sqe *sqes;
} queue;
size_t ring_sz;
};
struct io_ring {
int ring_fd;
struct io_uring_queue sq_ring;
struct io_uring_queue cq_ring;
};
int tests_cnt;
jmp_buf segv_env;
static void segv_handler(int sig)
{
ksft_print_msg("Get segmentation fault(%d).", sig);
siglongjmp(segv_env, 1);
}
static inline int lam_is_available(void)
{
unsigned int cpuinfo[4];
unsigned long bits = 0;
int ret;
__cpuid_count(0x7, 1, cpuinfo[0], cpuinfo[1], cpuinfo[2], cpuinfo[3]);
/* Check if cpu supports LAM */
if (!(cpuinfo[0] & (1 << 26))) {
ksft_print_msg("LAM is not supported!\n");
return 0;
}
/* Return 0 if CONFIG_ADDRESS_MASKING is not set */
ret = syscall(SYS_arch_prctl, ARCH_GET_MAX_TAG_BITS, &bits);
if (ret) {
ksft_print_msg("LAM is disabled in the kernel!\n");
return 0;
}
return 1;
}
static inline int la57_enabled(void)
{
int ret;
void *p;
p = mmap((void *)HIGH_ADDR, PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
ret = p == MAP_FAILED ? 0 : 1;
munmap(p, PAGE_SIZE);
return ret;
}
/*
* Set tagged address and read back untag mask.
* check if the untagged mask is expected.
*
* @return:
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `string.h`, `sys/syscall.h`, `sys/ioctl.h`, `time.h`, `signal.h`, `setjmp.h`.
- Detected declarations: `struct testcases`, `struct file_io`, `struct io_uring_queue`, `struct io_ring`, `function segv_handler`, `function lam_is_available`, `function la57_enabled`, `function set_lam`, `function get_default_tag_bits`, `function get_lam`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.