From nobody Thu Sep 29 16:37:45 2022 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 4MdfDB1YhVz4dggM; Thu, 29 Sep 2022 16:37:46 +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 4MdfD96klNz43Hk; Thu, 29 Sep 2022 16:37:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664469466; 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=nR465VS68btkRRNQ8ZJM/eG/2AZwlIcHpgDZcp/gv3w=; b=V0LZ23M2ZLD8F0fHbR8ThYdUn/r3mDubPeEbQjrNZ2025IQpFQcYYrXgKBMU3CT6YXJLA7 eooUdToC3zAIswV04MlOr/0FUA1z2528Ve5oVOe65I1b8Qfgdlq9/OsvFINdhCE2bVOniW ntXctfFfvbZqCw1tIT0z3ZfVUffY06ASz7s2Uiib2ZZLBGYg7zrbV2/7VdHSBz6GPUIP+O /A/qVxLmsX7Om1haEYG1qK++TGTp5oxQC+a64y0/Ot3yA5dfNRi2YSkU9KWIXSWMbUNnnY CsLqRVk6tZu09Kk5FTynePcKKpQcU9oq03vGBEyc+gLSOcCiz/S8a3rRS7A9Ig== 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 4MdfD95qH9zslw; Thu, 29 Sep 2022 16:37:45 +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 28TGbjkr090496; Thu, 29 Sep 2022 16:37:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28TGbjQ2090495; Thu, 29 Sep 2022 16:37:45 GMT (envelope-from git) Date: Thu, 29 Sep 2022 16:37:45 GMT Message-Id: <202209291637.28TGbjQ2090495@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 65b8109b4e07 - main - 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 65b8109b4e07ea1fe105ab10539d5baa0a613a14 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664469466; 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=nR465VS68btkRRNQ8ZJM/eG/2AZwlIcHpgDZcp/gv3w=; b=Gkg0VBAumacsPMqrqSjRQfD7G2e5GVV2X8ffotzrtdZihiJXCMLVB7wA6JSiagE2P4hGQ7 q/dHJKBUZVvhhlTlpCW/LNN3R4/Q4WVh0qdhMXb5PYCU3Brcrn69+rMaYNQxyaK2eZqVdF 9yA7Fs5h1YSy3xPjwQoA870R8POPcBrYBidw5eD+PkmJPRDzQGYkuZEgVTm+jsma3KMa+V HpcmNIToSv/OZfTrYmHHsEmkM1mck22J/aXdvJk61qzFo2Yj6HG15/HLEQSno7exExJval dMcVY/RDUd9yRHbsD8TsGN2Pcf1U+W7VWRUQvxuemzHzE8SLlfg6B2JrRt0O1A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664469466; a=rsa-sha256; cv=none; b=AlmtFnfF5GKCVvvHp1cKugYPmJONDq3BBdUiwdsyV/uwoTy/BtTgx5mdJtM9g1Qk5H+1WP IeEyxOmuGHlADgEwC2YhM9nWSvlcDuXc6PnesY3htxqFxDU2A5VV6rB+jDeiHQMYer4rSh ySUYJRquB6ghsV70yckWeqwy/xEw/uYUTBx+RiqjwFKXk+D48TITkYeJOqfhcBZaOzhRRK gTFiZO3lBhRUErfdq7KVE8GouDVVzr/3Tm8c+4Pf3Dm8ALMz2MClcNZHd+k5KQ1tpNHy6c I9Jrn9eBYdhhoOhgoL7OwqsGMq+6KcuklwDd47Pxp1SxuZFbYx3QcWbl5jzvjQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=65b8109b4e07ea1fe105ab10539d5baa0a613a14 commit 65b8109b4e07ea1fe105ab10539d5baa0a613a14 Author: Mark Johnston AuthorDate: 2022-09-08 23:08:10 +0000 Commit: Mark Johnston CommitDate: 2022-09-29 16:36:44 +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 --- 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 27f1d8ea8892..fb6e3b8a13df 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -198,7 +198,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; @@ -209,7 +209,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; @@ -582,7 +582,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)) { @@ -595,8 +595,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 /* @@ -685,7 +685,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); @@ -712,22 +712,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); @@ -745,24 +745,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++; @@ -770,10 +771,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++; @@ -781,7 +783,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++; @@ -795,7 +798,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++; @@ -804,10 +808,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++; @@ -823,7 +827,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; @@ -831,7 +835,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 @@ -840,22 +844,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; } @@ -866,7 +869,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); } @@ -874,13 +877,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); @@ -914,7 +917,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 @@ -928,10 +932,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); } @@ -1199,24 +1203,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); @@ -1239,8 +1243,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;