Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <[email protected]>
*/

#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
5 changes: 4 additions & 1 deletion arch/x86/kvm/svm/sev.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ static struct page **sev_pin_memory(struct kvm *kvm, unsigned long uaddr,
unsigned long locked, lock_limit;
struct page **pages;
unsigned long first, last;
unsigned int flags = 0;
int ret;

lockdep_assert_held(&kvm->lock);
Expand Down Expand Up @@ -442,8 +443,10 @@ static struct page **sev_pin_memory(struct kvm *kvm, unsigned long uaddr,
if (!pages)
return ERR_PTR(-ENOMEM);

flags = write ? FOLL_WRITE : 0;

/* Pin the user virtual address. */
npinned = pin_user_pages_fast(uaddr, npages, write ? FOLL_WRITE : 0, pages);
npinned = pin_user_pages_fast(uaddr, npages, flags | FOLL_LONGTERM, pages);
if (npinned != npages) {
pr_err("SEV: Failure locking %lu pages.\n", npages);
ret = -ENOMEM;
Expand Down
Loading