git: 85ccfcb79fee - stable/13 - vmm stat: Add a special nelems constant for arrays sized by vCPU count.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Thu, 26 Jan 2023 22:12:05 UTC
The branch stable/13 has been updated by jhb:

URL: https://cgit.FreeBSD.org/src/commit/?id=85ccfcb79fee1c6b607e7a5c911894032a25a015

commit 85ccfcb79fee1c6b607e7a5c911894032a25a015
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-11-18 18:04:23 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2023-01-26 22:04:41 +0000

    vmm stat: Add a special nelems constant for arrays sized by vCPU count.
    
    Reviewed by:    corvink, markj
    Differential Revision:  https://reviews.freebsd.org/D37170
    
    (cherry picked from commit d5118d0fc4599f69116ec8de59052606e36e6306)
---
 sys/amd64/vmm/io/vlapic.c | 2 +-
 sys/amd64/vmm/vmm_stat.c  | 3 +++
 sys/amd64/vmm/vmm_stat.h  | 2 ++
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/sys/amd64/vmm/io/vlapic.c b/sys/amd64/vmm/io/vlapic.c
index bcfe6b498721..9c61726e77d7 100644
--- a/sys/amd64/vmm/io/vlapic.c
+++ b/sys/amd64/vmm/io/vlapic.c
@@ -905,7 +905,7 @@ vlapic_calcdest(struct vm *vm, cpuset_t *dmask, uint32_t dest, bool phys,
 	}
 }
 
-static VMM_STAT_ARRAY(IPIS_SENT, VM_MAXCPU, "ipis sent to vcpu");
+static VMM_STAT_ARRAY(IPIS_SENT, VMM_STAT_NELEMS_VCPU, "ipis sent to vcpu");
 
 static void
 vlapic_set_tpr(struct vlapic *vlapic, uint8_t val)
diff --git a/sys/amd64/vmm/vmm_stat.c b/sys/amd64/vmm/vmm_stat.c
index 2df4423bc60f..168a380b221b 100644
--- a/sys/amd64/vmm/vmm_stat.c
+++ b/sys/amd64/vmm/vmm_stat.c
@@ -70,6 +70,9 @@ vmm_stat_register(void *arg)
 	if (vst->scope == VMM_STAT_SCOPE_AMD && !vmm_is_svm())
 		return;
 
+	if (vst->nelems == VMM_STAT_NELEMS_VCPU)
+		vst->nelems = VM_MAXCPU;
+
 	if (vst_num_elems + vst->nelems >= MAX_VMM_STAT_ELEMS) {
 		printf("Cannot accommodate vmm stat type \"%s\"!\n", vst->desc);
 		return;
diff --git a/sys/amd64/vmm/vmm_stat.h b/sys/amd64/vmm/vmm_stat.h
index e40a960ec82a..050d3c13dda1 100644
--- a/sys/amd64/vmm/vmm_stat.h
+++ b/sys/amd64/vmm/vmm_stat.h
@@ -58,6 +58,8 @@ struct vmm_stat_type {
 
 void	vmm_stat_register(void *arg);
 
+#define	VMM_STAT_NELEMS_VCPU	(-1)
+
 #define	VMM_STAT_FDEFINE(type, nelems, desc, func, scope)		\
 	struct vmm_stat_type type[1] = {				\
 		{ -1, nelems, desc, func, scope }			\