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

Configure Feed

Select the types of activity you want to include in your feed.

KVM: Remove subtle "struct kvm_stats_desc" pseudo-overlay

Remove KVM's internal pseudo-overlay of kvm_stats_desc, which subtly
aliases the flexible name[] in the uAPI definition with a fixed-size array
of the same name. The unusual embedded structure results in compiler
warnings due to -Wflex-array-member-not-at-end, and also necessitates an
extra level of dereferencing in KVM. To avoid the "overlay", define the
uAPI structure to have a fixed-size name when building for the kernel.

Opportunistically clean up the indentation for the stats macros, and
replace spaces with tabs.

No functional change intended.

Reported-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Closes: https://lore.kernel.org/all/aPfNKRpLfhmhYqfP@kspp
Acked-by: Marc Zyngier <maz@kernel.org>
Acked-by: Christian Borntraeger <borntraeger@linux.ibm.com>
[..]
Acked-by: Anup Patel <anup@brainfault.org>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Acked-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://patch.msgid.link/20251205232655.445294-1-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>

+70 -75
+2 -2
arch/arm64/kvm/guest.c
··· 29 29 30 30 #include "trace.h" 31 31 32 - const struct _kvm_stats_desc kvm_vm_stats_desc[] = { 32 + const struct kvm_stats_desc kvm_vm_stats_desc[] = { 33 33 KVM_GENERIC_VM_STATS() 34 34 }; 35 35 ··· 42 42 sizeof(kvm_vm_stats_desc), 43 43 }; 44 44 45 - const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { 45 + const struct kvm_stats_desc kvm_vcpu_stats_desc[] = { 46 46 KVM_GENERIC_VCPU_STATS(), 47 47 STATS_DESC_COUNTER(VCPU, hvc_exit_stat), 48 48 STATS_DESC_COUNTER(VCPU, wfe_exit_stat),
+1 -1
arch/loongarch/kvm/vcpu.c
··· 14 14 #define CREATE_TRACE_POINTS 15 15 #include "trace.h" 16 16 17 - const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { 17 + const struct kvm_stats_desc kvm_vcpu_stats_desc[] = { 18 18 KVM_GENERIC_VCPU_STATS(), 19 19 STATS_DESC_COUNTER(VCPU, int_exits), 20 20 STATS_DESC_COUNTER(VCPU, idle_exits),
+1 -1
arch/loongarch/kvm/vm.c
··· 10 10 #include <asm/kvm_eiointc.h> 11 11 #include <asm/kvm_pch_pic.h> 12 12 13 - const struct _kvm_stats_desc kvm_vm_stats_desc[] = { 13 + const struct kvm_stats_desc kvm_vm_stats_desc[] = { 14 14 KVM_GENERIC_VM_STATS(), 15 15 STATS_DESC_ICOUNTER(VM, pages), 16 16 STATS_DESC_ICOUNTER(VM, hugepages),
+2 -2
arch/mips/kvm/mips.c
··· 38 38 #define VECTORSPACING 0x100 /* for EI/VI mode */ 39 39 #endif 40 40 41 - const struct _kvm_stats_desc kvm_vm_stats_desc[] = { 41 + const struct kvm_stats_desc kvm_vm_stats_desc[] = { 42 42 KVM_GENERIC_VM_STATS() 43 43 }; 44 44 ··· 51 51 sizeof(kvm_vm_stats_desc), 52 52 }; 53 53 54 - const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { 54 + const struct kvm_stats_desc kvm_vcpu_stats_desc[] = { 55 55 KVM_GENERIC_VCPU_STATS(), 56 56 STATS_DESC_COUNTER(VCPU, wait_exits), 57 57 STATS_DESC_COUNTER(VCPU, cache_exits),
+2 -2
arch/powerpc/kvm/book3s.c
··· 38 38 39 39 /* #define EXIT_DEBUG */ 40 40 41 - const struct _kvm_stats_desc kvm_vm_stats_desc[] = { 41 + const struct kvm_stats_desc kvm_vm_stats_desc[] = { 42 42 KVM_GENERIC_VM_STATS(), 43 43 STATS_DESC_ICOUNTER(VM, num_2M_pages), 44 44 STATS_DESC_ICOUNTER(VM, num_1G_pages) ··· 53 53 sizeof(kvm_vm_stats_desc), 54 54 }; 55 55 56 - const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { 56 + const struct kvm_stats_desc kvm_vcpu_stats_desc[] = { 57 57 KVM_GENERIC_VCPU_STATS(), 58 58 STATS_DESC_COUNTER(VCPU, sum_exits), 59 59 STATS_DESC_COUNTER(VCPU, mmio_exits),
+2 -2
arch/powerpc/kvm/booke.c
··· 36 36 37 37 unsigned long kvmppc_booke_handlers; 38 38 39 - const struct _kvm_stats_desc kvm_vm_stats_desc[] = { 39 + const struct kvm_stats_desc kvm_vm_stats_desc[] = { 40 40 KVM_GENERIC_VM_STATS(), 41 41 STATS_DESC_ICOUNTER(VM, num_2M_pages), 42 42 STATS_DESC_ICOUNTER(VM, num_1G_pages) ··· 51 51 sizeof(kvm_vm_stats_desc), 52 52 }; 53 53 54 - const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { 54 + const struct kvm_stats_desc kvm_vcpu_stats_desc[] = { 55 55 KVM_GENERIC_VCPU_STATS(), 56 56 STATS_DESC_COUNTER(VCPU, sum_exits), 57 57 STATS_DESC_COUNTER(VCPU, mmio_exits),
+1 -1
arch/riscv/kvm/vcpu.c
··· 24 24 #define CREATE_TRACE_POINTS 25 25 #include "trace.h" 26 26 27 - const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { 27 + const struct kvm_stats_desc kvm_vcpu_stats_desc[] = { 28 28 KVM_GENERIC_VCPU_STATS(), 29 29 STATS_DESC_COUNTER(VCPU, ecall_exit_stat), 30 30 STATS_DESC_COUNTER(VCPU, wfi_exit_stat),
+1 -1
arch/riscv/kvm/vm.c
··· 13 13 #include <linux/kvm_host.h> 14 14 #include <asm/kvm_mmu.h> 15 15 16 - const struct _kvm_stats_desc kvm_vm_stats_desc[] = { 16 + const struct kvm_stats_desc kvm_vm_stats_desc[] = { 17 17 KVM_GENERIC_VM_STATS() 18 18 }; 19 19 static_assert(ARRAY_SIZE(kvm_vm_stats_desc) ==
+2 -2
arch/s390/kvm/kvm-s390.c
··· 64 64 #define VCPU_IRQS_MAX_BUF (sizeof(struct kvm_s390_irq) * \ 65 65 (KVM_MAX_VCPUS + LOCAL_IRQS)) 66 66 67 - const struct _kvm_stats_desc kvm_vm_stats_desc[] = { 67 + const struct kvm_stats_desc kvm_vm_stats_desc[] = { 68 68 KVM_GENERIC_VM_STATS(), 69 69 STATS_DESC_COUNTER(VM, inject_io), 70 70 STATS_DESC_COUNTER(VM, inject_float_mchk), ··· 90 90 sizeof(kvm_vm_stats_desc), 91 91 }; 92 92 93 - const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { 93 + const struct kvm_stats_desc kvm_vcpu_stats_desc[] = { 94 94 KVM_GENERIC_VCPU_STATS(), 95 95 STATS_DESC_COUNTER(VCPU, exit_userspace), 96 96 STATS_DESC_COUNTER(VCPU, exit_null),
+2 -2
arch/x86/kvm/x86.c
··· 237 237 bool __read_mostly enable_device_posted_irqs = true; 238 238 EXPORT_SYMBOL_FOR_KVM_INTERNAL(enable_device_posted_irqs); 239 239 240 - const struct _kvm_stats_desc kvm_vm_stats_desc[] = { 240 + const struct kvm_stats_desc kvm_vm_stats_desc[] = { 241 241 KVM_GENERIC_VM_STATS(), 242 242 STATS_DESC_COUNTER(VM, mmu_shadow_zapped), 243 243 STATS_DESC_COUNTER(VM, mmu_pte_write), ··· 263 263 sizeof(kvm_vm_stats_desc), 264 264 }; 265 265 266 - const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { 266 + const struct kvm_stats_desc kvm_vcpu_stats_desc[] = { 267 267 KVM_GENERIC_VCPU_STATS(), 268 268 STATS_DESC_COUNTER(VCPU, pf_taken), 269 269 STATS_DESC_COUNTER(VCPU, pf_fixed),
+35 -48
include/linux/kvm_host.h
··· 1927 1927 1928 1928 struct kvm_stat_data { 1929 1929 struct kvm *kvm; 1930 - const struct _kvm_stats_desc *desc; 1930 + const struct kvm_stats_desc *desc; 1931 1931 enum kvm_stat_kind kind; 1932 1932 }; 1933 1933 1934 - struct _kvm_stats_desc { 1935 - struct kvm_stats_desc desc; 1936 - char name[KVM_STATS_NAME_SIZE]; 1937 - }; 1938 - 1939 - #define STATS_DESC_COMMON(type, unit, base, exp, sz, bsz) \ 1940 - .flags = type | unit | base | \ 1941 - BUILD_BUG_ON_ZERO(type & ~KVM_STATS_TYPE_MASK) | \ 1942 - BUILD_BUG_ON_ZERO(unit & ~KVM_STATS_UNIT_MASK) | \ 1943 - BUILD_BUG_ON_ZERO(base & ~KVM_STATS_BASE_MASK), \ 1944 - .exponent = exp, \ 1945 - .size = sz, \ 1934 + #define STATS_DESC_COMMON(type, unit, base, exp, sz, bsz) \ 1935 + .flags = type | unit | base | \ 1936 + BUILD_BUG_ON_ZERO(type & ~KVM_STATS_TYPE_MASK) | \ 1937 + BUILD_BUG_ON_ZERO(unit & ~KVM_STATS_UNIT_MASK) | \ 1938 + BUILD_BUG_ON_ZERO(base & ~KVM_STATS_BASE_MASK), \ 1939 + .exponent = exp, \ 1940 + .size = sz, \ 1946 1941 .bucket_size = bsz 1947 1942 1948 - #define VM_GENERIC_STATS_DESC(stat, type, unit, base, exp, sz, bsz) \ 1949 - { \ 1950 - { \ 1951 - STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ 1952 - .offset = offsetof(struct kvm_vm_stat, generic.stat) \ 1953 - }, \ 1954 - .name = #stat, \ 1955 - } 1956 - #define VCPU_GENERIC_STATS_DESC(stat, type, unit, base, exp, sz, bsz) \ 1957 - { \ 1958 - { \ 1959 - STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ 1960 - .offset = offsetof(struct kvm_vcpu_stat, generic.stat) \ 1961 - }, \ 1962 - .name = #stat, \ 1963 - } 1964 - #define VM_STATS_DESC(stat, type, unit, base, exp, sz, bsz) \ 1965 - { \ 1966 - { \ 1967 - STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ 1968 - .offset = offsetof(struct kvm_vm_stat, stat) \ 1969 - }, \ 1970 - .name = #stat, \ 1971 - } 1972 - #define VCPU_STATS_DESC(stat, type, unit, base, exp, sz, bsz) \ 1973 - { \ 1974 - { \ 1975 - STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ 1976 - .offset = offsetof(struct kvm_vcpu_stat, stat) \ 1977 - }, \ 1978 - .name = #stat, \ 1979 - } 1943 + #define VM_GENERIC_STATS_DESC(stat, type, unit, base, exp, sz, bsz) \ 1944 + { \ 1945 + STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ 1946 + .offset = offsetof(struct kvm_vm_stat, generic.stat), \ 1947 + .name = #stat, \ 1948 + } 1949 + #define VCPU_GENERIC_STATS_DESC(stat, type, unit, base, exp, sz, bsz) \ 1950 + { \ 1951 + STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ 1952 + .offset = offsetof(struct kvm_vcpu_stat, generic.stat), \ 1953 + .name = #stat, \ 1954 + } 1955 + #define VM_STATS_DESC(stat, type, unit, base, exp, sz, bsz) \ 1956 + { \ 1957 + STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ 1958 + .offset = offsetof(struct kvm_vm_stat, stat), \ 1959 + .name = #stat, \ 1960 + } 1961 + #define VCPU_STATS_DESC(stat, type, unit, base, exp, sz, bsz) \ 1962 + { \ 1963 + STATS_DESC_COMMON(type, unit, base, exp, sz, bsz), \ 1964 + .offset = offsetof(struct kvm_vcpu_stat, stat), \ 1965 + .name = #stat, \ 1966 + } 1980 1967 /* SCOPE: VM, VM_GENERIC, VCPU, VCPU_GENERIC */ 1981 1968 #define STATS_DESC(SCOPE, stat, type, unit, base, exp, sz, bsz) \ 1982 1969 SCOPE##_STATS_DESC(stat, type, unit, base, exp, sz, bsz) ··· 2040 2053 STATS_DESC_IBOOLEAN(VCPU_GENERIC, blocking) 2041 2054 2042 2055 ssize_t kvm_stats_read(char *id, const struct kvm_stats_header *header, 2043 - const struct _kvm_stats_desc *desc, 2056 + const struct kvm_stats_desc *desc, 2044 2057 void *stats, size_t size_stats, 2045 2058 char __user *user_buffer, size_t size, loff_t *offset); 2046 2059 ··· 2085 2098 2086 2099 2087 2100 extern const struct kvm_stats_header kvm_vm_stats_header; 2088 - extern const struct _kvm_stats_desc kvm_vm_stats_desc[]; 2101 + extern const struct kvm_stats_desc kvm_vm_stats_desc[]; 2089 2102 extern const struct kvm_stats_header kvm_vcpu_stats_header; 2090 - extern const struct _kvm_stats_desc kvm_vcpu_stats_desc[]; 2103 + extern const struct kvm_stats_desc kvm_vcpu_stats_desc[]; 2091 2104 2092 2105 #ifdef CONFIG_KVM_GENERIC_MMU_NOTIFIER 2093 2106 static inline int mmu_invalidate_retry(struct kvm *kvm, unsigned long mmu_seq)
+8
include/uapi/linux/kvm.h
··· 14 14 #include <linux/ioctl.h> 15 15 #include <asm/kvm.h> 16 16 17 + #ifdef __KERNEL__ 18 + #include <linux/kvm_types.h> 19 + #endif 20 + 17 21 #define KVM_API_VERSION 12 18 22 19 23 /* ··· 1583 1579 __u16 size; 1584 1580 __u32 offset; 1585 1581 __u32 bucket_size; 1582 + #ifdef __KERNEL__ 1583 + char name[KVM_STATS_NAME_SIZE]; 1584 + #else 1586 1585 char name[]; 1586 + #endif 1587 1587 }; 1588 1588 1589 1589 #define KVM_GET_STATS_FD _IO(KVMIO, 0xce)
+1 -1
virt/kvm/binary_stats.c
··· 50 50 * Return: the number of bytes that has been successfully read 51 51 */ 52 52 ssize_t kvm_stats_read(char *id, const struct kvm_stats_header *header, 53 - const struct _kvm_stats_desc *desc, 53 + const struct kvm_stats_desc *desc, 54 54 void *stats, size_t size_stats, 55 55 char __user *user_buffer, size_t size, loff_t *offset) 56 56 {
+10 -10
virt/kvm/kvm_main.c
··· 983 983 kvm_free_memslot(kvm, memslot); 984 984 } 985 985 986 - static umode_t kvm_stats_debugfs_mode(const struct _kvm_stats_desc *pdesc) 986 + static umode_t kvm_stats_debugfs_mode(const struct kvm_stats_desc *desc) 987 987 { 988 - switch (pdesc->desc.flags & KVM_STATS_TYPE_MASK) { 988 + switch (desc->flags & KVM_STATS_TYPE_MASK) { 989 989 case KVM_STATS_TYPE_INSTANT: 990 990 return 0444; 991 991 case KVM_STATS_TYPE_CUMULATIVE: ··· 1020 1020 struct dentry *dent; 1021 1021 char dir_name[ITOA_MAX_LEN * 2]; 1022 1022 struct kvm_stat_data *stat_data; 1023 - const struct _kvm_stats_desc *pdesc; 1023 + const struct kvm_stats_desc *pdesc; 1024 1024 int i, ret = -ENOMEM; 1025 1025 int kvm_debugfs_num_entries = kvm_vm_stats_header.num_desc + 1026 1026 kvm_vcpu_stats_header.num_desc; ··· 6186 6186 switch (stat_data->kind) { 6187 6187 case KVM_STAT_VM: 6188 6188 r = kvm_get_stat_per_vm(stat_data->kvm, 6189 - stat_data->desc->desc.offset, val); 6189 + stat_data->desc->offset, val); 6190 6190 break; 6191 6191 case KVM_STAT_VCPU: 6192 6192 r = kvm_get_stat_per_vcpu(stat_data->kvm, 6193 - stat_data->desc->desc.offset, val); 6193 + stat_data->desc->offset, val); 6194 6194 break; 6195 6195 } 6196 6196 ··· 6208 6208 switch (stat_data->kind) { 6209 6209 case KVM_STAT_VM: 6210 6210 r = kvm_clear_stat_per_vm(stat_data->kvm, 6211 - stat_data->desc->desc.offset); 6211 + stat_data->desc->offset); 6212 6212 break; 6213 6213 case KVM_STAT_VCPU: 6214 6214 r = kvm_clear_stat_per_vcpu(stat_data->kvm, 6215 - stat_data->desc->desc.offset); 6215 + stat_data->desc->offset); 6216 6216 break; 6217 6217 } 6218 6218 ··· 6360 6360 static void kvm_init_debug(void) 6361 6361 { 6362 6362 const struct file_operations *fops; 6363 - const struct _kvm_stats_desc *pdesc; 6363 + const struct kvm_stats_desc *pdesc; 6364 6364 int i; 6365 6365 6366 6366 kvm_debugfs_dir = debugfs_create_dir("kvm", NULL); ··· 6373 6373 fops = &vm_stat_readonly_fops; 6374 6374 debugfs_create_file(pdesc->name, kvm_stats_debugfs_mode(pdesc), 6375 6375 kvm_debugfs_dir, 6376 - (void *)(long)pdesc->desc.offset, fops); 6376 + (void *)(long)pdesc->offset, fops); 6377 6377 } 6378 6378 6379 6379 for (i = 0; i < kvm_vcpu_stats_header.num_desc; ++i) { ··· 6384 6384 fops = &vcpu_stat_readonly_fops; 6385 6385 debugfs_create_file(pdesc->name, kvm_stats_debugfs_mode(pdesc), 6386 6386 kvm_debugfs_dir, 6387 - (void *)(long)pdesc->desc.offset, fops); 6387 + (void *)(long)pdesc->offset, fops); 6388 6388 } 6389 6389 } 6390 6390