arch/x86/coco/tdx/tdx-shared.c
Source file repositories/reference/linux-study-clean/arch/x86/coco/tdx/tdx-shared.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/coco/tdx/tdx-shared.c- Extension
.c- Size
- 2170 bytes
- Lines
- 92
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: implementation source
- Status
- source 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 or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/tdx.hasm/pgtable.h
Detected Declarations
function try_accept_onefunction tdx_accept_memoryfunction __tdx_hypercall
Annotated Snippet
#include <asm/tdx.h>
#include <asm/pgtable.h>
static unsigned long try_accept_one(phys_addr_t start, unsigned long len,
enum pg_level pg_level)
{
unsigned long accept_size = page_level_size(pg_level);
struct tdx_module_args args = {};
u8 page_size;
if (!IS_ALIGNED(start, accept_size))
return 0;
if (len < accept_size)
return 0;
/*
* Pass the page physical address to the TDX module to accept the
* pending, private page.
*
* Bits 2:0 of RCX encode page size: 0 - 4K, 1 - 2M, 2 - 1G.
*/
switch (pg_level) {
case PG_LEVEL_4K:
page_size = TDX_PS_4K;
break;
case PG_LEVEL_2M:
page_size = TDX_PS_2M;
break;
case PG_LEVEL_1G:
page_size = TDX_PS_1G;
break;
default:
return 0;
}
args.rcx = start | page_size;
if (__tdcall(TDG_MEM_PAGE_ACCEPT, &args))
return 0;
return accept_size;
}
bool tdx_accept_memory(phys_addr_t start, phys_addr_t end)
{
/*
* For shared->private conversion, accept the page using
* TDG_MEM_PAGE_ACCEPT TDX module call.
*/
while (start < end) {
unsigned long len = end - start;
unsigned long accept_size;
/*
* Try larger accepts first. It gives chance to VMM to keep
* 1G/2M Secure EPT entries where possible and speeds up
* process by cutting number of hypercalls (if successful).
*/
accept_size = try_accept_one(start, len, PG_LEVEL_1G);
if (!accept_size)
accept_size = try_accept_one(start, len, PG_LEVEL_2M);
if (!accept_size)
accept_size = try_accept_one(start, len, PG_LEVEL_4K);
if (!accept_size)
return false;
start += accept_size;
}
return true;
}
noinstr u64 __tdx_hypercall(struct tdx_module_args *args)
{
/*
* For TDVMCALL explicitly set RCX to the bitmap of shared registers.
* The caller isn't expected to set @args->rcx anyway.
*/
args->rcx = TDVMCALL_EXPOSE_REGS_MASK;
/*
* Failure of __tdcall_saved_ret() indicates a failure of the TDVMCALL
* mechanism itself and that something has gone horribly wrong with
* the TDX module. __tdx_hypercall_failed() never returns.
*/
if (__tdcall_saved_ret(TDG_VP_VMCALL, args))
__tdx_hypercall_failed();
/* TDVMCALL leaf return code is in R10 */
return args->r10;
Annotation
- Immediate include surface: `asm/tdx.h`, `asm/pgtable.h`.
- Detected declarations: `function try_accept_one`, `function tdx_accept_memory`, `function __tdx_hypercall`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source implementation candidate.
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.