Skip to contentSkip to conversation

Introduce light weight PC platform pc-lite

RFC In review Chao Peng 7 participants 32 messages Jun 17, 2016 – Jun 28, 2016

lore
Share & tools
lore

Chao Peng

author
#0 lore raw

cover Introduce light weight PC platform pc-lite

This patchset is against commit 585fcd4 (Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging) on master branch. I also put it on github:

https://github.com/chao-p/qemu pc-lite-v1

Although we have run the patchset internally for a while but it is still considered as RFC. Any comments (coding style or design issue) are welcome.

Introduction
============
The patch series introduces a new platform pc-lite, which is designed to be a virtual and light weight x86 PC platform. It is not designed to be compatible with old hardware and system. Instead, It removes the burden of legacy devices and emulates new fast hardware as much as possible. It is expected to be used together with optimized guest (though unoptimized guest works as well) to gain fast booting and small footprint benefits that are difficult to achieve for traditional hardware-emulated platform.

Basically:
- it removes old ISA devices and support only PCI devices;
- it removes 8259, instead use MSI as much as possible. IOAPIC and PCI PIN are still kept to support ACPI SCI;
- it supports PCIE ( you can use MMFG instead of 0xcf8/0xcfc port access);
- it gets rid of legacy firmware interfaces and supports ACPI tables;
- it loads guest kernel directly, no BIOS, no bootloader, no realmode code;
- it supports CPU/memory/PCI hotplug;
- it is FAST;

However:
- it supports KVM-host only at present;
- it supports Linux-guest only at present;
- You may need carefully configure guest kernel;
- You are forced to use virtio-serial-pci, old 8250/16550 is not there;

Want to have a try?
===================

Please follow https://github.com/chao-p/qemu-lite-tools.

Thanks,
Chao

Chao Peng (6):
acpi: introduce light weight ACPI PM emulation pm-lite
pci: introduce light weight PCIE Host emulation pci-lite
acpi: add support for pc-lite platform
pc: skip setting CMOS data when RTC device is unavailable
pc: support direct loading protected/long mode kernel
pc: introduce light weight PC board pc-lite

Haozhong Zhang (3):
acpi: expose data structurs and functions of BIOS linker loader
acpi: expose acpi_checksum()
acpi: patch guest ACPI for pc-lite

 default-configs/i386-softmmu.mak     |   1 +
 default-configs/x86_64-softmmu.mak   |   1 +
 docs/specs/acpi_cpu_hotplug.txt      |   1 +
 hw/acpi/Makefile.objs                |   2 +-
 hw/acpi/bios-linker-loader.c         |  83 +------
 hw/acpi/core.c                       |   2 +-
 hw/acpi/nvdimm.c                     |   6 +-
 hw/acpi/pm_lite.c                    | 446 +++++++++++++++++++++++++++++++++++
 hw/i386/Makefile.objs                |   2 +-
 hw/i386/acpi-build.c                 | 180 +++++++++-----
 hw/i386/pc.c                         | 263 ++++++++++++++++++---
 hw/i386/pc_lite.c                    | 205 ++++++++++++++++
 hw/i386/pc_lite_acpi.c               | 299 +++++++++++++++++++++++
 hw/i386/pc_piix.c                    |   2 +
 hw/i386/pc_q35.c                     |   2 +
 hw/pci-host/Makefile.objs            |   1 +
 hw/pci-host/pci_lite.c               | 259 ++++++++++++++++++++
 include/hw/acpi/acpi.h               |   2 +
 include/hw/acpi/bios-linker-loader.h |  85 +++++++
 include/hw/acpi/pc-hotplug.h         |   1 +
 include/hw/acpi/pm_lite.h            |   6 +
 include/hw/i386/pc.h                 |  17 ++
 include/hw/i386/pc_lite_acpi.h       |  10 +
 23 files changed, 1697 insertions(+), 179 deletions(-)
 create mode 100644 hw/acpi/pm_lite.c
 create mode 100644 hw/i386/pc_lite.c
 create mode 100644 hw/i386/pc_lite_acpi.c
 create mode 100644 hw/pci-host/pci_lite.c
 create mode 100644 include/hw/acpi/pm_lite.h
 create mode 100644 include/hw/i386/pc_lite_acpi.h
Signature · 1 line
1.8.3.1
author
#1 lore raw

RFC 1/9 acpi: introduce light weight ACPI PM emulation pm-lite

The code is loosely based on piix4_pm. The goal is to make it light weight and dedicated to the emulation of PM registers defined in ACPI spec. Unlike piix4_pm, the register address (PM_IO_BASE) is fixed so configuration in BIOS is impossible and unnecessary.

---
 docs/specs/acpi_cpu_hotplug.txt |   1 +
 hw/acpi/Makefile.objs           |   2 +-
 hw/acpi/pm_lite.c               | 446 ++++++++++++++++++++++++++++++++++++++++
 include/hw/acpi/pc-hotplug.h    |   1 +
 include/hw/acpi/pm_lite.h       |   6 +
 include/hw/i386/pc.h            |   4 +
 6 files changed, 459 insertions(+), 1 deletion(-)
 create mode 100644 hw/acpi/pm_lite.c
 create mode 100644 include/hw/acpi/pm_lite.h
docs/specs/acpi_cpu_hotplug.txt +1 -0
index 340b751..06ac18e 100644
@@ -13,6 +13,7 @@ hot-add/remove event to ACPI BIOS, via SCI interrupt.
 CPU present bitmap for:
   ICH9-LPC (IO port 0x0cd8-0xcf7, 1-byte access)
   PIIX-PM  (IO port 0xaf00-0xaf1f, 1-byte access)
+  PM-LITE  (IO port 0xaf00-0xaf1f, 1-byte access)
 ---------------------------------------------------------------
 One bit per CPU. Bit position reflects corresponding CPU APIC ID.
 Read-only.
hw/acpi/Makefile.objs +1 -1
index 66bd727..82adf32 100644
@@ -1,4 +1,4 @@
-common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o pcihp.o
+common-obj-$(CONFIG_ACPI_X86) += core.o piix4.o pcihp.o pm_lite.o
 common-obj-$(CONFIG_ACPI_X86_ICH) += ich9.o tco.o
 common-obj-$(CONFIG_ACPI_CPU_HOTPLUG) += cpu_hotplug.o
 common-obj-$(CONFIG_ACPI_MEMORY_HOTPLUG) += memory_hotplug.o memory_hotplug_acpi_table.o
hw/acpi/pm_lite.c new file +446 -0

446 lines not on this page · raw message

include/hw/acpi/pc-hotplug.h +1 -0
index 6a8d268..02dbe57 100644
@@ -27,6 +27,7 @@
 
 #define ICH9_CPU_HOTPLUG_IO_BASE 0x0CD8
 #define PIIX4_CPU_HOTPLUG_IO_BASE 0xaf00
+#define PM_LITE_CPU_HOTPLUG_IO_BASE 0xaf00
 #define CPU_HOTPLUG_RESOURCE_DEVICE PRES
 
 #define ACPI_MEMORY_HOTPLUG_IO_LEN 24
include/hw/acpi/pm_lite.h new file +6 -0
new file mode 100644
index 0000000..011233d
@@ -0,0 +1,6 @@
+#ifndef HW_ACPI_PM_LITE_H
+#define HW_ACPI_PM_LITE_H
+
+Object *pm_lite_find(void);
+
+#endif
include/hw/i386/pc.h +4 -0
index 49566c8..7c3506e 100644
@@ -278,6 +278,10 @@ I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
                       int smm_enabled, DeviceState **piix4_pm);
 void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr);
 
+/* pm_lite.c */
+
+DeviceState *pm_lite_init(PCIBus *bus, int devfn, qemu_irq sci_irq);
+
 /* hpet.c */
 extern int no_hpet;
 
Signature · 1 line
1.8.3.1
author
#2 lore raw

RFC 2/9 pci: introduce light weight PCIE Host emulation pci-lite

In reply to Chao Peng

A minimal emulation for PCIE host bridge that supports 0xcf8/0xcfc and MMFG. Actually there is already a gpex there, but it is designed mainly for ARM and is not quite suitable for x86:
- it lacks things like PCI hole properties which are required by ACPI.
- the corresponding driver in Linux is designed to work with device tree which is not suitable for x86. For this case, additional guest driver is even not needed.

Currently MMFG size is limited to 1M, which means only 1 bus is supported, this is aimed to reduce the scan time in guest. And it doesn't have a valid vendor ID/device ID assigned so guest may not recognize it, the functionality however is expected to be OK.

---
 default-configs/i386-softmmu.mak   |   1 +
 default-configs/x86_64-softmmu.mak |   1 +
 hw/pci-host/Makefile.objs          |   1 +
 hw/pci-host/pci_lite.c             | 259 +++++++++++++++++++++++++++++++++++++
 include/hw/i386/pc.h               |   5 +
 5 files changed, 267 insertions(+)
 create mode 100644 hw/pci-host/pci_lite.c
default-configs/i386-softmmu.mak +1 -0
index b177e52..421ad0a 100644
@@ -38,6 +38,7 @@ CONFIG_PFLASH_CFI01=y
 CONFIG_TPM_TIS=$(CONFIG_TPM)
 CONFIG_MC146818RTC=y
 CONFIG_PAM=y
+CONFIG_PCI_LITE=y
 CONFIG_PCI_PIIX=y
 CONFIG_WDT_IB700=y
 CONFIG_XEN_I386=$(CONFIG_XEN)
default-configs/x86_64-softmmu.mak +1 -0
index 6e3b312..f197cfd 100644
@@ -38,6 +38,7 @@ CONFIG_PFLASH_CFI01=y
 CONFIG_TPM_TIS=$(CONFIG_TPM)
 CONFIG_MC146818RTC=y
 CONFIG_PAM=y
+CONFIG_PCI_LITE=y
 CONFIG_PCI_PIIX=y
 CONFIG_WDT_IB700=y
 CONFIG_XEN_I386=$(CONFIG_XEN)
hw/pci-host/Makefile.objs +1 -0
index 45f1f0e..5dbb034 100644
@@ -16,3 +16,4 @@ common-obj-$(CONFIG_FULONG) += bonito.o
 common-obj-$(CONFIG_PCI_PIIX) += piix.o
 common-obj-$(CONFIG_PCI_Q35) += q35.o
 common-obj-$(CONFIG_PCI_GENERIC) += gpex.o
+common-obj-$(CONFIG_PCI_LITE) += pci_lite.o
hw/pci-host/pci_lite.c new file +259 -0

259 lines not on this page · raw message

include/hw/i386/pc.h +5 -0
index 7c3506e..ad7533b 100644
@@ -285,6 +285,11 @@ DeviceState *pm_lite_init(PCIBus *bus, int devfn, qemu_irq sci_irq);
 /* hpet.c */
 extern int no_hpet;
 
+/* pci_lite.c */
+PCIBus *pci_lite_init(MemoryRegion *address_space_mem,
+                      MemoryRegion *address_space_io,
+                      MemoryRegion *pci_memory);
+
 /* piix_pci.c */
 struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
Signature · 1 line
1.8.3.1
author
#3 lore raw

RFC 3/9 acpi: add support for pc-lite platform

In reply to Chao Peng

Basically, the to be added pc-lite platform uses pm-lite to support CPU/memory/PCI hotplug and pci-lite as the host bridge. The code here reuses some existing facilities for piix/q35 platform.

---
 hw/i386/acpi-build.c | 108 ++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 77 insertions(+), 31 deletions(-)
hw/i386/acpi-build.c +77 -31
index 8ca2032..4b5ed96 100644
@@ -47,6 +47,7 @@
 /* Supported chipsets: */
 #include "hw/acpi/piix4.h"
 #include "hw/acpi/pcihp.h"
+#include "hw/acpi/pm_lite.h"
 #include "hw/i386/ich9.h"
 #include "hw/pci/pci_bus.h"
 #include "hw/pci-host/q35.h"
@@ -76,6 +77,8 @@
 #define ACPI_BUILD_DPRINTF(fmt, ...)
 #endif
 
+#define ACPI_PORT_SMI_CMD           0x00b2 /* TODO: this is APM_CNT_IOPORT */
+
 typedef struct AcpiMcfgInfo {
     uint64_t mcfg_base;
     uint32_t mcfg_size;
@@ -87,6 +90,7 @@ typedef struct AcpiPmInfo {
     bool pcihp_bridge_en;
     uint8_t s4_val;
     uint16_t sci_int;
+    uint32_t smi_cmd;
     uint8_t acpi_enable_cmd;
     uint8_t acpi_disable_cmd;
     uint32_t gpe0_blk;
@@ -99,8 +103,14 @@ typedef struct AcpiPmInfo {
     uint16_t pcihp_io_len;
 } AcpiPmInfo;
 
+typedef enum {
+    PMTYPE_PIIX4   = 0,
+    PMTYPE_LPC     = 1,
+    PMTYPE_LITE    = 2,
+} PMType;
+
 typedef struct AcpiMiscInfo {
-    bool is_piix4;
+    PMType pm_type;
     bool has_hpet;
     TPMVersion tpm_version;
     const unsigned char *dsdt_code;
@@ -118,27 +128,32 @@ typedef struct AcpiBuildPciBusHotplugState {
 
 static void acpi_get_pm_info(AcpiPmInfo *pm)
 {
-    Object *piix = piix4_pm_find();
-    Object *lpc = ich9_lpc_find();
-    Object *obj = NULL;
+    Object *obj = ich9_lpc_find();
     QObject *o;
 
     pm->cpu_hp_io_base = 0;
     pm->pcihp_io_base = 0;
     pm->pcihp_io_len = 0;
-    if (piix) {
-        obj = piix;
-        pm->cpu_hp_io_base = PIIX4_CPU_HOTPLUG_IO_BASE;
+    pm->smi_cmd = ACPI_PORT_SMI_CMD;
+
+    if (obj) {
+        pm->cpu_hp_io_base = ICH9_CPU_HOTPLUG_IO_BASE;
+    } else {
+        obj = piix4_pm_find();
+        if (obj) {
+            pm->cpu_hp_io_base = PIIX4_CPU_HOTPLUG_IO_BASE;
+        } else {
+            obj = pm_lite_find();
+            assert(obj);
+            pm->smi_cmd = 0;
+            pm->cpu_hp_io_base = PM_LITE_CPU_HOTPLUG_IO_BASE;
+        }
+
         pm->pcihp_io_base =
             object_property_get_int(obj, ACPI_PCIHP_IO_BASE_PROP, NULL);
         pm->pcihp_io_len =
             object_property_get_int(obj, ACPI_PCIHP_IO_LEN_PROP, NULL);
     }
-    if (lpc) {
-        obj = lpc;
-        pm->cpu_hp_io_base = ICH9_CPU_HOTPLUG_IO_BASE;
-    }
-    assert(obj);
 
     pm->mem_hp_io_base = ACPI_MEMORY_HOTPLUG_BASE;
     pm->mem_hp_io_len = ACPI_MEMORY_HOTPLUG_IO_LEN;
@@ -188,15 +203,12 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
 
 static void acpi_get_misc_info(AcpiMiscInfo *info)
 {
-    Object *piix = piix4_pm_find();
-    Object *lpc = ich9_lpc_find();
-    assert(!!piix != !!lpc);
-
-    if (piix) {
-        info->is_piix4 = true;
-    }
-    if (lpc) {
-        info->is_piix4 = false;
+    if (piix4_pm_find()) {
+        info->pm_type = PMTYPE_PIIX4;
+    } else if (ich9_lpc_find()) {
+        info->pm_type = PMTYPE_LPC;
+    } else if (pm_lite_find()) {
+         info->pm_type = PMTYPE_LITE;
     }
 
     info->has_hpet = hpet_find();
@@ -222,6 +234,12 @@ static Object *acpi_get_i386_pci_host(void)
                             TYPE_PCI_HOST_BRIDGE);
     }
 
+    if (!host) {
+        host = OBJECT_CHECK(PCIHostState,
+                            object_resolve_path("/machine/pcilite", NULL),
+                            TYPE_PCI_HOST_BRIDGE);
+    }
+
     return OBJECT(host);
 }
 
@@ -247,8 +265,6 @@ static void acpi_get_pci_info(PcPciInfo *info)
                                             NULL);
 }
 
-#define ACPI_PORT_SMI_CMD           0x00b2 /* TODO: this is APM_CNT_IOPORT */
-
 static void acpi_align_size(GArray *blob, unsigned align)
 {
     /* Align size to multiple of given size. This reduces the chance
@@ -272,7 +288,7 @@ static void fadt_setup(AcpiFadtDescriptorRev1 *fadt, AcpiPmInfo *pm)
     fadt->model = 1;
     fadt->reserved1 = 0;
     fadt->sci_int = cpu_to_le16(pm->sci_int);
-    fadt->smi_cmd = cpu_to_le32(ACPI_PORT_SMI_CMD);
+    fadt->smi_cmd = cpu_to_le32(pm->smi_cmd);
     fadt->acpi_enable = pm->acpi_enable_cmd;
     fadt->acpi_disable = pm->acpi_disable_cmd;
     /* EVT, CNT, TMR offset matches hw/acpi/core.c */
@@ -1774,7 +1790,7 @@ static void build_piix4_isa_bridge(Aml *table)
     aml_append(table, scope);
 }
 
-static void build_piix4_pci_hotplug(Aml *table)
+static void build_pci_hotplug(Aml *table)
 {
     Aml *scope;
     Aml *field;
@@ -1815,7 +1831,7 @@ static void build_piix4_pci_hotplug(Aml *table)
     aml_append(table, scope);
 }
 
-static Aml *build_q35_osc_method(void)
+static Aml *build_osc_method(void)
 {
     Aml *if_ctx;
     Aml *if_ctx2;
@@ -1864,6 +1880,21 @@ static Aml *build_q35_osc_method(void)
     return method;
 }
 
+static void build_lite_pci0_int(Aml *table)
+{
+    Aml *sb_scope = aml_scope("_SB");
+    Aml *pci0_scope = aml_scope("PCI0");
+
+    aml_append(pci0_scope, build_prt(false));
+    aml_append(sb_scope, pci0_scope);
+
+    aml_append(sb_scope, build_gsi_link_dev("LNKA", 0x10, 0x10));
+    aml_append(sb_scope, build_gsi_link_dev("LNKB", 0x11, 0x11));
+    aml_append(sb_scope, build_gsi_link_dev("LNKC", 0x12, 0x12));
+    aml_append(sb_scope, build_gsi_link_dev("LNKD", 0x13, 0x13));
+    aml_append(table, sb_scope);
+}
+
 static void
 build_dsdt(GArray *table_data, BIOSLinker *linker,
            AcpiPmInfo *pm, AcpiMiscInfo *misc,
@@ -1885,7 +1916,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
     acpi_data_push(dsdt->buf, sizeof(AcpiTableHeader));
 
     build_dbg_aml(dsdt);
-    if (misc->is_piix4) {
+    if (misc->pm_type == PMTYPE_PIIX4) {
         sb_scope = aml_scope("_SB");
         dev = aml_device("PCI0");
         aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0A03")));
@@ -1898,9 +1929,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
         build_piix4_pm(dsdt);
         build_piix4_isa_bridge(dsdt);
         build_isa_devices_aml(dsdt);
-        build_piix4_pci_hotplug(dsdt);
+        build_pci_hotplug(dsdt);
         build_piix4_pci0_int(dsdt);
-    } else {
+    } else if (misc->pm_type == PMTYPE_LPC) {
         sb_scope = aml_scope("_SB");
         aml_append(sb_scope,
             aml_operation_region("PCST", AML_SYSTEM_IO, aml_int(0xae00), 0x0c));
@@ -1919,7 +1950,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
         aml_append(dev, aml_name_decl("_UID", aml_int(1)));
         aml_append(dev, aml_name_decl("SUPP", aml_int(0)));
         aml_append(dev, aml_name_decl("CTRL", aml_int(0)));
-        aml_append(dev, build_q35_osc_method());
+        aml_append(dev, build_osc_method());
         aml_append(sb_scope, dev);
         aml_append(dsdt, sb_scope);
 
@@ -1927,6 +1958,21 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
         build_q35_isa_bridge(dsdt);
         build_isa_devices_aml(dsdt);
         build_q35_pci0_int(dsdt);
+    } else { /* misc->pm_type == PMTYPE_LITE */
+        sb_scope = aml_scope("_SB");
+        dev = aml_device("PCI0");
+        aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0A08")));
+        aml_append(dev, aml_name_decl("_CID", aml_eisaid("PNP0A03")));
+        aml_append(dev, aml_name_decl("_ADR", aml_int(0)));
+        aml_append(dev, aml_name_decl("_UID", aml_int(1)));
+        aml_append(dev, aml_name_decl("SUPP", aml_int(0)));
+        aml_append(dev, aml_name_decl("CTRL", aml_int(0)));
+        aml_append(dev, build_osc_method());
+        aml_append(sb_scope, dev);
+        aml_append(dsdt, sb_scope);
+
+        build_pci_hotplug(dsdt);
+        build_lite_pci0_int(dsdt);
     }
 
     build_legacy_cpu_hotplug_aml(dsdt, machine, pm->cpu_hp_io_base);
@@ -1937,7 +1983,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,
     {
         aml_append(scope, aml_name_decl("_HID", aml_string("ACPI0006")));
 
-        if (misc->is_piix4) {
+        if (misc->pm_type == PMTYPE_PIIX4 || misc->pm_type == PMTYPE_LITE) {
             method = aml_method("_E01", 0, AML_NOTSERIALIZED);
             aml_append(method,
                 aml_acquire(aml_name("\\_SB.PCI0.BLCK"), 0xFFFF));
Signature · 1 line
1.8.3.1
author
#4 lore raw

RFC 4/9 acpi: expose data structurs and functions of BIOS linker loader

In reply to Chao Peng

From: Haozhong Zhang <[email protected]>

Expose some data structures and functions of BIOS linker loader which will be used by later commits.

---
 hw/acpi/bios-linker-loader.c         | 83 +----------------------------------
 include/hw/acpi/bios-linker-loader.h | 85 ++++++++++++++++++++++++++++++++++++
 2 files changed, 86 insertions(+), 82 deletions(-)
hw/acpi/bios-linker-loader.c +1 -82
index d963ebe..e9c19cf 100644
@@ -21,91 +21,10 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 #include "hw/acpi/bios-linker-loader.h"
-#include "hw/nvram/fw_cfg.h"
 
 #include "qemu/bswap.h"
 
 /*
- * Linker/loader is a paravirtualized interface that passes commands to guest.
- * The commands can be used to request guest to
- * - allocate memory chunks and initialize them from QEMU FW CFG files
- * - link allocated chunks by storing pointer to one chunk into another
- * - calculate ACPI checksum of part of the chunk and store into same chunk
- */
-#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
-
-struct BiosLinkerLoaderEntry {
-    uint32_t command;
-    union {
-        /*
-         * COMMAND_ALLOCATE - allocate a table from @alloc.file
-         * subject to @alloc.align alignment (must be power of 2)
-         * and @alloc.zone (can be HIGH or FSEG) requirements.
-         *
-         * Must appear exactly once for each file, and before
-         * this file is referenced by any other command.
-         */
-        struct {
-            char file[BIOS_LINKER_LOADER_FILESZ];
-            uint32_t align;
-            uint8_t zone;
-        } alloc;
-
-        /*
-         * COMMAND_ADD_POINTER - patch the table (originating from
-         * @dest_file) at @pointer.offset, by adding a pointer to the table
-         * originating from @src_file. 1,2,4 or 8 byte unsigned
-         * addition is used depending on @pointer.size.
-         */
-        struct {
-            char dest_file[BIOS_LINKER_LOADER_FILESZ];
-            char src_file[BIOS_LINKER_LOADER_FILESZ];
-            uint32_t offset;
-            uint8_t size;
-        } pointer;
-
-        /*
-         * COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by
-         * @cksum_start and @cksum_length fields,
-         * and then add the value at @cksum.offset.
-         * Checksum simply sums -X for each byte X in the range
-         * using 8-bit math.
-         */
-        struct {
-            char file[BIOS_LINKER_LOADER_FILESZ];
-            uint32_t offset;
-            uint32_t start;
-            uint32_t length;
-        } cksum;
-
-        /* padding */
-        char pad[124];
-    };
-} QEMU_PACKED;
-typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry;
-
-enum {
-    BIOS_LINKER_LOADER_COMMAND_ALLOCATE     = 0x1,
-    BIOS_LINKER_LOADER_COMMAND_ADD_POINTER  = 0x2,
-    BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
-};
-
-enum {
-    BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
-    BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
-};
-
-/*
- * BiosLinkerFileEntry:
- *
- * An internal type used for book-keeping file entries
- */
-typedef struct BiosLinkerFileEntry {
-    char *name; /* file name */
-    GArray *blob; /* data accosiated with @name */
-} BiosLinkerFileEntry;
-
-/*
  * bios_linker_loader_init: allocate a new linker object instance.
  *
  * After initialization, linker commands can be added, and will
@@ -137,7 +56,7 @@ void bios_linker_loader_cleanup(BIOSLinker *linker)
     g_free(linker);
 }
 
-static const BiosLinkerFileEntry *
+const BiosLinkerFileEntry *
 bios_linker_find_file(const BIOSLinker *linker, const char *name)
 {
     int i;
include/hw/acpi/bios-linker-loader.h +85 -0

101 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#5 lore raw

RFC 5/9 acpi: expose acpi_checksum()

In reply to Chao Peng

From: Haozhong Zhang <[email protected]>

It will be used in later commits.

---
 hw/acpi/core.c         | 2 +-
 include/hw/acpi/acpi.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
hw/acpi/core.c +1 -1
index d24b9a9..70ad6ff 100644
@@ -69,7 +69,7 @@ static void acpi_register_config(void)
 
 opts_init(acpi_register_config);
 
-static int acpi_checksum(const uint8_t *data, int len)
+int acpi_checksum(const uint8_t *data, int len)
 {
     int sum, i;
     sum = 0;
include/hw/acpi/acpi.h +2 -0
index c717f15..b23eff8 100644
@@ -188,4 +188,6 @@ struct AcpiSlicOem {
 };
 int acpi_get_slic_oem(AcpiSlicOem *oem);
 
+int acpi_checksum(const uint8_t *data, int len);
+
 #endif /* !QEMU_HW_ACPI_H */
Signature · 1 line
1.8.3.1
author
#6 lore raw

RFC 6/9 acpi: patch guest ACPI for pc-lite

In reply to Chao Peng

From: Haozhong Zhang <[email protected]>

Traditionally, guest firmware is responsible to patch ACPI tables generated by QEMU. However, no firmware is used with pc-lite and patching ACPI should be done in QEMU for pc-lite.

---
 hw/acpi/nvdimm.c               |   6 +-
 hw/i386/Makefile.objs          |   2 +-
 hw/i386/acpi-build.c           |  72 +++++-----
 hw/i386/pc_lite_acpi.c         | 299 +++++++++++++++++++++++++++++++++++++++++
 include/hw/i386/pc_lite_acpi.h |  10 ++
 5 files changed, 355 insertions(+), 34 deletions(-)
 create mode 100644 hw/i386/pc_lite_acpi.c
 create mode 100644 include/hw/i386/pc_lite_acpi.h
hw/acpi/nvdimm.c +4 -2
index b4c2262..523c744 100644
@@ -478,8 +478,10 @@ void nvdimm_init_acpi_state(AcpiNVDIMMState *state, MemoryRegion *io,
 
     state->dsm_mem = g_array_new(false, true /* clear */, 1);
     acpi_data_push(state->dsm_mem, sizeof(NvdimmDsmIn));
-    fw_cfg_add_file(fw_cfg, NVDIMM_DSM_MEM_FILE, state->dsm_mem->data,
-                    state->dsm_mem->len);
+    if (fw_cfg) {
+        fw_cfg_add_file(fw_cfg, NVDIMM_DSM_MEM_FILE, state->dsm_mem->data,
+                        state->dsm_mem->len);
+    }
 }
 
 #define NVDIMM_COMMON_DSM      "NCAL"
hw/i386/Makefile.objs +1 -1
index b52d5b8..7d29ec0 100644
@@ -1,6 +1,6 @@
 obj-$(CONFIG_KVM) += kvm/
 obj-y += multiboot.o
-obj-y += pc.o pc_piix.o pc_q35.o
+obj-y += pc.o pc_piix.o pc_q35.o pc_lite_acpi.o
 obj-y += pc_sysfw.o
 obj-y += intel_iommu.o
 obj-$(CONFIG_XEN) += ../xenpv/ xen/
hw/i386/acpi-build.c +41 -31

104 lines not on this page · raw message

hw/i386/pc_lite_acpi.c new file +299 -0

299 lines not on this page · raw message

include/hw/i386/pc_lite_acpi.h new file +10 -0
new file mode 100644
index 0000000..aa08415
@@ -0,0 +1,10 @@
+#ifndef HW_I386_PC_LITE_ACPI_H
+#define HW_I386_PC_LITE_ACPI_H
+
+#include "hw/i386/pc.h"
+#include "hw/acpi/bios-linker-loader.h"
+#include "qapi/error.h"
+
+void pc_lite_acpi_build(PCMachineState *pcms, BIOSLinker *linker, Error **errp);
+
+#endif
Signature · 1 line
1.8.3.1
author
#7 lore raw

RFC 7/9 pc: skip setting CMOS data when RTC device is unavailable

In reply to Chao Peng

... to make sure hotplug for new platform that without RTC support can still work.

---
 hw/i386/pc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
hw/i386/pc.c +4 -2
index 7198ed5..46ca0e3 100644
@@ -1695,8 +1695,10 @@ static void pc_cpu_plug(HotplugHandler *hotplug_dev,
         goto out;
     }
 
-    /* increment the number of CPUs */
-    rtc_set_memory(pcms->rtc, 0x5f, rtc_get_memory(pcms->rtc, 0x5f) + 1);
+    if (pcms->rtc) {
+        /* increment the number of CPUs */
+        rtc_set_memory(pcms->rtc, 0x5f, rtc_get_memory(pcms->rtc, 0x5f) + 1);
+    }
 
     apic_id.arch_id = cc->get_arch_id(CPU(dev));
     found_cpu = bsearch(&apic_id, pcms->possible_cpus->cpus,
Signature · 1 line
1.8.3.1
author
#8 lore raw

RFC 8/9 pc: support direct loading protected/long mode kernel

In reply to Chao Peng

Traditionally a PC follows the following booting steps:

    QEMU -> BIOS -> bootloader -> kernel realmode code
         -> kernel protected/longmode code.

This process takes lots of time. For platform like pc-lite we let QEMU loads protected/long mode kernel directly, hence skipping several steps and speed up the whole booting. We do this by filling the zero page per Linux booting protocol and then jumping to the kernel protected/long mode entry. Registers and paging should also be put in the correct state.

---
 hw/i386/pc.c | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 163 insertions(+), 3 deletions(-)
hw/i386/pc.c +163 -3
index 46ca0e3..64ce65c 100644
@@ -85,6 +85,31 @@
 #define FW_CFG_E820_TABLE (FW_CFG_ARCH_LOCAL + 3)
 #define FW_CFG_HPET (FW_CFG_ARCH_LOCAL + 4)
 
+#define BOOT_GDT                0x500
+#define BOOT_IDT                0x520
+#define BOOT_GDT_NULL           0
+#define BOOT_GDT_CODE           1
+#define BOOT_GDT_DATA           2
+#define BOOT_GDT_TSS            3
+#define BOOT_GDT_MAX            4
+#define BOOT_GDT_FLAGS_CODE     (DESC_P_MASK | DESC_S_MASK | DESC_CS_MASK | \
+                                 DESC_R_MASK | DESC_A_MASK | DESC_G_MASK )
+#define BOOT_GDT_FLAGS_DATA     (DESC_P_MASK | DESC_S_MASK | DESC_W_MASK |  \
+                                 DESC_A_MASK | DESC_B_MASK | DESC_G_MASK)
+#define BOOT_GDT_FLAGS_TSS      DESC_P_MASK | (11 << DESC_TYPE_SHIFT)
+#define BOOT_PML4               0x9000
+#define BOOT_PDPTE              0xA000
+#define BOOT_LOADER_SP          0x8000
+#define BOOT_CMDLINE_OFFSET     0x20000
+#define BOOT_ZEROPAGE_OFFSET    0x7000
+
+#define GDT_ENTRY(flags, base, limit)               \
+       ((((base)  & 0xff000000ULL) << (56-24)) |    \
+       (((flags) & 0x0000f0ffULL) << 40) |          \
+       (((limit) & 0x000f0000ULL) << (48-16)) |     \
+       (((base)  & 0x00ffffffULL) << 16) |          \
+       (((limit) & 0x0000ffffULL)))
+
 #define E820_NR_ENTRIES		16
 
 struct e820_entry {
@@ -98,6 +123,13 @@ struct e820_table {
     struct e820_entry entry[E820_NR_ENTRIES];
 } QEMU_PACKED __attribute((__aligned__(4)));
 
+struct kernel_boot_info {
+    uint64_t entry;
+    bool protected_mode;
+    bool long_mode;
+};
+
+static struct kernel_boot_info boot_info;
 static struct e820_table e820_reserve;
 static struct e820_entry *e820_table;
 static unsigned e820_entries;
@@ -667,6 +699,124 @@ bool e820_get_entry(int idx, uint32_t type, uint64_t *address, uint64_t *length)
     return false;
 }
 
+static void reset_cpu(CPUX86State *env)
+{
+    unsigned int flags = BOOT_GDT_FLAGS_CODE;
+
+    if (boot_info.long_mode) {
+        flags |= DESC_L_MASK;
+    }
+    cpu_x86_load_seg_cache(env, R_CS, BOOT_GDT_CODE * 8, 0, 0xfffff, flags);
+
+    cpu_x86_load_seg_cache(env, R_DS, BOOT_GDT_DATA * 8, 0, 0xfffff,
+                           BOOT_GDT_FLAGS_DATA);
+    cpu_x86_load_seg_cache(env, R_ES, BOOT_GDT_DATA * 8, 0, 0xfffff,
+                           BOOT_GDT_FLAGS_DATA);
+    cpu_x86_load_seg_cache(env, R_FS, BOOT_GDT_DATA * 8, 0, 0xfffff,
+                           BOOT_GDT_FLAGS_DATA);
+    cpu_x86_load_seg_cache(env, R_GS, BOOT_GDT_DATA * 8, 0, 0xfffff,
+                           BOOT_GDT_FLAGS_DATA);
+    cpu_x86_load_seg_cache(env, R_SS, BOOT_GDT_DATA * 8, 0, 0xfffff,
+                           BOOT_GDT_FLAGS_DATA);
+
+    env->gdt.base = BOOT_GDT;
+    env->gdt.limit = BOOT_GDT_MAX * 8 - 1;
+
+    env->idt.base = BOOT_IDT;
+
+    env->tr.selector = BOOT_GDT_TSS * 8;
+    env->tr.flags = BOOT_GDT_FLAGS_TSS;
+
+    env->cr[3] = BOOT_PML4;
+    env->cr[0] |= (CR0_PG_MASK | CR0_PE_MASK);
+
+    if (boot_info.long_mode) {
+        env->cr[4] |= CR4_PAE_MASK;
+        cpu_load_efer(env, env->efer | MSR_EFER_LME | MSR_EFER_LMA);
+    }
+
+    env->regs[R_ESP] = BOOT_LOADER_SP;
+    env->regs[R_ESI] = BOOT_ZEROPAGE_OFFSET;
+    env->eip = boot_info.entry;
+}
+
+static void setup_seg_desc_tables(void)
+{
+    uint64_t idt = 0;
+    uint64_t gdt[BOOT_GDT_MAX] = {
+             [BOOT_GDT_NULL] = GDT_ENTRY(0, 0, 0),
+             [BOOT_GDT_CODE] = GDT_ENTRY(BOOT_GDT_FLAGS_CODE, 0, 0xFFFFF),
+             [BOOT_GDT_DATA] = GDT_ENTRY(BOOT_GDT_FLAGS_DATA, 0, 0xFFFFF),
+             [BOOT_GDT_TSS ] = GDT_ENTRY(BOOT_GDT_FLAGS_TSS, 0, 0xFFFFF)
+            };
+
+    if (boot_info.long_mode) {
+        gdt[BOOT_GDT_CODE] |= (1UL << (32 + DESC_L_SHIFT));
+    }
+
+    cpu_physical_memory_write((hwaddr)BOOT_GDT, gdt, sizeof(gdt));
+    cpu_physical_memory_write((hwaddr)BOOT_IDT, &idt, sizeof(idt));
+}
+
+static void setup_page_tables(void)
+{
+    void *p;
+    size_t len = 4096;
+
+    p = cpu_physical_memory_map(BOOT_PML4, &len, 1);
+    memset(p, 0, 4096);
+    *(uint64_t*)p = (uint64_t)(BOOT_PDPTE | 3);
+    cpu_physical_memory_unmap(p, len, 1, len);
+
+    len = 4096;
+    p = cpu_physical_memory_map(BOOT_PDPTE, &len, 1);
+    memset(p, 0, 4096);
+    *(uint64_t*)p = 0x83;
+    cpu_physical_memory_unmap(p, len, 1, len);
+}
+
+static void setup_kernel_zero_page(void)
+{
+    int i;
+    uint8_t *zero_page;
+    void *e820_map;
+    size_t zero_page_size = 4096;
+    MachineState *machine = MACHINE(qdev_get_machine());
+    size_t cmdline_size = strlen(machine->kernel_cmdline) + 1;
+
+    cpu_physical_memory_write((hwaddr)BOOT_CMDLINE_OFFSET,
+                               machine->kernel_cmdline, cmdline_size);
+
+    zero_page = cpu_physical_memory_map((hwaddr)BOOT_ZEROPAGE_OFFSET,
+                                        &zero_page_size, 1);
+    memset(zero_page, 0, zero_page_size);
+
+    /* hdr.type_of_loader */
+    zero_page[0x210] = 0xFF;
+    /* hdr.boot_flag */
+    stw_p(zero_page + 0x1fe, 0xAA55);
+    /* hdr.header */
+    stl_p(zero_page + 0x202, 0x53726448);
+    /* hdr.cmd_line_ptr */
+    stl_p(zero_page + 0x228, BOOT_CMDLINE_OFFSET);
+    /* hdr.cmdline_size */
+    stl_p(zero_page + 0x238, cmdline_size);
+    /* e820_entries */
+    zero_page[0x1e8] = e820_entries;
+    /* e820_map */
+    e820_map = zero_page + 0x2d0;
+    for (i = 0; i < e820_entries; i++) {
+        stq_p(e820_map, e820_table[i].address);
+        e820_map += 8;
+        stq_p(e820_map, e820_table[i].length);
+        e820_map += 8;
+        stl_p(e820_map, e820_table[i].type);
+        e820_map += 4;
+    }
+
+    cpu_physical_memory_unmap(zero_page, zero_page_size, 1, zero_page_size);
+}
+
 /* Enables contiguous-apic-ID mode, for compatibility */
 static bool compat_apic_id_mode;
 
@@ -1928,15 +2078,25 @@ static void pc_machine_reset(void)
 
     qemu_devices_reset();
 
-    /* Reset APIC after devices have been reset to cancel
-     * any changes that qemu_devices_reset() might have done.
-     */
     CPU_FOREACH(cs) {
         cpu = X86_CPU(cs);
 
+        /* Reset APIC after devices have been reset to cancel
+         * any changes that qemu_devices_reset() might have done.
+         */
         if (cpu->apic_state) {
             device_reset(cpu->apic_state);
         }
+
+        if (boot_info.protected_mode && cpu_is_bsp(cpu)) {
+            reset_cpu(&cpu->env);
+        }
+    }
+
+    if (boot_info.protected_mode) {
+        setup_seg_desc_tables();
+        setup_page_tables();
+        setup_kernel_zero_page();
     }
 }
 
Signature · 1 line
1.8.3.1
author
#9 lore raw

RFC 9/9 pc: introduce light weight PC board pc-lite

In reply to Chao Peng

The new board gets rid of most legacy devices and mainly support modern PCI devices. BIOS is skipped and an ELF format kernel must be specified. QEMU will boot this kernel directly.

Add "-machine pc-lite -kernel $ELF_KERNEL -append $KERNEL_CMD" to use it.

---
 hw/i386/Makefile.objs |   2 +-
 hw/i386/pc.c          |  91 ++++++++++++++++------
 hw/i386/pc_lite.c     | 205 ++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/i386/pc_piix.c     |   2 +
 hw/i386/pc_q35.c      |   2 +
 include/hw/i386/pc.h  |   8 ++
 6 files changed, 284 insertions(+), 26 deletions(-)
 create mode 100644 hw/i386/pc_lite.c
hw/i386/Makefile.objs +1 -1
index 7d29ec0..af3f53d 100644
@@ -1,6 +1,6 @@
 obj-$(CONFIG_KVM) += kvm/
 obj-y += multiboot.o
-obj-y += pc.o pc_piix.o pc_q35.o pc_lite_acpi.o
+obj-y += pc.o pc_piix.o pc_q35.o pc_lite_acpi.o pc_lite.o
 obj-y += pc_sysfw.o
 obj-y += intel_iommu.o
 obj-$(CONFIG_XEN) += ../xenpv/ xen/
hw/i386/pc.c +66 -25

124 lines not on this page · raw message

hw/i386/pc_lite.c new file +205 -0

205 lines not on this page · raw message

hw/i386/pc_piix.c +2 -0
index 53bc968..9d25abc 100644
@@ -425,11 +425,13 @@ static void pc_xen_hvm_init(MachineState *machine)
 
 static void pc_i440fx_machine_options(MachineClass *m)
 {
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     m->family = "pc_piix";
     m->desc = "Standard PC (i440FX + PIIX, 1996)";
     m->hot_add_cpu = pc_hot_add_cpu;
     m->default_machine_opts = "firmware=bios-256k.bin";
     m->default_display = "std";
+    pcmc->type = PC_MACHINE_TYPE_PIIX;
 }
 
 static void pc_i440fx_2_7_machine_options(MachineClass *m)
hw/i386/pc_q35.c +2 -0
index e4b541f..af2c201 100644
@@ -274,6 +274,7 @@ static void pc_q35_init(MachineState *machine)
 
 static void pc_q35_machine_options(MachineClass *m)
 {
+    PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
     m->family = "pc_q35";
     m->desc = "Standard PC (Q35 + ICH9, 2009)";
     m->hot_add_cpu = pc_hot_add_cpu;
@@ -281,6 +282,7 @@ static void pc_q35_machine_options(MachineClass *m)
     m->default_machine_opts = "firmware=bios-256k.bin";
     m->default_display = "std";
     m->no_floppy = 1;
+    pcmc->type = PC_MACHINE_TYPE_Q35;
 }
 
 static void pc_q35_2_7_machine_options(MachineClass *m)
include/hw/i386/pc.h +8 -0
index ad7533b..ef0e3df 100644
@@ -33,6 +33,12 @@
 #define kvm_ioapic_in_kernel()   0
 #endif
 
+typedef enum {
+    PC_MACHINE_TYPE_PIIX    = 0,
+    PC_MACHINE_TYPE_Q35     = 1,
+    PC_MACHINE_TYPE_LITE    = 2,
+} PCMachineType;
+
 /**
  * PCMachineState:
  * @acpi_dev: link to ACPI PM device that performs ACPI hotplug handling
@@ -136,6 +142,8 @@ struct PCMachineClass {
 
     /* TSC rate migration: */
     bool save_tsc_khz;
+
+    PCMachineType type;
 };
 
 #define TYPE_PC_MACHINE "generic-pc-machine"
Signature · 1 line
1.8.3.1
#10 lore raw
In reply to Chao Peng
Quoted 2 lines · Chao Peng

Basically:
- it removes old ISA devices and support only PCI devices;

I think you need to keep at least the RTC, otherwise where does Linux get the time of day from?

Quoted 9 lines

- it removes 8259, instead use MSI as much as possible. IOAPIC and PCI PIN are still kept to support ACPI SCI;
- it supports PCIE ( you can use MMFG instead of 0xcf8/0xcfc port access);
- it gets rid of legacy firmware interfaces and supports ACPI tables;
- it supports CPU/memory/PCI hotplug;
- it supports Linux-guest only at present;
- You may need carefully configure guest kernel;
- You are forced to use virtio-serial-pci, old 8250/16550 is not there;

It doesn't support PCIe hotplug though, I think? (Because it doesn't support PCI bridges and PCIe hotplug doesn't work for root complex devices). So is it ACPI-based hotplug?

Lack of 8250/16550 means lack of earlyprintk. I know the driver is slow though, so I understand that.

Anyway, I guess all the items above are acceptable.

The ones that I think are "less acceptable" are just two. :)

1) I am a bit worried about introducing a custom northbridge and PM device. In principle you could remove most ISA devices (especially those that take long to initialize) and the 8259 while keeping Q35 and ICH9. This would make it easier to choose between having a firmware and direct guest kernel load.

In general I'd model the lightweight devices around Q35 and ICH9, not PIIX. ICH9 in particular is good because it integrates the PM device and it has an ISA bridge for the RTC and perhaps an optional 8250. But it would be even better to use Q35 and ICH9, not model around them. :)

2) this:

Quoted 2 lines

- it loads guest kernel directly, no BIOS, no bootloader, no realmode code;

... which is related to Linux-only support. How much does this gain over a minimal firmware (either SeaBIOS with the fw_cfg DMA interface, or qboot with cbfs in parallel flash)?

Quoted 1 line

- it supports KVM-host only at present;

Do you know why?

Paolo

author
#11 lore raw
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Chao Peng

Basically:
- it removes old ISA devices and support only PCI devices;

I think you need to keep at least the RTC, otherwise where does Linux get the time of day from?

PV clock will provide that.

Quoted 4 lines

It doesn't support PCIe hotplug though, I think? (Because it doesn't support PCI bridges and PCIe hotplug doesn't work for root complex devices). So is it ACPI-based hotplug?

Yes, this is ACPI-based.

Quoted 3 lines

Lack of 8250/16550 means lack of earlyprintk. I know the driver is slow though, so I understand that.

Understand, it might be a little bit hard for debugging, one solution would be adding 8250/16550 in debug build?

Quoted 11 lines

Anyway, I guess all the items above are acceptable.

The ones that I think are "less acceptable" are just two. :)

1) I am a bit worried about introducing a custom northbridge and PM device. In principle you could remove most ISA devices (especially those that take long to initialize) and the 8259 while keeping Q35 and ICH9. This would make it easier to choose between having a firmware and direct guest kernel load.

Quoted 4 lines

In general I'd model the lightweight devices around Q35 and ICH9, not PIIX. ICH9 in particular is good because it integrates the PM device and it has an ISA bridge for the RTC and perhaps an optional 8250. But it would be even better to use Q35 and ICH9, not model around them. :)

We actually have patches for Q35 + ICH9 and it does exactly the same thing you described here. Adding a new one is just:
1). to keep both Q35 and 'lite' code clean, and
2). don't expose two different Q35 implementations to guest.

One example: we saw smram/pam in Q35 causes guest boot time decrease so we want to strip them off, we change Q35 for our case (ifdef or whatever) but this changes the way guest sees it and also may not be in accord with Q35 spec.

I'm not strongly insist on this. Also reuse Q35 in QEMU can make code in other place (like BIOS) be reused as well (if not cause problem).

Quoted 9 lines

2) this:

Quoted 2 lines

- it loads guest kernel directly, no BIOS, no bootloader, no realmode code;

... which is related to Linux-only support. How much does this gain over a minimal firmware (either SeaBIOS with the fw_cfg DMA interface, or qboot with cbfs in parallel flash)?

We have tried Q35 version (as described above) with both SeaBIOS and qboot. The 'perfect' time with optimized BIOS we have seen is ~15ms, with the additional time in kernel real mode code, the total time overhead comparing to current Linux-aware implementation is more than 40ms. This sounds still a little too much for us.

One solution is to support both direct Linux booting and BIOS booting with a little overhead (but with more flexibility).

Quoted 5 lines
Quoted 3 lines

- it supports KVM-host only at present;

Do you know why?

Just because we have never tested that on other hypervisors (like Xen).

Thanks for comments and suggestions.

Chao

#12 lore raw
Quoted 11 lines · Chao Peng
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Chao Peng

Basically:
- it removes old ISA devices and support only PCI devices;

I think you need to keep at least the RTC, otherwise where does Linux get the time of day from?

PV clock will provide that.

It's KVM only, though. Sometimes TCG is useful for debugging.

Quoted 5 lines
Quoted 2 lines

Lack of 8250/16550 means lack of earlyprintk. I know the driver is slow though, so I understand that.

Understand, it might be a little bit hard for debugging, one solution would be adding 8250/16550 in debug build?

The serial port is optional anyway, it's not there unless you specify "-serial stdio" or similar.

Quoted 4 lines

We actually have patches for Q35 + ICH9 and it does exactly the same thing you described here. Adding a new one is just:
1). to keep both Q35 and 'lite' code clean, and
2). don't expose two different Q35 implementations to guest.

It would be nice to at least see the patches. :)

I think a lightweight q35 platform that can run the usual firmware could be acceptable in QEMU.

Quoted 9 lines
Quoted 8 lines

2) this:

Quoted 2 lines

- it loads guest kernel directly, no BIOS, no bootloader, no realmode code;

... which is related to Linux-only support. How much does this gain over a minimal firmware (either SeaBIOS with the fw_cfg DMA interface, or qboot with cbfs in parallel flash)?

Quoted 5 lines

We have tried Q35 version (as described above) with both SeaBIOS and qboot. The 'perfect' time with optimized BIOS we have seen is ~15ms, with the additional time in kernel real mode code, the total time overhead comparing to current Linux-aware implementation is more than 40ms. This sounds still a little too much for us.

I guess it is related to real mode decompression code?

My main issue is that there are other things that the firmware does. Not all of them are necessary (e.g. SMRAM is not needed, most PCI devices need not be initialized), but in general we don't like putting code in QEMU that modifies the guest state. For example another Intel person is adding code to SeaBIOS that initializes the feature control MSR.

I wonder if Linux could run as a multiboot-compliant ELF file, and what the performance would be... Multiboot omits the real mode stub.

Paolo

#13 lore raw
Quoted 2 lines · Paolo Bonzini

I wonder if Linux could run as a multiboot-compliant ELF file, and what the performance would be... Multiboot omits the real mode stub.

The Linux boot protocol does not require real mode. I think "64-bit BOOT PROTOCOL" in Documentation/x86/boot.txt could be used.

Stefan

#14 lore raw
Quoted 6 lines · Stefan Hajnoczi
Quoted 2 lines · Paolo Bonzini

I wonder if Linux could run as a multiboot-compliant ELF file, and what the performance would be... Multiboot omits the real mode stub.

The Linux boot protocol does not require real mode. I think "64-bit BOOT PROTOCOL" in Documentation/x86/boot.txt could be used.

Yes, the real mode is only needed to decompress the kernel, to retrieve the e820 memory map, and then invoke the Linux boot protocol. However, neither QEMU nor (I think) GRUB can boot a vmlinux file. So I wondered if it would be possible to compile Linux in a format that is not compressed (for speed) and can be invoked by both QEMU and GRUB.

Multiboot seems interesting because it has other advantages. For example it supports modules, so you can use it with an initrd, and it passes the e820 data directly to the loaded kernel.

Paolo

author
#15 lore raw
In reply to Paolo Bonzini
Quoted 4 lines

It would be nice to at least see the patches. :)

I think a lightweight q35 platform that can run the usual firmware could be acceptable in QEMU.

OK, I will send out v2.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

2) this:

Quoted 2 lines

- it loads guest kernel directly, no BIOS, no bootloader, no realmode code;

... which is related to Linux-only support. How much does this gain over a minimal firmware (either SeaBIOS with the fw_cfg DMA interface, or qboot with cbfs in parallel flash)?

Quoted 7 lines
Quoted 5 lines

We have tried Q35 version (as described above) with both SeaBIOS and qboot. The 'perfect' time with optimized BIOS we have seen is ~15ms, with the additional time in kernel real mode code, the total time overhead comparing to current Linux-aware implementation is more than 40ms. This sounds still a little too much for us.

I guess it is related to real mode decompression code?

Yes, that's the major part.

Quoted 10 lines

My main issue is that there are other things that the firmware does. Not all of them are necessary (e.g. SMRAM is not needed, most PCI devices need not be initialized), but in general we don't like putting code in QEMU that modifies the guest state. For example another Intel person is adding code to SeaBIOS that initializes the feature control MSR.

I wonder if Linux could run as a multiboot-compliant ELF file, and what the performance would be... Multiboot omits the real mode stub.

I can look into this. Thanks.

Chao

#16 lore raw
In reply to Paolo Bonzini
Quoted 31 lines · Paolo Bonzini
Quoted 11 lines · Chao Peng
Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Chao Peng

Basically:
- it removes old ISA devices and support only PCI devices;

I think you need to keep at least the RTC, otherwise where does Linux get the time of day from?

PV clock will provide that.

It's KVM only, though. Sometimes TCG is useful for debugging.

Quoted 5 lines
Quoted 2 lines

Lack of 8250/16550 means lack of earlyprintk. I know the driver is slow though, so I understand that.

Understand, it might be a little bit hard for debugging, one solution would be adding 8250/16550 in debug build?

The serial port is optional anyway, it's not there unless you specify "-serial stdio" or similar.

Quoted 4 lines

We actually have patches for Q35 + ICH9 and it does exactly the same thing you described here. Adding a new one is just:
1). to keep both Q35 and 'lite' code clean, and
2). don't expose two different Q35 implementations to guest.

Quoted 4 lines

It would be nice to at least see the patches. :)

I think a lightweight q35 platform that can run the usual firmware could be acceptable in QEMU.

I agree.

Quoted 15 lines
Quoted 9 lines
Quoted 8 lines

2) this:

Quoted 2 lines

- it loads guest kernel directly, no BIOS, no bootloader, no realmode code;

... which is related to Linux-only support. How much does this gain over a minimal firmware (either SeaBIOS with the fw_cfg DMA interface, or qboot with cbfs in parallel flash)?

Quoted 5 lines

We have tried Q35 version (as described above) with both SeaBIOS and qboot. The 'perfect' time with optimized BIOS we have seen is ~15ms, with the additional time in kernel real mode code, the total time overhead comparing to current Linux-aware implementation is more than 40ms. This sounds still a little too much for us.

Quoted 5 lines

I guess it is related to real mode decompression code?

My main issue is that there are other things that the firmware does. Not all of them are necessary (e.g. SMRAM is not needed, most PCI devices need not be initialized),

BTW there's a CMOS flag that says guest is PNP and so only boot devices need to be initialized. seabios could use it and skip non bootable PCI devices.

Quoted 8 lines

but in general we don't like putting
code in QEMU that modifies the guest state. For example another Intel person is adding code to SeaBIOS that initializes the feature control MSR.

I wonder if Linux could run as a multiboot-compliant ELF file, and what the performance would be... Multiboot omits the real mode stub.

Paolo

author
#17 lore raw
In reply to Paolo Bonzini
Quoted 3 lines

I think a lightweight q35 platform that can run the usual firmware could be acceptable in QEMU.

After re-thought the target usage model, I'm not sure if this is a good idea.

The original usage model is to replace kvm-tool with QEMU for Clear Containers (https://clearlinux.org/features/clear-containers). It's not going to present the guest a real PC platform, but instead, a totally virtual platform. Every little bit boot time saving is important because we are trying to achieve comparable result with that for Linux native container.

With this usage model, I doubt introducing a firmware layer is a good idea:

On one side, even with optimized and compact qboot it still takes us ~15ms. This is not a small value because current Linux kernel takes only ~50ms (and we are still on the way to optimize it). And when you look at the SeaBIOS or qboot, almost all the code are useless for this usage model. They are doing things that is important for traditional PC booting but cost 15ms doing useless things for us (It is really not easy to save 15ms in other place, for example, in Linux. Personally I tend to change the architecture for this new usage model, e.g. eliminate firmware).

On the other side, even boot the new pc-lite platform with firmware, it does not mean it can support non-Linux system like Windows. So generally I don't see the benefit of introducing a firmware layer.

Besides, I'm also not quite sure if build around Q35 is the best solution:

The problem with Q35 is some features like SMM/SMRAM/PAM slow done the booting even we actually never use them. While removing these features can cause guest see different feature set for a same device and it also prevents us to do further optimizations on that in guest.

Really appreciate if you could give some more suggestions or other usage models if you have.

Thanks,
Chao

#18 lore raw
Quoted 4 lines · Chao Peng

The original usage model is to replace kvm-tool with QEMU for Clear Containers (https://clearlinux.org/features/clear-containers). It's not going to present the guest a real PC platform, but instead, a totally virtual platform.

It is not completely virtual; it has PCI for example. Hyper-V is an example of a completely virtual platform, even the LAPIC is customized with paravirtual features.

qboot does basically four things: 1) relocate from ROM to 0xf0000; 2) initialize PCI; 2) provide the ACPI and e820 tables; 3) boot.

If Linux can boot without initializing PCI bridges and without INTX, we can remove that code from qboot. The PCI scan is the most expensive part, I think. (2) and (3) are the same no matter if you run them in QEMU or the guest.

That leaves out only relocation (PAM).

Quoted 9 lines

Every little bit boot time saving is important because
we are trying to achieve comparable result with that for Linux native container.

With this usage model, I doubt introducing a firmware layer is a good idea:

On one side, even with optimized and compact qboot it still takes us ~15ms.

Have you profiled it? If it is code in QEMU that we can optimize (e.g. memory.c), that would benefit all guests.

Quoted 9 lines

This is not a small value because current Linux kernel takes only ~50ms (and we are still on the way to optimize it). And when you look at the SeaBIOS or qboot, almost all the code are useless for this usage model. They are doing things that is important for traditional PC booting but cost 15ms doing useless things for us (It is really not easy to save 15ms in other place, for example, in Linux. Personally I tend to change the architecture for this new usage model, e.g. eliminate firmware).

Quoted 3 lines

On the other side, even boot the new pc-lite platform with firmware, it does not mean it can support non-Linux system like Windows. So generally I don't see the benefit of introducing a firmware layer.

The main benefit is maintainability, by reducing the amount of code specific to pc-lite.

Quoted 7 lines

Besides, I'm also not quite sure if build around Q35 is the best solution:

The problem with Q35 is some features like SMM/SMRAM/PAM slow done the booting even we actually never use them. While removing these features can cause guest see different feature set for a same device and it also prevents us to do further optimizations on that in guest.

Of these, qboot only uses PAM, and even that could be removed (PAM is only necessary because of how qboot probes parallel flash). SMRAM should not slow down booting if you don't use them. Do they?

Paolo

#19 lore raw

Hi Paolo,

Quoted 59 lines · Paolo Bonzini
Quoted 4 lines · Chao Peng

The original usage model is to replace kvm-tool with QEMU for Clear Containers (https://clearlinux.org/features/clear-containers). It's not going to present the guest a real PC platform, but instead, a totally virtual platform.

It is not completely virtual; it has PCI for example. Hyper-V is an example of a completely virtual platform, even the LAPIC is customized with paravirtual features.

qboot does basically four things: 1) relocate from ROM to 0xf0000; 2) initialize PCI; 2) provide the ACPI and e820 tables; 3) boot.

If Linux can boot without initializing PCI bridges and without INTX, we can remove that code from qboot. The PCI scan is the most expensive part, I think. (2) and (3) are the same no matter if you run them in QEMU or the guest.

That leaves out only relocation (PAM).

Quoted 9 lines

Every little bit boot time saving is important because
we are trying to achieve comparable result with that for Linux native container.

With this usage model, I doubt introducing a firmware layer is a good idea:

On one side, even with optimized and compact qboot it still takes us ~15ms.

Have you profiled it? If it is code in QEMU that we can optimize (e.g. memory.c), that would benefit all guests.

Quoted 9 lines

This is not a small value because current Linux kernel takes only ~50ms (and we are still on the way to optimize it). And when you look at the SeaBIOS or qboot, almost all the code are useless for this usage model. They are doing things that is important for traditional PC booting but cost 15ms doing useless things for us (It is really not easy to save 15ms in other place, for example, in Linux. Personally I tend to change the architecture for this new usage model, e.g. eliminate firmware).

Quoted 3 lines

On the other side, even boot the new pc-lite platform with firmware, it does not mean it can support non-Linux system like Windows. So generally I don't see the benefit of introducing a firmware layer.

The main benefit is maintainability, by reducing the amount of code specific to pc-lite.

Quoted 7 lines

Besides, I'm also not quite sure if build around Q35 is the best solution:

The problem with Q35 is some features like SMM/SMRAM/PAM slow done the booting even we actually never use them. While removing these features can cause guest see different feature set for a same device and it also prevents us to do further optimizations on that in guest.

Quoted 5 lines

Of these, qboot only uses PAM, and even that could be removed (PAM is only necessary because of how qboot probes parallel flash). SMRAM should not slow down booting if you don't use them. Do they?

Paolo

I use qboot for similar goals, you mention that PAM is necessary because of how qboot probes parallel flash, however in my custom platform I removed PAM completely from QEMU, and everything seems to work without any problems..

Ciao

Claudio

#20 lore raw
Quoted 62 lines · Claudio Fontana

Hi Paolo,

Quoted 59 lines · Paolo Bonzini
Quoted 4 lines · Chao Peng

The original usage model is to replace kvm-tool with QEMU for Clear Containers (https://clearlinux.org/features/clear-containers). It's not going to present the guest a real PC platform, but instead, a totally virtual platform.

It is not completely virtual; it has PCI for example. Hyper-V is an example of a completely virtual platform, even the LAPIC is customized with paravirtual features.

qboot does basically four things: 1) relocate from ROM to 0xf0000; 2) initialize PCI; 2) provide the ACPI and e820 tables; 3) boot.

If Linux can boot without initializing PCI bridges and without INTX, we can remove that code from qboot. The PCI scan is the most expensive part, I think. (2) and (3) are the same no matter if you run them in QEMU or the guest.

That leaves out only relocation (PAM).

Quoted 9 lines

Every little bit boot time saving is important because
we are trying to achieve comparable result with that for Linux native container.

With this usage model, I doubt introducing a firmware layer is a good idea:

On one side, even with optimized and compact qboot it still takes us ~15ms.

Have you profiled it? If it is code in QEMU that we can optimize (e.g. memory.c), that would benefit all guests.

Quoted 9 lines

This is not a small value because current Linux kernel takes only ~50ms (and we are still on the way to optimize it). And when you look at the SeaBIOS or qboot, almost all the code are useless for this usage model. They are doing things that is important for traditional PC booting but cost 15ms doing useless things for us (It is really not easy to save 15ms in other place, for example, in Linux. Personally I tend to change the architecture for this new usage model, e.g. eliminate firmware).

Quoted 3 lines

On the other side, even boot the new pc-lite platform with firmware, it does not mean it can support non-Linux system like Windows. So generally I don't see the benefit of introducing a firmware layer.

The main benefit is maintainability, by reducing the amount of code specific to pc-lite.

Quoted 7 lines

Besides, I'm also not quite sure if build around Q35 is the best solution:

The problem with Q35 is some features like SMM/SMRAM/PAM slow done the booting even we actually never use them. While removing these features can cause guest see different feature set for a same device and it also prevents us to do further optimizations on that in guest.

Quoted 9 lines
Quoted 5 lines

Of these, qboot only uses PAM, and even that could be removed (PAM is only necessary because of how qboot probes parallel flash). SMRAM should not slow down booting if you don't use them. Do they?

Paolo

I use qboot for similar goals, you mention that PAM is necessary because of how qboot probes parallel flash, however in my custom platform I removed PAM completely from QEMU, and everything seems to work without any problems..

Btw before you ask: yes I am booting with pflash.

Ciao

C.

#21 lore raw
Quoted 4 lines · Claudio Fontana
Quoted 2 lines

I use qboot for similar goals, you mention that PAM is necessary because of how qboot probes parallel flash, however in my custom platform I removed PAM completely from QEMU, and everything seems to work without any problems..

Btw before you ask: yes I am booting with pflash.

By default low memory points to PCI address space

    00000000000f0000-00000000000fffff (prio 1, RW): alias pam-ram @pc.ram 00000000000f0000-00000000000fffff [disabled]
    00000000000f0000-00000000000fffff (prio 1, RW): alias pam-pci @pc.ram 00000000000f0000-00000000000fffff [disabled]
    00000000000f0000-00000000000fffff (prio 1, R-): alias pam-rom @pc.ram 00000000000f0000-00000000000fffff [disabled]
    00000000000f0000-00000000000fffff (prio 1, RW): alias pam-pci @pci 00000000000f0000-00000000000fffff

All that qboot does is enabling pam-ram:

        // Make ram from 0xc0000-0xf0000 read-write
        int i;
        for (i=0; i<6; i++) {
                int pam = pambase + 1 + i;
                pci_config_writeb(bdf, pam, 0x33);
        }

        // Make ram from 0xf0000-0x100000 read-write and shadow BIOS
        // We're still running from 0xffff0000
        pci_config_writeb(bdf, pambase, 0x30);
        memcpy(low_start, bios_start, 0x10000);

So if you remove PAM but you are leaving 0xC000-0x10000 pointing to RAM, you are effectively moving qboot's PAM configuration to QEMU. :)

Of these writes, only the last write is strictly necessary. qboot currently uses 0xe0000-0xf0000 for the ACPI tables but we could move them to the EBDA instead and save the initial loop. But I'd like to see a trace saying how much time is spent configuring PAM exactly.

Paolo

#22 lore raw

Hi Paolo,

Quoted 32 lines · Paolo Bonzini
Quoted 4 lines · Claudio Fontana
Quoted 2 lines

I use qboot for similar goals, you mention that PAM is necessary because of how qboot probes parallel flash, however in my custom platform I removed PAM completely from QEMU, and everything seems to work without any problems..

Btw before you ask: yes I am booting with pflash.

By default low memory points to PCI address space

    00000000000f0000-00000000000fffff (prio 1, RW): alias pam-ram @pc.ram 00000000000f0000-00000000000fffff [disabled]
    00000000000f0000-00000000000fffff (prio 1, RW): alias pam-pci @pc.ram 00000000000f0000-00000000000fffff [disabled]
    00000000000f0000-00000000000fffff (prio 1, R-): alias pam-rom @pc.ram 00000000000f0000-00000000000fffff [disabled]
    00000000000f0000-00000000000fffff (prio 1, RW): alias pam-pci @pci 00000000000f0000-00000000000fffff

All that qboot does is enabling pam-ram:

        // Make ram from 0xc0000-0xf0000 read-write
        int i;
        for (i=0; i<6; i++) {
                int pam = pambase + 1 + i;
                pci_config_writeb(bdf, pam, 0x33);
        }

        // Make ram from 0xf0000-0x100000 read-write and shadow BIOS
        // We're still running from 0xffff0000
        pci_config_writeb(bdf, pambase, 0x30);
        memcpy(low_start, bios_start, 0x10000);

So if you remove PAM but you are leaving 0xC000-0x10000 pointing to RAM, you are effectively moving qboot's PAM configuration to QEMU. :)

Quoted 7 lines

Of these writes, only the last write is strictly necessary. qboot currently uses 0xe0000-0xf0000 for the ACPI tables but we could move them to the EBDA instead and save the initial loop. But I'd like to see a trace saying how much time is spent configuring PAM exactly.

Paolo

In my case the boot times are satisfactory including the PAM configuration loop in qboot.

The reason I removed the PAM backend in QEMU (or rather, made them configurable via existing CONFIG_PAM), is as part of memory saving patches, not because of boottime issues.

Ciao,

Claudio

author
#23 lore raw
In reply to Paolo Bonzini
Quoted 10 lines

qboot does basically four things: 1) relocate from ROM to 0xf0000; 2) initialize PCI; 2) provide the ACPI and e820 tables; 3) boot.

If Linux can boot without initializing PCI bridges and without INTX, we can remove that code from qboot. The PCI scan is the most expensive part, I think. (2) and (3) are the same no matter if you run them in QEMU or the guest.

That leaves out only relocation (PAM).

Yes, most 'overhead' comes from PCI stuff, fw_cfg related and PAM.

Quoted 5 lines
Quoted 5 lines

Every little bit boot time saving is important because
we are trying to achieve comparable result with that for Linux native container.

Quoted 8 lines
Quoted 5 lines

With this usage model, I doubt introducing a firmware layer is a good idea:

On one side, even with optimized and compact qboot it still takes us ~15ms.

Have you profiled it? If it is code in QEMU that we can optimize (e.g. memory.c), that would benefit all guests.

Most optimizations are not helpful for traditional guests (because there is functionalities missing), but there does exist some. For example, PAM for Q35 emulation contains 12 memory regions (info mtree). We can merge them into 1 to reduce loop time (even helpful for other memory regions access when PAM is disabled).

Quoted 10 lines
Quoted 10 lines

This is not a small value because current Linux kernel takes only ~50ms (and we are still on the way to optimize it). And when you look at the SeaBIOS or qboot, almost all the code are useless for this usage model. They are doing things that is important for traditional PC booting but cost 15ms doing useless things for us (It is really not easy to save 15ms in other place, for example, in Linux. Personally I tend to change the architecture for this new usage model, e.g. eliminate firmware).

Quoted 6 lines
Quoted 3 lines

On the other side, even boot the new pc-lite platform with firmware, it does not mean it can support non-Linux system like Windows. So generally I don't see the benefit of introducing a firmware layer.

The main benefit is maintainability, by reducing the amount of code specific to pc-lite.

Understand.

Chao

#24 lore raw
In reply to Paolo Bonzini
Quoted 19 lines · * Paolo Bonzini ([email protected]) wrote:
Quoted 2 lines · Chao Peng

Basically:
- it removes old ISA devices and support only PCI devices;

I think you need to keep at least the RTC, otherwise where does Linux get the time of day from?

Quoted 9 lines

- it removes 8259, instead use MSI as much as possible. IOAPIC and PCI PIN are still kept to support ACPI SCI;
- it supports PCIE ( you can use MMFG instead of 0xcf8/0xcfc port access);
- it gets rid of legacy firmware interfaces and supports ACPI tables;
- it supports CPU/memory/PCI hotplug;
- it supports Linux-guest only at present;
- You may need carefully configure guest kernel;
- You are forced to use virtio-serial-pci, old 8250/16550 is not there;

Quoted 6 lines

It doesn't support PCIe hotplug though, I think? (Because it doesn't support PCI bridges and PCIe hotplug doesn't work for root complex devices). So is it ACPI-based hotplug?

Lack of 8250/16550 means lack of earlyprintk. I know the driver is slow though, so I understand that.

You could always define a different way to get early debug; for example a chunk of RAM at a known address seems fine for a VM.

Dave
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#26 lore raw
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line · Chao Peng

- it is FAST;

Any numbers to demonstrate just how fast it is and fast at what?

On a 2.30GHz Haswell server, guest kernel booting time is 59.9ms by following test steps listed at

https://github.com/chao-p/qemu-lite-tools

Ran the same test with "-machine q35", the guest kernel booting time is 129.8ms. There is additional 75ms in SeaBIOS for Q35 case.

Thanks,
Chao

#27 lore raw
Quoted 6 lines · Chao Peng
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line · Chao Peng

- it is FAST;

Any numbers to demonstrate just how fast it is and fast at what?

Quoted 7 lines

On a 2.30GHz Haswell server, guest kernel booting time is 59.9ms by following test steps listed at

https://github.com/chao-p/qemu-lite-tools

Ran the same test with "-machine q35", the guest kernel booting time is 129.8ms. There is additional 75ms in SeaBIOS for Q35 case.

I think it'd be useful / interesting to understand why we have saved this time vs Q35. I'm not a huge fan of the idea of defining an arbitrarily cut down machine type, because inevitably one applications view of what is the "bare minimum required functionality" will be different from another applications' view.

It seems to me that whether some features emulated by QEMU are slow or not should only matter if the guest OS actually tries to use those features. IOW, could we achieve the same speed up in boot time, by making Linux more configurable at runtime. eg so with a single Linux kernel binary and standard Q35/PIIX machine type, we can disable slow functionality by just giving Linux suitable kernel command line arguments.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
author
#28 lore raw
Quoted 21 lines · Daniel P. Berrange
Quoted 6 lines · Chao Peng
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line · Chao Peng

- it is FAST;

Any numbers to demonstrate just how fast it is and fast at what?

Quoted 7 lines

On a 2.30GHz Haswell server, guest kernel booting time is 59.9ms by following test steps listed at

https://github.com/chao-p/qemu-lite-tools

Ran the same test with "-machine q35", the guest kernel booting time is 129.8ms. There is additional 75ms in SeaBIOS for Q35 case.

I think it'd be useful / interesting to understand why we have saved this time vs Q35. I'm not a huge fan of the idea of defining an arbitrarily cut down machine type, because inevitably one applications view of what is the "bare minimum required functionality" will be different from another applications' view.

Quoted 7 lines

It seems to me that whether some features emulated by QEMU are slow or not should only matter if the guest OS actually tries to use those features. IOW, could we achieve the same speed up in boot time, by making Linux more configurable at runtime. eg so with a single Linux kernel binary and standard Q35/PIIX machine type, we can disable slow functionality by just giving Linux suitable kernel command line arguments.

I totally agree with you. And our goal is reducing boot time so I don't mind using existing code to achieve this goal.

When I looked into this. I have thought there might be a minimal platform with which I can add other stuff on demand, or a full functional platform that allow me to disable unnecessary functionalities.

But in practice I can't get a system that exactly fit for me, regardless there is lots of configuration methods in both QEMU/BIOS/kernel.

Taking kernel time overhead with Q35 here for example. The most time saving comes from PCI initialization. New pc-lite platform supports only 1 bus so guest don't need to scan all the possible buses which save ~60ms. Another time saving place is new pc-lite platform removed SMBUS/SATA/LPC bridges that Q35 creates by default. Initialization for these devices costs ~20ms.

The problem is not all these functionalities can be disabled either in kernel or in QEMU, so in the end, turns out to introduce a new one.

Thanks,
Chao

#29 lore raw
Quoted 47 lines · Chao Peng
Quoted 21 lines · Daniel P. Berrange
Quoted 6 lines · Chao Peng
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line · Chao Peng

- it is FAST;

Any numbers to demonstrate just how fast it is and fast at what?

Quoted 7 lines

On a 2.30GHz Haswell server, guest kernel booting time is 59.9ms by following test steps listed at

https://github.com/chao-p/qemu-lite-tools

Ran the same test with "-machine q35", the guest kernel booting time is 129.8ms. There is additional 75ms in SeaBIOS for Q35 case.

I think it'd be useful / interesting to understand why we have saved this time vs Q35. I'm not a huge fan of the idea of defining an arbitrarily cut down machine type, because inevitably one applications view of what is the "bare minimum required functionality" will be different from another applications' view.

Quoted 7 lines

It seems to me that whether some features emulated by QEMU are slow or not should only matter if the guest OS actually tries to use those features. IOW, could we achieve the same speed up in boot time, by making Linux more configurable at runtime. eg so with a single Linux kernel binary and standard Q35/PIIX machine type, we can disable slow functionality by just giving Linux suitable kernel command line arguments.

I totally agree with you. And our goal is reducing boot time so I don't mind using existing code to achieve this goal.

When I looked into this. I have thought there might be a minimal platform with which I can add other stuff on demand, or a full functional platform that allow me to disable unnecessary functionalities.

But in practice I can't get a system that exactly fit for me, regardless there is lots of configuration methods in both QEMU/BIOS/kernel.

Taking kernel time overhead with Q35 here for example. The most time saving comes from PCI initialization. New pc-lite platform supports only 1 bus so guest don't need to scan all the possible buses which save ~60ms. Another time saving place is new pc-lite platform removed SMBUS/SATA/LPC bridges that Q35 creates by default. Initialization for these devices costs ~20ms.

Quoted 2 lines

The problem is not all these functionalities can be disabled either in kernel or in QEMU, so in the end, turns out to introduce a new one.

I know that can't be disable in *current* kernel / QEMU. What i'm suggesting is that you enhance the kernel / QEMU to allow more features to be disabled dynamically. Adding yet another machine type with a static fixed set of hardware will only ever suit niche use cases which happen to match whatever you've personally decided is important, while adding long term support burden on QEMU for yet another machine. IMHO it is a better long term payout to make existing kernel/qemu more dynamically configurable instead of adding yet another non-dynamic machine.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#30 lore raw
In reply to Chao Peng

Hi,

Quoted 33 lines · Chao Peng

This patchset is against commit 585fcd4 (Merge remote-tracking branch 'remotes/bonzini/tags/for-upstream' into staging) on master branch. I also put it on github:

https://github.com/chao-p/qemu pc-lite-v1

Although we have run the patchset internally for a while but it is still considered as RFC. Any comments (coding style or design issue) are welcome.

Introduction
============
The patch series introduces a new platform pc-lite, which is designed to be a virtual and light weight x86 PC platform. It is not designed to be compatible with old hardware and system. Instead, It removes the burden of legacy devices and emulates new fast hardware as much as possible. It is expected to be used together with optimized guest (though unoptimized guest works as well) to gain fast booting and small footprint benefits that are difficult to achieve for traditional hardware-emulated platform.

Basically:
- it removes old ISA devices and support only PCI devices;
- it removes 8259, instead use MSI as much as possible. IOAPIC and PCI PIN are still kept to support ACPI SCI;
- it supports PCIE ( you can use MMFG instead of 0xcf8/0xcfc port access);
- it gets rid of legacy firmware interfaces and supports ACPI tables;
- it loads guest kernel directly, no BIOS, no bootloader, no realmode code;
- it supports CPU/memory/PCI hotplug;
- it is FAST;

Quoted 8 lines

However:
- it supports KVM-host only at present;
- it supports Linux-guest only at present;
- You may need carefully configure guest kernel;
- You are forced to use virtio-serial-pci, old 8250/16550 is not there;

Want to have a try?
===================

The combination of devices removed/supported seems a bit arbitrary to me.
The use in this text of "legacy" and non-"legacy" is also arbitrary if not given a definition.

What is the use case of this new platform?

Care to share your numbers about how FAST is FAST? Like how much time you need to boot from qemu launch to the guest being booted, and on which hardware, and which guest kernel configuration?

Ciao,

Claudio

Quoted 50 lines

Please follow https://github.com/chao-p/qemu-lite-tools.

Thanks,
Chao

Chao Peng (6):
acpi: introduce light weight ACPI PM emulation pm-lite
pci: introduce light weight PCIE Host emulation pci-lite
acpi: add support for pc-lite platform
pc: skip setting CMOS data when RTC device is unavailable
pc: support direct loading protected/long mode kernel
pc: introduce light weight PC board pc-lite

Haozhong Zhang (3):
acpi: expose data structurs and functions of BIOS linker loader
acpi: expose acpi_checksum()
acpi: patch guest ACPI for pc-lite

 default-configs/i386-softmmu.mak     |   1 +
 default-configs/x86_64-softmmu.mak   |   1 +
 docs/specs/acpi_cpu_hotplug.txt      |   1 +
 hw/acpi/Makefile.objs                |   2 +-
 hw/acpi/bios-linker-loader.c         |  83 +------
 hw/acpi/core.c                       |   2 +-
 hw/acpi/nvdimm.c                     |   6 +-
 hw/acpi/pm_lite.c                    | 446 +++++++++++++++++++++++++++++++++++
 hw/i386/Makefile.objs                |   2 +-
 hw/i386/acpi-build.c                 | 180 +++++++++-----
 hw/i386/pc.c                         | 263 ++++++++++++++++++---
 hw/i386/pc_lite.c                    | 205 ++++++++++++++++
 hw/i386/pc_lite_acpi.c               | 299 +++++++++++++++++++++++
 hw/i386/pc_piix.c                    |   2 +
 hw/i386/pc_q35.c                     |   2 +
 hw/pci-host/Makefile.objs            |   1 +
 hw/pci-host/pci_lite.c               | 259 ++++++++++++++++++++
 include/hw/acpi/acpi.h               |   2 +
 include/hw/acpi/bios-linker-loader.h |  85 +++++++
 include/hw/acpi/pc-hotplug.h         |   1 +
 include/hw/acpi/pm_lite.h            |   6 +
 include/hw/i386/pc.h                 |  17 ++
 include/hw/i386/pc_lite_acpi.h       |  10 +
 23 files changed, 1697 insertions(+), 179 deletions(-)
 create mode 100644 hw/acpi/pm_lite.c
 create mode 100644 hw/i386/pc_lite.c
 create mode 100644 hw/i386/pc_lite_acpi.c
 create mode 100644 hw/pci-host/pci_lite.c
 create mode 100644 include/hw/acpi/pm_lite.h
 create mode 100644 include/hw/i386/pc_lite_acpi.h
author
#31 lore raw
Quoted 3 lines

The combination of devices removed/supported seems a bit arbitrary to me.
The use in this text of "legacy" and non-"legacy" is also arbitrary if not given a definition.

The criterial here is to remove the devices that have poor performance. You can think legacy devices here as ISA devices. Most of them are emulated with slow port IO and slow line-based IRQ handling.

Quoted 2 lines

What is the use case of this new platform?

You can have a look at Clear containers
(https://clearlinux.org/features/clear-containers) or other similar technologies. Basically they try to provide container-like service with VT to improve security. Clear containers employ kvm-tool to gain 'lite' benefit. This patch however try to achive the same with QEMU.

Quoted 2 lines

Care to share your numbers about how FAST is FAST? Like how much time you need to boot from qemu launch to the guest being booted, and on which hardware, and which guest kernel configuration?

Kernel .config is already listed in the repo I listed below. For guest kernel and BIOS performance data please see another reply to mst. QEMU bootup time itself however is mainly not improved with this patchset, but the optmized QEMU normally we see takes ~45ms.

Thanks,
Chao

Quoted 10 lines

Ciao,

Claudio

Quoted 5 lines

Please follow https://github.com/chao-p/qemu-lite-tools.

Thanks,
Chao