From nobody Wed Oct 11 13:25:21 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 4S5D6957r2z4xP3Q; Wed, 11 Oct 2023 13:25:21 +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 4S5D6936f2z3H28; Wed, 11 Oct 2023 13:25:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697030721; 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=tclKOW0aIFnAABMN8koLFvo6p1/cRJsHbmliqBXgXxs=; b=Fp60AnXTcZYuOVsRsGYHaDqj+YwZkPNWLlMIyQAcVa4NH2lB2k7ZriC5zgez1NyOi6qcVn +cWmoXCldSAflKZGfXnppCM/bXZvPHF2VeAbv6xoXkqtLGUgYzXRKYAeoHS16iioUa/58f Kw5F4YHA42kyqkK4A/3Oek57aI/EPcokDpkyitF9wEg6D6BcgQB5b0V2/yDw4PNRK132Yk uVAxRwrLTGa+iFMLKlc/pf4rYkfR1BiJWlufIzBJIVIMth94gcuE3EBI/rFmohScxRw4ER 7+VQxcXHoTcF4JGRCOTzxRoYr0fjnAi7OqbHVmhM4zTxb8Xt9JlHQGdRp61fFg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697030721; a=rsa-sha256; cv=none; b=cGjjnwOyMFjfYEFluh3SxXO87OOcvw6TlsuYdhhSTuskrMoX0MuSGlBbxi8ElJpkZIe/Za I/S+sOLat2x32tueIQGtriQR8TgUAxKnWes6YzYleCE2UZgLTMbefkP23kWb8xbqhlbMCY y6Nlyl8cshoPYWqWVD1st8Fhl6mzIs07UHHwuW5XkVCBTlUZYZipaYxTzkOVpvJ0gXLGVD bcm/qFVMmZERkLLEQtPNqlJr2S6MJ/6giCTOThLuKWESVx/NqnBehmjjcWF3hD6taxJKuI XTY0pSVjB4Suoh5aOzevZpg8W089/hTdVsneAsfZVQTE0v65+gxyKUzqa4jKvw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697030721; 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=tclKOW0aIFnAABMN8koLFvo6p1/cRJsHbmliqBXgXxs=; b=q5jiroD7GfG2JCyVMhzgPYJ/PxoU5sMs9bcEq+UB14p2ZMOGKOzOciW4iZsr/OkEWtKels ztrSrsgJUZqCfPAAVVftbi3bEa7kELih0SQE8ObIa0J78lDjlN9TNtM7fn4OKKXOxSpf57 RUdprmj8shh5XlZOl142wAFvZZ9kIzmSakoqFosOMcIrGxFedD/8IS7lIR3YNfrhkkDBoo b8lbWup5lxDDkOZ7TMIkAwaaKcCOcVsPRjFeRDvB67EgDtStnltOdfyOFqelEKFLTYuRDt aC27jLhw5Vb07wUiJIhxrOgx3G0vb1M9xctdcUG9Doxa/GL7IBiCCpUfERoggA== 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 4S5D692DbZz7MM; Wed, 11 Oct 2023 13:25:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39BDPLEN090670; Wed, 11 Oct 2023 13:25:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39BDPL7O090667; Wed, 11 Oct 2023 13:25:21 GMT (envelope-from git) Date: Wed, 11 Oct 2023 13:25:21 GMT Message-Id: <202310111325.39BDPL7O090667@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 15181b73025b - stable/14 - bhyve: Move most early initialization into an MD routine 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/stable/14 X-Git-Reftype: branch X-Git-Commit: 15181b73025b8fa7bb892f3e161e2067ce865297 Auto-Submitted: auto-generated The branch stable/14 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=15181b73025b8fa7bb892f3e161e2067ce865297 commit 15181b73025b8fa7bb892f3e161e2067ce865297 Author: Mark Johnston AuthorDate: 2023-10-04 16:27:54 +0000 Commit: Mark Johnston CommitDate: 2023-10-11 13:24:38 +0000 bhyve: Move most early initialization into an MD routine Prior to initializing PCI devices, main() calls a number of initialization routines, many of which are amd64-specific. Move this list of calls to bhyverun_machdep.c. Similarly, add an MD function to handle late initialization. No functional change intended. Reviewed by: corvink, jhb MFC after: 1 week Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D40989 (cherry picked from commit f82af74c76030029d4d8af95c29f2036a20796a4) --- usr.sbin/bhyve/amd64/bhyverun_machdep.c | 62 +++++++++++++++++++++++ usr.sbin/bhyve/amd64/xmsr.c | 7 +-- usr.sbin/bhyve/bhyverun.c | 88 ++------------------------------- usr.sbin/bhyve/bhyverun.h | 2 + 4 files changed, 72 insertions(+), 87 deletions(-) diff --git a/usr.sbin/bhyve/amd64/bhyverun_machdep.c b/usr.sbin/bhyve/amd64/bhyverun_machdep.c index f995c7aef195..9254fb5f94a0 100644 --- a/usr.sbin/bhyve/amd64/bhyverun_machdep.c +++ b/usr.sbin/bhyve/amd64/bhyverun_machdep.c @@ -33,9 +33,21 @@ #include +#include "acpi.h" +#include "atkbdc.h" #include "bhyverun.h" #include "config.h" +#include "e820.h" +#include "fwctl.h" +#include "ioapic.h" +#include "inout.h" +#include "kernemu_dev.h" +#include "mptbl.h" +#include "pci_irq.h" #include "pci_lpc.h" +#include "rtc.h" +#include "smbiostbl.h" +#include "xmsr.h" void bhyve_init_config(void) @@ -123,3 +135,53 @@ bhyve_start_vcpu(struct vcpu *vcpu, bool bsp) fbsdrun_addcpu(vcpu_id(vcpu)); } + +int +bhyve_init_platform(struct vmctx *ctx, struct vcpu *bsp __unused) +{ + int error; + + error = init_msr(); + if (error != 0) + return (error); + init_inout(); + kernemu_dev_init(); + atkbdc_init(ctx); + pci_irq_init(ctx); + ioapic_init(ctx); + rtc_init(ctx); + sci_init(ctx); + error = e820_init(ctx); + if (error != 0) + return (error); + + return (0); +} + +int +bhyve_init_platform_late(struct vmctx *ctx, struct vcpu *bsp __unused) +{ + int error; + + if (get_config_bool_default("x86.mptable", true)) { + error = mptable_build(ctx, guest_ncpus); + if (error != 0) + return (error); + } + error = smbios_build(ctx); + if (error != 0) + return (error); + error = e820_finalize(); + if (error != 0) + return (error); + + if (lpc_bootrom() && strcmp(lpc_fwcfg(), "bhyve") == 0) + fwctl_init(); + + if (get_config_bool("acpi_tables")) { + error = acpi_build(ctx, guest_ncpus); + assert(error == 0); + } + + return (0); +} diff --git a/usr.sbin/bhyve/amd64/xmsr.c b/usr.sbin/bhyve/amd64/xmsr.c index 99e758e84fff..7481df4669e7 100644 --- a/usr.sbin/bhyve/amd64/xmsr.c +++ b/usr.sbin/bhyve/amd64/xmsr.c @@ -33,12 +33,13 @@ #include #include -#include - +#include #include #include #include +#include + #include "debug.h" #include "xmsr.h" @@ -236,7 +237,7 @@ init_msr(void) cpu_vendor_intel = 1; } else { EPRINTLN("Unknown cpu vendor \"%s\"", cpu_vendor); - error = -1; + error = ENOENT; } return (error); } diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index d2bdba2e4a90..e3b297cfccca 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -71,52 +71,27 @@ #include -#include "bhyverun.h" #include "acpi.h" -#ifdef __amd64__ -#include "amd64/atkbdc.h" -#endif +#include "bhyverun.h" #include "bootrom.h" #include "config.h" -#ifdef __amd64__ -#include "amd64/inout.h" -#endif #include "debug.h" -#ifdef __amd64__ -#include "amd64/e820.h" -#include "amd64/fwctl.h" -#endif #ifdef BHYVE_GDB #include "gdb.h" #endif -#ifdef __amd64__ -#include "amd64/ioapic.h" -#include "amd64/kernemu_dev.h" -#endif #include "mem.h" #include "mevent.h" -#ifdef __amd64__ -#include "amd64/mptbl.h" -#endif #include "pci_emul.h" #ifdef __amd64__ -#include "amd64/pci_irq.h" #include "amd64/pci_lpc.h" #endif #include "qemu_fwcfg.h" -#include "smbiostbl.h" #ifdef BHYVE_SNAPSHOT #include "snapshot.h" #endif #include "tpm_device.h" -#ifdef __amd64__ -#include "amd64/rtc.h" -#endif #include "vmgenc.h" #include "vmexit.h" -#ifdef __amd64__ -#include "amd64/xmsr.h" -#endif #define MB (1024UL * 1024) #define GB (1024UL * MB) @@ -966,30 +941,10 @@ main(int argc, char *argv[]) exit(4); } -#ifdef __amd64__ - error = init_msr(); - if (error) { - fprintf(stderr, "init_msr error %d", error); - exit(4); - } -#endif - init_mem(guest_ncpus); -#ifdef __amd64__ - init_inout(); - kernemu_dev_init(); -#endif init_bootrom(ctx); -#ifdef __amd64__ - atkbdc_init(ctx); - pci_irq_init(ctx); - ioapic_init(ctx); -#endif - -#ifdef __amd64__ - rtc_init(ctx); - sci_init(ctx); -#endif + if (bhyve_init_platform(ctx, bsp) != 0) + exit(4); if (qemu_fwcfg_init(ctx) != 0) { fprintf(stderr, "qemu fwcfg initialization error"); @@ -1002,13 +957,6 @@ main(int argc, char *argv[]) exit(4); } -#ifdef __amd64__ - if (e820_init(ctx) != 0) { - fprintf(stderr, "Unable to setup E820"); - exit(4); - } -#endif - /* * Exit if a device emulation finds an error in its initialization */ @@ -1072,37 +1020,9 @@ main(int argc, char *argv[]) } #endif -#ifdef __amd64__ - if (get_config_bool_default("x86.mptable", true)) { - error = mptable_build(ctx, guest_ncpus); - if (error) { - perror("error to build the guest tables"); - exit(4); - } - } -#endif - - error = smbios_build(ctx); - if (error != 0) + if (bhyve_init_platform_late(ctx, bsp) != 0) exit(4); - if (get_config_bool("acpi_tables")) { - error = acpi_build(ctx, guest_ncpus); - assert(error == 0); - } - -#ifdef __amd64__ - error = e820_finalize(); - if (error != 0) - exit(4); -#endif - -#ifdef __amd64__ - if (lpc_bootrom() && strcmp(lpc_fwcfg(), "bhyve") == 0) { - fwctl_init(); - } -#endif - /* * Change the proc title to include the VM name. */ diff --git a/usr.sbin/bhyve/bhyverun.h b/usr.sbin/bhyve/bhyverun.h index 39e0916f08ef..5fe97ca07f0b 100644 --- a/usr.sbin/bhyve/bhyverun.h +++ b/usr.sbin/bhyve/bhyverun.h @@ -60,5 +60,7 @@ typedef int (*vmexit_handler_t)(struct vmctx *, struct vcpu *, struct vm_run *); void bhyve_init_config(void); void bhyve_init_vcpu(struct vcpu *vcpu); void bhyve_start_vcpu(struct vcpu *vcpu, bool bsp); +int bhyve_init_platform(struct vmctx *ctx, struct vcpu *bsp); +int bhyve_init_platform_late(struct vmctx *ctx, struct vcpu *bsp); #endif