// SPDX-License-Identifier: GPL-2.0-only /* * Helpers used for nested SVM testing * Largely inspired from KVM unit test svm.c * * Copyright (C) 2020, Red Hat, Inc.
*/
/* Allocate memory regions for nested SVM tests. * * Input Args: * vm - The VM to allocate guest-virtual addresses in. * * Output Args: * p_svm_gva - The guest virtual address for the struct svm_test_data. * * Return: * Pointer to structure with the addresses of the SVM areas.
*/ struct svm_test_data *
vcpu_alloc_svm(struct kvm_vm *vm, vm_vaddr_t *p_svm_gva)
{
vm_vaddr_t svm_gva = vm_vaddr_alloc_page(vm); struct svm_test_data *svm = addr_gva2hva(vm, svm_gva);
/* * selftests do not use interrupts so we dropped clgi/sti/cli/stgi * for now. registers involved in LOAD/SAVE_GPR_C are eventually * unmodified so they do not need to be in the clobber list.
*/ void run_guest(struct vmcb *vmcb, uint64_t vmcb_gpa)
{ asmvolatile ( "vmload %[vmcb_gpa]\n\t" "mov rflags, %%r15\n\t"// rflags "mov %%r15, 0x170(%[vmcb])\n\t" "mov guest_regs, %%r15\n\t"// rax "mov %%r15, 0x1f8(%[vmcb])\n\t"
LOAD_GPR_C "vmrun %[vmcb_gpa]\n\t"
SAVE_GPR_C "mov 0x170(%[vmcb]), %%r15\n\t"// rflags "mov %%r15, rflags\n\t" "mov 0x1f8(%[vmcb]), %%r15\n\t"// rax "mov %%r15, guest_regs\n\t" "vmsave %[vmcb_gpa]\n\t"
: : [vmcb] "r" (vmcb), [vmcb_gpa] "a" (vmcb_gpa)
: "r15", "memory");
}
/* * Open SEV_DEV_PATH if available, otherwise exit the entire program. * * Return: * The opened file descriptor of /dev/sev.
*/ int open_sev_dev_path_or_exit(void)
{ return open_path_or_exit(SEV_DEV_PATH, 0);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.