Remove duplicated stats definitions for debugfs
Subsystems (13)
cover Remove duplicated stats definitions for debugfs
This is a follow-up patchset to binary stats interface patchset as below:
https://lore.kernel.org/kvm/[email protected]
This patchset contains a commit to fix some missing stats and add static check to make sure we have the right number of stats descriptors and add an 'offset' field in stats descriptor to make sure the or order of stats descriptors is not relevant to the order of stats in vm/vcpu stats structure. This will totally avoid the possibility of missing stats and mismatched stats definitions.
The binary stats interface defines stats in another array of descriptors, while the original stats debugfs interface uses array of kvm_stats_debugfs item. To remove the duplicated stats definition, this patchset would utilize only the stats descriptors to provide stats information to debugfs interface. This patchset adds a 'mode' flag to support the read/write mode of stats, which can be used to indicate the file permission of debugfs stats files. It removes the usage of kvm_stats_debugfs_item and all the debugfs_entries defined in all archs.
The patch also fixes an issue that read only stats could be cleared in global level, though not permitted in VM level in the original debugfs code.
---
Jing Zhang (4):
KVM: stats: Make sure no missing or mismatched binary stats definition
KVM: stats: Use binary stats descriptors for debugfs interface
KVM: stats: Update documentation supporting stats mode and offset
KVM: selftests: Update binary stats test for stats mode
Documentation/virt/kvm/api.rst | 33 +- arch/arm64/kvm/guest.c | 32 +- arch/mips/kvm/mips.c | 99 ++---- arch/powerpc/kvm/book3s.c | 101 ++---- arch/powerpc/kvm/booke.c | 79 ++--- arch/s390/kvm/kvm-s390.c | 307 ++++++------------ arch/x86/kvm/x86.c | 120 +++---- include/linux/kvm_host.h | 186 ++++++----- include/uapi/linux/kvm.h | 11 +- .../selftests/kvm/kvm_binary_stats_test.c | 13 +- virt/kvm/kvm_main.c | 105 ++++-- 11 files changed, 477 insertions(+), 609 deletions(-)
base-commit: 39be2e28180a2e87af5fbb8d83643812e1a3b371
Signature · 1 line
2.32.0.272.g935e593368-goog
PATCH 1/4 KVM: stats: Make sure no missing or mismatched binary stats definition
Add static check to make sure the number of stats descriptors equals the number of stats defined in vm/vcpu stats structures. Add offset field in stats descriptor to let us define stats descriptors freely, don't have to be in the same order as stats in vm/vcpu stats structures.
Also fix some missing/mismatched stats from previous patch.
--- arch/arm64/kvm/guest.c | 16 +-- arch/mips/kvm/mips.c | 60 ++++++------ arch/powerpc/kvm/book3s.c | 68 +++++++------ arch/powerpc/kvm/booke.c | 54 ++++++----- arch/s390/kvm/kvm-s390.c | 199 +++++++++++++++++++------------------- arch/x86/kvm/x86.c | 73 +++++++------- include/linux/kvm_host.h | 151 ++++++++++++++++++----------- include/uapi/linux/kvm.h | 4 +- 8 files changed, 342 insertions(+), 283 deletions(-)
arch/arm64/kvm/guest.c +10 -6
@@ -31,6 +31,8 @@struct _kvm_stats_desc kvm_vm_stats_desc[] = {KVM_GENERIC_VM_STATS () }; +static_assert (ARRAY_SIZE (kvm_vm_stats_desc) = +sizeof (struct kvm_vm_stat ) /sizeof (u64));struct _kvm_stats_header kvm_vm_stats_header = { {
@@ -44,13 +46,15 @@ struct _kvm_stats_header kvm_vm_stats_header = {struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {KVM_GENERIC_VCPU_STATS (), -STATS_DESC_COUNTER ("hvc_exit_stat" ), -STATS_DESC_COUNTER ("wfe_exit_stat" ), -STATS_DESC_COUNTER ("wfi_exit_stat" ), -STATS_DESC_COUNTER ("mmio_exit_user" ), -STATS_DESC_COUNTER ("mmio_exit_kernel" ), -STATS_DESC_COUNTER ("exits" ) +STATS_DESC_COUNTER (VCPU , hvc_exit_stat), +STATS_DESC_COUNTER (VCPU , wfe_exit_stat), +STATS_DESC_COUNTER (VCPU , wfi_exit_stat), +STATS_DESC_COUNTER (VCPU , mmio_exit_user), +STATS_DESC_COUNTER (VCPU , mmio_exit_kernel), +STATS_DESC_COUNTER (VCPU , exits) }; +static_assert (ARRAY_SIZE (kvm_vcpu_stats_desc) = +sizeof (struct kvm_vcpu_stat ) /sizeof (u64));struct _kvm_stats_header kvm_vcpu_stats_header = { {
arch/mips/kvm/mips.c +31 -29
75 lines not on this page · raw message
arch/powerpc/kvm/book3s.c +36 -32
82 lines not on this page · raw message
arch/powerpc/kvm/booke.c +29 -25
68 lines not on this page · raw message
arch/s390/kvm/kvm-s390.c +102 -97
213 lines not on this page · raw message
arch/x86/kvm/x86.c +40 -33
87 lines not on this page · raw message
include/linux/kvm_host.h +92 -59
211 lines not on this page · raw message
include/uapi/linux/kvm.h +2 -2
@@ -1940,8 +1940,8 @@ struct kvm_stats_desc {__u32 flags;__s16 exponent;__u16 size; -__u32 unused1; -__u32 unused2; +__u32 offset; +__u32 unused;char name[0 ]; };
Signature · 1 line
2.32.0.272.g935e593368-goog
Re: [PATCH 1/4] KVM: stats: Make sure no missing or mismatched binary stats definition
Hi Jing,
Quoted 9 lines · Jing Zhang
Add static check to make sure the number of stats descriptors equals the number of stats defined in vm/vcpu stats structures. Add offset field in stats descriptor to let us define stats descriptors freely, don't have to be in the same order as stats in vm/vcpu stats structures.
Also fix some missing/mismatched stats from previous patch.Signed-off-by Jing Zhang <[email protected]>
I tested this for arm64, and it does assert if there's a mismatch. I couldn't find any missing statistics under any of the architectures either.
Quoted 7 lines
include/linux/kvm_host.h +0
-0@@ -1296,119 +1296,152 @@ struct _kvm_stats_desc { { n, offsetof(struct kvm_vcpu, stat.generic.x), \ KVM_STAT_VCPU, ## __VA_ARGS__ }
include/linux/kvm_host.h struct _kvm_stats_desc { · line 1306
Quoted 10 lines
include/linux/kvm_host.h +8
-1-#define STATS_DESC (stat, type, unit, base, exp) \ +#define STATS_DESC_COMMON (type, unit, base, exp) \ + .flags = type | unit | base | \ + BUILD_BUG_ON_ZERO(type & ~KVM_STATS_TYPE_MASK) | \ + BUILD_BUG_ON_ZERO(unit & ~KVM_STATS_UNIT_MASK) | \ + BUILD_BUG_ON_ZERO(base & ~KVM_STATS_BASE_MASK), \ + .exponent = exp, \ + .size = 1 +
nit: you seem to be mixing tabs and spaces here
Quoted 5 lines
include/linux/kvm_host.h +1
-2+#define VM_GENERIC_STATS_DESC (stat, type, unit, base, exp) \ { \ { \ - .flags = type | unit | base | \ - BUILD_BUG_ON_ZERO(type & ~KVM_STATS_TYPE_MASK) | \
include/linux/kvm_host.h struct _kvm_stats_desc { · line 1314
Quoted 10 lines
include/linux/kvm_host.h +3
-5-BUILD_BUG_ON_ZERO (unit & ~KVM_STATS_UNIT_MASK ) | \ - BUILD_BUG_ON_ZERO(base & ~KVM_STATS_BASE_MASK), \ - .exponent = exp, \ - .size =1 \ + STATS_DESC_COMMON(type, unit, base, exp), \ + .offset = offsetof(struct kvm_vm_stat, generic.stat) \ }, \ - .name = stat, \ + .name = #stat, \ }
nit: also here, mixing of tabs and spaces
Thanks,
/fuad
Re: [PATCH 1/4] KVM: stats: Make sure no missing or mismatched binary stats definition
Hi Fuad,
Quoted 54 lines · Fuad Tabba
Hi Jing,
Quoted 9 lines · Jing Zhang
Add static check to make sure the number of stats descriptors equals the number of stats defined in vm/vcpu stats structures. Add offset field in stats descriptor to let us define stats descriptors freely, don't have to be in the same order as stats in vm/vcpu stats structures.
Also fix some missing/mismatched stats from previous patch.Signed-off-by Jing Zhang <[email protected]>I tested this for arm64, and it does assert if there's a mismatch. I couldn't find any missing statistics under any of the architectures either.
Quoted 7 lines
include/linux/kvm_host.h +0
-0@@ -1296,119 +1296,152 @@ struct _kvm_stats_desc { { n, offsetof(struct kvm_vcpu, stat.generic.x), \ KVM_STAT_VCPU, ## __VA_ARGS__ }include/linux/kvm_host.h struct _kvm_stats_desc { · line 1306
Quoted 10 lines
include/linux/kvm_host.h +8
-1-#define STATS_DESC (stat, type, unit, base, exp) \ +#define STATS_DESC_COMMON (type, unit, base, exp) \ + .flags = type | unit | base | \ + BUILD_BUG_ON_ZERO(type & ~KVM_STATS_TYPE_MASK) | \ + BUILD_BUG_ON_ZERO(unit & ~KVM_STATS_UNIT_MASK) | \ + BUILD_BUG_ON_ZERO(base & ~KVM_STATS_BASE_MASK), \ + .exponent = exp, \ + .size = 1 +nit: you seem to be mixing tabs and spaces here
Quoted 5 lines
include/linux/kvm_host.h +1
-2+#define VM_GENERIC_STATS_DESC (stat, type, unit, base, exp) \ { \ { \ - .flags = type | unit | base | \ - BUILD_BUG_ON_ZERO(type & ~KVM_STATS_TYPE_MASK) | \include/linux/kvm_host.h struct _kvm_stats_desc { · line 1314
Quoted 10 lines
include/linux/kvm_host.h +3
-5-BUILD_BUG_ON_ZERO (unit & ~KVM_STATS_UNIT_MASK ) | \ - BUILD_BUG_ON_ZERO(base & ~KVM_STATS_BASE_MASK), \ - .exponent = exp, \ - .size =1 \ + STATS_DESC_COMMON(type, unit, base, exp), \ + .offset = offsetof(struct kvm_vm_stat, generic.stat) \ }, \ - .name = stat, \ + .name = #stat, \ }
Quoted 7 lines
nit: also here, mixing of tabs and spaces
Tested-by Fuad Tabba <[email protected]> #arm64Reviewed-by Fuad Tabba <[email protected]>Thanks,
/fuad
Thanks for the review and testing!
Jing
kernel test robot
build botRe: [PATCH 1/4] KVM: stats: Make sure no missing or mismatched binary stats definition
In reply to Jing ZhangThank you for the patch! Yet something to improve:
Hi Jing,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on 39be2e28180a2e87af5fbb8d83643812e1a3b371]
url: https://github.com/0day-ci/linux/commits/Jing-Zhang/Remove-duplicated-stats-definitions-for-debugfs/20210616-151523 base: 39be2e28180a2e87af5fbb8d83643812e1a3b371 config: s390-randconfig-r022-20210615 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 64720f57bea6a6bf033feef4a5751ab9c0c3b401)
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
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# https://github.com/0day-ci/linux/commit/2145147a4e85c8196c004804d103c1a3d7adeffe
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jing-Zhang/Remove-duplicated-stats-definitions-for-debugfs/20210616-151523 git checkout 2145147a4e85c8196c004804d103c1a3d7adeffe
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=s390
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from arch/s390/kvm/kvm-s390.c:23:
In file included from include/linux/kvm_host.h:35:
In file included from include/linux/kvm_para.h:5:
In file included from include/uapi/linux/kvm_para.h:37:
In file included from arch/s390/include/asm/kvm_para.h:25:
In file included from arch/s390/include/asm/diag.h:12:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:31:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:464:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __raw_readb(PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:477:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:36:59: note: expanded from macro '__le16_to_cpu'
#define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
^
include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16'
#define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
^
In file included from arch/s390/kvm/kvm-s390.c:23:
In file included from include/linux/kvm_host.h:35:
In file included from include/linux/kvm_para.h:5:
In file included from include/uapi/linux/kvm_para.h:37:
In file included from arch/s390/include/asm/kvm_para.h:25:
In file included from arch/s390/include/asm/diag.h:12:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:31:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
#define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
^
In file included from arch/s390/kvm/kvm-s390.c:23:
In file included from include/linux/kvm_host.h:35:
In file included from include/linux/kvm_para.h:5:
In file included from include/uapi/linux/kvm_para.h:37:
In file included from arch/s390/include/asm/kvm_para.h:25:
In file included from arch/s390/include/asm/diag.h:12:
In file included from include/linux/if_ether.h:19:
In file included from include/linux/skbuff.h:31:
In file included from include/linux/dma-mapping.h:10:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:501:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:511:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:521:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:609:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:617:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:625:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:634:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:643:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:652:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
>> arch/s390/kvm/kvm-s390.c:63:2: error: implicit declaration of function 'STATS_DESC_COUNTR' [-Werror,-Wimplicit-function-declaration]
STATS_DESC_COUNTR(VM, inject_io),
^
>> arch/s390/kvm/kvm-s390.c:63:20: error: use of undeclared identifier 'VM'
STATS_DESC_COUNTR(VM, inject_io),
^
>> arch/s390/kvm/kvm-s390.c:63:24: error: use of undeclared identifier 'inject_io'
STATS_DESC_COUNTR(VM, inject_io),
^
arch/s390/kvm/kvm-s390.c:64:20: error: use of undeclared identifier 'VM'
STATS_DESC_COUNTR(VM, inject_float_mchk),
^
>> arch/s390/kvm/kvm-s390.c:64:24: error: use of undeclared identifier 'inject_float_mchk'
STATS_DESC_COUNTR(VM, inject_float_mchk),
^
arch/s390/kvm/kvm-s390.c:65:20: error: use of undeclared identifier 'VM'
STATS_DESC_COUNTR(VM, inject_pfault_done),
^
>> arch/s390/kvm/kvm-s390.c:65:24: error: use of undeclared identifier 'inject_pfault_done'
STATS_DESC_COUNTR(VM, inject_pfault_done),
^
arch/s390/kvm/kvm-s390.c:66:20: error: use of undeclared identifier 'VM'
STATS_DESC_COUNTR(VM, inject_service_signal),
^
>> arch/s390/kvm/kvm-s390.c:66:24: error: use of undeclared identifier 'inject_service_signal'
STATS_DESC_COUNTR(VM, inject_service_signal),
^
arch/s390/kvm/kvm-s390.c:67:20: error: use of undeclared identifier 'VM'
STATS_DESC_COUNTR(VM, inject_virtio)
^
>> arch/s390/kvm/kvm-s390.c:67:24: error: use of undeclared identifier 'inject_virtio'
STATS_DESC_COUNTR(VM, inject_virtio)
^
>> arch/s390/kvm/kvm-s390.c:69:15: error: invalid application of 'sizeof' to an incomplete type 'struct _kvm_stats_desc []'
static_assert(ARRAY_SIZE(kvm_vm_stats_desc) ==
~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/kernel.h:42:32: note: expanded from macro 'ARRAY_SIZE'
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
^
include/linux/build_bug.h:77:50: note: expanded from macro 'static_assert'
#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:78:56: note: expanded from macro '__static_assert'
#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
^~~~
arch/s390/kvm/kvm-s390.c:75:12: error: invalid application of 'sizeof' to an incomplete type 'struct _kvm_stats_desc []'
.count = ARRAY_SIZE(kvm_vm_stats_desc),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/kernel.h:42:32: note: expanded from macro 'ARRAY_SIZE'
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
^~~~~
arch/s390/kvm/kvm-s390.c:78:10: error: invalid application of 'sizeof' to an incomplete type 'struct _kvm_stats_desc []'
sizeof(kvm_vm_stats_desc),
^~~~~~~~~~~~~~~~~~~12 warnings and 14 errors generated.
vim +/STATS_DESC_COUNTR +63 arch/s390/kvm/kvm-s390.c
55
56 #define MEM_OP_MAX_SIZE 65536 /* Maximum transfer size for KVM_S390_MEM_OP */
57 #define LOCAL_IRQS 32
58 #define VCPU_IRQS_MAX_BUF (sizeof(struct kvm_s390_irq) * \
59 (KVM_MAX_VCPUS + LOCAL_IRQS))
60
61 struct _kvm_stats_desc kvm_vm_stats_desc[] = {
62 KVM_GENERIC_VM_STATS(),
> 63 STATS_DESC_COUNTR(VM, inject_io),
> 64 STATS_DESC_COUNTR(VM, inject_float_mchk),
> 65 STATS_DESC_COUNTR(VM, inject_pfault_done),
> 66 STATS_DESC_COUNTR(VM, inject_service_signal),
> 67 STATS_DESC_COUNTR(VM, inject_virtio)
68 };
> 69 static_assert(ARRAY_SIZE(kvm_vm_stats_desc) ==
70 sizeof(struct kvm_vm_stat) / sizeof(u64));
71 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
PATCH 2/4 KVM: stats: Use binary stats descriptors for debugfs interface
In reply to Jing ZhangTo avoid duplication, use the binary stats descriptors for debugfs interface for KVM stats. Then we only have one stats definitions for both binary and debugfs interface.
--- arch/arm64/kvm/guest.c | 16 ------ arch/mips/kvm/mips.c | 39 -------------- arch/powerpc/kvm/book3s.c | 37 +------------ arch/powerpc/kvm/booke.c | 25 --------- arch/s390/kvm/kvm-s390.c | 108 -------------------------------------- arch/x86/kvm/x86.c | 51 +----------------- include/linux/kvm_host.h | 65 ++++++++++------------- include/uapi/linux/kvm.h | 7 +++ virt/kvm/kvm_main.c | 105 ++++++++++++++++++++++++++---------- 9 files changed, 117 insertions(+), 336 deletions(-)
arch/arm64/kvm/guest.c +0 -16
@@ -66,22 +66,6 @@ struct _kvm_stats_header kvm_vcpu_stats_header = { } }; -struct kvm_stats_debugfs_item debugfs_entries[] = { -VCPU_STAT_GENERIC ("halt_successful_poll" , halt_successful_poll), -VCPU_STAT_GENERIC ("halt_attempted_poll" , halt_attempted_poll), -VCPU_STAT_GENERIC ("halt_poll_invalid" , halt_poll_invalid), -VCPU_STAT_GENERIC ("halt_wakeup" , halt_wakeup), -VCPU_STAT ("hvc_exit_stat" , hvc_exit_stat), -VCPU_STAT ("wfe_exit_stat" , wfe_exit_stat), -VCPU_STAT ("wfi_exit_stat" , wfi_exit_stat), -VCPU_STAT ("mmio_exit_user" , mmio_exit_user), -VCPU_STAT ("mmio_exit_kernel" , mmio_exit_kernel), -VCPU_STAT ("exits" , exits), -VCPU_STAT_GENERIC ("halt_poll_success_ns" , halt_poll_success_ns), -VCPU_STAT_GENERIC ("halt_poll_fail_ns" , halt_poll_fail_ns), - {NULL } -}; -static bool core_reg_offset_is_vreg (u64 off) { return off >= KVM_REG_ARM_CORE_REG(fp_regs.vregs) &&
arch/mips/kvm/mips.c +0 -39
@@ -99,45 +99,6 @@ struct _kvm_stats_header kvm_vcpu_stats_header = { } }; -struct kvm_stats_debugfs_item debugfs_entries[] = { -VCPU_STAT ("wait" , wait_exits), -VCPU_STAT ("cache" , cache_exits), -VCPU_STAT ("signal" , signal_exits), -VCPU_STAT ("interrupt" , int_exits), -VCPU_STAT ("cop_unusable" , cop_unusable_exits), -VCPU_STAT ("tlbmod" , tlbmod_exits), -VCPU_STAT ("tlbmiss_ld" , tlbmiss_ld_exits), -VCPU_STAT ("tlbmiss_st" , tlbmiss_st_exits), -VCPU_STAT ("addrerr_st" , addrerr_st_exits), -VCPU_STAT ("addrerr_ld" , addrerr_ld_exits), -VCPU_STAT ("syscall" , syscall_exits), -VCPU_STAT ("resvd_inst" , resvd_inst_exits), -VCPU_STAT ("break_inst" , break_inst_exits), -VCPU_STAT ("trap_inst" , trap_inst_exits), -VCPU_STAT ("msa_fpe" , msa_fpe_exits), -VCPU_STAT ("fpe" , fpe_exits), -VCPU_STAT ("msa_disabled" , msa_disabled_exits), -VCPU_STAT ("flush_dcache" , flush_dcache_exits), -VCPU_STAT ("vz_gpsi" , vz_gpsi_exits), -VCPU_STAT ("vz_gsfc" , vz_gsfc_exits), -VCPU_STAT ("vz_hc" , vz_hc_exits), -VCPU_STAT ("vz_grr" , vz_grr_exits), -VCPU_STAT ("vz_gva" , vz_gva_exits), -VCPU_STAT ("vz_ghfc" , vz_ghfc_exits), -VCPU_STAT ("vz_gpa" , vz_gpa_exits), -VCPU_STAT ("vz_resvd" , vz_resvd_exits), -#ifdef CONFIG_CPU_LOONGSON64 -VCPU_STAT ("vz_cpucfg" , vz_cpucfg_exits), -#endif -VCPU_STAT_GENERIC ("halt_successful_poll" , halt_successful_poll), -VCPU_STAT_GENERIC ("halt_attempted_poll" , halt_attempted_poll), -VCPU_STAT_GENERIC ("halt_poll_invalid" , halt_poll_invalid), -VCPU_STAT_GENERIC ("halt_wakeup" , halt_wakeup), -VCPU_STAT_GENERIC ("halt_poll_success_ns" , halt_poll_success_ns), -VCPU_STAT_GENERIC ("halt_poll_fail_ns" , halt_poll_fail_ns), - {NULL } -}; -bool kvm_trace_guest_mode_change;int kvm_guest_mode_change_trace_reg (void )
arch/powerpc/kvm/book3s.c +2 -35
@@ -40,8 +40,8 @@struct _kvm_stats_desc kvm_vm_stats_desc[] = {KVM_GENERIC_VM_STATS (), -STATS_DESC_ICOUNTER (VM , num_2M_pages), -STATS_DESC_ICOUNTER (VM , num_1G_pages) +STATS_DESC_ICOUNTER_RONLY (VM , num_2M_pages), +STATS_DESC_ICOUNTER_RONLY (VM , num_1G_pages) };static_assert (ARRAY_SIZE (kvm_vm_stats_desc) =sizeof (struct kvm_vm_stat ) /sizeof (u64));
@@ -102,39 +102,6 @@ struct _kvm_stats_header kvm_vcpu_stats_header = { } }; -struct kvm_stats_debugfs_item debugfs_entries[] = { -VCPU_STAT ("exits" , sum_exits), -VCPU_STAT ("mmio" , mmio_exits), -VCPU_STAT ("sig" , signal_exits), -VCPU_STAT ("sysc" , syscall_exits), -VCPU_STAT ("inst_emu" , emulated_inst_exits), -VCPU_STAT ("dec" , dec_exits), -VCPU_STAT ("ext_intr" , ext_intr_exits), -VCPU_STAT ("queue_intr" , queue_intr), -VCPU_STAT_GENERIC ("halt_poll_success_ns" , halt_poll_success_ns), -VCPU_STAT_GENERIC ("halt_poll_fail_ns" , halt_poll_fail_ns), -VCPU_STAT ("halt_wait_ns" , halt_wait_ns), -VCPU_STAT_GENERIC ("halt_successful_poll" , halt_successful_poll), -VCPU_STAT_GENERIC ("halt_attempted_poll" , halt_attempted_poll), -VCPU_STAT ("halt_successful_wait" , halt_successful_wait), -VCPU_STAT_GENERIC ("halt_poll_invalid" , halt_poll_invalid), -VCPU_STAT_GENERIC ("halt_wakeup" , halt_wakeup), -VCPU_STAT ("pf_storage" , pf_storage), -VCPU_STAT ("sp_storage" , sp_storage), -VCPU_STAT ("pf_instruc" , pf_instruc), -VCPU_STAT ("sp_instruc" , sp_instruc), -VCPU_STAT ("ld" , ld), -VCPU_STAT ("ld_slow" , ld_slow), -VCPU_STAT ("st" , st), -VCPU_STAT ("st_slow" , st_slow), -VCPU_STAT ("pthru_all" , pthru_all), -VCPU_STAT ("pthru_host" , pthru_host), -VCPU_STAT ("pthru_bad_aff" , pthru_bad_aff), - VM_STAT("largepages_2M", num_2M_pages, .mode = 0444), - VM_STAT("largepages_1G", num_1G_pages, .mode = 0444), - {NULL } -}; -static inline void kvmppc_update_int_pending (struct kvm_vcpu *vcpu,unsigned long pending_now,unsigned long old_pending) {
arch/powerpc/kvm/booke.c +0 -25
@@ -93,31 +93,6 @@ struct _kvm_stats_header kvm_vcpu_stats_header = { } }; -struct kvm_stats_debugfs_item debugfs_entries[] = { -VCPU_STAT ("mmio" , mmio_exits), -VCPU_STAT ("sig" , signal_exits), -VCPU_STAT ("itlb_r" , itlb_real_miss_exits), -VCPU_STAT ("itlb_v" , itlb_virt_miss_exits), -VCPU_STAT ("dtlb_r" , dtlb_real_miss_exits), -VCPU_STAT ("dtlb_v" , dtlb_virt_miss_exits), -VCPU_STAT ("sysc" , syscall_exits), -VCPU_STAT ("isi" , isi_exits), -VCPU_STAT ("dsi" , dsi_exits), -VCPU_STAT ("inst_emu" , emulated_inst_exits), -VCPU_STAT ("dec" , dec_exits), -VCPU_STAT ("ext_intr" , ext_intr_exits), -VCPU_STAT_GENERIC ("halt_successful_poll" , halt_successful_poll), -VCPU_STAT_GENERIC ("halt_attempted_poll" , halt_attempted_poll), -VCPU_STAT_GENERIC ("halt_poll_invalid" , halt_poll_invalid), -VCPU_STAT_GENERIC ("halt_wakeup" , halt_wakeup), -VCPU_STAT ("doorbell" , dbell_exits), -VCPU_STAT ("guest doorbell" , gdbell_exits), -VCPU_STAT_GENERIC ("halt_poll_success_ns" , halt_poll_success_ns), -VCPU_STAT_GENERIC ("halt_poll_fail_ns" , halt_poll_fail_ns), -VM_STAT_GENERIC ("remote_tlb_flush" , remote_tlb_flush), - {NULL } -}; -/* TODO: use vcpu_printf() */ void kvmppc_dump_vcpu (struct kvm_vcpu *vcpu) {
arch/s390/kvm/kvm-s390.c +0 -108
114 lines not on this page · raw message
arch/x86/kvm/x86.c +2 -49
63 lines not on this page · raw message
include/linux/kvm_host.h +29 -36
124 lines not on this page · raw message
include/uapi/linux/kvm.h +7 -0
@@ -1936,6 +1936,13 @@ struct kvm_stats_header {#define KVM_STATS_BASE_POW2 (0x1 << KVM_STATS_BASE_SHIFT)#define KVM_STATS_BASE_MAX KVM_STATS_BASE_POW2 +#define KVM_STATS_MODE_SHIFT 12 +#define KVM_STATS_MODE_MASK (0xF << KVM_STATS_MODE_SHIFT) +#define KVM_STATS_MODE_RW (0x0 << KVM_STATS_MODE_SHIFT) +#define KVM_STATS_MODE_READ (0x1 << KVM_STATS_MODE_SHIFT) +#define KVM_STATS_MODE_WRITE (0x2 << KVM_STATS_MODE_SHIFT) +#define KVM_STATS_MODE_MAX KVM_STATS_MODE_WRITE +struct kvm_stats_desc {__u32 flags;__s16 exponent;
virt/kvm/kvm_main.c +77 -28
210 lines not on this page · raw message
Signature · 1 line
2.32.0.272.g935e593368-goog
Paolo Bonzini
maintainerRe: [PATCH 2/4] KVM: stats: Use binary stats descriptors for debugfs interface
arch/x86/kvm/x86.c struct _kvm_stats_desc kvm_vm_stats_desc[] = { · line 237
Quoted 3 lines · Jing Zhang
arch/x86/kvm/x86.c +2
-0+STATS_DESC_ICOUNTER_RONLY (VM , lpages), +STATS_DESC_ICOUNTER_RONLY (VM , nx_lpage_splits),STATS_DESC_ICOUNTER (VM , max_mmu_page_hash_collisions)
I think we're now adding too many macros.
max_mmu_page_hash_collisions is the only remaining instant counter that is not read-only. In fact, in the statsfs prototype we made all instant counters read-only.
You could add a third type in addition to instant and cumulative, let's call it "peak". This essentially corresponds to the "max" aggregation function in the statsfs prototype. Then instant counters would be read only, while cumulative and peak would be read-write.
Paolo
Re: [PATCH 2/4] KVM: stats: Use binary stats descriptors for debugfs interface
Hi Paolo,
Quoted 12 lines · Paolo Bonzini
arch/x86/kvm/x86.c struct _kvm_stats_desc kvm_vm_stats_desc[] = { · line 237
Quoted 3 lines · Jing Zhang
arch/x86/kvm/x86.c +2
-0+STATS_DESC_ICOUNTER_RONLY (VM , lpages), +STATS_DESC_ICOUNTER_RONLY (VM , nx_lpage_splits),STATS_DESC_ICOUNTER (VM , max_mmu_page_hash_collisions)I think we're now adding too many macros.
max_mmu_page_hash_collisionsis the only remaining instant counter that is not read-only. In fact, in the statsfs prototype we made all instant counters read-only.
Quoted 7 lines
You could add a third type in addition to instant and cumulative, let's call it "peak". This essentially corresponds to the "max" aggregation function in the statsfs prototype. Then instant counters would be read only, while cumulative and peak would be read-write.
Paolo
Thanks for the suggestion. Will do that.
Jing
PATCH 3/4 KVM: stats: Update documentation supporting stats mode and offset
In reply to Jing ZhangUpdate documentation to reflect that stats descriptor supports new flags for read/write mode and an offset field is added in stats descriptor.
--- Documentation/virt/kvm/api.rst | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-)
Documentation/virt/kvm/api.rst +26 -7
@@ -5160,12 +5160,19 @@ below code block:: #define KVM_STATS_BASE_POW2 (0x1 << KVM_STATS_BASE_SHIFT) #define KVM_STATS_BASE_MAX KVM_STATS_BASE_POW2 + #define KVM_STATS_MODE_SHIFT 12 + #define KVM_STATS_MODE_MASK (0xF << KVM_STATS_MODE_SHIFT) + #define KVM_STATS_MODE_RW (0x0 << KVM_STATS_MODE_SHIFT) + #define KVM_STATS_MODE_READ (0x1 << KVM_STATS_MODE_SHIFT) + #define KVM_STATS_MODE_WRITE (0x2 << KVM_STATS_MODE_SHIFT) + #define KVM_STATS_MODE_MAX KVM_STATS_MODE_WRITE + struct kvm_stats_desc { __u32 flags; __s16 exponent; __u16 size; - __u32 unused1; - __u32 unused2; + __u32 offset; + __u32 unused; char name[0]; };
@@ -5212,23 +5219,35 @@ Bits 4-7 of ``flags`` encode the unit: value is 200, ``exponent`` is 4, we can get the number of CPU clock cycles by ``value * pow(10, exponent) = 200 * pow(10, 4) = 2000000``. -Bits 7-11 of ``flags`` encode the base: +Bits 8-11 of ``flags`` encode the base: * ``KVM_STATS_BASE_POW10`` The scale is based on power of 10. It is used for measurement of time and CPU clock cycles. * ``KVM_STATS_BASE_POW2`` The scale is based on power of 2. It is used for measurement of memory size. +Bits 12-15 of ``flags`` encode the mode: + * ``KVM_STATS_MODE_RW`` + The corresponding statistics supports both read and write (clear). + * ``KVM_STATS_MODE_READ`` + The corresponding statistics supports read only. + * ``KVM_STATS_MODE_WRITE`` + The corresponding statistics supports write only. (Not used for now, added + for completeness) + The ``exponent`` field is the scale of corresponding statistics data. For example, if the unit is ``KVM_STATS_UNIT_BYTES``, the base is ``KVM_STATS_BASE_POW2``, the ``exponent`` is 10, then we know that the real unit of the statistics data is KBytes a.k.a pow(2, 10) = 1024 bytes. -The ``size`` field is the number of values of this statistics data. It is in the -unit of ``unsigned long`` for VM or ``__u64`` for VCPU. +The ``size`` field is the number of values (u64) of this statistics data. Its +value is usually 1 for most of simple statistics. + +The ``offset`` field is the offset from the start of Data Block to the start of +the corresponding statistics data. -The ``unused1`` and ``unused2`` fields are reserved for future -support for other types of statistics data, like log/linear histogram. +The ``unused`` fields are reserved for future support for other types of +statistics data, like log/linear histogram. The ``name`` field points to the name string of the statistics data. The name string starts at the end of ``struct kvm_stats_desc``.
Signature · 1 line
2.32.0.272.g935e593368-goog
PATCH 4/4 KVM: selftests: Update binary stats test for stats mode
In reply to Jing ZhangUpdate binary stats selftest to support sanity test for stats read/write mode and offset.
--- tools/testing/selftests/kvm/kvm_binary_stats_test.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/kvm_binary_stats_test.c +11 -2
@@ -77,6 +77,8 @@ static void stats_test(int stats_fd) <= KVM_STATS_UNIT_MAX, "Unknown KVM stats unit");TEST_ASSERT ((pdesc->flags &KVM_STATS_BASE_MASK ) <=KVM_STATS_BASE_MAX ,"Unknown KVM stats base" ); +TEST_ASSERT ((pdesc->flags &KVM_STATS_MODE_MASK ) + <=KVM_STATS_MODE_MAX ,"Unknown KVM stats mode" );/* Check exponent for stats unit * Exponent for counter should be greater than or equal to 0 * Exponent for unit bytes should be greater than or equal to 0
@@ -106,11 +108,18 @@ static void stats_test(int stats_fd) }/* Check overlap */ TEST_ASSERT (header->data_offset >= header->desc_offset - || header->data_offset + size_data <= header->desc_offset, -"Data block is overlapped with Descriptor block" ); + || header->data_offset + size_data <= header->desc_offset, +"Data block is overlapped with Descriptor block" );/* Check validity of all stats data size */ TEST_ASSERT (size_data >= header->count *sizeof (stats_data->value[0 ]),"Data size is not correct" ); +/* Check stats offset */ +for (i =0 ; i < header->count; ++i) { + pdesc = (void *)stats_desc + i * size_desc; +TEST_ASSERT (pdesc->offset < size_data, +"Invalid offset (%u) for stats: %s" , + pdesc->offset, pdesc->name); + }/* Allocate memory for stats data */ stats_data =malloc (size_data);
Signature · 1 line
2.32.0.272.g935e593368-goog
Paolo Bonzini
maintainerQuoted 19 lines · Jing Zhang
This is a follow-up patchset to binary stats interface patchset as below:
https://lore.kernel.org/kvm/[email protected]This patchset contains a commit to fix some missing stats and add static check to make sure we have the right number of stats descriptors and add an 'offset' field in stats descriptor to make sure the or order of stats descriptors is not relevant to the order of stats in vm/vcpu stats structure. This will totally avoid the possibility of missing stats and mismatched stats definitions.
The binary stats interface defines stats in another array of descriptors, while the original stats debugfs interface uses array of
kvm_stats_debugfsitem. To remove the duplicated stats definition, this patchset would utilize only the stats descriptors to provide stats information to debugfs interface. This patchset adds a 'mode' flag to support the read/write mode of stats, which can be used to indicate the file permission of debugfs stats files. It removes the usage ofkvm_stats_debugfs_itemand all thedebugfs_entriesdefined in all archs.
Quoted 3 lines
The patch also fixes an issue that read only stats could be cleared in global level, though not permitted in VM level in the original debugfs code.
Thanks for putting this together quickly. I think we can drop the mode, see the suggestion in patch 2.
It's probably best to fold the v8 for the stats functionality, these patches (squashed appropriately) and Fuad's remars in a single posting.
But I'm quite confident that it can make it in 5.14.
Paolo
Quoted 25 lines · Paolo Bonzini
Quoted 19 lines · Jing Zhang
This is a follow-up patchset to binary stats interface patchset as below:
https://lore.kernel.org/kvm/[email protected]This patchset contains a commit to fix some missing stats and add static check to make sure we have the right number of stats descriptors and add an 'offset' field in stats descriptor to make sure the or order of stats descriptors is not relevant to the order of stats in vm/vcpu stats structure. This will totally avoid the possibility of missing stats and mismatched stats definitions.
The binary stats interface defines stats in another array of descriptors, while the original stats debugfs interface uses array of
kvm_stats_debugfsitem. To remove the duplicated stats definition, this patchset would utilize only the stats descriptors to provide stats information to debugfs interface. This patchset adds a 'mode' flag to support the read/write mode of stats, which can be used to indicate the file permission of debugfs stats files. It removes the usage ofkvm_stats_debugfs_itemand all thedebugfs_entriesdefined in all archs.Quoted 3 lines
The patch also fixes an issue that read only stats could be cleared in global level, though not permitted in VM level in the original debugfs code.
Quoted 9 lines
Thanks for putting this together quickly. I think we can drop the mode, see the suggestion in patch 2.
It's probably best to fold the v8 for the stats functionality, these patches (squashed appropriately) and Fuad's remars in a single posting.
But I'm quite confident that it can make it in 5.14.Paolo
Thanks. Will drop the mode, squash stats functionality with v8 and fold them in another single posting (v9).
Jing