arch/x86/kernel/fpu/xstate.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/fpu/xstate.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/fpu/xstate.c- Extension
.c- Size
- 56765 bytes
- Lines
- 2012
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitops.hlinux/compat.hlinux/cpu.hlinux/mman.hlinux/kvm_types.hlinux/nospec.hlinux/pkeys.hlinux/seq_file.hlinux/proc_fs.hlinux/vmalloc.hlinux/coredump.hlinux/sort.hasm/fpu/api.hasm/fpu/regset.hasm/fpu/signal.hasm/fpu/xcr.hasm/cpuid/api.hasm/msr.hasm/tlbflush.hasm/prctl.hasm/elf.huapi/asm/elf.hcontext.hinternal.hlegacy.hxstate.h
Detected Declarations
function next_xfeature_orderfunction thefunction xfeature_is_aligned64function xfeature_is_supervisorfunction xfeature_get_offsetfunction fpu__init_cpu_xstatefunction xfeature_enabledfunction compare_xstate_offsetsfunction setup_xstate_cachefunction for_each_extended_xfeaturefunction print_xstate_featuresfunction print_xstate_offset_sizefunction for_each_extended_xfeaturefunction os_xrstor_bootingfunction setup_init_fpufunction xfeature_sizefunction validate_user_xstate_headerfunction __xstate_dump_leavesfunction check_xtile_data_against_structfunction check_xstate_against_structfunction xstate_calculate_sizefunction paranoid_xstate_size_validfunction for_each_extended_xfeaturefunction get_compacted_sizefunction get_xsave_compacted_sizefunction get_xsave_size_userfunction init_xstate_sizefunction fpu__init_disable_system_xstatefunction host_default_maskfunction guest_default_maskfunction fpu__init_system_xstatefunction fpu__resume_cpufunction arch_set_user_pkey_accessfunction copy_featurefunction __copy_xstate_to_uabi_buffunction for_each_extended_xfeature_in_orderfunction copy_xstate_to_uabi_buffunction copy_from_bufferfunction valuefunction copy_uabi_from_kernel_to_xstatefunction sigreturnfunction validate_independent_componentsfunction xsavesfunction xsavesfunction fpstate_clear_xstate_componentfunction xstate_op_validfunction xfd_validate_statefunction xfd_update_static_branch
Annotated Snippet
if (tile_size != sizeof(struct xtile_data)) {
pr_err("%s: struct is %zu bytes, cpu xtile %d bytes\n",
__stringify(XFEATURE_XTILE_DATA),
sizeof(struct xtile_data), tile_size);
__xstate_dump_leaves();
return -EINVAL;
}
if (max > max_tile)
max_tile = max;
}
state_size = sizeof(struct xtile_data) * max_tile;
if (size != state_size) {
pr_err("%s: calculated size is %u bytes, cpu state %d bytes\n",
__stringify(XFEATURE_XTILE_DATA), state_size, size);
__xstate_dump_leaves();
return -EINVAL;
}
return 0;
}
/*
* We have a C struct for each 'xstate'. We need to ensure
* that our software representation matches what the CPU
* tells us about the state's size.
*/
static bool __init check_xstate_against_struct(int nr)
{
/*
* Ask the CPU for the size of the state.
*/
int sz = xfeature_size(nr);
/*
* Match each CPU state with the corresponding software
* structure.
*/
switch (nr) {
case XFEATURE_YMM: return XCHECK_SZ(sz, nr, struct ymmh_struct);
case XFEATURE_BNDREGS: return XCHECK_SZ(sz, nr, struct mpx_bndreg_state);
case XFEATURE_BNDCSR: return XCHECK_SZ(sz, nr, struct mpx_bndcsr_state);
case XFEATURE_OPMASK: return XCHECK_SZ(sz, nr, struct avx_512_opmask_state);
case XFEATURE_ZMM_Hi256: return XCHECK_SZ(sz, nr, struct avx_512_zmm_uppers_state);
case XFEATURE_Hi16_ZMM: return XCHECK_SZ(sz, nr, struct avx_512_hi16_state);
case XFEATURE_PKRU: return XCHECK_SZ(sz, nr, struct pkru_state);
case XFEATURE_PASID: return XCHECK_SZ(sz, nr, struct ia32_pasid_state);
case XFEATURE_XTILE_CFG: return XCHECK_SZ(sz, nr, struct xtile_cfg);
case XFEATURE_CET_USER: return XCHECK_SZ(sz, nr, struct cet_user_state);
case XFEATURE_CET_KERNEL: return XCHECK_SZ(sz, nr, struct cet_supervisor_state);
case XFEATURE_APX: return XCHECK_SZ(sz, nr, struct apx_state);
case XFEATURE_XTILE_DATA: check_xtile_data_against_struct(sz); return true;
default:
XSTATE_WARN_ON(1, "No structure for xstate: %d\n", nr);
return false;
}
return true;
}
static unsigned int xstate_calculate_size(u64 xfeatures, bool compacted)
{
unsigned int topmost = fls64(xfeatures) - 1;
unsigned int offset, i;
if (topmost <= XFEATURE_SSE)
return sizeof(struct xregs_state);
if (compacted) {
offset = xfeature_get_offset(xfeatures, topmost);
} else {
/* Walk through the xfeature order to pick the last */
for_each_extended_xfeature_in_order(i, xfeatures)
topmost = xfeature_uncompact_order[i];
offset = xstate_offsets[topmost];
}
return offset + xstate_sizes[topmost];
}
/*
* This essentially double-checks what the cpu told us about
* how large the XSAVE buffer needs to be. We are recalculating
* it to be safe.
*
* Independent XSAVE features allocate their own buffers and are not
* covered by these checks. Only the size of the buffer for task->fpu
* is checked here.
*/
static bool __init paranoid_xstate_size_valid(unsigned int kernel_size)
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/compat.h`, `linux/cpu.h`, `linux/mman.h`, `linux/kvm_types.h`, `linux/nospec.h`, `linux/pkeys.h`, `linux/seq_file.h`.
- Detected declarations: `function next_xfeature_order`, `function the`, `function xfeature_is_aligned64`, `function xfeature_is_supervisor`, `function xfeature_get_offset`, `function fpu__init_cpu_xstate`, `function xfeature_enabled`, `function compare_xstate_offsets`, `function setup_xstate_cache`, `function for_each_extended_xfeature`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.