From nobody Fri Mar 17 08:35:43 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 4PdHWz5qxSz3y4N9; Fri, 17 Mar 2023 08:35:43 +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 4PdHWz5NQVz4KTP; Fri, 17 Mar 2023 08:35:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679042143; 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=JQnfd5nXZVdwOmhuDNL8cFvNWoJvLWJDjw6gwmkP8p8=; b=dK2jvMdsV1N1CI/RwcTTMvi6nLNWd+LA4hzA9dSvrQtfTD2qf0XmQlp8yvP1bDFm8f+fpQ sxwRlkyjOcsmbqM8r91nUbAenDTjhiHoaI5p9k6OICoxdXqE2JERqAY8cRL4+yBezpORRk RU92wymkGI+HwIsqB2pFNIMdOCcQyI/0pvgqJruWmx5prCCsYW+27D2P/yneaBZNUGqtyL W1vWDkNEZyGjnGPi864d29yOr3yxL6vdXqHjjxHQYm/Wc0w+othrhDnpK/ZHUJzjgc6kRW 9ywGjF1nPA0t2WiOk6xO5t4tDl3A834nASQpTWOeqGxL8hdBj5c/iCFdmQYUCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1679042143; 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=JQnfd5nXZVdwOmhuDNL8cFvNWoJvLWJDjw6gwmkP8p8=; b=OyYzCgI7iifvVVsWyl1+RR5Ccb3py+DSwHhb48/KGdmxPqgj3GA5K60F3u9njij7f0NVjN FifOgN5NELHVHrulH+eCQb+ob0xAPGqOHDMFqtleeCccbumzdx7asqHUgtGryuWXyG8cug 1+0k5fZv3jNxe3la+rrAUvhw4fNxeEQCeCpgK4XQP8OkrDwkw9DT/utr7bCcaibPL90sLU B56JKA+3tWMP+20n1F+VG4FzcTaw1cQX/3UCMUMibhcn5TWxnmJAX/ZNEJQoZwwGvZu4os ag01XlavXXdmnqXrUUkZeay89U4LYktrjJPguS3jISrHMeHzj+6i4cKH/9mjcQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1679042143; a=rsa-sha256; cv=none; b=jdRJ1wsD/4sgMRofkQQtaVEF8G2/qS1kTQ3SPjdhD3uJItdPmYca6myB1Oc0mISLl0dTBP E7PWKK1i+eXUCaxicaakh0/znxxguNZjmEqKhr/xf2an8mW6sOdvby/E2lHeEke65Vdf6y dkB3KIuNjq4/M2hz0/TLz9Bv2oPFLjQZEwFRo2AGWwvym1AZKJHifPei+X2qtaYy+1HoU0 nzNzw3SP5kfGfjPaUOweBcrXhEwE2Q9Io3B/y3kcKJBZAivUeam0smCf/wyKcaMz673VSz +RSoeTvXs2ntLe7dQrdrkQEqw4MXCQXKhxkGgl/GaNeoawdt6K/98ZPaqar7rA== 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 4PdHWz4QSmzJsk; Fri, 17 Mar 2023 08:35:43 +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 32H8Zhtq085630; Fri, 17 Mar 2023 08:35:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32H8Zhjf085629; Fri, 17 Mar 2023 08:35:43 GMT (envelope-from git) Date: Fri, 17 Mar 2023 08:35:43 GMT Message-Id: <202303170835.32H8Zhjf085629@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: =?utf-8?Q?Corvin=20K=C3=B6hne?= Subject: git: d85147f3d681 - main - bhyve: add cmdline option to enable qemu's fwcfg 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: corvink X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d85147f3d6811c04e250bfb4597783d8844de315 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by corvink: URL: https://cgit.FreeBSD.org/src/commit/?id=d85147f3d6811c04e250bfb4597783d8844de315 commit d85147f3d6811c04e250bfb4597783d8844de315 Author: Corvin Köhne AuthorDate: 2021-08-18 07:31:59 +0000 Commit: Corvin Köhne CommitDate: 2023-03-17 08:35:36 +0000 bhyve: add cmdline option to enable qemu's fwcfg Let the user decide if he wants to use bhyve's fwctl or qemu's fwcfg. He can set the interface by adding a fwcfg option to bootrom: -l bootrom,,fwcfg=bhyve -l bootrom,,fwcfg=qemu Reviewed by: markj MFC after: 1 week Sponsored by: Beckhoff Automation GmbH & Co. KG Differential Revision: https://reviews.freebsd.org/D38337 --- usr.sbin/bhyve/Makefile | 1 + usr.sbin/bhyve/bhyve.8 | 29 ++++++++++++++++-- usr.sbin/bhyve/bhyve_config.5 | 8 +++++ usr.sbin/bhyve/bhyverun.c | 16 +++++++++- usr.sbin/bhyve/pci_lpc.c | 18 ++++++++++- usr.sbin/bhyve/pci_lpc.h | 1 + usr.sbin/bhyve/qemu_fwcfg.c | 71 +++++++++++++++++++++++++------------------ 7 files changed, 111 insertions(+), 33 deletions(-) diff --git a/usr.sbin/bhyve/Makefile b/usr.sbin/bhyve/Makefile index 1c679a3c1578..a5a1dafebcd9 100644 --- a/usr.sbin/bhyve/Makefile +++ b/usr.sbin/bhyve/Makefile @@ -63,6 +63,7 @@ SRCS= \ post.c \ ps2kbd.c \ ps2mouse.c \ + qemu_fwcfg.c \ rfb.c \ rtc.c \ smbiostbl.c \ diff --git a/usr.sbin/bhyve/bhyve.8 b/usr.sbin/bhyve/bhyve.8 index 84e031f1340c..72018912e2c5 100644 --- a/usr.sbin/bhyve/bhyve.8 +++ b/usr.sbin/bhyve/bhyve.8 @@ -200,7 +200,9 @@ and .Cm com4 , the boot ROM device .Cm bootrom , -and the debug/test device +the +.Cm fwcfg +type and the debug/test device .Cm pc-testdev . .Pp The possible values for the @@ -345,7 +347,7 @@ PCI 16550 serial device. .It Cm lpc LPC PCI-ISA bridge with COM1, COM2, COM3, and COM4 16550 serial ports, a boot ROM, and, -optionally, the debug/test device. +optionally, a fwcfg type and the debug/test device. The LPC bridge emulation can only be configured on bus 0. .It Cm fbuf Raw framebuffer device attached to VNC server. @@ -520,6 +522,29 @@ address space, and any modifications the guest makes will be saved to that file. .El .Pp +Fwcfg types: +.Bl -tag -width 10n +.It Ar fwcfg +The fwcfg interface is used to pass information such as the CPU count or ACPI tables to the guest firmware. +Supported values are +.Ql bhyve +and +.Ql qemu . +Due to backward compatibility reasons, +.Ql bhyve +is the default option. +When +.Ql bhyve +is used, bhyve's fwctl interface is used. +It currently reports only the CPU count to the guest firmware. +The +.Ql qemu +option uses QEMU's fwcfg interface. +This interface is widely used and allows user-defined information to be passed to the guest. +It is used for passing the CPU count, ACPI tables, a boot order and many other things to the guest. +Some operating systems such as Fedora CoreOS can be configured by qemu's fwcfg interface as well. +.El +.Pp Pass-through device backends: .Sm off .Bl -bullet diff --git a/usr.sbin/bhyve/bhyve_config.5 b/usr.sbin/bhyve/bhyve_config.5 index 94a8a4d5cb1d..32658c11f9e2 100644 --- a/usr.sbin/bhyve/bhyve_config.5 +++ b/usr.sbin/bhyve/bhyve_config.5 @@ -259,6 +259,7 @@ VGA framebuffer device attached to VNC server. .It Li lpc LPC PCI-ISA bridge with COM1-COM4 16550 serial ports, a boot ROM, +an optional fwcfg type, and an optional debug/test device. This device must be configured on bus 0. .It Li hda @@ -529,6 +530,13 @@ Settings for the COM2 serial port device. Settings for the COM3 serial port device. .It Va com4 Ta node Ta Ta Settings for the COM4 serial port device. +.It Va fwcfg Ta string Ta bhyve Ta +The fwcfg type to be used. +Supported values are +.Dq bhyve +for fwctl and +.Dq qemu +for fwcfg. .It Va pc-testdev Ta bool Ta false Ta Enable the PC debug/test device. .El diff --git a/usr.sbin/bhyve/bhyverun.c b/usr.sbin/bhyve/bhyverun.c index af4d15666ae3..665fec73e48c 100644 --- a/usr.sbin/bhyve/bhyverun.c +++ b/usr.sbin/bhyve/bhyverun.c @@ -101,6 +101,7 @@ __FBSDID("$FreeBSD$"); #include "pci_emul.h" #include "pci_irq.h" #include "pci_lpc.h" +#include "qemu_fwcfg.h" #include "smbiostbl.h" #ifdef BHYVE_SNAPSHOT #include "snapshot.h" @@ -1231,6 +1232,7 @@ set_defaults(void) set_config_bool("acpi_tables", false); set_config_value("memory.size", "256M"); set_config_bool("x86.strictmsr", true); + set_config_value("lpc.fwcfg", "bhyve"); } int @@ -1460,6 +1462,17 @@ main(int argc, char *argv[]) rtc_init(ctx); sci_init(ctx); + if (qemu_fwcfg_init(ctx) != 0) { + fprintf(stderr, "qemu fwcfg initialization error"); + exit(4); + } + + if (qemu_fwcfg_add_file("opt/bhyve/hw.ncpu", sizeof(guest_ncpus), + &guest_ncpus) != 0) { + fprintf(stderr, "Could not add qemu fwcfg opt/bhyve/hw.ncpu"); + exit(4); + } + /* * Exit if a device emulation finds an error in its initilization */ @@ -1554,8 +1567,9 @@ main(int argc, char *argv[]) assert(error == 0); } - if (lpc_bootrom()) + if (lpc_bootrom() && strcmp(lpc_fwcfg(), "bhyve") == 0) { fwctl_init(); + } /* * Change the proc title to include the VM name. diff --git a/usr.sbin/bhyve/pci_lpc.c b/usr.sbin/bhyve/pci_lpc.c index 548726e27d0d..ad47230c005e 100644 --- a/usr.sbin/bhyve/pci_lpc.c +++ b/usr.sbin/bhyve/pci_lpc.c @@ -110,10 +110,20 @@ lpc_device_parse(const char *opts) set_config_value("lpc.bootrom", romfile); varfile = strsep(&str, ","); - if (varfile != NULL) { + if (varfile == NULL) { + error = 0; + goto done; + } + if (strchr(varfile, '=') == NULL) { set_config_value("lpc.bootvars", varfile); + } else { + /* varfile doesn't exist, it's another config + * option */ + pci_parse_legacy_config(find_config_node("lpc"), + varfile); } + pci_parse_legacy_config(find_config_node("lpc"), str); error = 0; goto done; } @@ -160,6 +170,12 @@ lpc_bootrom(void) return (get_config_value("lpc.bootrom")); } +const char * +lpc_fwcfg(void) +{ + return (get_config_value("lpc.fwcfg")); +} + static void lpc_uart_intr_assert(void *arg) { diff --git a/usr.sbin/bhyve/pci_lpc.h b/usr.sbin/bhyve/pci_lpc.h index 611b025d4386..ff3ea98b4f9c 100644 --- a/usr.sbin/bhyve/pci_lpc.h +++ b/usr.sbin/bhyve/pci_lpc.h @@ -72,5 +72,6 @@ void lpc_print_supported_devices(void); char *lpc_pirq_name(int pin); void lpc_pirq_routed(void); const char *lpc_bootrom(void); +const char *lpc_fwcfg(void); #endif diff --git a/usr.sbin/bhyve/qemu_fwcfg.c b/usr.sbin/bhyve/qemu_fwcfg.c index 5ee35d6764e6..1b0b5e3e9931 100644 --- a/usr.sbin/bhyve/qemu_fwcfg.c +++ b/usr.sbin/bhyve/qemu_fwcfg.c @@ -17,6 +17,7 @@ #include "acpi_device.h" #include "inout.h" +#include "pci_lpc.h" #include "qemu_fwcfg.h" #define QEMU_FWCFG_ACPI_DEVICE_NAME "FWCF" @@ -351,37 +352,49 @@ qemu_fwcfg_init(struct vmctx *const ctx) { int error; - error = acpi_device_create(&fwcfg_sc.acpi_dev, ctx, - QEMU_FWCFG_ACPI_DEVICE_NAME, QEMU_FWCFG_ACPI_HARDWARE_ID); - if (error) { - warnx("%s: failed to create ACPI device for QEMU FwCfg", - __func__); - goto done; - } + /* + * Bhyve supports fwctl (bhyve) and fwcfg (qemu) as firmware interfaces. + * Both are using the same ports. So, it's not possible to provide both + * interfaces at the same time to the guest. Therefore, only create acpi + * tables and register io ports for fwcfg, if it's used. + */ + if (strcmp(lpc_fwcfg(), "qemu") == 0) { + error = acpi_device_create(&fwcfg_sc.acpi_dev, ctx, + QEMU_FWCFG_ACPI_DEVICE_NAME, QEMU_FWCFG_ACPI_HARDWARE_ID); + if (error) { + warnx("%s: failed to create ACPI device for QEMU FwCfg", + __func__); + goto done; + } - error = acpi_device_add_res_fixed_ioport(fwcfg_sc.acpi_dev, - QEMU_FWCFG_SELECTOR_PORT_NUMBER, 2); - if (error) { - warnx("%s: failed to add fixed IO port for QEMU FwCfg", - __func__); - goto done; - } + error = acpi_device_add_res_fixed_ioport(fwcfg_sc.acpi_dev, + QEMU_FWCFG_SELECTOR_PORT_NUMBER, 2); + if (error) { + warnx("%s: failed to add fixed IO port for QEMU FwCfg", + __func__); + goto done; + } - /* add handlers for fwcfg ports */ - if ((error = qemu_fwcfg_register_port("qemu_fwcfg_selector", - QEMU_FWCFG_SELECTOR_PORT_NUMBER, QEMU_FWCFG_SELECTOR_PORT_SIZE, - QEMU_FWCFG_SELECTOR_PORT_FLAGS, - qemu_fwcfg_selector_port_handler)) != 0) { - warnx("%s: Unable to register qemu fwcfg selector port 0x%x", - __func__, QEMU_FWCFG_SELECTOR_PORT_NUMBER); - goto done; - } - if ((error = qemu_fwcfg_register_port("qemu_fwcfg_data", - QEMU_FWCFG_DATA_PORT_NUMBER, QEMU_FWCFG_DATA_PORT_SIZE, - QEMU_FWCFG_DATA_PORT_FLAGS, qemu_fwcfg_data_port_handler)) != 0) { - warnx("%s: Unable to register qemu fwcfg data port 0x%x", - __func__, QEMU_FWCFG_DATA_PORT_NUMBER); - goto done; + /* add handlers for fwcfg ports */ + if ((error = qemu_fwcfg_register_port("qemu_fwcfg_selector", + QEMU_FWCFG_SELECTOR_PORT_NUMBER, + QEMU_FWCFG_SELECTOR_PORT_SIZE, + QEMU_FWCFG_SELECTOR_PORT_FLAGS, + qemu_fwcfg_selector_port_handler)) != 0) { + warnx( + "%s: Unable to register qemu fwcfg selector port 0x%x", + __func__, QEMU_FWCFG_SELECTOR_PORT_NUMBER); + goto done; + } + if ((error = qemu_fwcfg_register_port("qemu_fwcfg_data", + QEMU_FWCFG_DATA_PORT_NUMBER, QEMU_FWCFG_DATA_PORT_SIZE, + QEMU_FWCFG_DATA_PORT_FLAGS, + qemu_fwcfg_data_port_handler)) != 0) { + warnx( + "%s: Unable to register qemu fwcfg data port 0x%x", + __func__, QEMU_FWCFG_DATA_PORT_NUMBER); + goto done; + } } /* add common fwcfg items */