1/* 2 * Based on the x86 implementation. 3 * 4 * Copyright (C) 2012 ARM Ltd. 5 * Author: Marc Zyngier <marc.zyngier@arm.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20#include <linux/perf_event.h> 21#include <linux/kvm_host.h> 22 23#include <asm/kvm_emulate.h> 24 25static int kvm_is_in_guest(void) 26{ 27 return kvm_arm_get_running_vcpu() != NULL; 28} 29 30static int kvm_is_user_mode(void) 31{ 32 struct kvm_vcpu *vcpu; 33 34 vcpu = kvm_arm_get_running_vcpu(); 35 36 if (vcpu) 37 return !vcpu_mode_priv(vcpu); 38 39 return 0; 40} 41 42static unsigned long kvm_get_guest_ip(void) 43{ 44 struct kvm_vcpu *vcpu; 45 46 vcpu = kvm_arm_get_running_vcpu(); 47 48 if (vcpu) 49 return *vcpu_pc(vcpu); 50 51 return 0; 52} 53 54static struct perf_guest_info_callbacks kvm_guest_cbs = { 55 .is_in_guest = kvm_is_in_guest, 56 .is_user_mode = kvm_is_user_mode, 57 .get_guest_ip = kvm_get_guest_ip, 58}; 59 60int kvm_perf_init(void) 61{ 62 return perf_register_guest_info_callbacks(&kvm_guest_cbs); 63} 64 65int kvm_perf_teardown(void) 66{ 67 return perf_unregister_guest_info_callbacks(&kvm_guest_cbs); 68} 69