linux/arch/x86/kvm/x86.h

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef ARCH_X86_KVM_X86_H
#define ARCH_X86_KVM_X86_H

#include <linux/kvm_host.h>
#include <asm/fpu/xstate.h>
#include <asm/mce.h>
#include <asm/pvclock.h>
#include "kvm_cache_regs.h"
#include "kvm_emulate.h"

struct kvm_caps {};

struct kvm_host_values {};

void kvm_spurious_fault(void);

#define KVM_NESTED_VMENTER_CONSISTENCY_CHECK(consistency_check)

/*
 * The first...last VMX feature MSRs that are emulated by KVM.  This may or may
 * not cover all known VMX MSRs, as KVM doesn't emulate an MSR until there's an
 * associated feature that KVM supports for nested virtualization.
 */
#define KVM_FIRST_EMULATED_VMX_MSR
#define KVM_LAST_EMULATED_VMX_MSR

#define KVM_DEFAULT_PLE_GAP
#define KVM_VMX_DEFAULT_PLE_WINDOW
#define KVM_DEFAULT_PLE_WINDOW_GROW
#define KVM_DEFAULT_PLE_WINDOW_SHRINK
#define KVM_VMX_DEFAULT_PLE_WINDOW_MAX
#define KVM_SVM_DEFAULT_PLE_WINDOW_MAX
#define KVM_SVM_DEFAULT_PLE_WINDOW

static inline unsigned int __grow_ple_window(unsigned int val,
		unsigned int base, unsigned int modifier, unsigned int max)
{}

static inline unsigned int __shrink_ple_window(unsigned int val,
		unsigned int base, unsigned int modifier, unsigned int min)
{}

#define MSR_IA32_CR_PAT_DEFAULT

void kvm_service_local_tlb_flush_requests(struct kvm_vcpu *vcpu);
int kvm_check_nested_events(struct kvm_vcpu *vcpu);

/* Forcibly leave the nested mode in cases like a vCPU reset */
static inline void kvm_leave_nested(struct kvm_vcpu *vcpu)
{}

static inline bool kvm_vcpu_has_run(struct kvm_vcpu *vcpu)
{}

static inline bool kvm_is_exception_pending(struct kvm_vcpu *vcpu)
{}

static inline void kvm_clear_exception_queue(struct kvm_vcpu *vcpu)
{}

static inline void kvm_queue_interrupt(struct kvm_vcpu *vcpu, u8 vector,
	bool soft)
{}

static inline void kvm_clear_interrupt_queue(struct kvm_vcpu *vcpu)
{}

static inline bool kvm_event_needs_reinjection(struct kvm_vcpu *vcpu)
{}

static inline bool kvm_exception_is_soft(unsigned int nr)
{}

static inline bool is_protmode(struct kvm_vcpu *vcpu)
{}

static inline bool is_long_mode(struct kvm_vcpu *vcpu)
{}

static inline bool is_64_bit_mode(struct kvm_vcpu *vcpu)
{}

static inline bool is_64_bit_hypercall(struct kvm_vcpu *vcpu)
{}

static inline bool x86_exception_has_error_code(unsigned int vector)
{}

static inline bool mmu_is_nested(struct kvm_vcpu *vcpu)
{}

static inline bool is_pae(struct kvm_vcpu *vcpu)
{}

static inline bool is_pse(struct kvm_vcpu *vcpu)
{}

static inline bool is_paging(struct kvm_vcpu *vcpu)
{}

static inline bool is_pae_paging(struct kvm_vcpu *vcpu)
{}

static inline u8 vcpu_virt_addr_bits(struct kvm_vcpu *vcpu)
{}

static inline bool is_noncanonical_address(u64 la, struct kvm_vcpu *vcpu)
{}

static inline void vcpu_cache_mmio_info(struct kvm_vcpu *vcpu,
					gva_t gva, gfn_t gfn, unsigned access)
{}

static inline bool vcpu_match_mmio_gen(struct kvm_vcpu *vcpu)
{}

/*
 * Clear the mmio cache info for the given gva. If gva is MMIO_GVA_ANY, we
 * clear all mmio cache info.
 */
#define MMIO_GVA_ANY

static inline void vcpu_clear_mmio_info(struct kvm_vcpu *vcpu, gva_t gva)
{}

static inline bool vcpu_match_mmio_gva(struct kvm_vcpu *vcpu, unsigned long gva)
{}

static inline bool vcpu_match_mmio_gpa(struct kvm_vcpu *vcpu, gpa_t gpa)
{}

static inline unsigned long kvm_register_read(struct kvm_vcpu *vcpu, int reg)
{}

static inline void kvm_register_write(struct kvm_vcpu *vcpu,
				       int reg, unsigned long val)
{}

static inline bool kvm_check_has_quirk(struct kvm *kvm, u64 quirk)
{}

void kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip);

u64 get_kvmclock_ns(struct kvm *kvm);
uint64_t kvm_get_wall_clock_epoch(struct kvm *kvm);
bool kvm_get_monotonic_and_clockread(s64 *kernel_ns, u64 *tsc_timestamp);

int kvm_read_guest_virt(struct kvm_vcpu *vcpu,
	gva_t addr, void *val, unsigned int bytes,
	struct x86_exception *exception);

int kvm_write_guest_virt_system(struct kvm_vcpu *vcpu,
	gva_t addr, void *val, unsigned int bytes,
	struct x86_exception *exception);

int handle_ud(struct kvm_vcpu *vcpu);

void kvm_deliver_exception_payload(struct kvm_vcpu *vcpu,
				   struct kvm_queued_exception *ex);

int kvm_mtrr_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data);
int kvm_mtrr_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata);
bool kvm_vector_hashing_enabled(void);
void kvm_fixup_and_inject_pf_error(struct kvm_vcpu *vcpu, gva_t gva, u16 error_code);
int x86_decode_emulated_instruction(struct kvm_vcpu *vcpu, int emulation_type,
				    void *insn, int insn_len);
int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
			    int emulation_type, void *insn, int insn_len);
fastpath_t handle_fastpath_set_msr_irqoff(struct kvm_vcpu *vcpu);
fastpath_t handle_fastpath_hlt(struct kvm_vcpu *vcpu);

extern struct kvm_caps kvm_caps;
extern struct kvm_host_values kvm_host;

extern bool enable_pmu;

/*
 * Get a filtered version of KVM's supported XCR0 that strips out dynamic
 * features for which the current process doesn't (yet) have permission to use.
 * This is intended to be used only when enumerating support to userspace,
 * e.g. in KVM_GET_SUPPORTED_CPUID and KVM_CAP_XSAVE2, it does NOT need to be
 * used to check/restrict guest behavior as KVM rejects KVM_SET_CPUID{2} if
 * userspace attempts to enable unpermitted features.
 */
static inline u64 kvm_get_filtered_xcr0(void)
{}

static inline bool kvm_mpx_supported(void)
{}

extern unsigned int min_timer_period_us;

extern bool enable_vmware_backdoor;

extern int pi_inject_timer;

extern bool report_ignored_msrs;

extern bool eager_page_split;

static inline void kvm_pr_unimpl_wrmsr(struct kvm_vcpu *vcpu, u32 msr, u64 data)
{}

static inline void kvm_pr_unimpl_rdmsr(struct kvm_vcpu *vcpu, u32 msr)
{}

static inline u64 nsec_to_cycles(struct kvm_vcpu *vcpu, u64 nsec)
{}

/* Same "calling convention" as do_div:
 * - divide (n << 32) by base
 * - put result in n
 * - return remainder
 */
#define do_shl32_div32(n, base)

static inline bool kvm_mwait_in_guest(struct kvm *kvm)
{}

static inline bool kvm_hlt_in_guest(struct kvm *kvm)
{}

static inline bool kvm_pause_in_guest(struct kvm *kvm)
{}

static inline bool kvm_cstate_in_guest(struct kvm *kvm)
{}

static inline bool kvm_notify_vmexit_enabled(struct kvm *kvm)
{}

static __always_inline void kvm_before_interrupt(struct kvm_vcpu *vcpu,
						 enum kvm_intr_type intr)
{}

static __always_inline void kvm_after_interrupt(struct kvm_vcpu *vcpu)
{}

static inline bool kvm_handling_nmi_from_guest(struct kvm_vcpu *vcpu)
{}

static inline bool kvm_pat_valid(u64 data)
{}

static inline bool kvm_dr7_valid(u64 data)
{}
static inline bool kvm_dr6_valid(u64 data)
{}

/*
 * Trigger machine check on the host. We assume all the MSRs are already set up
 * by the CPU and that we still run on the same CPU as the MCE occurred on.
 * We pass a fake environment to the machine check handler because we want
 * the guest to be always treated like user space, no matter what context
 * it used internally.
 */
static inline void kvm_machine_check(void)
{}

void kvm_load_guest_xsave_state(struct kvm_vcpu *vcpu);
void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu);
int kvm_spec_ctrl_test_value(u64 value);
bool __kvm_is_valid_cr4(struct kvm_vcpu *vcpu, unsigned long cr4);
int kvm_handle_memory_failure(struct kvm_vcpu *vcpu, int r,
			      struct x86_exception *e);
int kvm_handle_invpcid(struct kvm_vcpu *vcpu, unsigned long type, gva_t gva);
bool kvm_msr_allowed(struct kvm_vcpu *vcpu, u32 index, u32 type);

enum kvm_msr_access {};

/*
 * Internal error codes that are used to indicate that MSR emulation encountered
 * an error that should result in #GP in the guest, unless userspace handles it.
 * Note, '1', '0', and negative numbers are off limits, as they are used by KVM
 * as part of KVM's lightly documented internal KVM_RUN return codes.
 *
 * UNSUPPORTED	- The MSR isn't supported, either because it is completely
 *		  unknown to KVM, or because the MSR should not exist according
 *		  to the vCPU model.
 *
 * FILTERED	- Access to the MSR is denied by a userspace MSR filter.
 */
#define KVM_MSR_RET_UNSUPPORTED
#define KVM_MSR_RET_FILTERED

#define __cr4_reserved_bits(__cpu_has, __c)

int kvm_sev_es_mmio_write(struct kvm_vcpu *vcpu, gpa_t src, unsigned int bytes,
			  void *dst);
int kvm_sev_es_mmio_read(struct kvm_vcpu *vcpu, gpa_t src, unsigned int bytes,
			 void *dst);
int kvm_sev_es_string_io(struct kvm_vcpu *vcpu, unsigned int size,
			 unsigned int port, void *data,  unsigned int count,
			 int in);

#endif