linux/arch/x86/mm/mem_encrypt_amd.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * AMD Memory Encryption Support
 *
 * Copyright (C) 2016-2024 Advanced Micro Devices, Inc.
 *
 * Author: Tom Lendacky <[email protected]>
 */

#define DISABLE_BRANCH_PROFILING

#include <linux/linkage.h>
#include <linux/init.h>
#include <linux/mm.h>
#include <linux/dma-direct.h>
#include <linux/swiotlb.h>
#include <linux/mem_encrypt.h>
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/bitops.h>
#include <linux/dma-mapping.h>
#include <linux/cc_platform.h>

#include <asm/tlbflush.h>
#include <asm/fixmap.h>
#include <asm/setup.h>
#include <asm/mem_encrypt.h>
#include <asm/bootparam.h>
#include <asm/set_memory.h>
#include <asm/cacheflush.h>
#include <asm/processor-flags.h>
#include <asm/msr.h>
#include <asm/cmdline.h>
#include <asm/sev.h>
#include <asm/ia32.h>

#include "mm_internal.h"

/*
 * Since SME related variables are set early in the boot process they must
 * reside in the .data section so as not to be zeroed out when the .bss
 * section is later cleared.
 */
u64 sme_me_mask __section(".data") =;
u64 sev_status __section(".data") =;
u64 sev_check_data __section(".data") =;
EXPORT_SYMBOL();

/* Buffer used for early in-place encryption by BSP, no locking needed */
static char sme_early_buffer[PAGE_SIZE] __initdata __aligned();

/*
 * SNP-specific routine which needs to additionally change the page state from
 * private to shared before copying the data from the source to destination and
 * restore after the copy.
 */
static inline void __init snp_memcpy(void *dst, void *src, size_t sz,
				     unsigned long paddr, bool decrypt)
{}

/*
 * This routine does not change the underlying encryption setting of the
 * page(s) that map this memory. It assumes that eventually the memory is
 * meant to be accessed as either encrypted or decrypted but the contents
 * are currently not in the desired state.
 *
 * This routine follows the steps outlined in the AMD64 Architecture
 * Programmer's Manual Volume 2, Section 7.10.8 Encrypt-in-Place.
 */
static void __init __sme_early_enc_dec(resource_size_t paddr,
				       unsigned long size, bool enc)
{}

void __init sme_early_encrypt(resource_size_t paddr, unsigned long size)
{}

void __init sme_early_decrypt(resource_size_t paddr, unsigned long size)
{}

static void __init __sme_early_map_unmap_mem(void *vaddr, unsigned long size,
					     bool map)
{}

void __init sme_unmap_bootdata(char *real_mode_data)
{}

void __init sme_map_bootdata(char *real_mode_data)
{}

static unsigned long pg_level_to_pfn(int level, pte_t *kpte, pgprot_t *ret_prot)
{}

static bool amd_enc_tlb_flush_required(bool enc)
{}

static bool amd_enc_cache_flush_required(void)
{}

static void enc_dec_hypercall(unsigned long vaddr, unsigned long size, bool enc)
{}

static int amd_enc_status_change_prepare(unsigned long vaddr, int npages, bool enc)
{}

/* Return true unconditionally: return value doesn't matter for the SEV side */
static int amd_enc_status_change_finish(unsigned long vaddr, int npages, bool enc)
{}

static void __init __set_clr_pte_enc(pte_t *kpte, int level, bool enc)
{}

static int __init early_set_memory_enc_dec(unsigned long vaddr,
					   unsigned long size, bool enc)
{}

int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size)
{}

int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size)
{}

void __init early_set_mem_enc_dec_hypercall(unsigned long vaddr, unsigned long size, bool enc)
{}

void __init sme_early_init(void)
{}

void __init mem_encrypt_free_decrypted_mem(void)
{}