[PATCH v2 04/15] kvm: x86: Add per-VM APICv state debugfs
From: Suthikulpanit, Suravee
Date: Thu Aug 15 2019 - 12:25:18 EST
Currently, there is no way to tell whether APICv is active
on a particular VM. This often cause confusion since APICv
can be deactivated at runtime.
Introduce a debugfs entry to report APICv state of a VM.
This creates a read-only file:
/sys/kernel/debug/kvm/70860-14/apicv-state
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx>
---
arch/x86/kvm/debugfs.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c
index d62852c..bd9fd25 100644
--- a/arch/x86/kvm/debugfs.c
+++ b/arch/x86/kvm/debugfs.c
@@ -48,8 +48,30 @@ 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");
+static int kvm_get_apicv_state(void *data, u64 *val)
+{
+ struct kvm *kvm = (struct kvm *)data;
+
+ mutex_lock(&kvm->arch.apicv_lock);
+ *val = kvm->arch.apicv_state;
+ mutex_unlock(&kvm->arch.apicv_lock);
+ return 0;
+}
+
+DEFINE_SIMPLE_ATTRIBUTE(apicv_state_fops, kvm_get_apicv_state, NULL, "%llu\n");
+
int kvm_arch_create_vm_debugfs(struct kvm *kvm)
{
+ struct dentry *ret;
+
+ if (kvm_x86_ops->get_enable_apicv(kvm)) {
+ ret = debugfs_create_file("apicv-state", 0444,
+ kvm->debugfs_dentry,
+ kvm, &apicv_state_fops);
+ if (!ret)
+ return -ENOMEM;
+ }
+
return 0;
}
--
1.8.3.1