Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Based on the x86 implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Copyright (C) 2012 ARM Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  * Author: Marc Zyngier <marc.zyngier@arm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/perf_event.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/kvm_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/kvm_emulate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) DEFINE_STATIC_KEY_FALSE(kvm_arm_pmu_available);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) static int kvm_is_in_guest(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)         return kvm_get_running_vcpu() != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static int kvm_is_user_mode(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	struct kvm_vcpu *vcpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	vcpu = kvm_get_running_vcpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	if (vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 		return !vcpu_mode_priv(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static unsigned long kvm_get_guest_ip(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	struct kvm_vcpu *vcpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	vcpu = kvm_get_running_vcpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	if (vcpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		return *vcpu_pc(vcpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static struct perf_guest_info_callbacks kvm_guest_cbs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	.is_in_guest	= kvm_is_in_guest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	.is_user_mode	= kvm_is_user_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	.get_guest_ip	= kvm_get_guest_ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int kvm_perf_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	 * Check if HW_PERF_EVENTS are supported by checking the number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	 * hardware performance counters. This could ensure the presence of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	 * a physical PMU and CONFIG_PERF_EVENT is selected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	if (IS_ENABLED(CONFIG_ARM_PMU) && perf_num_counters() > 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 				       && !is_protected_kvm_enabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 		static_branch_enable(&kvm_arm_pmu_available);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	return perf_register_guest_info_callbacks(&kvm_guest_cbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) int kvm_perf_teardown(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	return perf_unregister_guest_info_callbacks(&kvm_guest_cbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }