KVM
Macros | Functions | Variables
debugfs.c File Reference
#include <linux/kvm_host.h>
#include <linux/debugfs.h>
#include "lapic.h"
#include "mmu.h"
#include "mmu/mmu_internal.h"
Include dependency graph for debugfs.c:

Go to the source code of this file.

Macros

#define pr_fmt(fmt)   KBUILD_MODNAME ": " fmt
 
#define RMAP_LOG_SIZE   11
 

Functions

static int vcpu_get_timer_advance_ns (void *data, u64 *val)
 
 DEFINE_SIMPLE_ATTRIBUTE (vcpu_timer_advance_ns_fops, vcpu_get_timer_advance_ns, NULL, "%llu\n")
 
static int vcpu_get_guest_mode (void *data, u64 *val)
 
 DEFINE_SIMPLE_ATTRIBUTE (vcpu_guest_mode_fops, vcpu_get_guest_mode, NULL, "%lld\n")
 
static int vcpu_get_tsc_offset (void *data, u64 *val)
 
 DEFINE_SIMPLE_ATTRIBUTE (vcpu_tsc_offset_fops, vcpu_get_tsc_offset, NULL, "%lld\n")
 
static int vcpu_get_tsc_scaling_ratio (void *data, u64 *val)
 
 DEFINE_SIMPLE_ATTRIBUTE (vcpu_tsc_scaling_fops, vcpu_get_tsc_scaling_ratio, NULL, "%llu\n")
 
static int vcpu_get_tsc_scaling_frac_bits (void *data, u64 *val)
 
 DEFINE_SIMPLE_ATTRIBUTE (vcpu_tsc_scaling_frac_fops, vcpu_get_tsc_scaling_frac_bits, NULL, "%llu\n")
 
void kvm_arch_create_vcpu_debugfs (struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry)
 
static int kvm_mmu_rmaps_stat_show (struct seq_file *m, void *v)
 
static int kvm_mmu_rmaps_stat_open (struct inode *inode, struct file *file)
 
static int kvm_mmu_rmaps_stat_release (struct inode *inode, struct file *file)
 
int kvm_arch_create_vm_debugfs (struct kvm *kvm)
 

Variables

static const char * kvm_lpage_str [KVM_NR_PAGE_SIZES] = { "4K", "2M", "1G" }
 
static const struct file_operations mmu_rmaps_stat_fops
 

Macro Definition Documentation

◆ pr_fmt

#define pr_fmt (   fmt)    KBUILD_MODNAME ": " fmt

Definition at line 7 of file debugfs.c.

◆ RMAP_LOG_SIZE

#define RMAP_LOG_SIZE   11

Definition at line 85 of file debugfs.c.

Function Documentation

◆ DEFINE_SIMPLE_ATTRIBUTE() [1/5]

DEFINE_SIMPLE_ATTRIBUTE ( vcpu_guest_mode_fops  ,
vcpu_get_guest_mode  ,
NULL  ,
"%lld\n"   
)

◆ DEFINE_SIMPLE_ATTRIBUTE() [2/5]

DEFINE_SIMPLE_ATTRIBUTE ( vcpu_timer_advance_ns_fops  ,
vcpu_get_timer_advance_ns  ,
NULL  ,
"%llu\n"   
)

◆ DEFINE_SIMPLE_ATTRIBUTE() [3/5]

DEFINE_SIMPLE_ATTRIBUTE ( vcpu_tsc_offset_fops  ,
vcpu_get_tsc_offset  ,
NULL  ,
"%lld\n"   
)

◆ DEFINE_SIMPLE_ATTRIBUTE() [4/5]

DEFINE_SIMPLE_ATTRIBUTE ( vcpu_tsc_scaling_fops  ,
vcpu_get_tsc_scaling_ratio  ,
NULL  ,
"%llu\n"   
)

◆ DEFINE_SIMPLE_ATTRIBUTE() [5/5]

DEFINE_SIMPLE_ATTRIBUTE ( vcpu_tsc_scaling_frac_fops  ,
vcpu_get_tsc_scaling_frac_bits  ,
NULL  ,
"%llu\n"   
)

◆ kvm_arch_create_vcpu_debugfs()

void kvm_arch_create_vcpu_debugfs ( struct kvm_vcpu *  vcpu,
struct dentry *  debugfs_dentry 
)

Definition at line 59 of file debugfs.c.

60 {
61  debugfs_create_file("guest_mode", 0444, debugfs_dentry, vcpu,
62  &vcpu_guest_mode_fops);
63  debugfs_create_file("tsc-offset", 0444, debugfs_dentry, vcpu,
64  &vcpu_tsc_offset_fops);
65 
66  if (lapic_in_kernel(vcpu))
67  debugfs_create_file("lapic_timer_advance_ns", 0444,
68  debugfs_dentry, vcpu,
69  &vcpu_timer_advance_ns_fops);
70 
72  debugfs_create_file("tsc-scaling-ratio", 0444,
73  debugfs_dentry, vcpu,
74  &vcpu_tsc_scaling_fops);
75  debugfs_create_file("tsc-scaling-ratio-frac-bits", 0444,
76  debugfs_dentry, vcpu,
77  &vcpu_tsc_scaling_frac_fops);
78  }
79 }
static bool lapic_in_kernel(struct kvm_vcpu *vcpu)
Definition: lapic.h:186
Definition: x86.h:12
bool has_tsc_control
Definition: x86.h:14
Here is the call graph for this function:

◆ kvm_arch_create_vm_debugfs()

int kvm_arch_create_vm_debugfs ( struct kvm *  kvm)

Definition at line 192 of file debugfs.c.

193 {
194  debugfs_create_file("mmu_rmaps_stat", 0644, kvm->debugfs_dentry, kvm,
196  return 0;
197 }
static const struct file_operations mmu_rmaps_stat_fops
Definition: debugfs.c:184

◆ kvm_mmu_rmaps_stat_open()

static int kvm_mmu_rmaps_stat_open ( struct inode *  inode,
struct file *  file 
)
static

Definition at line 160 of file debugfs.c.

161 {
162  struct kvm *kvm = inode->i_private;
163  int r;
164 
165  if (!kvm_get_kvm_safe(kvm))
166  return -ENOENT;
167 
168  r = single_open(file, kvm_mmu_rmaps_stat_show, kvm);
169  if (r < 0)
170  kvm_put_kvm(kvm);
171 
172  return r;
173 }
static int kvm_mmu_rmaps_stat_show(struct seq_file *m, void *v)
Definition: debugfs.c:89
void kvm_put_kvm(struct kvm *kvm)
Definition: kvm_main.c:1419
bool kvm_get_kvm_safe(struct kvm *kvm)
Definition: kvm_main.c:1413
Here is the call graph for this function:

◆ kvm_mmu_rmaps_stat_release()

static int kvm_mmu_rmaps_stat_release ( struct inode *  inode,
struct file *  file 
)
static

Definition at line 175 of file debugfs.c.

176 {
177  struct kvm *kvm = inode->i_private;
178 
179  kvm_put_kvm(kvm);
180 
181  return single_release(inode, file);
182 }
Here is the call graph for this function:

◆ kvm_mmu_rmaps_stat_show()

static int kvm_mmu_rmaps_stat_show ( struct seq_file *  m,
void *  v 
)
static

Definition at line 89 of file debugfs.c.

90 {
91  struct kvm_rmap_head *rmap;
92  struct kvm *kvm = m->private;
93  struct kvm_memory_slot *slot;
94  struct kvm_memslots *slots;
95  unsigned int lpage_size, index;
96  /* Still small enough to be on the stack */
97  unsigned int *log[KVM_NR_PAGE_SIZES], *cur;
98  int i, j, k, l, ret;
99 
100  if (!kvm_memslots_have_rmaps(kvm))
101  return 0;
102 
103  ret = -ENOMEM;
104  memset(log, 0, sizeof(log));
105  for (i = 0; i < KVM_NR_PAGE_SIZES; i++) {
106  log[i] = kcalloc(RMAP_LOG_SIZE, sizeof(unsigned int), GFP_KERNEL);
107  if (!log[i])
108  goto out;
109  }
110 
111  mutex_lock(&kvm->slots_lock);
112  write_lock(&kvm->mmu_lock);
113 
114  for (i = 0; i < kvm_arch_nr_memslot_as_ids(kvm); i++) {
115  int bkt;
116 
117  slots = __kvm_memslots(kvm, i);
118  kvm_for_each_memslot(slot, bkt, slots)
119  for (k = 0; k < KVM_NR_PAGE_SIZES; k++) {
120  rmap = slot->arch.rmap[k];
121  lpage_size = kvm_mmu_slot_lpages(slot, k + 1);
122  cur = log[k];
123  for (l = 0; l < lpage_size; l++) {
124  index = ffs(pte_list_count(&rmap[l]));
125  if (WARN_ON_ONCE(index >= RMAP_LOG_SIZE))
126  index = RMAP_LOG_SIZE - 1;
127  cur[index]++;
128  }
129  }
130  }
131 
132  write_unlock(&kvm->mmu_lock);
133  mutex_unlock(&kvm->slots_lock);
134 
135  /* index=0 counts no rmap; index=1 counts 1 rmap */
136  seq_printf(m, "Rmap_Count:\t0\t1\t");
137  for (i = 2; i < RMAP_LOG_SIZE; i++) {
138  j = 1 << (i - 1);
139  k = (1 << i) - 1;
140  seq_printf(m, "%d-%d\t", j, k);
141  }
142  seq_printf(m, "\n");
143 
144  for (i = 0; i < KVM_NR_PAGE_SIZES; i++) {
145  seq_printf(m, "Level=%s:\t", kvm_lpage_str[i]);
146  cur = log[i];
147  for (j = 0; j < RMAP_LOG_SIZE; j++)
148  seq_printf(m, "%d\t", cur[j]);
149  seq_printf(m, "\n");
150  }
151 
152  ret = 0;
153 out:
154  for (i = 0; i < KVM_NR_PAGE_SIZES; i++)
155  kfree(log[i]);
156 
157  return ret;
158 }
static const char * kvm_lpage_str[KVM_NR_PAGE_SIZES]
Definition: debugfs.c:87
#define RMAP_LOG_SIZE
Definition: debugfs.c:85
unsigned int pte_list_count(struct kvm_rmap_head *rmap_head)
Definition: mmu.c:1073
static unsigned long kvm_mmu_slot_lpages(struct kvm_memory_slot *slot, int level)
Definition: mmu.h:300
static bool kvm_memslots_have_rmaps(struct kvm *kvm)
Definition: mmu.h:279
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vcpu_get_guest_mode()

static int vcpu_get_guest_mode ( void *  data,
u64 *  val 
)
static

Definition at line 24 of file debugfs.c.

25 {
26  struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
27  *val = vcpu->stat.guest_mode;
28  return 0;
29 }

◆ vcpu_get_timer_advance_ns()

static int vcpu_get_timer_advance_ns ( void *  data,
u64 *  val 
)
static

Definition at line 15 of file debugfs.c.

16 {
17  struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
18  *val = vcpu->arch.apic->lapic_timer.timer_advance_ns;
19  return 0;
20 }

◆ vcpu_get_tsc_offset()

static int vcpu_get_tsc_offset ( void *  data,
u64 *  val 
)
static

Definition at line 33 of file debugfs.c.

34 {
35  struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
36  *val = vcpu->arch.tsc_offset;
37  return 0;
38 }

◆ vcpu_get_tsc_scaling_frac_bits()

static int vcpu_get_tsc_scaling_frac_bits ( void *  data,
u64 *  val 
)
static

Definition at line 51 of file debugfs.c.

52 {
54  return 0;
55 }
u8 tsc_scaling_ratio_frac_bits
Definition: x86.h:18

◆ vcpu_get_tsc_scaling_ratio()

static int vcpu_get_tsc_scaling_ratio ( void *  data,
u64 *  val 
)
static

Definition at line 42 of file debugfs.c.

43 {
44  struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
45  *val = vcpu->arch.tsc_scaling_ratio;
46  return 0;
47 }

Variable Documentation

◆ kvm_lpage_str

const char* kvm_lpage_str[KVM_NR_PAGE_SIZES] = { "4K", "2M", "1G" }
static

Definition at line 87 of file debugfs.c.

◆ mmu_rmaps_stat_fops

const struct file_operations mmu_rmaps_stat_fops
static
Initial value:
= {
.owner = THIS_MODULE,
.read = seq_read,
.llseek = seq_lseek,
}
static int kvm_mmu_rmaps_stat_open(struct inode *inode, struct file *file)
Definition: debugfs.c:160
static int kvm_mmu_rmaps_stat_release(struct inode *inode, struct file *file)
Definition: debugfs.c:175

Definition at line 175 of file debugfs.c.