arch/x86/kernel/tboot.c
Source file repositories/reference/linux-study-clean/arch/x86/kernel/tboot.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kernel/tboot.c- Extension
.c- Size
- 12836 bytes
- Lines
- 517
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/init_task.hlinux/spinlock.hlinux/export.hlinux/delay.hlinux/sched.hlinux/init.hlinux/dmar.hlinux/cpu.hlinux/pfn.hlinux/mm.hlinux/tboot.hlinux/debugfs.hasm/realmode.hasm/processor.hasm/bootparam.hasm/pgalloc.hasm/fixmap.hasm/proto.hasm/setup.hasm/e820/api.hasm/io.h../realmode/rm/wakeup.h
Detected Declarations
struct sha1_hashstruct sinit_mle_datafunction tboot_enabledfunction check_tboot_versionfunction tboot_probefunction set_fixmapfunction switch_to_tboot_ptfunction map_tboot_pagefunction map_tboot_pagesfunction tboot_create_trampolinefunction add_mac_regionfunction tboot_setup_sleepfunction tboot_setup_sleepfunction tboot_shutdownfunction tboot_copy_fadtfunction tboot_sleepfunction tboot_extended_sleepfunction tboot_wait_for_apsfunction tboot_dying_cpufunction tboot_log_readfunction tboot_late_init
Annotated Snippet
static const struct file_operations tboot_log_fops = {
.read = tboot_log_read,
.llseek = default_llseek,
};
#endif /* CONFIG_DEBUG_FS */
static __init int tboot_late_init(void)
{
if (!tboot_enabled())
return 0;
tboot_create_trampoline();
atomic_set(&ap_wfs_count, 0);
cpuhp_setup_state(CPUHP_AP_X86_TBOOT_DYING, "x86/tboot:dying", NULL,
tboot_dying_cpu);
#ifdef CONFIG_DEBUG_FS
debugfs_create_file("tboot_log", S_IRUSR,
arch_debugfs_dir, NULL, &tboot_log_fops);
#endif
acpi_os_set_prepare_sleep(&tboot_sleep);
acpi_os_set_prepare_extended_sleep(&tboot_extended_sleep);
return 0;
}
late_initcall(tboot_late_init);
/*
* TXT configuration registers (offsets from TXT_{PUB, PRIV}_CONFIG_REGS_BASE)
*/
#define TXT_PUB_CONFIG_REGS_BASE 0xfed30000
#define TXT_PRIV_CONFIG_REGS_BASE 0xfed20000
/* # pages for each config regs space - used by fixmap */
#define NR_TXT_CONFIG_PAGES ((TXT_PUB_CONFIG_REGS_BASE - \
TXT_PRIV_CONFIG_REGS_BASE) >> PAGE_SHIFT)
/* offsets from pub/priv config space */
#define TXTCR_HEAP_BASE 0x0300
#define TXTCR_HEAP_SIZE 0x0308
#define SHA1_SIZE 20
struct sha1_hash {
u8 hash[SHA1_SIZE];
};
struct sinit_mle_data {
u32 version; /* currently 6 */
struct sha1_hash bios_acm_id;
u32 edx_senter_flags;
u64 mseg_valid;
struct sha1_hash sinit_hash;
struct sha1_hash mle_hash;
struct sha1_hash stm_hash;
struct sha1_hash lcp_policy_hash;
u32 lcp_policy_control;
u32 rlp_wakeup_addr;
u32 reserved;
u32 num_mdrs;
u32 mdrs_off;
u32 num_vtd_dmars;
u32 vtd_dmars_off;
} __packed;
struct acpi_table_header *tboot_get_dmar_table(struct acpi_table_header *dmar_tbl)
{
void *heap_base, *heap_ptr, *config;
if (!tboot_enabled())
return dmar_tbl;
/*
* ACPI tables may not be DMA protected by tboot, so use DMAR copy
* SINIT saved in SinitMleData in TXT heap (which is DMA protected)
*/
/* map config space in order to get heap addr */
config = ioremap(TXT_PUB_CONFIG_REGS_BASE, NR_TXT_CONFIG_PAGES *
PAGE_SIZE);
if (!config)
return NULL;
/* now map TXT heap */
heap_base = ioremap(*(u64 *)(config + TXTCR_HEAP_BASE),
*(u64 *)(config + TXTCR_HEAP_SIZE));
iounmap(config);
Annotation
- Immediate include surface: `linux/init_task.h`, `linux/spinlock.h`, `linux/export.h`, `linux/delay.h`, `linux/sched.h`, `linux/init.h`, `linux/dmar.h`, `linux/cpu.h`.
- Detected declarations: `struct sha1_hash`, `struct sinit_mle_data`, `function tboot_enabled`, `function check_tboot_version`, `function tboot_probe`, `function set_fixmap`, `function switch_to_tboot_pt`, `function map_tboot_page`, `function map_tboot_pages`, `function tboot_create_trampoline`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: pattern 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.