cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

svm_util.h (1279B)


      1/* SPDX-License-Identifier: GPL-2.0-only */
      2/*
      3 * tools/testing/selftests/kvm/include/x86_64/svm_utils.h
      4 * Header for nested SVM testing
      5 *
      6 * Copyright (C) 2020, Red Hat, Inc.
      7 */
      8
      9#ifndef SELFTEST_KVM_SVM_UTILS_H
     10#define SELFTEST_KVM_SVM_UTILS_H
     11
     12#include <stdint.h>
     13#include "svm.h"
     14#include "processor.h"
     15
     16#define CPUID_SVM_BIT		2
     17#define CPUID_SVM		BIT_ULL(CPUID_SVM_BIT)
     18
     19#define SVM_EXIT_MSR		0x07c
     20#define SVM_EXIT_VMMCALL	0x081
     21
     22struct svm_test_data {
     23	/* VMCB */
     24	struct vmcb *vmcb; /* gva */
     25	void *vmcb_hva;
     26	uint64_t vmcb_gpa;
     27
     28	/* host state-save area */
     29	struct vmcb_save_area *save_area; /* gva */
     30	void *save_area_hva;
     31	uint64_t save_area_gpa;
     32
     33	/* MSR-Bitmap */
     34	void *msr; /* gva */
     35	void *msr_hva;
     36	uint64_t msr_gpa;
     37};
     38
     39struct svm_test_data *vcpu_alloc_svm(struct kvm_vm *vm, vm_vaddr_t *p_svm_gva);
     40void generic_svm_setup(struct svm_test_data *svm, void *guest_rip, void *guest_rsp);
     41void run_guest(struct vmcb *vmcb, uint64_t vmcb_gpa);
     42bool nested_svm_supported(void);
     43void nested_svm_check_supported(void);
     44
     45static inline bool cpu_has_svm(void)
     46{
     47	u32 eax = 0x80000001, ecx;
     48
     49	asm("cpuid" :
     50	    "=a" (eax), "=c" (ecx) : "0" (eax) : "ebx", "edx");
     51
     52	return ecx & CPUID_SVM;
     53}
     54
     55int open_sev_dev_path_or_exit(void);
     56
     57#endif /* SELFTEST_KVM_SVM_UTILS_H */