mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2026-08-09 06:14:34 +02:00
Use u64 instead of uint64_t to make the KVM selftests code more concise and more similar to the kernel (since selftests are primarily developed by kernel developers). This commit was generated with the following command: git ls-files tools/testing/selftests/kvm | xargs sed -i 's/uint64_t/u64/g' Then by manually adjusting whitespace to make checkpatch.pl happy. Include <linux/types.h> in include/kvm_util_types.h, iinclude/test_util.h, and include/x86/pmu.h to pick up the tools-defined u64. Arguably, all headers (especially kvm_util_types.h) should have already been including stdint.h to get uint64_t from the libc headers, but the missing dependency only rears its head once KVM uses u64 instead of uint64_t. No functional change intended. Signed-off-by: David Matlack <dmatlack@google.com> [sean: rename pread_uint64() => pread_u64, expand on types.h include] Link: https://patch.msgid.link/20260420212004.3938325-5-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
72 lines
1.6 KiB
C
72 lines
1.6 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
/*
|
|
* Copyright (C) 2020, Red Hat, Inc.
|
|
*/
|
|
|
|
#ifndef SELFTEST_KVM_SVM_UTILS_H
|
|
#define SELFTEST_KVM_SVM_UTILS_H
|
|
|
|
#include <asm/svm.h>
|
|
|
|
#include <stdint.h>
|
|
#include "svm.h"
|
|
#include "processor.h"
|
|
|
|
struct svm_test_data {
|
|
/* VMCB */
|
|
struct vmcb *vmcb; /* gva */
|
|
void *vmcb_hva;
|
|
u64 vmcb_gpa;
|
|
|
|
/* host state-save area */
|
|
struct vmcb_save_area *save_area; /* gva */
|
|
void *save_area_hva;
|
|
u64 save_area_gpa;
|
|
|
|
/* MSR-Bitmap */
|
|
void *msr; /* gva */
|
|
void *msr_hva;
|
|
u64 msr_gpa;
|
|
|
|
/* NPT */
|
|
u64 ncr3_gpa;
|
|
};
|
|
|
|
static inline void vmmcall(void)
|
|
{
|
|
/*
|
|
* Stuff RAX and RCX with "safe" values to make sure L0 doesn't handle
|
|
* it as a valid hypercall (e.g. Hyper-V L2 TLB flush) as the intended
|
|
* use of this function is to exit to L1 from L2. Clobber all other
|
|
* GPRs as L1 doesn't correctly preserve them during vmexits.
|
|
*/
|
|
__asm__ __volatile__("push %%rbp; vmmcall; pop %%rbp"
|
|
: : "a"(0xdeadbeef), "c"(0xbeefdead)
|
|
: "rbx", "rdx", "rsi", "rdi", "r8", "r9",
|
|
"r10", "r11", "r12", "r13", "r14", "r15");
|
|
}
|
|
|
|
#define stgi() \
|
|
__asm__ __volatile__( \
|
|
"stgi\n" \
|
|
)
|
|
|
|
#define clgi() \
|
|
__asm__ __volatile__( \
|
|
"clgi\n" \
|
|
)
|
|
|
|
struct svm_test_data *vcpu_alloc_svm(struct kvm_vm *vm, gva_t *p_svm_gva);
|
|
void generic_svm_setup(struct svm_test_data *svm, void *guest_rip, void *guest_rsp);
|
|
void run_guest(struct vmcb *vmcb, u64 vmcb_gpa);
|
|
|
|
static inline bool kvm_cpu_has_npt(void)
|
|
{
|
|
return kvm_cpu_has(X86_FEATURE_NPT);
|
|
}
|
|
void vm_enable_npt(struct kvm_vm *vm);
|
|
|
|
int open_sev_dev_path_or_exit(void);
|
|
|
|
#endif /* SELFTEST_KVM_SVM_UTILS_H */
|