1 // SPDX-License-Identifier: GPL-2.0-only
3 * Kernel-based Virtual Machine driver for Linux
5 * Copyright 2016 Red Hat, Inc. and/or its affiliates.
7 #include <linux/kvm_host.h>
8 #include <linux/debugfs.h>
11 static int vcpu_get_timer_advance_ns(void *data, u64 *val)
13 struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
14 *val = vcpu->arch.apic->lapic_timer.timer_advance_ns;
18 DEFINE_SIMPLE_ATTRIBUTE(vcpu_timer_advance_ns_fops, vcpu_get_timer_advance_ns, NULL, "%llu\n");
20 static int vcpu_get_guest_mode(void *data, u64 *val)
22 struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
23 *val = vcpu->stat.guest_mode;
27 DEFINE_SIMPLE_ATTRIBUTE(vcpu_guest_mode_fops, vcpu_get_guest_mode, NULL, "%lld\n");
29 static int vcpu_get_tsc_offset(void *data, u64 *val)
31 struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
32 *val = vcpu->arch.tsc_offset;
36 DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_offset_fops, vcpu_get_tsc_offset, NULL, "%lld\n");
38 static int vcpu_get_tsc_scaling_ratio(void *data, u64 *val)
40 struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
41 *val = vcpu->arch.tsc_scaling_ratio;
45 DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_fops, vcpu_get_tsc_scaling_ratio, NULL, "%llu\n");
47 static int vcpu_get_tsc_scaling_frac_bits(void *data, u64 *val)
49 *val = kvm_tsc_scaling_ratio_frac_bits;
53 DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bits, NULL, "%llu\n");
55 void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry)
57 debugfs_create_file("guest_mode", 0444, debugfs_dentry, vcpu,
58 &vcpu_guest_mode_fops);
59 debugfs_create_file("tsc-offset", 0444, debugfs_dentry, vcpu,
60 &vcpu_tsc_offset_fops);
62 if (lapic_in_kernel(vcpu))
63 debugfs_create_file("lapic_timer_advance_ns", 0444,
65 &vcpu_timer_advance_ns_fops);
67 if (kvm_has_tsc_control) {
68 debugfs_create_file("tsc-scaling-ratio", 0444,
70 &vcpu_tsc_scaling_fops);
71 debugfs_create_file("tsc-scaling-ratio-frac-bits", 0444,
73 &vcpu_tsc_scaling_frac_fops);