arch/x86/mm/mem_encrypt_amd.c
Source file repositories/reference/linux-study-clean/arch/x86/mm/mem_encrypt_amd.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/mm/mem_encrypt_amd.c- Extension
.c- Size
- 15269 bytes
- Lines
- 570
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/linkage.hlinux/init.hlinux/mm.hlinux/dma-direct.hlinux/swiotlb.hlinux/mem_encrypt.hlinux/device.hlinux/kernel.hlinux/bitops.hlinux/dma-mapping.hlinux/cc_platform.hasm/tlbflush.hasm/fixmap.hasm/setup.hasm/mem_encrypt.hasm/bootparam.hasm/set_memory.hasm/cacheflush.hasm/processor-flags.hasm/msr.hasm/cmdline.hasm/sev.hasm/ia32.hmm_internal.h
Detected Declarations
function snp_memcpyfunction pagefunction sme_early_encryptfunction sme_early_decryptfunction __sme_early_map_unmap_memfunction sme_unmap_bootdatafunction sme_map_bootdatafunction pg_level_to_pfnfunction amd_enc_tlb_flush_requiredfunction amd_enc_cache_flush_requiredfunction enc_dec_hypercallfunction amd_enc_status_change_preparefunction amd_enc_status_change_finishfunction prepare_pte_encfunction set_pte_enc_maskfunction __set_clr_pte_encfunction early_set_memory_enc_decfunction early_set_memory_decryptedfunction early_set_memory_encryptedfunction early_set_mem_enc_dec_hypercallfunction sme_early_initfunction mem_encrypt_free_decrypted_memfunction sme_postprocess_startupexport sme_me_mask
Annotated Snippet
if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) {
snp_memcpy(sme_early_buffer, src, len, paddr, enc);
snp_memcpy(dst, sme_early_buffer, len, paddr, !enc);
} else {
memcpy(sme_early_buffer, src, len);
memcpy(dst, sme_early_buffer, len);
}
early_memunmap(dst, len);
early_memunmap(src, len);
paddr += len;
size -= len;
}
}
void __init sme_early_encrypt(resource_size_t paddr, unsigned long size)
{
__sme_early_enc_dec(paddr, size, true);
}
void __init sme_early_decrypt(resource_size_t paddr, unsigned long size)
{
__sme_early_enc_dec(paddr, size, false);
}
static void __init __sme_early_map_unmap_mem(void *vaddr, unsigned long size,
bool map)
{
unsigned long paddr = (unsigned long)vaddr - __PAGE_OFFSET;
pmdval_t pmd_flags, pmd;
/* Use early_pmd_flags but remove the encryption mask */
pmd_flags = __sme_clr(early_pmd_flags);
do {
pmd = map ? (paddr & PMD_MASK) + pmd_flags : 0;
__early_make_pgtable((unsigned long)vaddr, pmd);
vaddr += PMD_SIZE;
paddr += PMD_SIZE;
size = (size <= PMD_SIZE) ? 0 : size - PMD_SIZE;
} while (size);
flush_tlb_local();
}
void __init sme_unmap_bootdata(char *real_mode_data)
{
struct boot_params *boot_data;
unsigned long cmdline_paddr;
if (!cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
return;
/* Get the command line address before unmapping the real_mode_data */
boot_data = (struct boot_params *)real_mode_data;
cmdline_paddr = boot_data->hdr.cmd_line_ptr | ((u64)boot_data->ext_cmd_line_ptr << 32);
__sme_early_map_unmap_mem(real_mode_data, sizeof(boot_params), false);
if (!cmdline_paddr)
return;
__sme_early_map_unmap_mem(__va(cmdline_paddr), COMMAND_LINE_SIZE, false);
}
void __init sme_map_bootdata(char *real_mode_data)
{
struct boot_params *boot_data;
unsigned long cmdline_paddr;
if (!cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
return;
__sme_early_map_unmap_mem(real_mode_data, sizeof(boot_params), true);
/* Get the command line address after mapping the real_mode_data */
boot_data = (struct boot_params *)real_mode_data;
cmdline_paddr = boot_data->hdr.cmd_line_ptr | ((u64)boot_data->ext_cmd_line_ptr << 32);
if (!cmdline_paddr)
return;
__sme_early_map_unmap_mem(__va(cmdline_paddr), COMMAND_LINE_SIZE, true);
}
static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot)
{
unsigned long pfn = 0;
Annotation
- Immediate include surface: `linux/linkage.h`, `linux/init.h`, `linux/mm.h`, `linux/dma-direct.h`, `linux/swiotlb.h`, `linux/mem_encrypt.h`, `linux/device.h`, `linux/kernel.h`.
- Detected declarations: `function snp_memcpy`, `function page`, `function sme_early_encrypt`, `function sme_early_decrypt`, `function __sme_early_map_unmap_mem`, `function sme_unmap_bootdata`, `function sme_map_bootdata`, `function pg_level_to_pfn`, `function amd_enc_tlb_flush_required`, `function amd_enc_cache_flush_required`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: integration 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.