18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2020-2022 Loongson Technology Corporation Limited 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef __LOONGARCH_KVM_HOST_H__ 78c2ecf20Sopenharmony_ci#define __LOONGARCH_KVM_HOST_H__ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/cpumask.h> 108c2ecf20Sopenharmony_ci#include <linux/mutex.h> 118c2ecf20Sopenharmony_ci#include <linux/hrtimer.h> 128c2ecf20Sopenharmony_ci#include <linux/interrupt.h> 138c2ecf20Sopenharmony_ci#include <linux/types.h> 148c2ecf20Sopenharmony_ci#include <linux/kvm.h> 158c2ecf20Sopenharmony_ci#include <linux/kvm_types.h> 168c2ecf20Sopenharmony_ci#include <linux/threads.h> 178c2ecf20Sopenharmony_ci#include <linux/spinlock.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#include <asm/inst.h> 208c2ecf20Sopenharmony_ci#include <asm/loongarchregs.h> 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_ci#define __KVM_HAVE_ARCH_VCPU_DEBUGFS 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* Loongarch KVM register ids */ 258c2ecf20Sopenharmony_ci#define LOONGARCH_CSR_32(_R, _S) \ 268c2ecf20Sopenharmony_ci (KVM_REG_LOONGARCH_CSR | KVM_REG_SIZE_U32 | (8 * (_R) + (_S))) 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#define LOONGARCH_CSR_64(_R, _S) \ 298c2ecf20Sopenharmony_ci (KVM_REG_LOONGARCH_CSR | KVM_REG_SIZE_U64 | (8 * (_R) + (_S))) 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#define KVM_IOC_CSRID(id) LOONGARCH_CSR_64(id, 0) 328c2ecf20Sopenharmony_ci#define KVM_GET_IOC_CSRIDX(id) ((id & KVM_CSR_IDX_MASK) >> 3) 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define LOONGSON_VIRT_REG_BASE 0x1f000000 358c2ecf20Sopenharmony_ci#define KVM_MAX_VCPUS 256 368c2ecf20Sopenharmony_ci#define KVM_USER_MEM_SLOTS 256 378c2ecf20Sopenharmony_ci/* memory slots that does not exposed to userspace */ 388c2ecf20Sopenharmony_ci#define KVM_PRIVATE_MEM_SLOTS 0 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci#define KVM_HALT_POLL_NS_DEFAULT 500000 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define KVM_REQ_RECORD_STEAL KVM_ARCH_REQ(1) 438c2ecf20Sopenharmony_ci#define KVM_REQ_EVENT KVM_ARCH_REQ(4) 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define KVM_INVALID_ADDR 0xdeadbeef 468c2ecf20Sopenharmony_ci#define KVM_HVA_ERR_BAD (-1UL) 478c2ecf20Sopenharmony_ci#define KVM_HVA_ERR_RO_BAD (-2UL) 488c2ecf20Sopenharmony_cistatic inline bool kvm_is_error_hva(unsigned long addr) 498c2ecf20Sopenharmony_ci{ 508c2ecf20Sopenharmony_ci return IS_ERR_VALUE(addr); 518c2ecf20Sopenharmony_ci} 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_cistruct kvm_vm_stat { 548c2ecf20Sopenharmony_ci ulong remote_tlb_flush; 558c2ecf20Sopenharmony_ci u64 vm_ioctl_irq_line; 568c2ecf20Sopenharmony_ci u64 ls7a_ioapic_update; 578c2ecf20Sopenharmony_ci u64 ls7a_ioapic_set_irq; 588c2ecf20Sopenharmony_ci u64 ioapic_reg_write; 598c2ecf20Sopenharmony_ci u64 ioapic_reg_read; 608c2ecf20Sopenharmony_ci u64 set_ls7a_ioapic; 618c2ecf20Sopenharmony_ci u64 get_ls7a_ioapic; 628c2ecf20Sopenharmony_ci u64 set_ls3a_ext_irq; 638c2ecf20Sopenharmony_ci u64 get_ls3a_ext_irq; 648c2ecf20Sopenharmony_ci u64 trigger_ls3a_ext_irq; 658c2ecf20Sopenharmony_ci u64 pip_read_exits; 668c2ecf20Sopenharmony_ci u64 pip_write_exits; 678c2ecf20Sopenharmony_ci u64 ls7a_msi_irq; 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_cistruct kvm_vcpu_stat { 708c2ecf20Sopenharmony_ci u64 excep_exits[EXCCODE_INT_START]; 718c2ecf20Sopenharmony_ci u64 idle_exits; 728c2ecf20Sopenharmony_ci u64 signal_exits; 738c2ecf20Sopenharmony_ci u64 int_exits; 748c2ecf20Sopenharmony_ci u64 rdcsr_cpu_feature_exits; 758c2ecf20Sopenharmony_ci u64 rdcsr_misc_func_exits; 768c2ecf20Sopenharmony_ci u64 rdcsr_ipi_access_exits; 778c2ecf20Sopenharmony_ci u64 cpucfg_exits; 788c2ecf20Sopenharmony_ci u64 huge_dec_exits; 798c2ecf20Sopenharmony_ci u64 huge_thp_exits; 808c2ecf20Sopenharmony_ci u64 huge_adjust_exits; 818c2ecf20Sopenharmony_ci u64 huge_set_exits; 828c2ecf20Sopenharmony_ci u64 huge_merge_exits; 838c2ecf20Sopenharmony_ci u64 halt_successful_poll; 848c2ecf20Sopenharmony_ci u64 halt_attempted_poll; 858c2ecf20Sopenharmony_ci u64 halt_poll_success_ns; 868c2ecf20Sopenharmony_ci u64 halt_poll_fail_ns; 878c2ecf20Sopenharmony_ci u64 halt_poll_invalid; 888c2ecf20Sopenharmony_ci u64 halt_wakeup; 898c2ecf20Sopenharmony_ci}; 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci#define KVM_MEMSLOT_DISABLE_THP (1UL << 17) 928c2ecf20Sopenharmony_cistruct kvm_arch_memory_slot { 938c2ecf20Sopenharmony_ci unsigned int flags; 948c2ecf20Sopenharmony_ci}; 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cienum { 978c2ecf20Sopenharmony_ci IOCSR_FEATURES, 988c2ecf20Sopenharmony_ci IOCSR_VENDOR, 998c2ecf20Sopenharmony_ci IOCSR_CPUNAME, 1008c2ecf20Sopenharmony_ci IOCSR_NODECNT, 1018c2ecf20Sopenharmony_ci IOCSR_MISC_FUNC, 1028c2ecf20Sopenharmony_ci IOCSR_MAX 1038c2ecf20Sopenharmony_ci}; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_cistruct kvm_context { 1068c2ecf20Sopenharmony_ci unsigned long gid_mask; 1078c2ecf20Sopenharmony_ci unsigned long gid_ver_mask; 1088c2ecf20Sopenharmony_ci unsigned long gid_fisrt_ver; 1098c2ecf20Sopenharmony_ci unsigned long vpid_cache; 1108c2ecf20Sopenharmony_ci struct kvm_vcpu *last_vcpu; 1118c2ecf20Sopenharmony_ci}; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistruct kvm_arch { 1148c2ecf20Sopenharmony_ci /* Guest physical mm */ 1158c2ecf20Sopenharmony_ci struct mm_struct gpa_mm; 1168c2ecf20Sopenharmony_ci /* Mask of CPUs needing GPA ASID flush */ 1178c2ecf20Sopenharmony_ci cpumask_t asid_flush_mask; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci unsigned char online_vcpus; 1208c2ecf20Sopenharmony_ci unsigned char is_migrate; 1218c2ecf20Sopenharmony_ci s64 stablecounter_gftoffset; 1228c2ecf20Sopenharmony_ci u32 cpucfg_lasx; 1238c2ecf20Sopenharmony_ci struct ls7a_kvm_ioapic *v_ioapic; 1248c2ecf20Sopenharmony_ci struct ls3a_kvm_ipi *v_gipi; 1258c2ecf20Sopenharmony_ci struct ls3a_kvm_routerirq *v_routerirq; 1268c2ecf20Sopenharmony_ci struct ls3a_kvm_extirq *v_extirq; 1278c2ecf20Sopenharmony_ci spinlock_t iocsr_lock; 1288c2ecf20Sopenharmony_ci struct kvm_iocsr_entry iocsr[IOCSR_MAX]; 1298c2ecf20Sopenharmony_ci struct kvm_cpucfg cpucfgs; 1308c2ecf20Sopenharmony_ci struct kvm_context __percpu *vmcs; 1318c2ecf20Sopenharmony_ci}; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ci#define LOONGARCH_CSRS 0x100 1358c2ecf20Sopenharmony_ci#define CSR_UCWIN_BASE 0x100 1368c2ecf20Sopenharmony_ci#define CSR_UCWIN_SIZE 0x10 1378c2ecf20Sopenharmony_ci#define CSR_DMWIN_BASE 0x180 1388c2ecf20Sopenharmony_ci#define CSR_DMWIN_SIZE 0x4 1398c2ecf20Sopenharmony_ci#define CSR_PERF_BASE 0x200 1408c2ecf20Sopenharmony_ci#define CSR_PERF_SIZE 0x8 1418c2ecf20Sopenharmony_ci#define CSR_DEBUG_BASE 0x500 1428c2ecf20Sopenharmony_ci#define CSR_DEBUG_SIZE 0x3 1438c2ecf20Sopenharmony_ci#define CSR_ALL_SIZE 0x800 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_cistruct loongarch_csrs { 1468c2ecf20Sopenharmony_ci unsigned long csrs[CSR_ALL_SIZE]; 1478c2ecf20Sopenharmony_ci}; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci/* Resume Flags */ 1508c2ecf20Sopenharmony_ci#define RESUME_FLAG_DR (1<<0) /* Reload guest nonvolatile state? */ 1518c2ecf20Sopenharmony_ci#define RESUME_FLAG_HOST (1<<1) /* Resume host? */ 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci#define RESUME_GUEST 0 1548c2ecf20Sopenharmony_ci#define RESUME_GUEST_DR RESUME_FLAG_DR 1558c2ecf20Sopenharmony_ci#define RESUME_HOST RESUME_FLAG_HOST 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_cienum emulation_result { 1588c2ecf20Sopenharmony_ci EMULATE_DONE, /* no further processing */ 1598c2ecf20Sopenharmony_ci EMULATE_DO_MMIO, /* kvm_run filled with MMIO request */ 1608c2ecf20Sopenharmony_ci EMULATE_FAIL, /* can't emulate this instruction */ 1618c2ecf20Sopenharmony_ci EMULATE_WAIT, /* WAIT instruction */ 1628c2ecf20Sopenharmony_ci EMULATE_PRIV_FAIL, 1638c2ecf20Sopenharmony_ci EMULATE_EXCEPT, /* A guest exception has been generated */ 1648c2ecf20Sopenharmony_ci EMULATE_PV_HYPERCALL, /* HYPCALL instruction */ 1658c2ecf20Sopenharmony_ci EMULATE_DEBUG, /* Emulate guest kernel debug */ 1668c2ecf20Sopenharmony_ci EMULATE_DO_IOCSR, /* handle IOCSR request */ 1678c2ecf20Sopenharmony_ci}; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci#define KVM_LARCH_FPU (0x1 << 0) 1708c2ecf20Sopenharmony_ci#define KVM_LARCH_LSX (0x1 << 1) 1718c2ecf20Sopenharmony_ci#define KVM_LARCH_LASX (0x1 << 2) 1728c2ecf20Sopenharmony_ci#define KVM_LARCH_FP_ALL (KVM_LARCH_FPU | KVM_LARCH_LSX | KVM_LARCH_LASX) 1738c2ecf20Sopenharmony_ci#define KVM_LARCH_DATA_HWBP (0x1 << 3) 1748c2ecf20Sopenharmony_ci#define KVM_LARCH_INST_HWBP (0x1 << 4) 1758c2ecf20Sopenharmony_ci#define KVM_LARCH_HWBP (KVM_LARCH_DATA_HWBP | KVM_LARCH_INST_HWBP) 1768c2ecf20Sopenharmony_ci#define KVM_LARCH_RESET (0x1 << 5) 1778c2ecf20Sopenharmony_ci#define KVM_LARCH_PERF (0x1 << 6) 1788c2ecf20Sopenharmony_ci#define KVM_LARCH_LBT (0x1 << 7) 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_cistruct kvm_vcpu_arch { 1818c2ecf20Sopenharmony_ci unsigned long guest_eentry; 1828c2ecf20Sopenharmony_ci unsigned long host_eentry; 1838c2ecf20Sopenharmony_ci int (*vcpu_run)(struct kvm_run *run, struct kvm_vcpu *vcpu); 1848c2ecf20Sopenharmony_ci int (*handle_exit)(struct kvm_run *run, struct kvm_vcpu *vcpu); 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci /* Host registers preserved across guest mode execution */ 1878c2ecf20Sopenharmony_ci unsigned long host_stack; 1888c2ecf20Sopenharmony_ci unsigned long host_gp; 1898c2ecf20Sopenharmony_ci unsigned long host_pgd; 1908c2ecf20Sopenharmony_ci unsigned long host_pgdhi; 1918c2ecf20Sopenharmony_ci unsigned long host_entryhi; 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci /* Host CSR registers used when handling exits from guest */ 1948c2ecf20Sopenharmony_ci unsigned long badv; 1958c2ecf20Sopenharmony_ci unsigned long host_estat; 1968c2ecf20Sopenharmony_ci unsigned long badi; 1978c2ecf20Sopenharmony_ci unsigned long host_ecfg; 1988c2ecf20Sopenharmony_ci unsigned long host_percpu; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci u32 is_hypcall; 2018c2ecf20Sopenharmony_ci /* GPRS */ 2028c2ecf20Sopenharmony_ci unsigned long gprs[32]; 2038c2ecf20Sopenharmony_ci unsigned long pc; 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci /* FPU State */ 2068c2ecf20Sopenharmony_ci struct loongarch_fpu fpu FPU_ALIGN; 2078c2ecf20Sopenharmony_ci struct loongarch_lbt lbt; 2088c2ecf20Sopenharmony_ci /* Which auxiliary state is loaded (KVM_LOONGARCH_AUX_*) */ 2098c2ecf20Sopenharmony_ci unsigned int aux_inuse; 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci /* CSR State */ 2128c2ecf20Sopenharmony_ci struct loongarch_csrs *csr; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci /* GPR used as IO source/target */ 2158c2ecf20Sopenharmony_ci u32 io_gpr; 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci struct hrtimer swtimer; 2188c2ecf20Sopenharmony_ci /* Count timer control KVM register */ 2198c2ecf20Sopenharmony_ci u32 count_ctl; 2208c2ecf20Sopenharmony_ci 2218c2ecf20Sopenharmony_ci /* Bitmask of exceptions that are pending */ 2228c2ecf20Sopenharmony_ci unsigned long irq_pending; 2238c2ecf20Sopenharmony_ci /* Bitmask of pending exceptions to be cleared */ 2248c2ecf20Sopenharmony_ci unsigned long irq_clear; 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci /* Cache some mmu pages needed inside spinlock regions */ 2278c2ecf20Sopenharmony_ci struct kvm_mmu_memory_cache mmu_page_cache; 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_ci /* vcpu's vpid is different on each host cpu in an smp system */ 2308c2ecf20Sopenharmony_ci u64 vpid[NR_CPUS]; 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci /* Period of stable timer tick in ns */ 2338c2ecf20Sopenharmony_ci u64 timer_period; 2348c2ecf20Sopenharmony_ci /* Frequency of stable timer in Hz */ 2358c2ecf20Sopenharmony_ci u64 timer_mhz; 2368c2ecf20Sopenharmony_ci /* Stable bias from the raw time */ 2378c2ecf20Sopenharmony_ci u64 timer_bias; 2388c2ecf20Sopenharmony_ci /* Dynamic nanosecond bias (multiple of timer_period) to avoid overflow */ 2398c2ecf20Sopenharmony_ci s64 timer_dyn_bias; 2408c2ecf20Sopenharmony_ci /* Save ktime */ 2418c2ecf20Sopenharmony_ci ktime_t stable_ktime_saved; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci u64 core_ext_ioisr[4]; 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci /* Last CPU the VCPU state was loaded on */ 2468c2ecf20Sopenharmony_ci int last_sched_cpu; 2478c2ecf20Sopenharmony_ci /* Last CPU the VCPU actually executed guest code on */ 2488c2ecf20Sopenharmony_ci int last_exec_cpu; 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci u8 fpu_enabled; 2518c2ecf20Sopenharmony_ci u8 lsx_enabled; 2528c2ecf20Sopenharmony_ci /* paravirt steal time */ 2538c2ecf20Sopenharmony_ci struct { 2548c2ecf20Sopenharmony_ci u64 guest_addr; 2558c2ecf20Sopenharmony_ci u64 last_steal; 2568c2ecf20Sopenharmony_ci struct gfn_to_pfn_cache cache; 2578c2ecf20Sopenharmony_ci } st; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci /* pv related host specific info */ 2608c2ecf20Sopenharmony_ci struct { 2618c2ecf20Sopenharmony_ci bool pv_unhalted; 2628c2ecf20Sopenharmony_ci } pv; 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_ci struct kvm_guest_debug_arch guest_debug; 2658c2ecf20Sopenharmony_ci /* save host pmu csr */ 2668c2ecf20Sopenharmony_ci u64 perf_ctrl[4]; 2678c2ecf20Sopenharmony_ci u64 perf_cntr[4]; 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci}; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_cistatic inline unsigned long readl_sw_gcsr(struct loongarch_csrs *csr, int reg) 2728c2ecf20Sopenharmony_ci{ 2738c2ecf20Sopenharmony_ci return csr->csrs[reg]; 2748c2ecf20Sopenharmony_ci} 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_cistatic inline void writel_sw_gcsr(struct loongarch_csrs *csr, int reg, \ 2778c2ecf20Sopenharmony_ci unsigned long val) 2788c2ecf20Sopenharmony_ci{ 2798c2ecf20Sopenharmony_ci csr->csrs[reg] = val; 2808c2ecf20Sopenharmony_ci} 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci/* Helpers */ 2838c2ecf20Sopenharmony_cistatic inline bool _kvm_guest_has_fpu(struct kvm_vcpu_arch *arch) 2848c2ecf20Sopenharmony_ci{ 2858c2ecf20Sopenharmony_ci return cpu_has_fpu && arch->fpu_enabled; 2868c2ecf20Sopenharmony_ci} 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_cistatic inline bool _kvm_guest_has_lsx(struct kvm_vcpu_arch *arch) 2908c2ecf20Sopenharmony_ci{ 2918c2ecf20Sopenharmony_ci return cpu_has_lsx && arch->lsx_enabled; 2928c2ecf20Sopenharmony_ci} 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_cibool _kvm_guest_has_lasx(struct kvm_vcpu *vcpu); 2958c2ecf20Sopenharmony_civoid _kvm_init_fault(void); 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ci/* Debug: dump vcpu state */ 2988c2ecf20Sopenharmony_ciint kvm_arch_vcpu_dump_regs(struct kvm_vcpu *vcpu); 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci/* MMU handling */ 3018c2ecf20Sopenharmony_ciint kvm_handle_mm_fault(struct kvm_vcpu *vcpu, unsigned long badv, bool write); 3028c2ecf20Sopenharmony_civoid kvm_flush_tlb_all(void); 3038c2ecf20Sopenharmony_civoid _kvm_destroy_mm(struct kvm *kvm); 3048c2ecf20Sopenharmony_cipgd_t *kvm_pgd_alloc(void); 3058c2ecf20Sopenharmony_civoid kvm_mmu_free_memory_caches(struct kvm_vcpu *vcpu); 3068c2ecf20Sopenharmony_ci 3078c2ecf20Sopenharmony_cienum _kvm_fault_result { 3088c2ecf20Sopenharmony_ci KVM_LOONGARCH_MAPPED = 0, 3098c2ecf20Sopenharmony_ci KVM_LOONGARCH_GVA, 3108c2ecf20Sopenharmony_ci KVM_LOONGARCH_GPA, 3118c2ecf20Sopenharmony_ci KVM_LOONGARCH_TLB, 3128c2ecf20Sopenharmony_ci KVM_LOONGARCH_TLBINV, 3138c2ecf20Sopenharmony_ci KVM_LOONGARCH_TLBMOD, 3148c2ecf20Sopenharmony_ci}; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci#define KVM_ARCH_WANT_MMU_NOTIFIER 3178c2ecf20Sopenharmony_ciint kvm_unmap_hva_range(struct kvm *kvm, 3188c2ecf20Sopenharmony_ci unsigned long start, unsigned long end, bool blockable); 3198c2ecf20Sopenharmony_ciint kvm_set_spte_hva(struct kvm *kvm, unsigned long hva, pte_t pte); 3208c2ecf20Sopenharmony_ciint kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end); 3218c2ecf20Sopenharmony_ciint kvm_test_age_hva(struct kvm *kvm, unsigned long hva); 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_cistatic inline void update_pc(struct kvm_vcpu_arch *arch) 3248c2ecf20Sopenharmony_ci{ 3258c2ecf20Sopenharmony_ci arch->pc += 4; 3268c2ecf20Sopenharmony_ci} 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci/** 3298c2ecf20Sopenharmony_ci * kvm_is_ifetch_fault() - Find whether a TLBL exception is due to ifetch fault. 3308c2ecf20Sopenharmony_ci * @vcpu: Virtual CPU. 3318c2ecf20Sopenharmony_ci * 3328c2ecf20Sopenharmony_ci * Returns: Whether the TLBL exception was likely due to an instruction 3338c2ecf20Sopenharmony_ci * fetch fault rather than a data load fault. 3348c2ecf20Sopenharmony_ci */ 3358c2ecf20Sopenharmony_cistatic inline bool kvm_is_ifetch_fault(struct kvm_vcpu_arch *arch) 3368c2ecf20Sopenharmony_ci{ 3378c2ecf20Sopenharmony_ci if (arch->pc == arch->badv) 3388c2ecf20Sopenharmony_ci return true; 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci return false; 3418c2ecf20Sopenharmony_ci} 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci/* Misc */ 3448c2ecf20Sopenharmony_cistatic inline void kvm_arch_hardware_unsetup(void) {} 3458c2ecf20Sopenharmony_cistatic inline void kvm_arch_sync_events(struct kvm *kvm) {} 3468c2ecf20Sopenharmony_cistatic inline void kvm_arch_free_memslot(struct kvm *kvm, 3478c2ecf20Sopenharmony_ci struct kvm_memory_slot *slot) {} 3488c2ecf20Sopenharmony_cistatic inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {} 3498c2ecf20Sopenharmony_cistatic inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} 3508c2ecf20Sopenharmony_cistatic inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {} 3518c2ecf20Sopenharmony_cistatic inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {} 3528c2ecf20Sopenharmony_cistatic inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {} 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ciextern int kvm_enter_guest(struct kvm_run *run, struct kvm_vcpu *vcpu); 3558c2ecf20Sopenharmony_ciextern void kvm_exception_entry(void); 3568c2ecf20Sopenharmony_ci#endif /* __LOONGARCH_KVM_HOST_H__ */ 357