2019-10-02 09:03:19 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Intel Corporation
|
|
|
|
* Copyright (c) 2019 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2 or later, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "qemu/error-report.h"
|
|
|
|
#include "qemu/cutils.h"
|
|
|
|
#include "qemu/units.h"
|
|
|
|
#include "qapi/error.h"
|
|
|
|
#include "qapi/visitor.h"
|
|
|
|
#include "qapi/qapi-visit-common.h"
|
|
|
|
#include "sysemu/sysemu.h"
|
|
|
|
#include "sysemu/cpus.h"
|
|
|
|
#include "sysemu/numa.h"
|
|
|
|
#include "sysemu/reset.h"
|
2020-09-15 15:08:56 +03:00
|
|
|
#include "sysemu/runstate.h"
|
|
|
|
#include "acpi-microvm.h"
|
2021-10-14 22:36:17 +03:00
|
|
|
#include "microvm-dt.h"
|
2019-10-02 09:03:19 +03:00
|
|
|
|
|
|
|
#include "hw/loader.h"
|
|
|
|
#include "hw/irq.h"
|
|
|
|
#include "hw/kvm/clock.h"
|
|
|
|
#include "hw/i386/microvm.h"
|
|
|
|
#include "hw/i386/x86.h"
|
|
|
|
#include "target/i386/cpu.h"
|
2019-12-12 19:15:43 +03:00
|
|
|
#include "hw/intc/i8259.h"
|
2019-10-02 09:03:19 +03:00
|
|
|
#include "hw/timer/i8254.h"
|
2019-10-26 16:36:22 +03:00
|
|
|
#include "hw/rtc/mc146818rtc.h"
|
2019-10-02 09:03:19 +03:00
|
|
|
#include "hw/char/serial.h"
|
2020-09-15 15:09:09 +03:00
|
|
|
#include "hw/display/ramfb.h"
|
2019-10-02 09:03:19 +03:00
|
|
|
#include "hw/i386/topology.h"
|
|
|
|
#include "hw/i386/e820_memory_layout.h"
|
|
|
|
#include "hw/i386/fw_cfg.h"
|
|
|
|
#include "hw/virtio/virtio-mmio.h"
|
2020-09-15 15:08:56 +03:00
|
|
|
#include "hw/acpi/acpi.h"
|
|
|
|
#include "hw/acpi/generic_event_device.h"
|
2020-09-28 13:42:49 +03:00
|
|
|
#include "hw/pci-host/gpex.h"
|
2020-10-20 10:48:39 +03:00
|
|
|
#include "hw/usb/xhci.h"
|
2019-10-02 09:03:19 +03:00
|
|
|
|
|
|
|
#include "elf.h"
|
2020-12-12 18:55:08 +03:00
|
|
|
#include "kvm/kvm_i386.h"
|
2019-10-02 09:03:19 +03:00
|
|
|
#include "hw/xen/start_info.h"
|
|
|
|
|
2020-09-15 15:08:49 +03:00
|
|
|
#define MICROVM_QBOOT_FILENAME "qboot.rom"
|
2020-09-15 15:08:59 +03:00
|
|
|
#define MICROVM_BIOS_FILENAME "bios-microvm.bin"
|
2019-10-02 09:03:19 +03:00
|
|
|
|
|
|
|
static void microvm_set_rtc(MicrovmMachineState *mms, ISADevice *s)
|
|
|
|
{
|
|
|
|
X86MachineState *x86ms = X86_MACHINE(mms);
|
|
|
|
int val;
|
|
|
|
|
|
|
|
val = MIN(x86ms->below_4g_mem_size / KiB, 640);
|
|
|
|
rtc_set_memory(s, 0x15, val);
|
|
|
|
rtc_set_memory(s, 0x16, val >> 8);
|
|
|
|
/* extended memory (next 64MiB) */
|
|
|
|
if (x86ms->below_4g_mem_size > 1 * MiB) {
|
|
|
|
val = (x86ms->below_4g_mem_size - 1 * MiB) / KiB;
|
|
|
|
} else {
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
if (val > 65535) {
|
|
|
|
val = 65535;
|
|
|
|
}
|
|
|
|
rtc_set_memory(s, 0x17, val);
|
|
|
|
rtc_set_memory(s, 0x18, val >> 8);
|
|
|
|
rtc_set_memory(s, 0x30, val);
|
|
|
|
rtc_set_memory(s, 0x31, val >> 8);
|
|
|
|
/* memory between 16MiB and 4GiB */
|
|
|
|
if (x86ms->below_4g_mem_size > 16 * MiB) {
|
|
|
|
val = (x86ms->below_4g_mem_size - 16 * MiB) / (64 * KiB);
|
|
|
|
} else {
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
if (val > 65535) {
|
|
|
|
val = 65535;
|
|
|
|
}
|
|
|
|
rtc_set_memory(s, 0x34, val);
|
|
|
|
rtc_set_memory(s, 0x35, val >> 8);
|
|
|
|
/* memory above 4GiB */
|
|
|
|
val = x86ms->above_4g_mem_size / 65536;
|
|
|
|
rtc_set_memory(s, 0x5b, val);
|
|
|
|
rtc_set_memory(s, 0x5c, val >> 8);
|
|
|
|
rtc_set_memory(s, 0x5d, val >> 16);
|
|
|
|
}
|
|
|
|
|
2020-09-28 13:42:49 +03:00
|
|
|
static void create_gpex(MicrovmMachineState *mms)
|
|
|
|
{
|
|
|
|
X86MachineState *x86ms = X86_MACHINE(mms);
|
|
|
|
MemoryRegion *mmio32_alias;
|
|
|
|
MemoryRegion *mmio64_alias;
|
|
|
|
MemoryRegion *mmio_reg;
|
|
|
|
MemoryRegion *ecam_alias;
|
|
|
|
MemoryRegion *ecam_reg;
|
|
|
|
DeviceState *dev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
dev = qdev_new(TYPE_GPEX_HOST);
|
|
|
|
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
|
|
|
|
|
|
|
|
/* Map only the first size_ecam bytes of ECAM space */
|
|
|
|
ecam_alias = g_new0(MemoryRegion, 1);
|
|
|
|
ecam_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 0);
|
|
|
|
memory_region_init_alias(ecam_alias, OBJECT(dev), "pcie-ecam",
|
|
|
|
ecam_reg, 0, mms->gpex.ecam.size);
|
|
|
|
memory_region_add_subregion(get_system_memory(),
|
|
|
|
mms->gpex.ecam.base, ecam_alias);
|
|
|
|
|
|
|
|
/* Map the MMIO window into system address space so as to expose
|
|
|
|
* the section of PCI MMIO space which starts at the same base address
|
|
|
|
* (ie 1:1 mapping for that part of PCI MMIO space visible through
|
|
|
|
* the window).
|
|
|
|
*/
|
|
|
|
mmio_reg = sysbus_mmio_get_region(SYS_BUS_DEVICE(dev), 1);
|
|
|
|
if (mms->gpex.mmio32.size) {
|
|
|
|
mmio32_alias = g_new0(MemoryRegion, 1);
|
|
|
|
memory_region_init_alias(mmio32_alias, OBJECT(dev), "pcie-mmio32", mmio_reg,
|
|
|
|
mms->gpex.mmio32.base, mms->gpex.mmio32.size);
|
|
|
|
memory_region_add_subregion(get_system_memory(),
|
|
|
|
mms->gpex.mmio32.base, mmio32_alias);
|
|
|
|
}
|
|
|
|
if (mms->gpex.mmio64.size) {
|
|
|
|
mmio64_alias = g_new0(MemoryRegion, 1);
|
|
|
|
memory_region_init_alias(mmio64_alias, OBJECT(dev), "pcie-mmio64", mmio_reg,
|
|
|
|
mms->gpex.mmio64.base, mms->gpex.mmio64.size);
|
|
|
|
memory_region_add_subregion(get_system_memory(),
|
|
|
|
mms->gpex.mmio64.base, mmio64_alias);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < GPEX_NUM_IRQS; i++) {
|
|
|
|
sysbus_connect_irq(SYS_BUS_DEVICE(dev), i,
|
|
|
|
x86ms->gsi[mms->gpex.irq + i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-03 13:54:18 +03:00
|
|
|
static int microvm_ioapics(MicrovmMachineState *mms)
|
|
|
|
{
|
|
|
|
if (!x86_machine_is_acpi_enabled(X86_MACHINE(mms))) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (mms->ioapic2 == ON_OFF_AUTO_OFF) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2019-10-02 09:03:19 +03:00
|
|
|
static void microvm_devices_init(MicrovmMachineState *mms)
|
|
|
|
{
|
2020-10-26 17:30:18 +03:00
|
|
|
const char *default_firmware;
|
2019-10-02 09:03:19 +03:00
|
|
|
X86MachineState *x86ms = X86_MACHINE(mms);
|
|
|
|
ISABus *isa_bus;
|
|
|
|
ISADevice *rtc_state;
|
|
|
|
GSIState *gsi_state;
|
2020-12-03 13:54:18 +03:00
|
|
|
int ioapics;
|
2019-10-02 09:03:19 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Core components */
|
2020-12-03 13:54:18 +03:00
|
|
|
ioapics = microvm_ioapics(mms);
|
2019-10-02 09:03:19 +03:00
|
|
|
gsi_state = g_malloc0(sizeof(*gsi_state));
|
2020-12-03 13:54:18 +03:00
|
|
|
x86ms->gsi = qemu_allocate_irqs(gsi_handler, gsi_state,
|
|
|
|
IOAPIC_NUM_PINS * ioapics);
|
2019-10-02 09:03:19 +03:00
|
|
|
|
|
|
|
isa_bus = isa_bus_new(NULL, get_system_memory(), get_system_io(),
|
|
|
|
&error_abort);
|
|
|
|
isa_bus_irqs(isa_bus, x86ms->gsi);
|
|
|
|
|
|
|
|
ioapic_init_gsi(gsi_state, "machine");
|
2020-12-03 13:54:18 +03:00
|
|
|
if (ioapics > 1) {
|
|
|
|
x86ms->ioapic2 = ioapic_init_secondary(gsi_state);
|
|
|
|
}
|
2019-10-02 09:03:19 +03:00
|
|
|
|
2020-09-22 18:19:34 +03:00
|
|
|
kvmclock_create(true);
|
2019-10-02 09:03:19 +03:00
|
|
|
|
2020-12-03 13:54:15 +03:00
|
|
|
mms->virtio_irq_base = 5;
|
|
|
|
mms->virtio_num_transports = 8;
|
2020-12-03 13:54:18 +03:00
|
|
|
if (x86ms->ioapic2) {
|
|
|
|
mms->pcie_irq_base = 16; /* 16 -> 19 */
|
|
|
|
/* use second ioapic (24 -> 47) for virtio-mmio irq lines */
|
|
|
|
mms->virtio_irq_base = IO_APIC_SECONDARY_IRQBASE;
|
|
|
|
mms->virtio_num_transports = IOAPIC_NUM_PINS;
|
|
|
|
} else if (x86_machine_is_acpi_enabled(x86ms)) {
|
|
|
|
mms->pcie_irq_base = 12; /* 12 -> 15 */
|
|
|
|
mms->virtio_irq_base = 16; /* 16 -> 23 */
|
2020-12-03 13:54:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < mms->virtio_num_transports; i++) {
|
2019-10-02 09:03:19 +03:00
|
|
|
sysbus_create_simple("virtio-mmio",
|
|
|
|
VIRTIO_MMIO_BASE + i * 512,
|
2020-09-15 15:08:55 +03:00
|
|
|
x86ms->gsi[mms->virtio_irq_base + i]);
|
2019-10-02 09:03:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Optional and legacy devices */
|
2020-09-15 15:08:56 +03:00
|
|
|
if (x86_machine_is_acpi_enabled(x86ms)) {
|
|
|
|
DeviceState *dev = qdev_new(TYPE_ACPI_GED_X86);
|
|
|
|
qdev_prop_set_uint32(dev, "ged-event", ACPI_GED_PWR_DOWN_EVT);
|
|
|
|
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, GED_MMIO_BASE);
|
|
|
|
/* sysbus_mmio_map(SYS_BUS_DEVICE(dev), 1, GED_MMIO_BASE_MEMHP); */
|
|
|
|
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 2, GED_MMIO_BASE_REGS);
|
|
|
|
sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0,
|
|
|
|
x86ms->gsi[GED_MMIO_IRQ]);
|
|
|
|
sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
|
2020-09-15 15:09:02 +03:00
|
|
|
x86ms->acpi_dev = HOTPLUG_HANDLER(dev);
|
2020-09-15 15:08:56 +03:00
|
|
|
}
|
2019-10-02 09:03:19 +03:00
|
|
|
|
2020-10-20 10:48:39 +03:00
|
|
|
if (x86_machine_is_acpi_enabled(x86ms) && machine_usb(MACHINE(mms))) {
|
|
|
|
DeviceState *dev = qdev_new(TYPE_XHCI_SYSBUS);
|
|
|
|
qdev_prop_set_uint32(dev, "intrs", 1);
|
|
|
|
qdev_prop_set_uint32(dev, "slots", XHCI_MAXSLOTS);
|
|
|
|
qdev_prop_set_uint32(dev, "p2", 8);
|
|
|
|
qdev_prop_set_uint32(dev, "p3", 8);
|
|
|
|
sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
|
|
|
|
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, MICROVM_XHCI_BASE);
|
|
|
|
sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0,
|
|
|
|
x86ms->gsi[MICROVM_XHCI_IRQ]);
|
|
|
|
}
|
|
|
|
|
2020-09-28 13:42:49 +03:00
|
|
|
if (x86_machine_is_acpi_enabled(x86ms) && mms->pcie == ON_OFF_AUTO_ON) {
|
2020-09-28 13:42:50 +03:00
|
|
|
/* use topmost 25% of the address space available */
|
|
|
|
hwaddr phys_size = (hwaddr)1 << X86_CPU(first_cpu)->phys_bits;
|
|
|
|
if (phys_size > 0x1000000ll) {
|
|
|
|
mms->gpex.mmio64.size = phys_size / 4;
|
|
|
|
mms->gpex.mmio64.base = phys_size - mms->gpex.mmio64.size;
|
|
|
|
}
|
2020-09-28 13:42:49 +03:00
|
|
|
mms->gpex.mmio32.base = PCIE_MMIO_BASE;
|
|
|
|
mms->gpex.mmio32.size = PCIE_MMIO_SIZE;
|
|
|
|
mms->gpex.ecam.base = PCIE_ECAM_BASE;
|
|
|
|
mms->gpex.ecam.size = PCIE_ECAM_SIZE;
|
2020-12-03 13:54:16 +03:00
|
|
|
mms->gpex.irq = mms->pcie_irq_base;
|
2020-09-28 13:42:49 +03:00
|
|
|
create_gpex(mms);
|
2020-12-03 13:54:16 +03:00
|
|
|
x86ms->pci_irq_mask = ((1 << (mms->pcie_irq_base + 0)) |
|
|
|
|
(1 << (mms->pcie_irq_base + 1)) |
|
|
|
|
(1 << (mms->pcie_irq_base + 2)) |
|
|
|
|
(1 << (mms->pcie_irq_base + 3)));
|
2020-10-16 14:38:32 +03:00
|
|
|
} else {
|
|
|
|
x86ms->pci_irq_mask = 0;
|
2020-09-28 13:42:49 +03:00
|
|
|
}
|
|
|
|
|
2022-03-10 15:28:11 +03:00
|
|
|
if (x86ms->pic == ON_OFF_AUTO_ON || x86ms->pic == ON_OFF_AUTO_AUTO) {
|
2019-10-02 09:03:19 +03:00
|
|
|
qemu_irq *i8259;
|
|
|
|
|
2019-12-12 16:14:40 +03:00
|
|
|
i8259 = i8259_init(isa_bus, x86_allocate_cpu_irq());
|
2019-10-02 09:03:19 +03:00
|
|
|
for (i = 0; i < ISA_NUM_IRQS; i++) {
|
|
|
|
gsi_state->i8259_irq[i] = i8259[i];
|
|
|
|
}
|
|
|
|
g_free(i8259);
|
|
|
|
}
|
|
|
|
|
2022-03-10 15:28:10 +03:00
|
|
|
if (x86ms->pit == ON_OFF_AUTO_ON || x86ms->pit == ON_OFF_AUTO_AUTO) {
|
2019-10-02 09:03:19 +03:00
|
|
|
if (kvm_pit_in_kernel()) {
|
|
|
|
kvm_pit_init(isa_bus, 0x40);
|
|
|
|
} else {
|
|
|
|
i8254_pit_init(isa_bus, 0x40, 0, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mms->rtc == ON_OFF_AUTO_ON ||
|
|
|
|
(mms->rtc == ON_OFF_AUTO_AUTO && !kvm_enabled())) {
|
|
|
|
rtc_state = mc146818_rtc_init(isa_bus, 2000, NULL);
|
|
|
|
microvm_set_rtc(mms, rtc_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mms->isa_serial) {
|
|
|
|
serial_hds_isa_init(isa_bus, 0, 1);
|
|
|
|
}
|
|
|
|
|
2020-10-26 17:30:18 +03:00
|
|
|
default_firmware = x86_machine_is_acpi_enabled(x86ms)
|
2020-09-15 15:08:59 +03:00
|
|
|
? MICROVM_BIOS_FILENAME
|
|
|
|
: MICROVM_QBOOT_FILENAME;
|
2020-10-26 17:30:18 +03:00
|
|
|
x86_bios_rom_init(MACHINE(mms), default_firmware, get_system_memory(), true);
|
2019-10-02 09:03:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void microvm_memory_init(MicrovmMachineState *mms)
|
|
|
|
{
|
|
|
|
MachineState *machine = MACHINE(mms);
|
|
|
|
X86MachineState *x86ms = X86_MACHINE(mms);
|
2020-02-19 19:09:16 +03:00
|
|
|
MemoryRegion *ram_below_4g, *ram_above_4g;
|
2019-10-02 09:03:19 +03:00
|
|
|
MemoryRegion *system_memory = get_system_memory();
|
|
|
|
FWCfgState *fw_cfg;
|
2020-05-29 10:39:54 +03:00
|
|
|
ram_addr_t lowmem = 0xc0000000; /* 3G */
|
2019-10-02 09:03:19 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (machine->ram_size > lowmem) {
|
|
|
|
x86ms->above_4g_mem_size = machine->ram_size - lowmem;
|
|
|
|
x86ms->below_4g_mem_size = lowmem;
|
|
|
|
} else {
|
|
|
|
x86ms->above_4g_mem_size = 0;
|
|
|
|
x86ms->below_4g_mem_size = machine->ram_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
ram_below_4g = g_malloc(sizeof(*ram_below_4g));
|
2020-02-19 19:09:16 +03:00
|
|
|
memory_region_init_alias(ram_below_4g, NULL, "ram-below-4g", machine->ram,
|
2019-10-02 09:03:19 +03:00
|
|
|
0, x86ms->below_4g_mem_size);
|
|
|
|
memory_region_add_subregion(system_memory, 0, ram_below_4g);
|
|
|
|
|
|
|
|
e820_add_entry(0, x86ms->below_4g_mem_size, E820_RAM);
|
|
|
|
|
|
|
|
if (x86ms->above_4g_mem_size > 0) {
|
|
|
|
ram_above_4g = g_malloc(sizeof(*ram_above_4g));
|
2020-02-19 19:09:16 +03:00
|
|
|
memory_region_init_alias(ram_above_4g, NULL, "ram-above-4g",
|
|
|
|
machine->ram,
|
2019-10-02 09:03:19 +03:00
|
|
|
x86ms->below_4g_mem_size,
|
|
|
|
x86ms->above_4g_mem_size);
|
|
|
|
memory_region_add_subregion(system_memory, 0x100000000ULL,
|
|
|
|
ram_above_4g);
|
|
|
|
e820_add_entry(0x100000000ULL, x86ms->above_4g_mem_size, E820_RAM);
|
|
|
|
}
|
|
|
|
|
|
|
|
fw_cfg = fw_cfg_init_io_dma(FW_CFG_IO_BASE, FW_CFG_IO_BASE + 4,
|
|
|
|
&address_space_memory);
|
|
|
|
|
|
|
|
fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, machine->smp.cpus);
|
|
|
|
fw_cfg_add_i16(fw_cfg, FW_CFG_MAX_CPUS, machine->smp.max_cpus);
|
|
|
|
fw_cfg_add_i64(fw_cfg, FW_CFG_RAM_SIZE, (uint64_t)machine->ram_size);
|
2020-09-22 23:19:22 +03:00
|
|
|
fw_cfg_add_i32(fw_cfg, FW_CFG_IRQ0_OVERRIDE, 1);
|
2019-10-02 09:03:19 +03:00
|
|
|
fw_cfg_add_file(fw_cfg, "etc/e820", e820_table,
|
|
|
|
sizeof(struct e820_entry) * e820_get_num_entries());
|
|
|
|
|
|
|
|
rom_set_fw(fw_cfg);
|
|
|
|
|
|
|
|
if (machine->kernel_filename != NULL) {
|
2022-09-21 12:31:34 +03:00
|
|
|
x86_load_linux(x86ms, fw_cfg, 0, true, false);
|
2019-10-02 09:03:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mms->option_roms) {
|
|
|
|
for (i = 0; i < nb_option_roms; i++) {
|
|
|
|
rom_add_option(option_rom[i].name, option_rom[i].bootindex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
x86ms->fw_cfg = fw_cfg;
|
|
|
|
x86ms->ioapic_as = &address_space_memory;
|
|
|
|
}
|
|
|
|
|
2020-09-15 15:08:55 +03:00
|
|
|
static gchar *microvm_get_mmio_cmdline(gchar *name, uint32_t virtio_irq_base)
|
2019-10-02 09:03:19 +03:00
|
|
|
{
|
|
|
|
gchar *cmdline;
|
|
|
|
gchar *separator;
|
|
|
|
long int index;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
separator = g_strrstr(name, ".");
|
|
|
|
if (!separator) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (qemu_strtol(separator + 1, NULL, 10, &index) != 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmdline = g_malloc0(VIRTIO_CMDLINE_MAXLEN);
|
|
|
|
ret = g_snprintf(cmdline, VIRTIO_CMDLINE_MAXLEN,
|
|
|
|
" virtio_mmio.device=512@0x%lx:%ld",
|
|
|
|
VIRTIO_MMIO_BASE + index * 512,
|
2020-09-15 15:08:55 +03:00
|
|
|
virtio_irq_base + index);
|
2019-10-02 09:03:19 +03:00
|
|
|
if (ret < 0 || ret >= VIRTIO_CMDLINE_MAXLEN) {
|
|
|
|
g_free(cmdline);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmdline;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void microvm_fix_kernel_cmdline(MachineState *machine)
|
|
|
|
{
|
|
|
|
X86MachineState *x86ms = X86_MACHINE(machine);
|
2020-09-15 15:08:55 +03:00
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(machine);
|
2019-10-02 09:03:19 +03:00
|
|
|
BusState *bus;
|
|
|
|
BusChild *kid;
|
x86: don't let decompressed kernel image clobber setup_data
The setup_data links are appended to the compressed kernel image. Since
the kernel image is typically loaded at 0x100000, setup_data lives at
`0x100000 + compressed_size`, which does not get relocated during the
kernel's boot process.
The kernel typically decompresses the image starting at address
0x1000000 (note: there's one more zero there than the compressed image
above). This usually is fine for most kernels.
However, if the compressed image is actually quite large, then
setup_data will live at a `0x100000 + compressed_size` that extends into
the decompressed zone at 0x1000000. In other words, if compressed_size
is larger than `0x1000000 - 0x100000`, then the decompression step will
clobber setup_data, resulting in crashes.
Visually, what happens now is that QEMU appends setup_data to the kernel
image:
kernel image setup_data
|--------------------------||----------------|
0x100000 0x100000+l1 0x100000+l1+l2
The problem is that this decompresses to 0x1000000 (one more zero). So
if l1 is > (0x1000000-0x100000), then this winds up looking like:
kernel image setup_data
|--------------------------||----------------|
0x100000 0x100000+l1 0x100000+l1+l2
d e c o m p r e s s e d k e r n e l
|-------------------------------------------------------------|
0x1000000 0x1000000+l3
The decompressed kernel seemingly overwriting the compressed kernel
image isn't a problem, because that gets relocated to a higher address
early on in the boot process, at the end of startup_64. setup_data,
however, stays in the same place, since those links are self referential
and nothing fixes them up. So the decompressed kernel clobbers it.
Fix this by appending setup_data to the cmdline blob rather than the
kernel image blob, which remains at a lower address that won't get
clobbered.
This could have been done by overwriting the initrd blob instead, but
that poses big difficulties, such as no longer being able to use memory
mapped files for initrd, hurting performance, and, more importantly, the
initrd address calculation is hard coded in qboot, and it always grows
down rather than up, which means lots of brittle semantics would have to
be changed around, incurring more complexity. In contrast, using cmdline
is simple and doesn't interfere with anything.
The microvm machine has a gross hack where it fiddles with fw_cfg data
after the fact. So this hack is updated to account for this appending,
by reserving some bytes.
Fixup-by: Michael S. Tsirkin <mst@redhat.com>
Cc: x86@kernel.org
Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Message-Id: <20221230220725.618763-1-Jason@zx2c4.com>
Message-ID: <20230128061015-mutt-send-email-mst@kernel.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Eric Biggers <ebiggers@google.com>
Tested-by: Mathias Krause <minipli@grsecurity.net>
2022-12-31 01:07:25 +03:00
|
|
|
char *cmdline, *existing_cmdline;
|
|
|
|
size_t len;
|
2019-10-02 09:03:19 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find MMIO transports with attached devices, and add them to the kernel
|
|
|
|
* command line.
|
|
|
|
*
|
|
|
|
* Yes, this is a hack, but one that heavily improves the UX without
|
|
|
|
* introducing any significant issues.
|
|
|
|
*/
|
x86: don't let decompressed kernel image clobber setup_data
The setup_data links are appended to the compressed kernel image. Since
the kernel image is typically loaded at 0x100000, setup_data lives at
`0x100000 + compressed_size`, which does not get relocated during the
kernel's boot process.
The kernel typically decompresses the image starting at address
0x1000000 (note: there's one more zero there than the compressed image
above). This usually is fine for most kernels.
However, if the compressed image is actually quite large, then
setup_data will live at a `0x100000 + compressed_size` that extends into
the decompressed zone at 0x1000000. In other words, if compressed_size
is larger than `0x1000000 - 0x100000`, then the decompression step will
clobber setup_data, resulting in crashes.
Visually, what happens now is that QEMU appends setup_data to the kernel
image:
kernel image setup_data
|--------------------------||----------------|
0x100000 0x100000+l1 0x100000+l1+l2
The problem is that this decompresses to 0x1000000 (one more zero). So
if l1 is > (0x1000000-0x100000), then this winds up looking like:
kernel image setup_data
|--------------------------||----------------|
0x100000 0x100000+l1 0x100000+l1+l2
d e c o m p r e s s e d k e r n e l
|-------------------------------------------------------------|
0x1000000 0x1000000+l3
The decompressed kernel seemingly overwriting the compressed kernel
image isn't a problem, because that gets relocated to a higher address
early on in the boot process, at the end of startup_64. setup_data,
however, stays in the same place, since those links are self referential
and nothing fixes them up. So the decompressed kernel clobbers it.
Fix this by appending setup_data to the cmdline blob rather than the
kernel image blob, which remains at a lower address that won't get
clobbered.
This could have been done by overwriting the initrd blob instead, but
that poses big difficulties, such as no longer being able to use memory
mapped files for initrd, hurting performance, and, more importantly, the
initrd address calculation is hard coded in qboot, and it always grows
down rather than up, which means lots of brittle semantics would have to
be changed around, incurring more complexity. In contrast, using cmdline
is simple and doesn't interfere with anything.
The microvm machine has a gross hack where it fiddles with fw_cfg data
after the fact. So this hack is updated to account for this appending,
by reserving some bytes.
Fixup-by: Michael S. Tsirkin <mst@redhat.com>
Cc: x86@kernel.org
Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Message-Id: <20221230220725.618763-1-Jason@zx2c4.com>
Message-ID: <20230128061015-mutt-send-email-mst@kernel.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Eric Biggers <ebiggers@google.com>
Tested-by: Mathias Krause <minipli@grsecurity.net>
2022-12-31 01:07:25 +03:00
|
|
|
existing_cmdline = fw_cfg_read_bytes_ptr(x86ms->fw_cfg, FW_CFG_CMDLINE_DATA);
|
|
|
|
cmdline = g_strdup(existing_cmdline);
|
2019-10-02 09:03:19 +03:00
|
|
|
bus = sysbus_get_default();
|
|
|
|
QTAILQ_FOREACH(kid, &bus->children, sibling) {
|
|
|
|
DeviceState *dev = kid->child;
|
|
|
|
ObjectClass *class = object_get_class(OBJECT(dev));
|
|
|
|
|
|
|
|
if (class == object_class_by_name(TYPE_VIRTIO_MMIO)) {
|
|
|
|
VirtIOMMIOProxy *mmio = VIRTIO_MMIO(OBJECT(dev));
|
|
|
|
VirtioBusState *mmio_virtio_bus = &mmio->bus;
|
|
|
|
BusState *mmio_bus = &mmio_virtio_bus->parent_obj;
|
|
|
|
|
|
|
|
if (!QTAILQ_EMPTY(&mmio_bus->children)) {
|
2020-09-15 15:08:55 +03:00
|
|
|
gchar *mmio_cmdline = microvm_get_mmio_cmdline
|
|
|
|
(mmio_bus->name, mms->virtio_irq_base);
|
2019-10-02 09:03:19 +03:00
|
|
|
if (mmio_cmdline) {
|
|
|
|
char *newcmd = g_strjoin(NULL, cmdline, mmio_cmdline, NULL);
|
|
|
|
g_free(mmio_cmdline);
|
|
|
|
g_free(cmdline);
|
|
|
|
cmdline = newcmd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
x86: don't let decompressed kernel image clobber setup_data
The setup_data links are appended to the compressed kernel image. Since
the kernel image is typically loaded at 0x100000, setup_data lives at
`0x100000 + compressed_size`, which does not get relocated during the
kernel's boot process.
The kernel typically decompresses the image starting at address
0x1000000 (note: there's one more zero there than the compressed image
above). This usually is fine for most kernels.
However, if the compressed image is actually quite large, then
setup_data will live at a `0x100000 + compressed_size` that extends into
the decompressed zone at 0x1000000. In other words, if compressed_size
is larger than `0x1000000 - 0x100000`, then the decompression step will
clobber setup_data, resulting in crashes.
Visually, what happens now is that QEMU appends setup_data to the kernel
image:
kernel image setup_data
|--------------------------||----------------|
0x100000 0x100000+l1 0x100000+l1+l2
The problem is that this decompresses to 0x1000000 (one more zero). So
if l1 is > (0x1000000-0x100000), then this winds up looking like:
kernel image setup_data
|--------------------------||----------------|
0x100000 0x100000+l1 0x100000+l1+l2
d e c o m p r e s s e d k e r n e l
|-------------------------------------------------------------|
0x1000000 0x1000000+l3
The decompressed kernel seemingly overwriting the compressed kernel
image isn't a problem, because that gets relocated to a higher address
early on in the boot process, at the end of startup_64. setup_data,
however, stays in the same place, since those links are self referential
and nothing fixes them up. So the decompressed kernel clobbers it.
Fix this by appending setup_data to the cmdline blob rather than the
kernel image blob, which remains at a lower address that won't get
clobbered.
This could have been done by overwriting the initrd blob instead, but
that poses big difficulties, such as no longer being able to use memory
mapped files for initrd, hurting performance, and, more importantly, the
initrd address calculation is hard coded in qboot, and it always grows
down rather than up, which means lots of brittle semantics would have to
be changed around, incurring more complexity. In contrast, using cmdline
is simple and doesn't interfere with anything.
The microvm machine has a gross hack where it fiddles with fw_cfg data
after the fact. So this hack is updated to account for this appending,
by reserving some bytes.
Fixup-by: Michael S. Tsirkin <mst@redhat.com>
Cc: x86@kernel.org
Cc: Philippe Mathieu-Daudé <philmd@linaro.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Message-Id: <20221230220725.618763-1-Jason@zx2c4.com>
Message-ID: <20230128061015-mutt-send-email-mst@kernel.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Eric Biggers <ebiggers@google.com>
Tested-by: Mathias Krause <minipli@grsecurity.net>
2022-12-31 01:07:25 +03:00
|
|
|
len = strlen(cmdline);
|
|
|
|
if (len > VIRTIO_CMDLINE_TOTAL_MAX_LEN + strlen(existing_cmdline)) {
|
|
|
|
fprintf(stderr, "qemu: virtio mmio cmdline too large, skipping\n");
|
|
|
|
} else {
|
|
|
|
memcpy(existing_cmdline, cmdline, len + 1);
|
|
|
|
}
|
2019-11-12 19:34:23 +03:00
|
|
|
g_free(cmdline);
|
2019-10-02 09:03:19 +03:00
|
|
|
}
|
|
|
|
|
2020-09-15 15:09:04 +03:00
|
|
|
static void microvm_device_pre_plug_cb(HotplugHandler *hotplug_dev,
|
|
|
|
DeviceState *dev, Error **errp)
|
|
|
|
{
|
2020-09-28 13:42:50 +03:00
|
|
|
X86CPU *cpu = X86_CPU(dev);
|
|
|
|
|
|
|
|
cpu->host_phys_bits = true; /* need reliable phys-bits */
|
2020-09-15 15:09:04 +03:00
|
|
|
x86_cpu_pre_plug(hotplug_dev, dev, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void microvm_device_plug_cb(HotplugHandler *hotplug_dev,
|
|
|
|
DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
x86_cpu_plug(hotplug_dev, dev, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void microvm_device_unplug_request_cb(HotplugHandler *hotplug_dev,
|
|
|
|
DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
error_setg(errp, "unplug not supported by microvm");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void microvm_device_unplug_cb(HotplugHandler *hotplug_dev,
|
|
|
|
DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
error_setg(errp, "unplug not supported by microvm");
|
|
|
|
}
|
|
|
|
|
|
|
|
static HotplugHandler *microvm_get_hotplug_handler(MachineState *machine,
|
|
|
|
DeviceState *dev)
|
|
|
|
{
|
|
|
|
if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) {
|
|
|
|
return HOTPLUG_HANDLER(machine);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-10-02 09:03:19 +03:00
|
|
|
static void microvm_machine_state_init(MachineState *machine)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(machine);
|
|
|
|
X86MachineState *x86ms = X86_MACHINE(machine);
|
|
|
|
|
|
|
|
microvm_memory_init(mms);
|
|
|
|
|
|
|
|
x86_cpus_init(x86ms, CPU_VERSION_LATEST);
|
|
|
|
|
|
|
|
microvm_devices_init(mms);
|
|
|
|
}
|
|
|
|
|
2022-10-25 03:43:17 +03:00
|
|
|
static void microvm_machine_reset(MachineState *machine, ShutdownCause reason)
|
2019-10-02 09:03:19 +03:00
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(machine);
|
|
|
|
CPUState *cs;
|
|
|
|
X86CPU *cpu;
|
|
|
|
|
2020-09-15 15:09:00 +03:00
|
|
|
if (!x86_machine_is_acpi_enabled(X86_MACHINE(machine)) &&
|
|
|
|
machine->kernel_filename != NULL &&
|
2019-10-02 09:03:19 +03:00
|
|
|
mms->auto_kernel_cmdline && !mms->kernel_cmdline_fixed) {
|
|
|
|
microvm_fix_kernel_cmdline(machine);
|
|
|
|
mms->kernel_cmdline_fixed = true;
|
|
|
|
}
|
|
|
|
|
2022-10-25 03:43:17 +03:00
|
|
|
qemu_devices_reset(reason);
|
2019-10-02 09:03:19 +03:00
|
|
|
|
|
|
|
CPU_FOREACH(cs) {
|
|
|
|
cpu = X86_CPU(cs);
|
|
|
|
|
2022-09-30 18:52:03 +03:00
|
|
|
x86_cpu_after_reset(cpu);
|
2019-10-02 09:03:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void microvm_machine_get_rtc(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(obj);
|
|
|
|
OnOffAuto rtc = mms->rtc;
|
|
|
|
|
|
|
|
visit_type_OnOffAuto(v, name, &rtc, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void microvm_machine_set_rtc(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(obj);
|
|
|
|
|
|
|
|
visit_type_OnOffAuto(v, name, &mms->rtc, errp);
|
|
|
|
}
|
|
|
|
|
2020-09-28 13:42:49 +03:00
|
|
|
static void microvm_machine_get_pcie(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(obj);
|
|
|
|
OnOffAuto pcie = mms->pcie;
|
|
|
|
|
|
|
|
visit_type_OnOffAuto(v, name, &pcie, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void microvm_machine_set_pcie(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(obj);
|
|
|
|
|
|
|
|
visit_type_OnOffAuto(v, name, &mms->pcie, errp);
|
|
|
|
}
|
|
|
|
|
2020-12-03 13:54:18 +03:00
|
|
|
static void microvm_machine_get_ioapic2(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(obj);
|
|
|
|
OnOffAuto ioapic2 = mms->ioapic2;
|
|
|
|
|
|
|
|
visit_type_OnOffAuto(v, name, &ioapic2, errp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void microvm_machine_set_ioapic2(Object *obj, Visitor *v, const char *name,
|
|
|
|
void *opaque, Error **errp)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(obj);
|
|
|
|
|
|
|
|
visit_type_OnOffAuto(v, name, &mms->ioapic2, errp);
|
|
|
|
}
|
|
|
|
|
2019-10-02 09:03:19 +03:00
|
|
|
static bool microvm_machine_get_isa_serial(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(obj);
|
|
|
|
|
|
|
|
return mms->isa_serial;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void microvm_machine_set_isa_serial(Object *obj, bool value,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(obj);
|
|
|
|
|
|
|
|
mms->isa_serial = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool microvm_machine_get_option_roms(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(obj);
|
|
|
|
|
|
|
|
return mms->option_roms;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void microvm_machine_set_option_roms(Object *obj, bool value,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(obj);
|
|
|
|
|
|
|
|
mms->option_roms = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool microvm_machine_get_auto_kernel_cmdline(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(obj);
|
|
|
|
|
|
|
|
return mms->auto_kernel_cmdline;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void microvm_machine_set_auto_kernel_cmdline(Object *obj, bool value,
|
|
|
|
Error **errp)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(obj);
|
|
|
|
|
|
|
|
mms->auto_kernel_cmdline = value;
|
|
|
|
}
|
|
|
|
|
2020-09-15 15:08:56 +03:00
|
|
|
static void microvm_machine_done(Notifier *notifier, void *data)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = container_of(notifier, MicrovmMachineState,
|
|
|
|
machine_done);
|
|
|
|
|
|
|
|
acpi_setup_microvm(mms);
|
2021-10-14 22:36:17 +03:00
|
|
|
dt_setup_microvm(mms);
|
2020-09-15 15:08:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void microvm_powerdown_req(Notifier *notifier, void *data)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = container_of(notifier, MicrovmMachineState,
|
|
|
|
powerdown_req);
|
2020-09-15 15:09:02 +03:00
|
|
|
X86MachineState *x86ms = X86_MACHINE(mms);
|
2020-09-15 15:08:56 +03:00
|
|
|
|
2020-09-15 15:09:02 +03:00
|
|
|
if (x86ms->acpi_dev) {
|
|
|
|
Object *obj = OBJECT(x86ms->acpi_dev);
|
2020-09-15 15:08:56 +03:00
|
|
|
AcpiDeviceIfClass *adevc = ACPI_DEVICE_IF_GET_CLASS(obj);
|
2020-09-15 15:09:02 +03:00
|
|
|
adevc->send_event(ACPI_DEVICE_IF(x86ms->acpi_dev),
|
|
|
|
ACPI_POWER_DOWN_STATUS);
|
2020-09-15 15:08:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-02 09:03:19 +03:00
|
|
|
static void microvm_machine_initfn(Object *obj)
|
|
|
|
{
|
|
|
|
MicrovmMachineState *mms = MICROVM_MACHINE(obj);
|
|
|
|
|
|
|
|
/* Configuration */
|
|
|
|
mms->rtc = ON_OFF_AUTO_AUTO;
|
2020-09-28 13:42:49 +03:00
|
|
|
mms->pcie = ON_OFF_AUTO_AUTO;
|
2020-12-03 13:54:18 +03:00
|
|
|
mms->ioapic2 = ON_OFF_AUTO_AUTO;
|
2019-10-02 09:03:19 +03:00
|
|
|
mms->isa_serial = true;
|
|
|
|
mms->option_roms = true;
|
|
|
|
mms->auto_kernel_cmdline = true;
|
|
|
|
|
|
|
|
/* State */
|
|
|
|
mms->kernel_cmdline_fixed = false;
|
2020-09-15 15:08:56 +03:00
|
|
|
|
|
|
|
mms->machine_done.notify = microvm_machine_done;
|
|
|
|
qemu_add_machine_init_done_notifier(&mms->machine_done);
|
|
|
|
mms->powerdown_req.notify = microvm_powerdown_req;
|
|
|
|
qemu_register_powerdown_notifier(&mms->powerdown_req);
|
2019-10-02 09:03:19 +03:00
|
|
|
}
|
|
|
|
|
2022-07-01 12:15:16 +03:00
|
|
|
GlobalProperty microvm_properties[] = {
|
|
|
|
/*
|
|
|
|
* pcie host bridge (gpex) on microvm has no io address window,
|
|
|
|
* so reserving io space is not going to work. Turn it off.
|
|
|
|
*/
|
|
|
|
{ "pcie-root-port", "io-reserve", "0" },
|
|
|
|
};
|
|
|
|
|
2019-10-02 09:03:19 +03:00
|
|
|
static void microvm_class_init(ObjectClass *oc, void *data)
|
|
|
|
{
|
2021-10-20 15:48:10 +03:00
|
|
|
X86MachineClass *x86mc = X86_MACHINE_CLASS(oc);
|
2019-10-02 09:03:19 +03:00
|
|
|
MachineClass *mc = MACHINE_CLASS(oc);
|
2020-09-15 15:09:04 +03:00
|
|
|
HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
|
2019-10-02 09:03:19 +03:00
|
|
|
|
|
|
|
mc->init = microvm_machine_state_init;
|
|
|
|
|
|
|
|
mc->family = "microvm_i386";
|
|
|
|
mc->desc = "microvm (i386)";
|
|
|
|
mc->units_per_default_bus = 1;
|
|
|
|
mc->no_floppy = 1;
|
|
|
|
mc->max_cpus = 288;
|
|
|
|
mc->has_hotpluggable_cpus = false;
|
|
|
|
mc->auto_enable_numa_with_memhp = false;
|
2020-06-26 10:22:48 +03:00
|
|
|
mc->auto_enable_numa_with_memdev = false;
|
2019-10-02 09:03:19 +03:00
|
|
|
mc->default_cpu_type = TARGET_DEFAULT_CPU_TYPE;
|
|
|
|
mc->nvdimm_supported = false;
|
2020-02-19 19:09:16 +03:00
|
|
|
mc->default_ram_id = "microvm.ram";
|
2019-10-02 09:03:19 +03:00
|
|
|
|
|
|
|
/* Avoid relying too much on kernel components */
|
|
|
|
mc->default_kernel_irqchip_split = true;
|
|
|
|
|
|
|
|
/* Machine class handlers */
|
|
|
|
mc->reset = microvm_machine_reset;
|
|
|
|
|
2020-09-15 15:09:04 +03:00
|
|
|
/* hotplug (for cpu coldplug) */
|
|
|
|
mc->get_hotplug_handler = microvm_get_hotplug_handler;
|
|
|
|
hc->pre_plug = microvm_device_pre_plug_cb;
|
|
|
|
hc->plug = microvm_device_plug_cb;
|
|
|
|
hc->unplug_request = microvm_device_unplug_request_cb;
|
|
|
|
hc->unplug = microvm_device_unplug_cb;
|
|
|
|
|
2021-10-20 15:48:10 +03:00
|
|
|
x86mc->fwcfg_dma_enabled = true;
|
|
|
|
|
2019-10-02 09:03:19 +03:00
|
|
|
object_class_property_add(oc, MICROVM_MACHINE_RTC, "OnOffAuto",
|
|
|
|
microvm_machine_get_rtc,
|
|
|
|
microvm_machine_set_rtc,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
NULL, NULL);
|
2019-10-02 09:03:19 +03:00
|
|
|
object_class_property_set_description(oc, MICROVM_MACHINE_RTC,
|
2020-05-05 18:29:15 +03:00
|
|
|
"Enable MC146818 RTC");
|
2019-10-02 09:03:19 +03:00
|
|
|
|
2020-09-28 13:42:49 +03:00
|
|
|
object_class_property_add(oc, MICROVM_MACHINE_PCIE, "OnOffAuto",
|
|
|
|
microvm_machine_get_pcie,
|
|
|
|
microvm_machine_set_pcie,
|
|
|
|
NULL, NULL);
|
|
|
|
object_class_property_set_description(oc, MICROVM_MACHINE_PCIE,
|
|
|
|
"Enable PCIe");
|
|
|
|
|
2020-12-03 13:54:18 +03:00
|
|
|
object_class_property_add(oc, MICROVM_MACHINE_IOAPIC2, "OnOffAuto",
|
|
|
|
microvm_machine_get_ioapic2,
|
|
|
|
microvm_machine_set_ioapic2,
|
|
|
|
NULL, NULL);
|
|
|
|
object_class_property_set_description(oc, MICROVM_MACHINE_IOAPIC2,
|
|
|
|
"Enable second IO-APIC");
|
|
|
|
|
2019-10-02 09:03:19 +03:00
|
|
|
object_class_property_add_bool(oc, MICROVM_MACHINE_ISA_SERIAL,
|
|
|
|
microvm_machine_get_isa_serial,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
microvm_machine_set_isa_serial);
|
2019-10-02 09:03:19 +03:00
|
|
|
object_class_property_set_description(oc, MICROVM_MACHINE_ISA_SERIAL,
|
2020-05-05 18:29:15 +03:00
|
|
|
"Set off to disable the instantiation an ISA serial port");
|
2019-10-02 09:03:19 +03:00
|
|
|
|
|
|
|
object_class_property_add_bool(oc, MICROVM_MACHINE_OPTION_ROMS,
|
|
|
|
microvm_machine_get_option_roms,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
microvm_machine_set_option_roms);
|
2019-10-02 09:03:19 +03:00
|
|
|
object_class_property_set_description(oc, MICROVM_MACHINE_OPTION_ROMS,
|
2020-05-05 18:29:15 +03:00
|
|
|
"Set off to disable loading option ROMs");
|
2019-10-02 09:03:19 +03:00
|
|
|
|
|
|
|
object_class_property_add_bool(oc, MICROVM_MACHINE_AUTO_KERNEL_CMDLINE,
|
|
|
|
microvm_machine_get_auto_kernel_cmdline,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
microvm_machine_set_auto_kernel_cmdline);
|
2019-10-02 09:03:19 +03:00
|
|
|
object_class_property_set_description(oc,
|
|
|
|
MICROVM_MACHINE_AUTO_KERNEL_CMDLINE,
|
2020-05-05 18:29:15 +03:00
|
|
|
"Set off to disable adding virtio-mmio devices to the kernel cmdline");
|
2020-09-15 15:09:09 +03:00
|
|
|
|
|
|
|
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE);
|
2022-07-01 12:15:16 +03:00
|
|
|
|
|
|
|
compat_props_add(mc->compat_props, microvm_properties,
|
|
|
|
G_N_ELEMENTS(microvm_properties));
|
2019-10-02 09:03:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo microvm_machine_info = {
|
|
|
|
.name = TYPE_MICROVM_MACHINE,
|
|
|
|
.parent = TYPE_X86_MACHINE,
|
|
|
|
.instance_size = sizeof(MicrovmMachineState),
|
|
|
|
.instance_init = microvm_machine_initfn,
|
|
|
|
.class_size = sizeof(MicrovmMachineClass),
|
|
|
|
.class_init = microvm_class_init,
|
|
|
|
.interfaces = (InterfaceInfo[]) {
|
2020-09-15 15:09:04 +03:00
|
|
|
{ TYPE_HOTPLUG_HANDLER },
|
2019-10-02 09:03:19 +03:00
|
|
|
{ }
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void microvm_machine_init(void)
|
|
|
|
{
|
|
|
|
type_register_static(µvm_machine_info);
|
|
|
|
}
|
|
|
|
type_init(microvm_machine_init);
|