9bd93e0d5f6385c53381627bc8a023ef8b7396fc
[linux-2.6-microblaze.git] / arch / x86 / kvm / debugfs.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Kernel-based Virtual Machine driver for Linux
4  *
5  * Copyright 2016 Red Hat, Inc. and/or its affiliates.
6  */
7 #include <linux/kvm_host.h>
8 #include <linux/debugfs.h>
9 #include "lapic.h"
10
11 static int vcpu_get_timer_advance_ns(void *data, u64 *val)
12 {
13         struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
14         *val = vcpu->arch.apic->lapic_timer.timer_advance_ns;
15         return 0;
16 }
17
18 DEFINE_SIMPLE_ATTRIBUTE(vcpu_timer_advance_ns_fops, vcpu_get_timer_advance_ns, NULL, "%llu\n");
19
20 static int vcpu_get_tsc_offset(void *data, u64 *val)
21 {
22         struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
23         *val = vcpu->arch.tsc_offset;
24         return 0;
25 }
26
27 DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_offset_fops, vcpu_get_tsc_offset, NULL, "%lld\n");
28
29 static int vcpu_get_tsc_scaling_ratio(void *data, u64 *val)
30 {
31         struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
32         *val = vcpu->arch.tsc_scaling_ratio;
33         return 0;
34 }
35
36 DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_fops, vcpu_get_tsc_scaling_ratio, NULL, "%llu\n");
37
38 static int vcpu_get_tsc_scaling_frac_bits(void *data, u64 *val)
39 {
40         *val = kvm_tsc_scaling_ratio_frac_bits;
41         return 0;
42 }
43
44 DEFINE_SIMPLE_ATTRIBUTE(vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bits, NULL, "%llu\n");
45
46 int kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu)
47 {
48         struct dentry *ret;
49
50         ret = debugfs_create_file("tsc-offset", 0444,
51                                                         vcpu->debugfs_dentry,
52                                                         vcpu, &vcpu_tsc_offset_fops);
53         if (!ret)
54                 return -ENOMEM;
55
56         if (lapic_in_kernel(vcpu)) {
57                 ret = debugfs_create_file("lapic_timer_advance_ns", 0444,
58                                                                 vcpu->debugfs_dentry,
59                                                                 vcpu, &vcpu_timer_advance_ns_fops);
60                 if (!ret)
61                         return -ENOMEM;
62         }
63
64         if (kvm_has_tsc_control) {
65                 ret = debugfs_create_file("tsc-scaling-ratio", 0444,
66                                                         vcpu->debugfs_dentry,
67                                                         vcpu, &vcpu_tsc_scaling_fops);
68                 if (!ret)
69                         return -ENOMEM;
70                 ret = debugfs_create_file("tsc-scaling-ratio-frac-bits", 0444,
71                                                         vcpu->debugfs_dentry,
72                                                         vcpu, &vcpu_tsc_scaling_frac_fops);
73                 if (!ret)
74                         return -ENOMEM;
75
76         }
77
78         return 0;
79 }