arch/x86/virt/vmx/tdx/tdx.c
Source file repositories/reference/linux-study-clean/arch/x86/virt/vmx/tdx/tdx.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/virt/vmx/tdx/tdx.c- Extension
.c- Size
- 50207 bytes
- Lines
- 2035
- 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.
- 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
asm/page_types.hlinux/types.hlinux/cache.hlinux/init.hlinux/errno.hlinux/printk.hlinux/cpu.hlinux/spinlock.hlinux/percpu-defs.hlinux/mutex.hlinux/list.hlinux/memblock.hlinux/memory.hlinux/minmax.hlinux/sizes.hlinux/pfn.hlinux/align.hlinux/sort.hlinux/log2.hlinux/acpi.hlinux/suspend.hlinux/syscore_ops.hlinux/idr.hasm/page.hasm/special_insns.hasm/msr-index.hasm/msr.hasm/cpufeature.hasm/tdx.hasm/shared/tdx_errno.hasm/cpu_device_id.hasm/processor.h
Detected Declarations
struct tdx_module_statefunction try_init_module_globalfunction tdx_cpu_enablefunction tdx_online_cpufunction tdx_cpu_flush_cachefunction tdx_offline_cpufunction tdx_shutdown_cpufunction tdx_shutdownfunction tdx_suspendfunction tdx_resumefunction add_tdx_memblockfunction free_tdx_memlistfunction build_tdx_memlistfunction for_each_mem_pfn_rangefunction read_sys_metadata_fieldfunction check_featuresfunction tdmr_size_singlefunction alloc_tdmr_listfunction free_tdmr_listfunction tdmr_endfunction fill_out_tdmrsfunction regionfunction tdmr_get_pamt_szfunction tdmr_get_nidfunction tdmr_set_up_pamtfunction tdmr_get_pamtfunction tdmr_do_pamt_funcfunction free_pamtfunction tdmr_free_pamtfunction tdmrs_free_pamt_allfunction tdmrs_set_up_pamt_allfunction tdx_quirk_reset_paddrfunction tdmr_quirk_reset_pamtfunction tdmrs_quirk_reset_pamt_allfunction tdmrs_count_pamt_kbfunction tdmr_add_rsvd_areafunction tdmr_populate_rsvd_holesfunction tdmr_populate_rsvd_pamtsfunction rsvd_area_cmp_funcfunction tdmr_populate_rsvd_areasfunction holesfunction construct_tdmrsfunction config_tdx_modulefunction do_global_key_configfunction config_global_keyidfunction for_each_online_cpufunction init_tdmrfunction init_tdmrs
Annotated Snippet
subsys_initcall(tdx_enable);
int tdx_module_shutdown(void)
{
struct tdx_sys_info_handoff handoff = {};
struct tdx_module_args args = {};
int ret;
int cpu;
ret = get_tdx_sys_info_handoff(&handoff);
/*
* Handoff information is required for proper
* shutdown. Refuse to shut down without it.
*/
if (ret)
return ret;
/*
* Use the module's handoff version as it is the highest the
* module can produce and most likely supported by newer modules.
*/
args.rcx = handoff.module_hv;
ret = seamcall_prerr(TDH_SYS_SHUTDOWN, &args);
if (ret)
return ret;
/*
* Clear global and per-CPU initialization flags so the new module
* can be fully re-initialized after a successful update.
*
* No locks needed as no concurrent accesses can occur here.
*/
memset(&tdx_module_state, 0, sizeof(tdx_module_state));
for_each_possible_cpu(cpu)
per_cpu(tdx_lp_initialized, cpu) = false;
return 0;
}
int tdx_module_run_update(void)
{
struct tdx_module_args args = {};
int ret;
ret = seamcall_prerr(TDH_SYS_UPDATE, &args);
if (ret)
return ret;
ret = get_tdx_sys_info_version(&tdx_sysinfo.version);
/*
* Only fails if there is something unexpected
* and severely wrong with the module.
*/
WARN_ON_ONCE(ret);
tdx_module_state.initialized = true;
return 0;
}
static bool is_pamt_page(unsigned long phys)
{
struct tdmr_info_list *tdmr_list = &tdx_tdmr_list;
int i;
/* Ensure that all remote 'tdmr_list' writes are visible: */
smp_rmb();
/*
* The TDX module is no longer returning TDX_SYS_NOT_READY and
* is initialized. The 'tdmr_list' was initialized long ago
* and is now read-only.
*/
for (i = 0; i < tdmr_list->nr_consumed_tdmrs; i++) {
unsigned long base, size;
tdmr_get_pamt(tdmr_entry(tdmr_list, i), &base, &size);
if (phys >= base && phys < (base + size))
return true;
}
return false;
}
/*
* Return whether the memory page at the given physical address is TDX
* private memory or not.
*
* This can be imprecise for two known reasons:
Annotation
- Immediate include surface: `asm/page_types.h`, `linux/types.h`, `linux/cache.h`, `linux/init.h`, `linux/errno.h`, `linux/printk.h`, `linux/cpu.h`, `linux/spinlock.h`.
- Detected declarations: `struct tdx_module_state`, `function try_init_module_global`, `function tdx_cpu_enable`, `function tdx_online_cpu`, `function tdx_cpu_flush_cache`, `function tdx_offline_cpu`, `function tdx_shutdown_cpu`, `function tdx_shutdown`, `function tdx_suspend`, `function tdx_resume`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: integration implementation candidate.
- 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.