arch/x86/coco/tdx/tdx.c
Source file repositories/reference/linux-study-clean/arch/x86/coco/tdx/tdx.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/coco/tdx/tdx.c- Extension
.c- Size
- 32295 bytes
- Lines
- 1198
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cpufeature.hlinux/export.hlinux/io.hlinux/kexec.hasm/coco.hasm/tdx.hasm/vmx.hasm/ia32.hasm/insn.hasm/insn-eval.hasm/cpuid/api.hasm/paravirt_types.hasm/pgtable.hasm/set_memory.hasm/traps.h
Detected Declarations
function __tdx_hypercall_failedfunction tdx_kvm_hypercallfunction tdcallfunction tdg_vm_rdfunction tdg_vm_wrfunction tdx_mcall_get_report0function tdx_mcall_extend_rtmrfunction tdx_hcall_get_quotefunction tdx_panicfunction disable_sept_vefunction enable_cpu_topology_enumerationfunction reduce_unnecessary_vefunction tdx_setupfunction ve_instr_lenfunction __haltfunction handle_haltfunction tdx_haltfunction tdx_safe_haltfunction read_msrfunction write_msrfunction handle_cpuidfunction mmio_readfunction mmio_writefunction handle_mmiofunction handle_infunction handle_outfunction handle_iofunction tdx_early_handle_vefunction tdx_get_ve_infofunction virt_exception_userfunction is_private_gpafunction virt_exception_kernelfunction tdx_handle_virt_exceptionfunction tdx_tlb_flush_requiredfunction tdx_cache_flush_requiredfunction tdx_map_gpafunction tdx_enc_status_changedfunction tdx_enc_status_change_preparefunction tdx_enc_status_change_finishfunction tdx_kexec_beginfunction tdx_kexec_finishfunction tdx_enc_status_changedfunction tdx_announcefunction tdx_early_initexport tdx_kvm_hypercallexport tdx_mcall_get_report0export tdx_mcall_extend_rtmrexport tdx_hcall_get_quote
Annotated Snippet
if (map_fail_paddr == start) {
retry_count++;
continue;
}
start = map_fail_paddr;
retry_count = 0;
}
return false;
}
/*
* Inform the VMM of the guest's intent for this physical page: shared with
* the VMM or private to the guest. The VMM is expected to change its mapping
* of the page in response.
*/
static bool tdx_enc_status_changed(unsigned long vaddr, int numpages, bool enc)
{
phys_addr_t start = __pa(vaddr);
phys_addr_t end = __pa(vaddr + numpages * PAGE_SIZE);
if (!tdx_map_gpa(start, end, enc))
return false;
/* shared->private conversion requires memory to be accepted before use */
if (enc)
return tdx_accept_memory(start, end);
return true;
}
static int tdx_enc_status_change_prepare(unsigned long vaddr, int numpages,
bool enc)
{
/*
* Only handle shared->private conversion here.
* See the comment in tdx_early_init().
*/
if (enc && !tdx_enc_status_changed(vaddr, numpages, enc))
return -EIO;
return 0;
}
static int tdx_enc_status_change_finish(unsigned long vaddr, int numpages,
bool enc)
{
/*
* Only handle private->shared conversion here.
* See the comment in tdx_early_init().
*/
if (!enc && !tdx_enc_status_changed(vaddr, numpages, enc))
return -EIO;
if (enc)
atomic_long_sub(numpages, &nr_shared);
else
atomic_long_add(numpages, &nr_shared);
return 0;
}
/* Stop new private<->shared conversions */
static void tdx_kexec_begin(void)
{
if (!IS_ENABLED(CONFIG_KEXEC_CORE))
return;
/*
* Crash kernel reaches here with interrupts disabled: can't wait for
* conversions to finish.
*
* If race happened, just report and proceed.
*/
if (!set_memory_enc_stop_conversion())
pr_warn("Failed to stop shared<->private conversions\n");
}
/* Walk direct mapping and convert all shared memory back to private */
static void tdx_kexec_finish(void)
{
unsigned long addr, end;
long found = 0, shared;
if (!IS_ENABLED(CONFIG_KEXEC_CORE))
return;
lockdep_assert_irqs_disabled();
Annotation
- Immediate include surface: `linux/cpufeature.h`, `linux/export.h`, `linux/io.h`, `linux/kexec.h`, `asm/coco.h`, `asm/tdx.h`, `asm/vmx.h`, `asm/ia32.h`.
- Detected declarations: `function __tdx_hypercall_failed`, `function tdx_kvm_hypercall`, `function tdcall`, `function tdg_vm_rd`, `function tdg_vm_wr`, `function tdx_mcall_get_report0`, `function tdx_mcall_extend_rtmr`, `function tdx_hcall_get_quote`, `function tdx_panic`, `function disable_sept_ve`.
- 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.