Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 d56f5136b010 ("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

authored by

Alexey Kardashevskiy and committed by
Michael Ellerman
faf01aef c1c8a663

+51 -82
+2 -4
arch/powerpc/include/asm/kvm_host.h
··· 26 26 #include <asm/hvcall.h> 27 27 #include <asm/mce.h> 28 28 29 + #define __KVM_HAVE_ARCH_VCPU_DEBUGFS 30 + 29 31 #define KVM_MAX_VCPUS NR_CPUS 30 32 #define KVM_MAX_VCORES NR_CPUS 31 33 ··· 297 295 bool dawr1_enabled; 298 296 pgd_t *pgtable; 299 297 u64 process_table; 300 - struct dentry *debugfs_dir; 301 298 struct kvm_resize_hpt *resize_hpt; /* protected by kvm->lock */ 302 299 #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ 303 300 #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE ··· 674 673 u64 timing_min_duration[__NUMBER_OF_KVM_EXIT_TYPES]; 675 674 u64 timing_max_duration[__NUMBER_OF_KVM_EXIT_TYPES]; 676 675 u64 timing_last_exit; 677 - struct dentry *debugfs_exit_timing; 678 676 #endif 679 677 680 678 #ifdef CONFIG_PPC_BOOK3S ··· 831 831 struct kvmhv_tb_accumulator rm_exit; /* real-mode exit code */ 832 832 struct kvmhv_tb_accumulator guest_time; /* guest execution */ 833 833 struct kvmhv_tb_accumulator cede_time; /* time napping inside guest */ 834 - 835 - struct dentry *debugfs_dir; 836 834 #endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */ 837 835 }; 838 836
+2
arch/powerpc/include/asm/kvm_ppc.h
··· 314 314 int (*svm_off)(struct kvm *kvm); 315 315 int (*enable_dawr1)(struct kvm *kvm); 316 316 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); 317 319 }; 318 320 319 321 extern struct kvmppc_ops *kvmppc_hv_ops;
+1 -1
arch/powerpc/kvm/book3s_64_mmu_hv.c
··· 2112 2112 2113 2113 void kvmppc_mmu_debugfs_init(struct kvm *kvm) 2114 2114 { 2115 - debugfs_create_file("htab", 0400, kvm->arch.debugfs_dir, kvm, 2115 + debugfs_create_file("htab", 0400, kvm->debugfs_dentry, kvm, 2116 2116 &debugfs_htab_fops); 2117 2117 } 2118 2118
+1 -1
arch/powerpc/kvm/book3s_64_mmu_radix.c
··· 1454 1454 1455 1455 void kvmhv_radix_debugfs_init(struct kvm *kvm) 1456 1456 { 1457 - debugfs_create_file("radix", 0400, kvm->arch.debugfs_dir, kvm, 1457 + debugfs_create_file("radix", 0400, kvm->debugfs_dentry, kvm, 1458 1458 &debugfs_radix_fops); 1459 1459 } 1460 1460
+12 -19
arch/powerpc/kvm/book3s_hv.c
··· 2767 2767 }; 2768 2768 2769 2769 /* 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) 2771 2771 { 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, 2778 2773 &debugfs_timings_ops); 2774 + return 0; 2779 2775 } 2780 2776 2781 2777 #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) 2783 2779 { 2780 + return 0; 2784 2781 } 2785 2782 #endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */ 2786 2783 ··· 2899 2902 2900 2903 vcpu->arch.cpu_type = KVM_CPU_3S_64; 2901 2904 kvmppc_sanity_check(vcpu); 2902 - 2903 - debugfs_vcpu_init(vcpu, id); 2904 2905 2905 2906 return 0; 2906 2907 } ··· 5218 5223 static int kvmppc_core_init_vm_hv(struct kvm *kvm) 5219 5224 { 5220 5225 unsigned long lpcr, lpid; 5221 - char buf[32]; 5222 5226 int ret; 5223 5227 5224 5228 mutex_init(&kvm->arch.uvmem_lock); ··· 5350 5356 kvm->arch.smt_mode = 1; 5351 5357 kvm->arch.emul_smt_mode = 1; 5352 5358 5353 - /* 5354 - * Create a debugfs directory for the VM 5355 - */ 5356 - snprintf(buf, sizeof(buf), "vm%d", current->pid); 5357 - kvm->arch.debugfs_dir = debugfs_create_dir(buf, kvm_debugfs_dir); 5359 + return 0; 5360 + } 5361 + 5362 + static int kvmppc_arch_create_vm_debugfs_hv(struct kvm *kvm) 5363 + { 5358 5364 kvmppc_mmu_debugfs_init(kvm); 5359 5365 if (radix_enabled()) 5360 5366 kvmhv_radix_debugfs_init(kvm); 5361 - 5362 5367 return 0; 5363 5368 } 5364 5369 ··· 5372 5379 5373 5380 static void kvmppc_core_destroy_vm_hv(struct kvm *kvm) 5374 5381 { 5375 - debugfs_remove_recursive(kvm->arch.debugfs_dir); 5376 - 5377 5382 if (!cpu_has_feature(CPU_FTR_ARCH_300)) 5378 5383 kvm_hv_vm_deactivated(); 5379 5384 ··· 6033 6042 .svm_off = kvmhv_svm_off, 6034 6043 .enable_dawr1 = kvmhv_enable_dawr1, 6035 6044 .hash_v3_possible = kvmppc_hash_v3_possible, 6045 + .create_vcpu_debugfs = kvmppc_arch_create_vcpu_debugfs_hv, 6046 + .create_vm_debugfs = kvmppc_arch_create_vm_debugfs_hv, 6036 6047 }; 6037 6048 6038 6049 static int kvm_init_subcore_bitmap(void)
+2 -11
arch/powerpc/kvm/book3s_xics.c
··· 1016 1016 1017 1017 static void xics_debugfs_init(struct kvmppc_xics *xics) 1018 1018 { 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, 1028 1020 xics, &xics_debug_fops); 1029 1021 1030 - pr_debug("%s: created %s\n", __func__, name); 1031 - kfree(name); 1022 + pr_debug("%s: created\n", __func__); 1032 1023 } 1033 1024 1034 1025 static struct kvmppc_ics *kvmppc_xics_create_ics(struct kvm *kvm,
+2 -11
arch/powerpc/kvm/book3s_xive.c
··· 2354 2354 2355 2355 static void xive_debugfs_init(struct kvmppc_xive *xive) 2356 2356 { 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, 2366 2358 xive, &xive_debug_fops); 2367 2359 2368 - pr_debug("%s: created %s\n", __func__, name); 2369 - kfree(name); 2360 + pr_debug("%s: created\n", __func__); 2370 2361 } 2371 2362 2372 2363 static void kvmppc_xive_init(struct kvm_device *dev)
+2 -11
arch/powerpc/kvm/book3s_xive_native.c
··· 1259 1259 1260 1260 static void xive_native_debugfs_init(struct kvmppc_xive *xive) 1261 1261 { 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, 1271 1263 xive, &xive_native_debug_fops); 1272 1264 1273 - pr_debug("%s: created %s\n", __func__, name); 1274 - kfree(name); 1265 + pr_debug("%s: created\n", __func__); 1275 1266 } 1276 1267 1277 1268 static void kvmppc_xive_native_init(struct kvm_device *dev)
+1
arch/powerpc/kvm/e500.c
··· 495 495 .emulate_op = kvmppc_core_emulate_op_e500, 496 496 .emulate_mtspr = kvmppc_core_emulate_mtspr_e500, 497 497 .emulate_mfspr = kvmppc_core_emulate_mfspr_e500, 498 + .create_vcpu_debugfs = kvmppc_create_vcpu_debugfs_e500, 498 499 }; 499 500 500 501 static int __init kvmppc_e500_init(void)
+1
arch/powerpc/kvm/e500mc.c
··· 381 381 .emulate_op = kvmppc_core_emulate_op_e500, 382 382 .emulate_mtspr = kvmppc_core_emulate_mtspr_e500, 383 383 .emulate_mfspr = kvmppc_core_emulate_mfspr_e500, 384 + .create_vcpu_debugfs = kvmppc_create_vcpu_debugfs_e500, 384 385 }; 385 386 386 387 static int __init kvmppc_e500mc_init(void)
+13 -3
arch/powerpc/kvm/powerpc.c
··· 777 777 778 778 rcuwait_init(&vcpu->arch.wait); 779 779 vcpu->arch.waitp = &vcpu->arch.wait; 780 - kvmppc_create_vcpu_debugfs(vcpu, vcpu->vcpu_id); 781 780 return 0; 782 781 783 782 out_vcpu_uninit: ··· 792 793 { 793 794 /* Make sure we're not using the vcpu anymore */ 794 795 hrtimer_cancel(&vcpu->arch.dec_timer); 795 - 796 - kvmppc_remove_vcpu_debugfs(vcpu); 797 796 798 797 switch (vcpu->arch.irq_type) { 799 798 case KVMPPC_IRQ_MPIC: ··· 2518 2521 } 2519 2522 2520 2523 EXPORT_TRACEPOINT_SYMBOL_GPL(kvm_ppc_instr); 2524 + 2525 + void kvm_arch_create_vcpu_debugfs(struct kvm_vcpu *vcpu, struct dentry *debugfs_dentry) 2526 + { 2527 + if (vcpu->kvm->arch.kvm_ops->create_vcpu_debugfs) 2528 + vcpu->kvm->arch.kvm_ops->create_vcpu_debugfs(vcpu, debugfs_dentry); 2529 + } 2530 + 2531 + int kvm_arch_create_vm_debugfs(struct kvm *kvm) 2532 + { 2533 + if (kvm->arch.kvm_ops->create_vm_debugfs) 2534 + kvm->arch.kvm_ops->create_vm_debugfs(kvm); 2535 + return 0; 2536 + }
+5 -16
arch/powerpc/kvm/timing.c
··· 204 204 .release = single_release, 205 205 }; 206 206 207 - void kvmppc_create_vcpu_debugfs(struct kvm_vcpu *vcpu, unsigned int id) 207 + int kvmppc_create_vcpu_debugfs_e500(struct kvm_vcpu *vcpu, 208 + struct dentry *debugfs_dentry) 208 209 { 209 - static char dbg_fname[50]; 210 - struct dentry *debugfs_file; 211 - 212 - snprintf(dbg_fname, sizeof(dbg_fname), "vm%u_vcpu%u_timing", 213 - current->pid, id); 214 - debugfs_file = debugfs_create_file(dbg_fname, 0666, kvm_debugfs_dir, 215 - vcpu, &kvmppc_exit_timing_fops); 216 - 217 - vcpu->arch.debugfs_exit_timing = debugfs_file; 218 - } 219 - 220 - void kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu) 221 - { 222 - debugfs_remove(vcpu->arch.debugfs_exit_timing); 223 - vcpu->arch.debugfs_exit_timing = NULL; 210 + debugfs_create_file("timing", 0666, debugfs_dentry, 211 + vcpu, &kvmppc_exit_timing_fops); 212 + return 0; 224 213 }
+7 -5
arch/powerpc/kvm/timing.h
··· 14 14 #ifdef CONFIG_KVM_EXIT_TIMING 15 15 void kvmppc_init_timing_stats(struct kvm_vcpu *vcpu); 16 16 void kvmppc_update_timing_stats(struct kvm_vcpu *vcpu); 17 - void kvmppc_create_vcpu_debugfs(struct kvm_vcpu *vcpu, unsigned int id); 18 - void kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu); 17 + int kvmppc_create_vcpu_debugfs_e500(struct kvm_vcpu *vcpu, 18 + struct dentry *debugfs_dentry); 19 19 20 20 static inline void kvmppc_set_exit_type(struct kvm_vcpu *vcpu, int type) 21 21 { ··· 26 26 /* if exit timing is not configured there is no need to build the c file */ 27 27 static inline void kvmppc_init_timing_stats(struct kvm_vcpu *vcpu) {} 28 28 static inline void kvmppc_update_timing_stats(struct kvm_vcpu *vcpu) {} 29 - static inline void kvmppc_create_vcpu_debugfs(struct kvm_vcpu *vcpu, 30 - unsigned int id) {} 31 - static inline void kvmppc_remove_vcpu_debugfs(struct kvm_vcpu *vcpu) {} 29 + static inline int kvmppc_create_vcpu_debugfs_e500(struct kvm_vcpu *vcpu, 30 + struct dentry *debugfs_dentry) 31 + { 32 + return 0; 33 + } 32 34 static inline void kvmppc_set_exit_type(struct kvm_vcpu *vcpu, int type) {} 33 35 #endif /* CONFIG_KVM_EXIT_TIMING */ 34 36