Skip to content

Commit faf01ae

Browse files
aikmpe
authored andcommitted
KVM: PPC: Merge powerpc's debugfs entry content into generic entry
At the moment KVM on PPC creates 4 types of entries under the kvm debugfs: 1) "%pid-%fd" per a KVM instance (for all platforms); 2) "vm%pid" (for PPC Book3s HV KVM); 3) "vm%u_vcpu%u_timing" (for PPC Book3e KVM); 4) "kvm-xive-%p" (for XIVE PPC Book3s KVM, the same for XICS); The problem with this is that multiple VMs per process is not allowed for 2) and 3) which makes it possible for userspace to trigger errors when creating duplicated debugfs entries. This merges all these into 1). This defines kvm_arch_create_kvm_debugfs() similar to kvm_arch_create_vcpu_debugfs(). This defines 2 hooks in kvmppc_ops that allow specific KVM implementations add necessary entries, this adds the _e500 suffix to kvmppc_create_vcpu_debugfs_e500() to make it clear what platform it is for. This makes use of already existing kvm_arch_create_vcpu_debugfs() on PPC. This removes no more used debugfs_dir pointers from PPC kvm_arch structs. This stops removing vcpu entries as once created vcpus stay around for the entire life of a VM and removed when the KVM instance is closed, see commit d56f513 ("KVM: let kvm_destroy_vm_debugfs clean up vCPU debugfs directories"). Suggested-by: Fabiano Rosas <farosas@linux.ibm.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru> Reviewed-by: Cédric Le Goater <clg@kaod.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20220111005404.162219-1-aik@ozlabs.ru
1 parent c1c8a66 commit faf01ae

13 files changed

Lines changed: 51 additions & 82 deletions

File tree

arch/powerpc/include/asm/kvm_host.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <asm/hvcall.h>
2727
#include <asm/mce.h>
2828

29+
#define __KVM_HAVE_ARCH_VCPU_DEBUGFS
30+
2931
#define KVM_MAX_VCPUS NR_CPUS
3032
#define KVM_MAX_VCORES NR_CPUS
3133

@@ -295,7 +297,6 @@ struct kvm_arch {
295297
bool dawr1_enabled;
296298
pgd_t *pgtable;
297299
u64 process_table;
298-
struct dentry *debugfs_dir;
299300
struct kvm_resize_hpt *resize_hpt; /* protected by kvm->lock */
300301
#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
301302
#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
@@ -673,7 +674,6 @@ struct kvm_vcpu_arch {
673674
u64 timing_min_duration[__NUMBER_OF_KVM_EXIT_TYPES];
674675
u64 timing_max_duration[__NUMBER_OF_KVM_EXIT_TYPES];
675676
u64 timing_last_exit;
676-
struct dentry *debugfs_exit_timing;
677677
#endif
678678

679679
#ifdef CONFIG_PPC_BOOK3S
@@ -831,8 +831,6 @@ struct kvm_vcpu_arch {
831831
struct kvmhv_tb_accumulator rm_exit; /* real-mode exit code */
832832
struct kvmhv_tb_accumulator guest_time; /* guest execution */
833833
struct kvmhv_tb_accumulator cede_time; /* time napping inside guest */
834-
835-
struct dentry *debugfs_dir;
836834
#endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
837835
};
838836

arch/powerpc/include/asm/kvm_ppc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ struct kvmppc_ops {
314314
int (*svm_off)(struct kvm *kvm);
315315
int (*enable_dawr1)(struct kvm *kvm);
316316
bool (*hash_v3_possible)(void);
317+
int (*create_vm_debugfs)(struct kvm *kvm);
318+
int (*create_vcpu_debugfs)(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry);
317319
};
318320

319321
extern struct kvmppc_ops *kvmppc_hv_ops;

arch/powerpc/kvm/book3s_64_mmu_hv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2112,7 +2112,7 @@ static const struct file_operations debugfs_htab_fops = {
21122112

21132113
void kvmppc_mmu_debugfs_init(struct kvm *kvm)
21142114
{
2115-
debugfs_create_file("htab", 0400, kvm->arch.debugfs_dir, kvm,
2115+
debugfs_create_file("htab", 0400, kvm->debugfs_dentry, kvm,
21162116
&debugfs_htab_fops);
21172117
}
21182118

arch/powerpc/kvm/book3s_64_mmu_radix.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ static const struct file_operations debugfs_radix_fops = {
14541454

14551455
void kvmhv_radix_debugfs_init(struct kvm *kvm)
14561456
{
1457-
debugfs_create_file("radix", 0400, kvm->arch.debugfs_dir, kvm,
1457+
debugfs_create_file("radix", 0400, kvm->debugfs_dentry, kvm,
14581458
&debugfs_radix_fops);
14591459
}
14601460

arch/powerpc/kvm/book3s_hv.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,20 +2767,17 @@ static const struct file_operations debugfs_timings_ops = {
27672767
};
27682768

27692769
/* Create a debugfs directory for the vcpu */
2770-
static void debugfs_vcpu_init(struct kvm_vcpu *vcpu, unsigned int id)
2770+
static int kvmppc_arch_create_vcpu_debugfs_hv(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry)
27712771
{
2772-
char buf[16];
2773-
struct kvm *kvm = vcpu->kvm;
2774-
2775-
snprintf(buf, sizeof(buf), "vcpu%u", id);
2776-
vcpu->arch.debugfs_dir = debugfs_create_dir(buf, kvm->arch.debugfs_dir);
2777-
debugfs_create_file("timings", 0444, vcpu->arch.debugfs_dir, vcpu,
2772+
debugfs_create_file("timings", 0444, debugfs_dentry, vcpu,
27782773
&debugfs_timings_ops);
2774+
return 0;
27792775
}
27802776

27812777
#else /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
2782-
static void debugfs_vcpu_init(struct kvm_vcpu *vcpu, unsigned int id)
2778+
static int kvmppc_arch_create_vcpu_debugfs_hv(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry)
27832779
{
2780+
return 0;
27842781
}
27852782
#endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
27862783

@@ -2903,8 +2900,6 @@ static int kvmppc_core_vcpu_create_hv(struct kvm_vcpu *vcpu)
29032900
vcpu->arch.cpu_type = KVM_CPU_3S_64;
29042901
kvmppc_sanity_check(vcpu);
29052902

2906-
debugfs_vcpu_init(vcpu, id);
2907-
29082903
return 0;
29092904
}
29102905

@@ -5223,7 +5218,6 @@ void kvmppc_free_host_rm_ops(void)
52235218
static int kvmppc_core_init_vm_hv(struct kvm *kvm)
52245219
{
52255220
unsigned long lpcr, lpid;
5226-
char buf[32];
52275221
int ret;
52285222

52295223
mutex_init(&kvm->arch.uvmem_lock);
@@ -5356,15 +5350,14 @@ static int kvmppc_core_init_vm_hv(struct kvm *kvm)
53565350
kvm->arch.smt_mode = 1;
53575351
kvm->arch.emul_smt_mode = 1;
53585352

5359-
/*
5360-
* Create a debugfs directory for the VM
5361-
*/
5362-
snprintf(buf, sizeof(buf), "vm%d", current->pid);
5363-
kvm->arch.debugfs_dir = debugfs_create_dir(buf, kvm_debugfs_dir);
5353+
return 0;
5354+
}
5355+
5356+
static int kvmppc_arch_create_vm_debugfs_hv(struct kvm *kvm)
5357+
{
53645358
kvmppc_mmu_debugfs_init(kvm);
53655359
if (radix_enabled())
53665360
kvmhv_radix_debugfs_init(kvm);
5367-
53685361
return 0;
53695362
}
53705363

@@ -5379,8 +5372,6 @@ static void kvmppc_free_vcores(struct kvm *kvm)
53795372

53805373
static void kvmppc_core_destroy_vm_hv(struct kvm *kvm)
53815374
{
5382-
debugfs_remove_recursive(kvm->arch.debugfs_dir);
5383-
53845375
if (!cpu_has_feature(CPU_FTR_ARCH_300))
53855376
kvm_hv_vm_deactivated();
53865377

@@ -6042,6 +6033,8 @@ static struct kvmppc_ops kvm_ops_hv = {
60426033
.svm_off = kvmhv_svm_off,
60436034
.enable_dawr1 = kvmhv_enable_dawr1,
60446035
.hash_v3_possible = kvmppc_hash_v3_possible,
6036+
.create_vcpu_debugfs = kvmppc_arch_create_vcpu_debugfs_hv,
6037+
.create_vm_debugfs = kvmppc_arch_create_vm_debugfs_hv,
60456038
};
60466039

60476040
static int kvm_init_subcore_bitmap(void)

arch/powerpc/kvm/book3s_xics.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,19 +1016,10 @@ DEFINE_SHOW_ATTRIBUTE(xics_debug);
10161016

10171017
static void xics_debugfs_init(struct kvmppc_xics *xics)
10181018
{
1019-
char *name;
1020-
1021-
name = kasprintf(GFP_KERNEL, "kvm-xics-%p", xics);
1022-
if (!name) {
1023-
pr_err("%s: no memory for name\n", __func__);
1024-
return;
1025-
}
1026-
1027-
xics->dentry = debugfs_create_file(name, 0444, arch_debugfs_dir,
1019+
xics->dentry = debugfs_create_file("xics", 0444, xics->kvm->debugfs_dentry,
10281020
xics, &xics_debug_fops);
10291021

1030-
pr_debug("%s: created %s\n", __func__, name);
1031-
kfree(name);
1022+
pr_debug("%s: created\n", __func__);
10321023
}
10331024

10341025
static struct kvmppc_ics *kvmppc_xics_create_ics(struct kvm *kvm,

arch/powerpc/kvm/book3s_xive.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,19 +2354,10 @@ DEFINE_SHOW_ATTRIBUTE(xive_debug);
23542354

23552355
static void xive_debugfs_init(struct kvmppc_xive *xive)
23562356
{
2357-
char *name;
2358-
2359-
name = kasprintf(GFP_KERNEL, "kvm-xive-%p", xive);
2360-
if (!name) {
2361-
pr_err("%s: no memory for name\n", __func__);
2362-
return;
2363-
}
2364-
2365-
xive->dentry = debugfs_create_file(name, S_IRUGO, arch_debugfs_dir,
2357+
xive->dentry = debugfs_create_file("xive", S_IRUGO, xive->kvm->debugfs_dentry,
23662358
xive, &xive_debug_fops);
23672359

2368-
pr_debug("%s: created %s\n", __func__, name);
2369-
kfree(name);
2360+
pr_debug("%s: created\n", __func__);
23702361
}
23712362

23722363
static void kvmppc_xive_init(struct kvm_device *dev)

arch/powerpc/kvm/book3s_xive_native.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,19 +1259,10 @@ DEFINE_SHOW_ATTRIBUTE(xive_native_debug);
12591259

12601260
static void xive_native_debugfs_init(struct kvmppc_xive *xive)
12611261
{
1262-
char *name;
1263-
1264-
name = kasprintf(GFP_KERNEL, "kvm-xive-%p", xive);
1265-
if (!name) {
1266-
pr_err("%s: no memory for name\n", __func__);
1267-
return;
1268-
}
1269-
1270-
xive->dentry = debugfs_create_file(name, 0444, arch_debugfs_dir,
1262+
xive->dentry = debugfs_create_file("xive", 0444, xive->kvm->debugfs_dentry,
12711263
xive, &xive_native_debug_fops);
12721264

1273-
pr_debug("%s: created %s\n", __func__, name);
1274-
kfree(name);
1265+
pr_debug("%s: created\n", __func__);
12751266
}
12761267

12771268
static void kvmppc_xive_native_init(struct kvm_device *dev)

arch/powerpc/kvm/e500.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ static struct kvmppc_ops kvm_ops_e500 = {
495495
.emulate_op = kvmppc_core_emulate_op_e500,
496496
.emulate_mtspr = kvmppc_core_emulate_mtspr_e500,
497497
.emulate_mfspr = kvmppc_core_emulate_mfspr_e500,
498+
.create_vcpu_debugfs = kvmppc_create_vcpu_debugfs_e500,
498499
};
499500

500501
static int __init kvmppc_e500_init(void)

arch/powerpc/kvm/e500mc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ static struct kvmppc_ops kvm_ops_e500mc = {
381381
.emulate_op = kvmppc_core_emulate_op_e500,
382382
.emulate_mtspr = kvmppc_core_emulate_mtspr_e500,
383383
.emulate_mfspr = kvmppc_core_emulate_mfspr_e500,
384+
.create_vcpu_debugfs = kvmppc_create_vcpu_debugfs_e500,
384385
};
385386

386387
static int __init kvmppc_e500mc_init(void)

0 commit comments

Comments
 (0)