KVM: PPC: Merge powerpc's debugfs entry content into generic entry
Subsystems (3)
PATCH v3 1/1 KVM: PPC: Merge powerpc's debugfs entry content into generic entry
At the moment KVM on PPC creates 3 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).
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").
---
Changes:
v3:
* reworked commit log, especially, the bit about removing vcpus
v2:
* handled powerpc-booke
* s/kvm/vm/ in arch hooks
--- arch/powerpc/include/asm/kvm_host.h | 6 ++--- arch/powerpc/include/asm/kvm_ppc.h | 2 ++ arch/powerpc/kvm/timing.h | 9 ++++---- arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +- arch/powerpc/kvm/book3s_64_mmu_radix.c | 2 +- arch/powerpc/kvm/book3s_hv.c | 31 ++++++++++---------------- arch/powerpc/kvm/e500.c | 1 + arch/powerpc/kvm/e500mc.c | 1 + arch/powerpc/kvm/powerpc.c | 16 ++++++++++--- arch/powerpc/kvm/timing.c | 20 ++++------------- 10 files changed, 41 insertions(+), 49 deletions(-)
arch/powerpc/include/asm/kvm_host.h +2 -4
@@ -26,6 +26,8 @@#include <asm/hvcall.h> #include <asm/mce.h> +#define __KVM_HAVE_ARCH_VCPU_DEBUGFS +#define KVM_MAX_VCPUS NR_CPUS#define KVM_MAX_VCORES NR_CPUS
@@ -295,7 +297,6 @@ struct kvm_arch {bool dawr1_enabled;pgd_t *pgtable;u64 process_table; -struct dentry *debugfs_dir;struct kvm_resize_hpt *resize_hpt;/* protected by kvm->lock */ #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
@@ -673,7 +674,6 @@ struct kvm_vcpu_arch {u64 timing_min_duration[__NUMBER_OF_KVM_EXIT_TYPES];u64 timing_max_duration[__NUMBER_OF_KVM_EXIT_TYPES];u64 timing_last_exit; -struct dentry *debugfs_exit_timing;#endif #ifdef CONFIG_PPC_BOOK3S
@@ -829,8 +829,6 @@ struct kvm_vcpu_arch {struct kvmhv_tb_accumulator rm_exit;/* real-mode exit code */ struct kvmhv_tb_accumulator guest_time;/* guest execution */ struct kvmhv_tb_accumulator cede_time;/* time napping inside guest */ - -struct dentry *debugfs_dir;#endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */ };
arch/powerpc/include/asm/kvm_ppc.h +2 -0
@@ -316,6 +316,8 @@ struct kvmppc_ops {int (*svm_off)(struct kvm *kvm);int (*enable_dawr1)(struct kvm *kvm);bool (*hash_v3_possible)(void ); +int (*create_vm_debugfs)(struct kvm *kvm); +int (*create_vcpu_debugfs)(struct kvm_vcpu *vcpu,struct dentry *debugfs_dentry); };extern struct kvmppc_ops *kvmppc_hv_ops;
arch/powerpc/kvm/timing.h +4 -5
@@ -14,8 +14,8 @@#ifdef CONFIG_KVM_EXIT_TIMING void kvmppc_init_timing_stats (struct kvm_vcpu *vcpu);void kvmppc_update_timing_stats (struct kvm_vcpu *vcpu); -void kvmppc_create_vcpu_debugfs (struct kvm_vcpu *vcpu,unsigned int id); -void kvmppc_remove_vcpu_debugfs (struct kvm_vcpu *vcpu); +void kvmppc_create_vcpu_debugfs_e500 (struct kvm_vcpu *vcpu, +struct dentry *debugfs_dentry);static inline void kvmppc_set_exit_type (struct kvm_vcpu *vcpu,int type) {
@@ -26,9 +26,8 @@ static inline void kvmppc_set_exit_type(struct kvm_vcpu *vcpu, int type)/* if exit timing is not configured there is no need to build the c file */ static inline void kvmppc_init_timing_stats (struct kvm_vcpu *vcpu) {}static inline void kvmppc_update_timing_stats (struct kvm_vcpu *vcpu) {} -static inline void kvmppc_create_vcpu_debugfs (struct kvm_vcpu *vcpu, -unsigned int id) {} -static inline void kvmppc_remove_vcpu_debugfs (struct kvm_vcpu *vcpu) {} +static inline void kvmppc_create_vcpu_debugfs_e500 (struct kvm_vcpu *vcpu, +struct dentry *debugfs_dentry) {}static inline void kvmppc_set_exit_type (struct kvm_vcpu *vcpu,int type) {}#endif /* CONFIG_KVM_EXIT_TIMING */
arch/powerpc/kvm/book3s_64_mmu_hv.c +1 -1
@@ -2112,7 +2112,7 @@ static const struct file_operations debugfs_htab_fops = {void kvmppc_mmu_debugfs_init (struct kvm *kvm) { -debugfs_create_file ("htab" ,0400 , kvm->arch.debugfs_dir, kvm, +debugfs_create_file ("htab" ,0400 , kvm->debugfs_dentry, kvm, &debugfs_htab_fops); }
arch/powerpc/kvm/book3s_64_mmu_radix.c +1 -1
@@ -1454,7 +1454,7 @@ static const struct file_operations debugfs_radix_fops = {void kvmhv_radix_debugfs_init (struct kvm *kvm) { -debugfs_create_file ("radix" ,0400 , kvm->arch.debugfs_dir, kvm, +debugfs_create_file ("radix" ,0400 , kvm->debugfs_dentry, kvm, &debugfs_radix_fops); }
arch/powerpc/kvm/book3s_hv.c +12 -19
@@ -2768,20 +2768,17 @@ static const struct file_operations debugfs_timings_ops = { };/* Create a debugfs directory for the vcpu */ -static void debugfs_vcpu_init (struct kvm_vcpu *vcpu,unsigned int id) +static int kvmppc_arch_create_vcpu_debugfs_hv (struct kvm_vcpu *vcpu,struct dentry *debugfs_dentry) { -char buf[16 ]; -struct kvm *kvm = vcpu->kvm; - -snprintf (buf,sizeof (buf),"vcpu%u" , id); - vcpu->arch.debugfs_dir =debugfs_create_dir (buf, kvm->arch.debugfs_dir); -debugfs_create_file ("timings" ,0444 , vcpu->arch.debugfs_dir, vcpu, +debugfs_create_file ("timings" ,0444 , debugfs_dentry, vcpu, &debugfs_timings_ops); +return 0 ; }#else /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */ -static void debugfs_vcpu_init (struct kvm_vcpu *vcpu,unsigned int id) +static int kvmppc_arch_create_vcpu_debugfs_hv (struct kvm_vcpu *vcpu,struct dentry *debugfs_dentry) { +return 0 ; }#endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */
@@ -2904,8 +2901,6 @@ static int kvmppc_core_vcpu_create_hv(struct kvm_vcpu *vcpu) vcpu->arch.cpu_type =KVM_CPU_3S_64 ;kvmppc_sanity_check (vcpu); -debugfs_vcpu_init (vcpu, id); -return 0 ; }
@@ -5226,7 +5221,6 @@ void kvmppc_free_host_rm_ops(void)static int kvmppc_core_init_vm_hv (struct kvm *kvm) {unsigned long lpcr, lpid; -char buf[32 ];int ret;mutex_init (&kvm->arch.uvmem_lock);
@@ -5359,15 +5353,14 @@ static int kvmppc_core_init_vm_hv(struct kvm *kvm) kvm->arch.smt_mode =1 ; kvm->arch.emul_smt_mode =1 ; -/* -* Create a debugfs directory for the VM -*/ -snprintf (buf,sizeof (buf),"vm%d" , current->pid); - kvm->arch.debugfs_dir =debugfs_create_dir (buf, kvm_debugfs_dir); +return 0 ; +} + +static int kvmppc_arch_create_vm_debugfs_hv (struct kvm *kvm) +{kvmppc_mmu_debugfs_init (kvm);if (radix_enabled ())kvmhv_radix_debugfs_init (kvm); -return 0 ; }
@@ -5382,8 +5375,6 @@ static void kvmppc_free_vcores(struct kvm *kvm)static void kvmppc_core_destroy_vm_hv (struct kvm *kvm) { -debugfs_remove_recursive (kvm->arch.debugfs_dir); -if (!cpu_has_feature (CPU_FTR_ARCH_300 ))kvm_hv_vm_deactivated ();
@@ -6044,6 +6035,8 @@ static struct kvmppc_ops kvm_ops_hv = { .svm_off = kvmhv_svm_off, .enable_dawr1 = kvmhv_enable_dawr1, .hash_v3_possible = kvmppc_hash_v3_possible, + .create_vcpu_debugfs = kvmppc_arch_create_vcpu_debugfs_hv, + .create_vm_debugfs = kvmppc_arch_create_vm_debugfs_hv, };static int kvm_init_subcore_bitmap (void )
arch/powerpc/kvm/e500.c +1 -0
@@ -495,6 +495,7 @@ static struct kvmppc_ops kvm_ops_e500 = { .emulate_op = kvmppc_core_emulate_op_e500, .emulate_mtspr = kvmppc_core_emulate_mtspr_e500, .emulate_mfspr = kvmppc_core_emulate_mfspr_e500, + .create_vcpu_debugfs = kvmppc_create_vcpu_debugfs_e500, };static int __init kvmppc_e500_init (void )
arch/powerpc/kvm/e500mc.c +1 -0
@@ -381,6 +381,7 @@ static struct kvmppc_ops kvm_ops_e500mc = { .emulate_op = kvmppc_core_emulate_op_e500, .emulate_mtspr = kvmppc_core_emulate_mtspr_e500, .emulate_mfspr = kvmppc_core_emulate_mfspr_e500, + .create_vcpu_debugfs = kvmppc_create_vcpu_debugfs_e500, };static int __init kvmppc_e500mc_init (void )
arch/powerpc/kvm/powerpc.c +13 -3
@@ -763,7 +763,6 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) goto out_vcpu_uninit; vcpu->arch.waitp = &vcpu->wait; -kvmppc_create_vcpu_debugfs (vcpu, vcpu->vcpu_id);return 0 ; out_vcpu_uninit:
@@ -780,8 +779,6 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)/* Make sure we're not using the vcpu anymore */ hrtimer_cancel (&vcpu->arch.dec_timer); -kvmppc_remove_vcpu_debugfs (vcpu); -switch (vcpu->arch.irq_type) {case KVMPPC_IRQ_MPIC :kvmppc_mpic_disconnect_vcpu (vcpu->arch.mpic, vcpu);
@@ -2505,3 +2502,16 @@ int kvm_arch_init(void *opaque) }EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_ppc_instr); + +void kvm_arch_create_vcpu_debugfs (struct kvm_vcpu *vcpu,struct dentry *debugfs_dentry) +{ +if (vcpu->kvm->arch.kvm_ops->create_vcpu_debugfs) + vcpu->kvm->arch.kvm_ops->create_vcpu_debugfs (vcpu, debugfs_dentry); +} + +int kvm_arch_create_vm_debugfs (struct kvm *kvm) +{ +if (kvm->arch.kvm_ops->create_vm_debugfs) + kvm->arch.kvm_ops->create_vm_debugfs (kvm); +return 0 ; +}
arch/powerpc/kvm/timing.c +4 -16
@@ -204,21 +204,9 @@ static const struct file_operations kvmppc_exit_timing_fops = { .release = single_release, }; -void kvmppc_create_vcpu_debugfs (struct kvm_vcpu *vcpu,unsigned int id) +void kvmppc_create_vcpu_debugfs_e500 (struct kvm_vcpu *vcpu, +struct dentry *debugfs_dentry) { -static char dbg_fname[50 ]; -struct dentry *debugfs_file; - -snprintf (dbg_fname,sizeof (dbg_fname),"vm%u_vcpu%u_timing" , - current->pid, id); - debugfs_file =debugfs_create_file (dbg_fname,0666 , kvm_debugfs_dir, - vcpu, &kvmppc_exit_timing_fops); - - vcpu->arch.debugfs_exit_timing = debugfs_file; -} - -void kvmppc_remove_vcpu_debugfs (struct kvm_vcpu *vcpu) -{ -debugfs_remove (vcpu->arch.debugfs_exit_timing); - vcpu->arch.debugfs_exit_timing =NULL ; +debugfs_create_file ("timing" ,0666 , debugfs_dentry, + vcpu, &kvmppc_exit_timing_fops); }
Signature · 1 line
2.30.2
kernel test robot
build botThank you for the patch! Yet something to improve:
Hi Alexey,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on powerpc/topic/ppc-kvm]
[also build test ERROR on v5.16-rc5]
[cannot apply to next-20211214]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Alexey-Kardashevskiy/KVM-PPC-Merge-powerpc-s-debugfs-entry-content-into-generic-entry/20211215-094051 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git topic/ppc-kvm config: powerpc-randconfig-r003-20211214 (https://download.01.org/0day-ci/archive/20211215/[email protected]/config) compiler: powerpc-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/bb4c492cb444748049b4392c1d6f97ca5c82f846
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Alexey-Kardashevskiy/KVM-PPC-Merge-powerpc-s-debugfs-entry-content-into-generic-entry/20211215-094051 git checkout bb4c492cb444748049b4392c1d6f97ca5c82f846
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=powerpc SHELL=/bin/bash arch/powerpc/kvm/
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> arch/powerpc/kvm/e500.c:498:32: error: initialization of 'int (*)(struct kvm_vcpu *, struct dentry *)' from incompatible pointer type 'void (*)(struct kvm_vcpu *, struct dentry *)' [-Werror=incompatible-pointer-types]
498 | .create_vcpu_debugfs = kvmppc_create_vcpu_debugfs_e500,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/powerpc/kvm/e500.c:498:32: note: (near initialization for 'kvm_ops_e500.create_vcpu_debugfs')
cc1: all warnings being treated as errors
Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for HOTPLUG_CPU
Depends on SMP && (PPC_PSERIES || PPC_PMAC || PPC_POWERNV || FSL_SOC_BOOKE Selected by
- PM_SLEEP_SMP && SMP && (ARCH_SUSPEND_POSSIBLE || ARCH_HIBERNATION_POSSIBLE && PM_SLEEP
vim +498 arch/powerpc/kvm/e500.c
483
484 static struct kvmppc_ops kvm_ops_e500 = {
485 .get_sregs = kvmppc_core_get_sregs_e500,
486 .set_sregs = kvmppc_core_set_sregs_e500,
487 .get_one_reg = kvmppc_get_one_reg_e500,
488 .set_one_reg = kvmppc_set_one_reg_e500,
489 .vcpu_load = kvmppc_core_vcpu_load_e500,
490 .vcpu_put = kvmppc_core_vcpu_put_e500,
491 .vcpu_create = kvmppc_core_vcpu_create_e500,
492 .vcpu_free = kvmppc_core_vcpu_free_e500,
493 .init_vm = kvmppc_core_init_vm_e500,
494 .destroy_vm = kvmppc_core_destroy_vm_e500,
495 .emulate_op = kvmppc_core_emulate_op_e500,
496 .emulate_mtspr = kvmppc_core_emulate_mtspr_e500,
497 .emulate_mfspr = kvmppc_core_emulate_mfspr_e500,
> 498 .create_vcpu_debugfs = kvmppc_create_vcpu_debugfs_e500,
499 };
500
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
Quoted 18 lines · Alexey Kardashevskiy
At the moment KVM on PPC creates 3 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).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 tokvm_arch_create_vcpu_debugfs().This defines 2 hooks in
kvmppc_opsthat allow specific KVM implementations add necessary entries, this adds the_e500suffix tokvmppc_create_vcpu_debugfs_e500()to make it clear what platform it is for.
Quoted 8 lines
This makes use of already existing
kvm_arch_create_vcpu_debugfs()on PPC.This removes no more used
debugfs_dirpointers from PPCkvm_archstructs.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: letkvm_destroy_vm_debugfsclean up vCPU debugfs directories").
It would nice to also move the KVM device debugfs files :
/sys/kernel/debug/powerpc/kvm-xive-%p
These are dynamically created and destroyed at run time depending on the interrupt mode negociated by CAS. It might be more complex ?
C.
Quoted 307 lines
Suggested-by Fabiano Rosas <[email protected]>Signed-off-by Alexey Kardashevskiy <[email protected]>---
Changes:
v3:
* reworked commit log, especially, the bit about removing vcpusv2:
* handled powerpc-booke
* s/kvm/vm/ in arch hooks--- arch/powerpc/include/asm/kvm_host.h | 6 ++--- arch/powerpc/include/asm/kvm_ppc.h | 2 ++ arch/powerpc/kvm/timing.h | 9 ++++---- arch/powerpc/kvm/book3s_64_mmu_hv.c | 2 +- arch/powerpc/kvm/book3s_64_mmu_radix.c | 2 +- arch/powerpc/kvm/book3s_hv.c | 31 ++++++++++---------------- arch/powerpc/kvm/e500.c | 1 + arch/powerpc/kvm/e500mc.c | 1 + arch/powerpc/kvm/powerpc.c | 16 ++++++++++--- arch/powerpc/kvm/timing.c | 20 ++++------------- 10 files changed, 41 insertions(+), 49 deletions(-)arch/powerpc/include/asm/kvm_host.h +2
-4@@ -26,6 +26,8 @@#include <asm/hvcall.h> #include <asm/mce.h> +#define __KVM_HAVE_ARCH_VCPU_DEBUGFS +#define KVM_MAX_VCPUS NR_CPUS#define KVM_MAX_VCORES NR_CPUS@@ -295,7 +297,6 @@ struct kvm_arch {bool dawr1_enabled;pgd_t *pgtable;u64 process_table; -struct dentry *debugfs_dir;struct kvm_resize_hpt *resize_hpt;/* protected by kvm->lock */ #endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */ #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE @@ -673,7 +674,6 @@ struct kvm_vcpu_arch {u64 timing_min_duration[__NUMBER_OF_KVM_EXIT_TYPES];u64 timing_max_duration[__NUMBER_OF_KVM_EXIT_TYPES];u64 timing_last_exit; -struct dentry *debugfs_exit_timing;#endif #ifdef CONFIG_PPC_BOOK3S @@ -829,8 +829,6 @@ struct kvm_vcpu_arch {struct kvmhv_tb_accumulator rm_exit;/* real-mode exit code */ struct kvmhv_tb_accumulator guest_time;/* guest execution */ struct kvmhv_tb_accumulator cede_time;/* time napping inside guest */ - -struct dentry *debugfs_dir;#endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */ };arch/powerpc/include/asm/kvm_ppc.h +2
-0@@ -316,6 +316,8 @@ struct kvmppc_ops {int (*svm_off)(struct kvm *kvm);int (*enable_dawr1)(struct kvm *kvm);bool (*hash_v3_possible)(void ); +int (*create_vm_debugfs)(struct kvm *kvm); +int (*create_vcpu_debugfs)(struct kvm_vcpu *vcpu,struct dentry *debugfs_dentry); };extern struct kvmppc_ops *kvmppc_hv_ops;arch/powerpc/kvm/timing.h +4
-5@@ -14,8 +14,8 @@#ifdef CONFIG_KVM_EXIT_TIMING void kvmppc_init_timing_stats (struct kvm_vcpu *vcpu);void kvmppc_update_timing_stats (struct kvm_vcpu *vcpu); -void kvmppc_create_vcpu_debugfs (struct kvm_vcpu *vcpu,unsigned int id); -void kvmppc_remove_vcpu_debugfs (struct kvm_vcpu *vcpu); +void kvmppc_create_vcpu_debugfs_e500 (struct kvm_vcpu *vcpu, +struct dentry *debugfs_dentry);static inline void kvmppc_set_exit_type (struct kvm_vcpu *vcpu,int type) {@@ -26,9 +26,8 @@ static inline void kvmppc_set_exit_type(struct kvm_vcpu *vcpu, int type)/* if exit timing is not configured there is no need to build the c file */ static inline void kvmppc_init_timing_stats (struct kvm_vcpu *vcpu) {}static inline void kvmppc_update_timing_stats (struct kvm_vcpu *vcpu) {} -static inline void kvmppc_create_vcpu_debugfs (struct kvm_vcpu *vcpu, -unsigned int id) {} -static inline void kvmppc_remove_vcpu_debugfs (struct kvm_vcpu *vcpu) {} +static inline void kvmppc_create_vcpu_debugfs_e500 (struct kvm_vcpu *vcpu, +struct dentry *debugfs_dentry) {}static inline void kvmppc_set_exit_type (struct kvm_vcpu *vcpu,int type) {}#endif /* CONFIG_KVM_EXIT_TIMING */ arch/powerpc/kvm/book3s_64_mmu_hv.c +1
-1@@ -2112,7 +2112,7 @@ static const struct file_operations debugfs_htab_fops = {void kvmppc_mmu_debugfs_init (struct kvm *kvm) { -debugfs_create_file ("htab" ,0400 , kvm->arch.debugfs_dir, kvm, +debugfs_create_file ("htab" ,0400 , kvm->debugfs_dentry, kvm, &debugfs_htab_fops); }arch/powerpc/kvm/book3s_64_mmu_radix.c +1
-1@@ -1454,7 +1454,7 @@ static const struct file_operations debugfs_radix_fops = {void kvmhv_radix_debugfs_init (struct kvm *kvm) { -debugfs_create_file ("radix" ,0400 , kvm->arch.debugfs_dir, kvm, +debugfs_create_file ("radix" ,0400 , kvm->debugfs_dentry, kvm, &debugfs_radix_fops); }arch/powerpc/kvm/book3s_hv.c +12
-19@@ -2768,20 +2768,17 @@ static const struct file_operations debugfs_timings_ops = { };/* Create a debugfs directory for the vcpu */ -static void debugfs_vcpu_init (struct kvm_vcpu *vcpu,unsigned int id) +static int kvmppc_arch_create_vcpu_debugfs_hv (struct kvm_vcpu *vcpu,struct dentry *debugfs_dentry) { -char buf[16 ]; -struct kvm *kvm = vcpu->kvm; - -snprintf (buf,sizeof (buf),"vcpu%u" , id); - vcpu->arch.debugfs_dir =debugfs_create_dir (buf, kvm->arch.debugfs_dir); -debugfs_create_file ("timings" ,0444 , vcpu->arch.debugfs_dir, vcpu, +debugfs_create_file ("timings" ,0444 , debugfs_dentry, vcpu, &debugfs_timings_ops); +return 0 ; }#else /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */ -static void debugfs_vcpu_init (struct kvm_vcpu *vcpu,unsigned int id) +static int kvmppc_arch_create_vcpu_debugfs_hv (struct kvm_vcpu *vcpu,struct dentry *debugfs_dentry) { +return 0 ; }#endif /* CONFIG_KVM_BOOK3S_HV_EXIT_TIMING */ @@ -2904,8 +2901,6 @@ static int kvmppc_core_vcpu_create_hv(struct kvm_vcpu *vcpu) vcpu->arch.cpu_type =KVM_CPU_3S_64 ;kvmppc_sanity_check (vcpu); -debugfs_vcpu_init (vcpu, id); -return 0 ; }@@ -5226,7 +5221,6 @@ void kvmppc_free_host_rm_ops(void)static int kvmppc_core_init_vm_hv (struct kvm *kvm) {unsigned long lpcr, lpid; -char buf[32 ];int ret;mutex_init (&kvm->arch.uvmem_lock);@@ -5359,15 +5353,14 @@ static int kvmppc_core_init_vm_hv(struct kvm *kvm) kvm->arch.smt_mode =1 ; kvm->arch.emul_smt_mode =1 ; -/* -* Create a debugfs directory for the VM -*/ -snprintf (buf,sizeof (buf),"vm%d" , current->pid); - kvm->arch.debugfs_dir =debugfs_create_dir (buf, kvm_debugfs_dir); +return 0 ; +} + +static int kvmppc_arch_create_vm_debugfs_hv (struct kvm *kvm) +{kvmppc_mmu_debugfs_init (kvm);if (radix_enabled ())kvmhv_radix_debugfs_init (kvm); -return 0 ; }@@ -5382,8 +5375,6 @@ static void kvmppc_free_vcores(struct kvm *kvm)static void kvmppc_core_destroy_vm_hv (struct kvm *kvm) { -debugfs_remove_recursive (kvm->arch.debugfs_dir); -if (!cpu_has_feature (CPU_FTR_ARCH_300 ))kvm_hv_vm_deactivated ();@@ -6044,6 +6035,8 @@ static struct kvmppc_ops kvm_ops_hv = { .svm_off = kvmhv_svm_off, .enable_dawr1 = kvmhv_enable_dawr1, .hash_v3_possible = kvmppc_hash_v3_possible, + .create_vcpu_debugfs = kvmppc_arch_create_vcpu_debugfs_hv, + .create_vm_debugfs = kvmppc_arch_create_vm_debugfs_hv, };static int kvm_init_subcore_bitmap (void )arch/powerpc/kvm/e500.c +1
-0@@ -495,6 +495,7 @@ static struct kvmppc_ops kvm_ops_e500 = { .emulate_op = kvmppc_core_emulate_op_e500, .emulate_mtspr = kvmppc_core_emulate_mtspr_e500, .emulate_mfspr = kvmppc_core_emulate_mfspr_e500, + .create_vcpu_debugfs = kvmppc_create_vcpu_debugfs_e500, };static int __init kvmppc_e500_init (void )arch/powerpc/kvm/e500mc.c +1
-0@@ -381,6 +381,7 @@ static struct kvmppc_ops kvm_ops_e500mc = { .emulate_op = kvmppc_core_emulate_op_e500, .emulate_mtspr = kvmppc_core_emulate_mtspr_e500, .emulate_mfspr = kvmppc_core_emulate_mfspr_e500, + .create_vcpu_debugfs = kvmppc_create_vcpu_debugfs_e500, };static int __init kvmppc_e500mc_init (void )arch/powerpc/kvm/powerpc.c +13
-3@@ -763,7 +763,6 @@ int kvm_arch_vcpu_create(struct kvm_vcpu *vcpu) goto out_vcpu_uninit; vcpu->arch.waitp = &vcpu->wait; -kvmppc_create_vcpu_debugfs (vcpu, vcpu->vcpu_id);return 0 ; out_vcpu_uninit:@@ -780,8 +779,6 @@ void kvm_arch_vcpu_destroy(struct kvm_vcpu *vcpu)/* Make sure we're not using the vcpu anymore */ hrtimer_cancel (&vcpu->arch.dec_timer); -kvmppc_remove_vcpu_debugfs (vcpu); -switch (vcpu->arch.irq_type) {case KVMPPC_IRQ_MPIC :kvmppc_mpic_disconnect_vcpu (vcpu->arch.mpic, vcpu);@@ -2505,3 +2502,16 @@ int kvm_arch_init(void *opaque) }EXPORT_TRACEPOINT_SYMBOL_GPL (kvm_ppc_instr); + +void kvm_arch_create_vcpu_debugfs (struct kvm_vcpu *vcpu,struct dentry *debugfs_dentry) +{ +if (vcpu->kvm->arch.kvm_ops->create_vcpu_debugfs) + vcpu->kvm->arch.kvm_ops->create_vcpu_debugfs (vcpu, debugfs_dentry); +} + +int kvm_arch_create_vm_debugfs (struct kvm *kvm) +{ +if (kvm->arch.kvm_ops->create_vm_debugfs) + kvm->arch.kvm_ops->create_vm_debugfs (kvm); +return 0 ; +}arch/powerpc/kvm/timing.c +4
-16@@ -204,21 +204,9 @@ static const struct file_operations kvmppc_exit_timing_fops = { .release = single_release, }; -void kvmppc_create_vcpu_debugfs (struct kvm_vcpu *vcpu,unsigned int id) +void kvmppc_create_vcpu_debugfs_e500 (struct kvm_vcpu *vcpu, +struct dentry *debugfs_dentry) { -static char dbg_fname[50 ]; -struct dentry *debugfs_file; - -snprintf (dbg_fname,sizeof (dbg_fname),"vm%u_vcpu%u_timing" , - current->pid, id); - debugfs_file =debugfs_create_file (dbg_fname,0666 , kvm_debugfs_dir, - vcpu, &kvmppc_exit_timing_fops); - - vcpu->arch.debugfs_exit_timing = debugfs_file; -} - -void kvmppc_remove_vcpu_debugfs (struct kvm_vcpu *vcpu) -{ -debugfs_remove (vcpu->arch.debugfs_exit_timing); - vcpu->arch.debugfs_exit_timing =NULL ; +debugfs_create_file ("timing" ,0666 , debugfs_dentry, + vcpu, &kvmppc_exit_timing_fops); }
Quoted 28 lines · Cédric Le Goater
Quoted 18 lines · Alexey Kardashevskiy
At the moment KVM on PPC creates 3 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).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 tokvm_arch_create_vcpu_debugfs().This defines 2 hooks in
kvmppc_opsthat allow specific KVM implementations add necessary entries, this adds the_e500suffix tokvmppc_create_vcpu_debugfs_e500()to make it clear what platform it is for.Quoted 8 lines
This makes use of already existing
kvm_arch_create_vcpu_debugfs()on PPC.This removes no more used
debugfs_dirpointers from PPCkvm_archstructs.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: letkvm_destroy_vm_debugfsclean up vCPU debugfs directories").
Quoted 6 lines
It would nice to also move the KVM device debugfs files :
/sys/kernel/debug/powerpc/kvm-xive-%p
These are dynamically created and destroyed at run time depending on the interrupt mode negociated by CAS. It might be more complex ?
With this addition:
(quoted diff) +0 -0
b/arch/powerpc/kvm/book3s_xive_native.c
index 99db9ac49901..511f643e2875 100644
arch/powerpc/kvm/book3s_xive_native.c +0 -0
@@ -1267,10 +1267,10 @@ static void xive_native_debugfs_init(struct
kvmppc_xive *xive)
return;
}- xive->dentry = debugfs_create_file(name, 0444, arch_debugfs_dir,
+ xive->dentry = debugfs_create_file(name, 0444,xive->kvm->debugfs_dentry,
xive, &xive_native_debug_fops);
it looks fine, this is "before":
root@zz1:/sys/kernel/debug# find -iname "*xive*" ./slab/xive-provision ./powerpc/kvm-xive-c0000000208c0000 ./powerpc/xive
and this is "after" the patch applied.
root@zz1:/sys/kernel/debug# find -iname "*xive*" ./kvm/29058-11/kvm-xive-c0000000208c0000 ./slab/xive-provision ./powerpc/xive
I'll repost unless there is something more to it. Thanks,
Signature · 1 line
Alexey
Quoted 64 lines · Alexey Kardashevskiy
Quoted 28 lines · Cédric Le Goater
Quoted 18 lines · Alexey Kardashevskiy
At the moment KVM on PPC creates 3 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).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 tokvm_arch_create_vcpu_debugfs().This defines 2 hooks in
kvmppc_opsthat allow specific KVM implementations add necessary entries, this adds the_e500suffix tokvmppc_create_vcpu_debugfs_e500()to make it clear what platform it is for.Quoted 8 lines
This makes use of already existing
kvm_arch_create_vcpu_debugfs()on PPC.This removes no more used
debugfs_dirpointers from PPCkvm_archstructs.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: letkvm_destroy_vm_debugfsclean up vCPU debugfs directories").Quoted 6 lines
It would nice to also move the KVM device debugfs files :
/sys/kernel/debug/powerpc/kvm-xive-%p
These are dynamically created and destroyed at run time depending on the interrupt mode negociated by CAS. It might be more complex ?
With this addition:
arch/powerpc/kvm/book3s_xive_native.c +1
-1@@ -1267,10 +1267,10 @@ static void xive_native_debugfs_init(struct kvmppc_xive *xive) return; } - xive->dentry =debugfs_create_file (name,0444 , arch_debugfs_dir, + xive->dentry =debugfs_create_file (name,0444 , xive->kvm->debugfs_dentry, xive, &xive_native_debug_fops);it looks fine, this is "before":
root@zz1:/sys/kernel/debug# find -iname "*xive*" ./slab/xive-provision ./powerpc/kvm-xive-c0000000208c0000 ./powerpc/xive
Quoted 7 lines
and this is "after" the patch applied.
root@zz1:/sys/kernel/debug# find -iname "*xive*" ./kvm/29058-11/kvm-xive-c0000000208c0000 ./slab/xive-provision ./powerpc/xive
I think "./kvm/29058-11/xive" should be enough now. The KVM prefix is redundant and so is the %p which was used to distinguish VMs.
The same change could be done for the KVM XICS device.
Thanks,
C.