From nobody Thu Jan 26 19:47:44 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P2rpS42lsz3bnGK; Thu, 26 Jan 2023 19:47:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P2rpS3Hvwz3CTD; Thu, 26 Jan 2023 19:47:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674762464; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rsNjLAsoWsvqlU7mefzWjMQ+ouySbdisRuqW58s9RTs=; b=CaoMigjzDzkOHQXa2/U4azrK14mEkwvrKd/PLP8pq3IgMmVw6iIVp9WlrUiC69hvrmNyY3 IYMGt+SZbEgfG9aZbTlvT2qO+qVevqIPRbxqILHuefcSlX9PIDNktdJRvMWqSBWVxSKt6Z q7XuVoM7fiySWFBXQkM36bMLywTvLpD4kw9c0Wy/ElBviTMa7t+1ATnc8vzFnulscCP4G/ u65fBMeu0Q5SpmdZYN59kMlRmUyUxKnKeAKbgXQikqDe0hWVYTf3Q2/uX4aHWIR08zZzoj HxxqXMWJ9IVLr8LcMTs1/GI8B0AalF+djYVTJC352eZCxHd0CfJO+QhjY0aVig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674762464; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rsNjLAsoWsvqlU7mefzWjMQ+ouySbdisRuqW58s9RTs=; b=Ytq+prrOTTjCFh5oLJPs7s9UNMAdPxKnByLzteNPn+aLbhftrJOxm+NzvzODzx3nDeT9Y0 +SvTN7CvQ+vwe71vA7wuiLq3nGpfqJHuzSOsv7hLY3EUUq/MTBBK2vob7X0a9Lysugml+5 2uRWJ7s1hhmnmgTAW1UWQGtwpHzFl1TZ1jHv+DXpo8ct22CKmrxQo34z7Ai1hXHItcM40X C1ia5tiuQTRSYsKJwnEq9BK09ALzr9O+yMMRtexiiAgVPxKhI6+jXc2jCYgLrNdAASs3Yp 0BYumwJLumcVi4KZosrhGIiW2Ubo4oM6gca9bEQIf60KJS2ti0v5nq7B7mNJ7A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674762464; a=rsa-sha256; cv=none; b=gDNKBGUo6WDH4CbbNw9ATuu9zM7PrxErN9gFkpppljD5ZQnt+IbCDT+N8qHl6TPOnMCDKW 2MbeLFcYUE5xkPtmXOXZwfZRppJLzwIt8Nl1Y4JxYSkWx/Tc5HpmfLKHYnfZvB/Z0pwsC/ pmyGB2qm8MzDOgJzqvPw5RvSgKId1Urylw6R9bV1v7BcDFMU6lpVrZAsXfZBB0OFFWRgKJ yW+MjXrCcZVtYHdTcWijIzA5/iMJ4lh1s+KBJazvk1MHbE7BHhyZr3kD9ywj0k31nfOWu3 xyZo72Tm7i72hIC12QWmpwL67y4lswhxYbTDbjOlvEQYsYKe4mFuUup32U5+AQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P2rpS2PK0zhkw; Thu, 26 Jan 2023 19:47:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 30QJlim9007012; Thu, 26 Jan 2023 19:47:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30QJliJJ007011; Thu, 26 Jan 2023 19:47:44 GMT (envelope-from git) Date: Thu, 26 Jan 2023 19:47:44 GMT Message-Id: <202301261947.30QJliJJ007011@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 542eea73db5d - stable/13 - bhyve: Address some warnings in bhyverun.c List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 542eea73db5deb6a7f4cd8dda4f5ef0735bb7cf3 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=542eea73db5deb6a7f4cd8dda4f5ef0735bb7cf3 commit 542eea73db5deb6a7f4cd8dda4f5ef0735bb7cf3 Author: Mark Johnston AuthorDate: 2022-09-08 23:08:10 +0000 Commit: John Baldwin CommitDate: 2023-01-26 19:30:16 +0000 bhyve: Address some warnings in bhyverun.c - Add const and __unused qualifiers where appropriate. - Localize some global variables. - Consistently spell vmexit state as "vme" in vmexit handlers, to avoid shadowing the global vm_exit state array. - Similarly, avoid shadowing "optarg". MFC after: 2 weeks (cherry picked from commit 65b8109b4e07ea1fe105ab10539d5baa0a613a14) --- usr.sbin/bhyve/bhyverun.c | 111 ++++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 54 deletions(-) diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index 453c24794907..7d62ff58919e 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -199,7 +199,7 @@ static void vm_loop(struct vmctx *ctx, int vcpu, uint64_t rip); static struct vm_exit *vmexit; -struct bhyvestats { +static struct bhyvestats { uint64_t vmexit_bogus; uint64_t vmexit_reqidle; uint64_t vmexit_hlt; @@ -210,7 +210,7 @@ struct bhyvestats { uint64_t cpu_switch_direct; } stats; -struct mt_vmm_info { +static struct mt_vmm_info { pthread_t mt_thr; struct vmctx *mt_ctx; int mt_vcpu; @@ -584,7 +584,7 @@ fbsdrun_addcpu(struct vmctx *ctx, int newcpu, uint64_t rip, bool suspend) } static int -fbsdrun_deletecpu(struct vmctx *ctx, int vcpu) +fbsdrun_deletecpu(int vcpu) { if (!CPU_ISSET(vcpu, &cpumask)) { @@ -597,8 +597,8 @@ fbsdrun_deletecpu(struct vmctx *ctx, int vcpu) } static int -vmexit_handle_notify(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu, - uint32_t eax) +vmexit_handle_notify(struct vmctx *ctx __unused, struct vm_exit *vme __unused, + int *pvcpu __unused, uint32_t eax __unused) { #if BHYVE_DEBUG /* @@ -687,7 +687,7 @@ vmexit_wrmsr(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu) } static int -vmexit_spinup_ap(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu) +vmexit_spinup_ap(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu __unused) { (void)spinup_ap(ctx, vme->u.spinup_ap.vcpu, vme->u.spinup_ap.rip); @@ -714,22 +714,22 @@ vmexit_vmx_desc(uint32_t exit_reason) } static int -vmexit_vmx(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) +vmexit_vmx(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu) { fprintf(stderr, "vm exit[%d]\n", *pvcpu); fprintf(stderr, "\treason\t\tVMX\n"); - fprintf(stderr, "\trip\t\t0x%016lx\n", vmexit->rip); - fprintf(stderr, "\tinst_length\t%d\n", vmexit->inst_length); - fprintf(stderr, "\tstatus\t\t%d\n", vmexit->u.vmx.status); - fprintf(stderr, "\texit_reason\t%u (%s)\n", vmexit->u.vmx.exit_reason, - vmexit_vmx_desc(vmexit->u.vmx.exit_reason)); + fprintf(stderr, "\trip\t\t0x%016lx\n", vme->rip); + fprintf(stderr, "\tinst_length\t%d\n", vme->inst_length); + fprintf(stderr, "\tstatus\t\t%d\n", vme->u.vmx.status); + fprintf(stderr, "\texit_reason\t%u (%s)\n", vme->u.vmx.exit_reason, + vmexit_vmx_desc(vme->u.vmx.exit_reason)); fprintf(stderr, "\tqualification\t0x%016lx\n", - vmexit->u.vmx.exit_qualification); - fprintf(stderr, "\tinst_type\t\t%d\n", vmexit->u.vmx.inst_type); - fprintf(stderr, "\tinst_error\t\t%d\n", vmexit->u.vmx.inst_error); + vme->u.vmx.exit_qualification); + fprintf(stderr, "\tinst_type\t\t%d\n", vme->u.vmx.inst_type); + fprintf(stderr, "\tinst_error\t\t%d\n", vme->u.vmx.inst_error); #ifdef DEBUG_EPT_MISCONFIG - if (vmexit->u.vmx.exit_reason == EXIT_REASON_EPT_MISCONFIG) { + if (vme->u.vmx.exit_reason == EXIT_REASON_EPT_MISCONFIG) { vm_get_register(ctx, *pvcpu, VMCS_IDENT(VMCS_GUEST_PHYSICAL_ADDRESS), &ept_misconfig_gpa); @@ -747,24 +747,25 @@ vmexit_vmx(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) } static int -vmexit_svm(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) +vmexit_svm(struct vmctx *ctx __unused, struct vm_exit *vme, int *pvcpu) { fprintf(stderr, "vm exit[%d]\n", *pvcpu); fprintf(stderr, "\treason\t\tSVM\n"); - fprintf(stderr, "\trip\t\t0x%016lx\n", vmexit->rip); - fprintf(stderr, "\tinst_length\t%d\n", vmexit->inst_length); - fprintf(stderr, "\texitcode\t%#lx\n", vmexit->u.svm.exitcode); - fprintf(stderr, "\texitinfo1\t%#lx\n", vmexit->u.svm.exitinfo1); - fprintf(stderr, "\texitinfo2\t%#lx\n", vmexit->u.svm.exitinfo2); + fprintf(stderr, "\trip\t\t0x%016lx\n", vme->rip); + fprintf(stderr, "\tinst_length\t%d\n", vme->inst_length); + fprintf(stderr, "\texitcode\t%#lx\n", vme->u.svm.exitcode); + fprintf(stderr, "\texitinfo1\t%#lx\n", vme->u.svm.exitinfo1); + fprintf(stderr, "\texitinfo2\t%#lx\n", vme->u.svm.exitinfo2); return (VMEXIT_ABORT); } static int -vmexit_bogus(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) +vmexit_bogus(struct vmctx *ctx __unused, struct vm_exit *vme, + int *pvcpu __unused) { - assert(vmexit->inst_length == 0); + assert(vme->inst_length == 0); stats.vmexit_bogus++; @@ -772,10 +773,11 @@ vmexit_bogus(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) } static int -vmexit_reqidle(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) +vmexit_reqidle(struct vmctx *ctx __unused, struct vm_exit *vme, + int *pvcpu __unused) { - assert(vmexit->inst_length == 0); + assert(vme->inst_length == 0); stats.vmexit_reqidle++; @@ -783,7 +785,8 @@ vmexit_reqidle(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) } static int -vmexit_hlt(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) +vmexit_hlt(struct vmctx *ctx __unused, struct vm_exit *vme __unused, + int *pvcpu __unused) { stats.vmexit_hlt++; @@ -797,7 +800,8 @@ vmexit_hlt(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) } static int -vmexit_pause(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) +vmexit_pause(struct vmctx *ctx __unused, struct vm_exit *vme __unused, + int *pvcpu __unused) { stats.vmexit_pause++; @@ -806,10 +810,10 @@ vmexit_pause(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) } static int -vmexit_mtrap(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) +vmexit_mtrap(struct vmctx *ctx __unused, struct vm_exit *vme, int *pvcpu) { - assert(vmexit->inst_length == 0); + assert(vme->inst_length == 0); stats.vmexit_mtrap++; @@ -825,7 +829,7 @@ vmexit_mtrap(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) } static int -vmexit_inst_emul(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) +vmexit_inst_emul(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu) { int err, i, cs_d; struct vie *vie; @@ -833,7 +837,7 @@ vmexit_inst_emul(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) stats.vmexit_inst_emul++; - vie = &vmexit->u.inst_emul.vie; + vie = &vme->u.inst_emul.vie; if (!vie->decoded) { /* * Attempt to decode in userspace as a fallback. This allows @@ -842,22 +846,21 @@ vmexit_inst_emul(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) * emulation. */ vie_restart(vie); - mode = vmexit->u.inst_emul.paging.cpu_mode; - cs_d = vmexit->u.inst_emul.cs_d; + mode = vme->u.inst_emul.paging.cpu_mode; + cs_d = vme->u.inst_emul.cs_d; if (vmm_decode_instruction(mode, cs_d, vie) != 0) goto fail; if (vm_set_register(ctx, *pvcpu, VM_REG_GUEST_RIP, - vmexit->rip + vie->num_processed) != 0) + vme->rip + vie->num_processed) != 0) goto fail; } - err = emulate_mem(ctx, *pvcpu, vmexit->u.inst_emul.gpa, - vie, &vmexit->u.inst_emul.paging); - + err = emulate_mem(ctx, *pvcpu, vme->u.inst_emul.gpa, + vie, &vme->u.inst_emul.paging); if (err) { if (err == ESRCH) { EPRINTLN("Unhandled memory access to 0x%lx\n", - vmexit->u.inst_emul.gpa); + vme->u.inst_emul.gpa); } goto fail; } @@ -868,7 +871,7 @@ fail: fprintf(stderr, "Failed to emulate instruction sequence [ "); for (i = 0; i < vie->num_valid; i++) fprintf(stderr, "%02x", vie->inst[i]); - FPRINTLN(stderr, " ] at 0x%lx", vmexit->rip); + FPRINTLN(stderr, " ] at 0x%lx", vme->rip); return (VMEXIT_ABORT); } @@ -876,13 +879,13 @@ static pthread_mutex_t resetcpu_mtx = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t resetcpu_cond = PTHREAD_COND_INITIALIZER; static int -vmexit_suspend(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) +vmexit_suspend(struct vmctx *ctx, struct vm_exit *vme, int *pvcpu) { enum vm_suspend_how how; - how = vmexit->u.suspended.how; + how = vme->u.suspended.how; - fbsdrun_deletecpu(ctx, *pvcpu); + fbsdrun_deletecpu(*pvcpu); if (*pvcpu != BSP) { pthread_mutex_lock(&resetcpu_mtx); @@ -916,7 +919,8 @@ vmexit_suspend(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) } static int -vmexit_debug(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) +vmexit_debug(struct vmctx *ctx __unused, struct vm_exit *vme __unused, + int *pvcpu) { #ifdef BHYVE_SNAPSHOT @@ -930,10 +934,10 @@ vmexit_debug(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) } static int -vmexit_breakpoint(struct vmctx *ctx, struct vm_exit *vmexit, int *pvcpu) +vmexit_breakpoint(struct vmctx *ctx __unused, struct vm_exit *vme, int *pvcpu) { - gdb_cpu_breakpoint(*pvcpu, vmexit); + gdb_cpu_breakpoint(*pvcpu, vme); return (VMEXIT_CONTINUE); } @@ -1222,24 +1226,24 @@ parse_simple_config_file(const char *path) } static void -parse_gdb_options(char *optarg) +parse_gdb_options(const char *opt) { const char *sport; char *colon; - if (optarg[0] == 'w') { + if (opt[0] == 'w') { set_config_bool("gdb.wait", true); - optarg++; + opt++; } - colon = strrchr(optarg, ':'); + colon = strrchr(opt, ':'); if (colon == NULL) { - sport = optarg; + sport = opt; } else { *colon = '\0'; colon++; sport = colon; - set_config_value("gdb.address", optarg); + set_config_value("gdb.address", opt); } set_config_value("gdb.port", sport); @@ -1262,8 +1266,7 @@ main(int argc, char *argv[]) struct vmctx *ctx; uint64_t rip; size_t memsize; - const char *value, *vmname; - char *optstr; + const char *optstr, *value, *vmname; #ifdef BHYVE_SNAPSHOT char *restore_file; struct restore_state rstate;