git: a20c00c60e1c - main - bhyve: Allocate struct vm_exit on the stack in vm_loop.

From: John Baldwin <jhb_at_FreeBSD.org>
Date: Wed, 21 Dec 2022 18:34:04 UTC
The branch main has been updated by jhb:

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

commit a20c00c60e1c022f77a7bc638f29d3d6d9456953
Author:     John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2022-12-21 18:32:45 +0000
Commit:     John Baldwin <jhb@FreeBSD.org>
CommitDate: 2022-12-21 18:32:45 +0000

    bhyve: Allocate struct vm_exit on the stack in vm_loop.
    
    The global vmexit[] array is no longer needed to smuggle the rip
    value from fbsdrun_addcpu() to vm_loop().
    
    Reviewed by:    corvink, markj
    Differential Revision:  https://reviews.freebsd.org/D37644
---
 usr.sbin/bhyve/bhyverun.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c
index e40229e79828..31cb7c2ceaf3 100644
--- a/usr.sbin/bhyve/bhyverun.c
+++ b/usr.sbin/bhyve/bhyverun.c
@@ -196,8 +196,6 @@ static cpuset_t cpumask;
 
 static void vm_loop(struct vmctx *ctx, int vcpu);
 
-static struct vm_exit *vmexit;
-
 static struct bhyvestats {
 	uint64_t	vmexit_bogus;
 	uint64_t	vmexit_reqidle;
@@ -619,7 +617,7 @@ vmexit_inout(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu)
 		fprintf(stderr, "Unhandled %s%c 0x%04x at 0x%lx\n",
 		    in ? "in" : "out",
 		    bytes == 1 ? 'b' : (bytes == 2 ? 'w' : 'l'),
-		    port, vmexit->rip);
+		    port, vme->rip);
 		return (VMEXIT_ABORT);
 	} else {
 		return (VMEXIT_CONTINUE);
@@ -968,6 +966,7 @@ static vmexit_handler_t handler[VM_EXITCODE_MAX] = {
 static void
 vm_loop(struct vmctx *ctx, int vcpu)
 {
+	struct vm_exit vme;
 	int error, rc;
 	enum vm_exitcode exitcode;
 	cpuset_t active_cpus;
@@ -982,18 +981,18 @@ vm_loop(struct vmctx *ctx, int vcpu)
 	assert(CPU_ISSET(vcpu, &active_cpus));
 
 	while (1) {
-		error = vm_run(ctx, vcpu, &vmexit[vcpu]);
+		error = vm_run(ctx, vcpu, &vme);
 		if (error != 0)
 			break;
 
-		exitcode = vmexit[vcpu].exitcode;
+		exitcode = vme.exitcode;
 		if (exitcode >= VM_EXITCODE_MAX || handler[exitcode] == NULL) {
 			fprintf(stderr, "vm_loop: unexpected exitcode 0x%x\n",
 			    exitcode);
 			exit(4);
 		}
 
-		rc = (*handler[exitcode])(ctx, &vmexit[vcpu], &vcpu);
+		rc = (*handler[exitcode])(ctx, &vme, &vcpu);
 
 		switch (rc) {
 		case VMEXIT_CONTINUE:
@@ -1582,7 +1581,6 @@ main(int argc, char *argv[])
 #endif
 
 	/* Allocate per-VCPU resources. */
-	vmexit = calloc(guest_ncpus, sizeof(*vmexit));
 	mt_vmm_info = calloc(guest_ncpus, sizeof(*mt_vmm_info));
 
 	/*