Skip to content

Commit

Permalink
x86/mm: Manage CSV3 guest's private memory by CMA
Browse files Browse the repository at this point in the history
hygon inclusion
category: feature
CVE: NA

---------------------------

The private memory of a CSV3 guest is isolated from VMM and has to be
physically contiguous. CMA (Contiguous Memory Allocator) is a memory
allocator within the kernel for contiguous physical memory.

Use the CMA for the CSV3 private memory management. In order to
support CSV3, select MMU and CMA when CONIFG_HYGON_CSV is
configured.

Signed-off-by: Xin Jiang <jiangxin@hygon.cn>
Signed-off-by: hanliyang <hanliyang@hygon.cn>
  • Loading branch information
Xin Jiang authored and Avenger-285714 committed Aug 19, 2024
1 parent c26f93e commit 207ab26
Show file tree
Hide file tree
Showing 7 changed files with 461 additions and 4 deletions.
2 changes: 2 additions & 0 deletions arch/x86/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2020,6 +2020,8 @@ config HYGON_CSV
bool "Hygon secure virtualization CSV support"
default y
depends on CPU_SUP_HYGON && AMD_MEM_ENCRYPT
select MMU
select CMA
help
Hygon CSV integrates secure processor, memory encryption and
memory isolation to provide the ability to protect guest's private
Expand Down
53 changes: 53 additions & 0 deletions arch/x86/include/asm/csv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Hygon China Secure Virtualization (CSV)
*
* Copyright (C) Hygon Info Technologies Ltd.
*
* Author: Jiang Xin <jiangxin@hygon.cn>
*/

#ifndef __ASM_X86_CSV_H__
#define __ASM_X86_CSV_H__

#ifndef __ASSEMBLY__

#ifdef CONFIG_HYGON_CSV

struct csv_mem {
uint64_t start;
uint64_t size;
};

#define CSV_MR_ALIGN_BITS (28)

extern struct csv_mem *csv_smr;
extern unsigned int csv_smr_num;

void __init early_csv_reserve_mem(void);

phys_addr_t csv_alloc_from_contiguous(size_t size, nodemask_t *nodes_allowed,
unsigned int align);
void csv_release_to_contiguous(phys_addr_t pa, size_t size);

uint32_t csv_get_smr_entry_shift(void);

#else /* !CONFIG_HYGON_CSV */

#define csv_smr NULL
#define csv_smr_num 0U

static inline void __init early_csv_reserve_mem(void) { }

static inline phys_addr_t
csv_alloc_from_contiguous(size_t size, nodemask_t *nodes_allowed,
unsigned int align) { return 0; }
static inline void csv_release_to_contiguous(phys_addr_t pa, size_t size) { }

static inline uint32_t csv_get_smr_entry_shift(void) { return 0; }

#endif /* CONFIG_HYGON_CSV */

#endif /* __ASSEMBLY__ */

#endif /* __ASM_X86_CSV_H__ */
5 changes: 5 additions & 0 deletions arch/x86/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include <asm/unwind.h>
#include <asm/vsyscall.h>
#include <linux/vmalloc.h>
#include <asm/csv.h>

/*
* max_low_pfn_mapped: highest directly mapped pfn < 4 GB
Expand Down Expand Up @@ -1219,6 +1220,10 @@ void __init setup_arch(char **cmdline_p)
early_acpi_boot_init();

initmem_init();

/* Try to reserve contiguous memory to support CSV3 */
early_csv_reserve_mem();

dma_contiguous_reserve(max_pfn_mapped << PAGE_SHIFT);

if (boot_cpu_has(X86_FEATURE_GBPAGES))
Expand Down
Loading

0 comments on commit 207ab26

Please sign in to comment.