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#if !defined(_TRACE_KVM_H) || defined(TRACE_HEADER_MULTI_READ) 78c2ecf20Sopenharmony_ci#define _TRACE_KVM_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/tracepoint.h> 108c2ecf20Sopenharmony_ci#include "kvm_compat.h" 118c2ecf20Sopenharmony_ci#include "kvmcsr.h" 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#undef TRACE_SYSTEM 148c2ecf20Sopenharmony_ci#define TRACE_SYSTEM kvm 158c2ecf20Sopenharmony_ci#define TRACE_INCLUDE_PATH . 168c2ecf20Sopenharmony_ci#define TRACE_INCLUDE_FILE trace 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci/* 198c2ecf20Sopenharmony_ci * arch/loongarch/kvm/loongarch.c 208c2ecf20Sopenharmony_ci */ 218c2ecf20Sopenharmony_ciextern bool kvm_trace_guest_mode_change; 228c2ecf20Sopenharmony_ciint kvm_guest_mode_change_trace_reg(void); 238c2ecf20Sopenharmony_civoid kvm_guest_mode_change_trace_unreg(void); 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* 268c2ecf20Sopenharmony_ci * Tracepoints for VM enters 278c2ecf20Sopenharmony_ci */ 288c2ecf20Sopenharmony_ciDECLARE_EVENT_CLASS(kvm_transition, 298c2ecf20Sopenharmony_ci TP_PROTO(struct kvm_vcpu *vcpu), 308c2ecf20Sopenharmony_ci TP_ARGS(vcpu), 318c2ecf20Sopenharmony_ci TP_STRUCT__entry( 328c2ecf20Sopenharmony_ci __field(unsigned long, pc) 338c2ecf20Sopenharmony_ci ), 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci TP_fast_assign( 368c2ecf20Sopenharmony_ci __entry->pc = vcpu->arch.pc; 378c2ecf20Sopenharmony_ci ), 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci TP_printk("PC: 0x%08lx", 408c2ecf20Sopenharmony_ci __entry->pc) 418c2ecf20Sopenharmony_ci); 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ciDEFINE_EVENT(kvm_transition, kvm_enter, 448c2ecf20Sopenharmony_ci TP_PROTO(struct kvm_vcpu *vcpu), 458c2ecf20Sopenharmony_ci TP_ARGS(vcpu)); 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ciDEFINE_EVENT(kvm_transition, kvm_reenter, 488c2ecf20Sopenharmony_ci TP_PROTO(struct kvm_vcpu *vcpu), 498c2ecf20Sopenharmony_ci TP_ARGS(vcpu)); 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ciDEFINE_EVENT(kvm_transition, kvm_out, 528c2ecf20Sopenharmony_ci TP_PROTO(struct kvm_vcpu *vcpu), 538c2ecf20Sopenharmony_ci TP_ARGS(vcpu)); 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci/* The first 32 exit reasons correspond to Cause.ExcCode */ 568c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_INT 0 578c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_TLBLD (EXCCODE_TLBL) 588c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_TLBST (EXCCODE_TLBS) 598c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_TLBI (EXCCODE_TLBI) 608c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_TLBMOD (EXCCODE_TLBM) 618c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_TLBNR (EXCCODE_TLBNR) 628c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_TLBNX (EXCCODE_TLBNX) 638c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_TLBPE (EXCCODE_TLBPE) 648c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_ADDE (EXCCODE_ADE) 658c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_UNALIGN (EXCCODE_ALE) 668c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_ODB (EXCCODE_BCE) 678c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_SYSCALL (EXCCODE_SYS) 688c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_BP (EXCCODE_BP) 698c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_INE (EXCCODE_INE) 708c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_IPE (EXCCODE_IPE) 718c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_FPDIS (EXCCODE_FPDIS) 728c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_LSXDIS (EXCCODE_LSXDIS) 738c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_LASXDIS (EXCCODE_LASXDIS) 748c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_FPE (EXCCODE_FPE) 758c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_WATCH (EXCCODE_WATCH) 768c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_GSPR (EXCCODE_GSPR) 778c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_HC (EXCCODE_HVC) 788c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_GCM (EXCCODE_GCM) 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/* Further exit reasons */ 818c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_IDLE 64 828c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_CACHE 65 838c2ecf20Sopenharmony_ci#define KVM_TRACE_EXIT_SIGNAL 66 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/* Tracepoints for VM exits */ 868c2ecf20Sopenharmony_ci#define kvm_trace_symbol_exit_types \ 878c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_INT, "Interrupt" }, \ 888c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_TLBLD, "TLB (LD)" }, \ 898c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_TLBST, "TLB (ST)" }, \ 908c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_TLBI, "TLB Ifetch" }, \ 918c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_TLBMOD, "TLB Mod" }, \ 928c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_TLBNR, "TLB RI" }, \ 938c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_TLBNX, "TLB XI" }, \ 948c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_TLBPE, "TLB Previlege Error" },\ 958c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_ADDE, "Address Error" }, \ 968c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_UNALIGN, "Address unalign" }, \ 978c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_ODB, "Out boundary" }, \ 988c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_SYSCALL, "System Call" }, \ 998c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_BP, "Breakpoint" }, \ 1008c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_INE, "Reserved Inst" }, \ 1018c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_IPE, "Inst prev error" }, \ 1028c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_FPDIS, "FPU disable" }, \ 1038c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_LSXDIS, "LSX disable" }, \ 1048c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_LASXDIS, "LASX disable" }, \ 1058c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_FPE, "FPE" }, \ 1068c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_WATCH, "DEBUG" }, \ 1078c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_GSPR, "GSPR" }, \ 1088c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_HC, "Hypercall" }, \ 1098c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_GCM, "CSR Mod" }, \ 1108c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_IDLE, "IDLE" }, \ 1118c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_CACHE, "CACHE" }, \ 1128c2ecf20Sopenharmony_ci { KVM_TRACE_EXIT_SIGNAL, "Signal" } 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ciTRACE_EVENT(kvm_exit, 1158c2ecf20Sopenharmony_ci TP_PROTO(struct kvm_vcpu *vcpu, unsigned int reason), 1168c2ecf20Sopenharmony_ci TP_ARGS(vcpu, reason), 1178c2ecf20Sopenharmony_ci TP_STRUCT__entry( 1188c2ecf20Sopenharmony_ci __field(unsigned long, pc) 1198c2ecf20Sopenharmony_ci __field(unsigned int, reason) 1208c2ecf20Sopenharmony_ci ), 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci TP_fast_assign( 1238c2ecf20Sopenharmony_ci __entry->pc = vcpu->arch.pc; 1248c2ecf20Sopenharmony_ci __entry->reason = reason; 1258c2ecf20Sopenharmony_ci ), 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci TP_printk("[%s]PC: 0x%08lx", 1288c2ecf20Sopenharmony_ci __print_symbolic(__entry->reason, 1298c2ecf20Sopenharmony_ci kvm_trace_symbol_exit_types), 1308c2ecf20Sopenharmony_ci __entry->pc) 1318c2ecf20Sopenharmony_ci); 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci#define KVM_TRACE_AUX_RESTORE 0 1348c2ecf20Sopenharmony_ci#define KVM_TRACE_AUX_SAVE 1 1358c2ecf20Sopenharmony_ci#define KVM_TRACE_AUX_ENABLE 2 1368c2ecf20Sopenharmony_ci#define KVM_TRACE_AUX_DISABLE 3 1378c2ecf20Sopenharmony_ci#define KVM_TRACE_AUX_DISCARD 4 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci#define KVM_TRACE_AUX_FPU 1 1408c2ecf20Sopenharmony_ci#define KVM_TRACE_AUX_LSX 2 1418c2ecf20Sopenharmony_ci#define KVM_TRACE_AUX_FPU_LSX 3 1428c2ecf20Sopenharmony_ci#define KVM_TRACE_AUX_LASX 4 1438c2ecf20Sopenharmony_ci#define KVM_TRACE_AUX_FPU_LSX_LASX 7 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci#define kvm_trace_symbol_aux_op \ 1468c2ecf20Sopenharmony_ci { KVM_TRACE_AUX_RESTORE, "restore" }, \ 1478c2ecf20Sopenharmony_ci { KVM_TRACE_AUX_SAVE, "save" }, \ 1488c2ecf20Sopenharmony_ci { KVM_TRACE_AUX_ENABLE, "enable" }, \ 1498c2ecf20Sopenharmony_ci { KVM_TRACE_AUX_DISABLE, "disable" }, \ 1508c2ecf20Sopenharmony_ci { KVM_TRACE_AUX_DISCARD, "discard" } 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci#define kvm_trace_symbol_aux_state \ 1538c2ecf20Sopenharmony_ci { KVM_TRACE_AUX_FPU, "FPU" }, \ 1548c2ecf20Sopenharmony_ci { KVM_TRACE_AUX_LSX, "LSX" }, \ 1558c2ecf20Sopenharmony_ci { KVM_TRACE_AUX_LASX, "LASX" }, \ 1568c2ecf20Sopenharmony_ci { KVM_TRACE_AUX_FPU_LSX, "FPU & LSX" }, \ 1578c2ecf20Sopenharmony_ci { KVM_TRACE_AUX_FPU_LSX_LASX, "FPU & LSX & LASX" } 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ciTRACE_EVENT(kvm_aux, 1608c2ecf20Sopenharmony_ci TP_PROTO(struct kvm_vcpu *vcpu, unsigned int op, 1618c2ecf20Sopenharmony_ci unsigned int state), 1628c2ecf20Sopenharmony_ci TP_ARGS(vcpu, op, state), 1638c2ecf20Sopenharmony_ci TP_STRUCT__entry( 1648c2ecf20Sopenharmony_ci __field(unsigned long, pc) 1658c2ecf20Sopenharmony_ci __field(u8, op) 1668c2ecf20Sopenharmony_ci __field(u8, state) 1678c2ecf20Sopenharmony_ci ), 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci TP_fast_assign( 1708c2ecf20Sopenharmony_ci __entry->pc = vcpu->arch.pc; 1718c2ecf20Sopenharmony_ci __entry->op = op; 1728c2ecf20Sopenharmony_ci __entry->state = state; 1738c2ecf20Sopenharmony_ci ), 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci TP_printk("%s %s PC: 0x%08lx", 1768c2ecf20Sopenharmony_ci __print_symbolic(__entry->op, 1778c2ecf20Sopenharmony_ci kvm_trace_symbol_aux_op), 1788c2ecf20Sopenharmony_ci __print_symbolic(__entry->state, 1798c2ecf20Sopenharmony_ci kvm_trace_symbol_aux_state), 1808c2ecf20Sopenharmony_ci __entry->pc) 1818c2ecf20Sopenharmony_ci); 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ciTRACE_EVENT(kvm_vpid_change, 1848c2ecf20Sopenharmony_ci TP_PROTO(struct kvm_vcpu *vcpu, unsigned long vpid), 1858c2ecf20Sopenharmony_ci TP_ARGS(vcpu, vpid), 1868c2ecf20Sopenharmony_ci TP_STRUCT__entry( 1878c2ecf20Sopenharmony_ci __field(unsigned long, vpid) 1888c2ecf20Sopenharmony_ci ), 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci TP_fast_assign( 1918c2ecf20Sopenharmony_ci __entry->vpid = vpid; 1928c2ecf20Sopenharmony_ci ), 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci TP_printk("vpid: 0x%08lx", 1958c2ecf20Sopenharmony_ci __entry->vpid) 1968c2ecf20Sopenharmony_ci); 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci#endif /* _TRACE_KVM_H */ 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci/* This part must be outside protection */ 2018c2ecf20Sopenharmony_ci#include <trace/define_trace.h> 202