Re: [PATCH kernel v3] KVM: PPC: Merge powerpc's debugfs entry content into generic entry
On 12/17/21 04:07, Alexey Kardashevskiy wrote: On 12/16/21 05:11, Cédric Le Goater wrote: On 12/15/21 02:33, Alexey Kardashevskiy wrote: 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"). 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: diff --git a/arch/powerpc/kvm/book3s_xive_native.c b/arch/powerpc/kvm/book3s_xive_native.c index 99db9ac49901..511f643e2875 100644 --- a/arch/powerpc/kvm/book3s_xive_native.c +++ b/arch/powerpc/kvm/book3s_xive_native.c @@ -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, _native_debug_fops); it looks fine, this is "before": root@zz1:/sys/kernel/debug# find -iname "*xive*" ./slab/xive-provision ./powerpc/kvm-xive-c000208c ./powerpc/xive and this is "after" the patch applied. root@zz1:/sys/kernel/debug# find -iname "*xive*" ./kvm/29058-11/kvm-xive-c000208c ./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.
Re: [PATCH kernel v3] KVM: PPC: Merge powerpc's debugfs entry content into generic entry
On 12/16/21 05:11, Cédric Le Goater wrote: > On 12/15/21 02:33, Alexey Kardashevskiy wrote: >> 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"). > > 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: diff --git a/arch/powerpc/kvm/book3s_xive_native.c b/arch/powerpc/kvm/book3s_xive_native.c index 99db9ac49901..511f643e2875 100644 --- a/arch/powerpc/kvm/book3s_xive_native.c +++ b/arch/powerpc/kvm/book3s_xive_native.c @@ -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, _native_debug_fops); it looks fine, this is "before": root@zz1:/sys/kernel/debug# find -iname "*xive*" ./slab/xive-provision ./powerpc/kvm-xive-c000208c ./powerpc/xive and this is "after" the patch applied. root@zz1:/sys/kernel/debug# find -iname "*xive*" ./kvm/29058-11/kvm-xive-c000208c ./slab/xive-provision ./powerpc/xive I'll repost unless there is something more to it. Thanks, -- Alexey
Re: [PATCH kernel v3] KVM: PPC: Merge powerpc's debugfs entry content into generic entry
On 12/15/21 02:33, Alexey Kardashevskiy wrote: 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"). 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. Suggested-by: Fabiano Rosas Signed-off-by: Alexey Kardashevskiy --- 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(-) diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index 17263276189e..f5e14fa683f4 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -26,6 +26,8 @@ #include #include +#define __KVM_HAVE_ARCH_VCPU_DEBUGFS + #define KVM_MAX_VCPUS NR_CPUS #define KVM_MAX_VCORESNR_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 */ }; diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h index 33db83b82fbd..d2b192dea0d2 100644 --- a/arch/powerpc/include/asm/kvm_ppc.h +++ b/arch/powerpc/include/asm/kvm_ppc.h @@ -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; diff --git a/arch/powerpc/kvm/timing.h b/arch/powerpc/kvm/timing.h index feef7885ba82..493a7d510fd5 100644 --- a/arch/powerpc/kvm/timing.h +++ b/arch/powerpc/kvm/timing.h @@ -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
Re: [PATCH kernel v3] KVM: PPC: Merge powerpc's debugfs entry content into generic entry
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/202112151845.kedqxkhk-...@intel.com/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 Reported-by: kernel test robot 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/kbuild-...@lists.01.org
[PATCH kernel v3] 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"). Suggested-by: Fabiano Rosas Signed-off-by: Alexey Kardashevskiy --- 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(-) diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index 17263276189e..f5e14fa683f4 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -26,6 +26,8 @@ #include #include +#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 */ }; diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h index 33db83b82fbd..d2b192dea0d2 100644 --- a/arch/powerpc/include/asm/kvm_ppc.h +++ b/arch/powerpc/include/asm/kvm_ppc.h @@ -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; diff --git a/arch/powerpc/kvm/timing.h b/arch/powerpc/kvm/timing.h index feef7885ba82..493a7d510fd5 100644 --- a/arch/powerpc/kvm/timing.h +++ b/arch/powerpc/kvm/timing.h @@ -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