Skip to contentSkip to conversation

pc: hide linuxboot RNG seed behind a machine property

PATCH In review Paolo Bonzini 2 participants 4 messages Aug 10, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 pc: hide linuxboot RNG seed behind a machine property

OVMF does not support Linux setup_data and it is not clear how to fix this, so disable the support for the random number seed for the 7.1 release. Using a property allows shipping the code even if it is disabled by default. The property name has "x-" prepended because the implementation might change in the future; migration from future versions to QEMU 7.1 is only guaranteed to work if the property is left to its default of "off". At the time the property is enabled by default, the "x-" can be removed.

Using a property has other advantages in general: it makes it possible to use the normal compat property mechanism instead of ad hoc code, and it avoids parameter proliferation in x86_load_linux.

---
 hw/i386/microvm.c     |  2 +-
 hw/i386/pc.c          |  4 ++--
 hw/i386/pc_piix.c     |  2 +-
 hw/i386/pc_q35.c      |  2 +-
 hw/i386/x86.c         | 33 +++++++++++++++++++++++++++++----
 include/hw/i386/pc.h  |  3 ---
 include/hw/i386/x86.h |  5 +++--
 7 files changed, 37 insertions(+), 14 deletions(-)
hw/i386/microvm.c +1 -1
index 7fe8cce03e..dc929727dc 100644
@@ -332,7 +332,7 @@ static void microvm_memory_init(MicrovmMachineState *mms)
     rom_set_fw(fw_cfg);
 
     if (machine->kernel_filename != NULL) {
-        x86_load_linux(x86ms, fw_cfg, 0, true, false);
+        x86_load_linux(x86ms, fw_cfg, 0, true);
     }
 
     if (mms->option_roms) {
hw/i386/pc.c +2 -2
index 7280c02ce3..4518f3c546 100644
@@ -796,7 +796,7 @@ void xen_load_linux(PCMachineState *pcms)
     rom_set_fw(fw_cfg);
 
     x86_load_linux(x86ms, fw_cfg, pcmc->acpi_data_size,
-                   pcmc->pvh_enabled, pcmc->legacy_no_rng_seed);
+                   pcmc->pvh_enabled);
     for (i = 0; i < nb_option_roms; i++) {
         assert(!strcmp(option_rom[i].name, "linuxboot.bin") ||
                !strcmp(option_rom[i].name, "linuxboot_dma.bin") ||
@@ -1118,7 +1118,7 @@ void pc_memory_init(PCMachineState *pcms,
 
     if (linux_boot) {
         x86_load_linux(x86ms, fw_cfg, pcmc->acpi_data_size,
-                       pcmc->pvh_enabled, pcmc->legacy_no_rng_seed);
+                       pcmc->pvh_enabled);
     }
 
     for (i = 0; i < nb_option_roms; i++) {
hw/i386/pc_piix.c +1 -1
index a5c65c1c35..1526b7e3fd 100644
@@ -447,10 +447,10 @@ DEFINE_I440FX_MACHINE(v7_1, "pc-i440fx-7.1", NULL,
 static void pc_i440fx_7_0_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
+
     pc_i440fx_7_1_machine_options(m);
     m->alias = NULL;
     m->is_default = false;
-    pcmc->legacy_no_rng_seed = true;
     pcmc->enforce_amd_1tb_hole = false;
     compat_props_add(m->compat_props, hw_compat_7_0, hw_compat_7_0_len);
     compat_props_add(m->compat_props, pc_compat_7_0, pc_compat_7_0_len);
hw/i386/pc_q35.c +1 -1
index 3a35193ff7..c5b38edc65 100644
@@ -384,9 +384,9 @@ DEFINE_Q35_MACHINE(v7_1, "pc-q35-7.1", NULL,
 static void pc_q35_7_0_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
+
     pc_q35_7_1_machine_options(m);
     m->alias = NULL;
-    pcmc->legacy_no_rng_seed = true;
     pcmc->enforce_amd_1tb_hole = false;
     compat_props_add(m->compat_props, hw_compat_7_0, hw_compat_7_0_len);
     compat_props_add(m->compat_props, pc_compat_7_0, pc_compat_7_0_len);
hw/i386/x86.c +29 -4
index 050eedc0c8..01bad1972b 100644
@@ -60,6 +60,8 @@
 #include CONFIG_DEVICES
 #include "kvm/kvm_i386.h"
 
+#define RNG_SEED_LENGTH 32
+
 /* Physical Address of PVH entry point read from kernel ELF NOTE */
 static size_t pvh_start_addr;
 
@@ -767,8 +769,7 @@ static bool load_elfboot(const char *kernel_filename,
 void x86_load_linux(X86MachineState *x86ms,
                     FWCfgState *fw_cfg,
                     int acpi_data_size,
-                    bool pvh_enabled,
-                    bool legacy_no_rng_seed)
+                    bool pvh_enabled)
 {
     bool linuxboot_dma_enabled = X86_MACHINE_GET_CLASS(x86ms)->fwcfg_dma_enabled;
     uint16_t protocol;
@@ -786,7 +787,6 @@ void x86_load_linux(X86MachineState *x86ms,
     const char *dtb_filename = machine->dtb;
     const char *kernel_cmdline = machine->kernel_cmdline;
     SevKernelLoaderContext sev_load_ctx = {};
-    enum { RNG_SEED_LENGTH = 32 };
 
     /* Align to 16 bytes as a paranoia measure */
     cmdline_size = (strlen(kernel_cmdline) + 16) & ~15;
@@ -1076,7 +1076,8 @@ void x86_load_linux(X86MachineState *x86ms,
         load_image_size(dtb_filename, setup_data->data, dtb_size);
     }
 
-    if (!legacy_no_rng_seed) {
+    if (x86ms->linuxboot_randomness != ON_OFF_AUTO_OFF &&
+        (protocol >= 0x209 || x86ms->linuxboot_randomness == ON_OFF_AUTO_ON)) {
         setup_data_offset = QEMU_ALIGN_UP(kernel_size, 16);
         kernel_size = setup_data_offset + sizeof(struct setup_data) + RNG_SEED_LENGTH;
         kernel = g_realloc(kernel, kernel_size);
@@ -1237,6 +1238,23 @@ static void x86_machine_set_smm(Object *obj, Visitor *v, const char *name,
     visit_type_OnOffAuto(v, name, &x86ms->smm, errp);
 }
 
+static void x86_machine_get_linuxboot_randomness(Object *obj, Visitor *v, const char *name,
+                                           void *opaque, Error **errp)
+{
+    X86MachineState *x86ms = X86_MACHINE(obj);
+    OnOffAuto linuxboot_randomness = x86ms->linuxboot_randomness;
+
+    visit_type_OnOffAuto(v, name, &linuxboot_randomness, errp);
+}
+
+static void x86_machine_set_linuxboot_randomness(Object *obj, Visitor *v, const char *name,
+                                           void *opaque, Error **errp)
+{
+    X86MachineState *x86ms = X86_MACHINE(obj);
+
+    visit_type_OnOffAuto(v, name, &x86ms->linuxboot_randomness, errp);
+}
+
 bool x86_machine_is_acpi_enabled(const X86MachineState *x86ms)
 {
     if (x86ms->acpi == ON_OFF_AUTO_OFF) {
@@ -1387,6 +1405,7 @@ static void x86_machine_initfn(Object *obj)
     x86ms->acpi = ON_OFF_AUTO_AUTO;
     x86ms->pit = ON_OFF_AUTO_AUTO;
     x86ms->pic = ON_OFF_AUTO_AUTO;
+    x86ms->linuxboot_randomness = ON_OFF_AUTO_OFF;
     x86ms->pci_irq_mask = ACPI_BUILD_PCI_IRQS;
     x86ms->oem_id = g_strndup(ACPI_BUILD_APPNAME6, 6);
     x86ms->oem_table_id = g_strndup(ACPI_BUILD_APPNAME8, 8);
@@ -1426,6 +1445,12 @@ static void x86_machine_class_init(ObjectClass *oc, void *data)
     object_class_property_set_description(oc, X86_MACHINE_PIT,
         "Enable i8254 PIT");
 
+    object_class_property_add(oc, X86_MACHINE_LINUXBOOT_RANDOMNESS, "OnOffAuto",
+        x86_machine_get_linuxboot_randomness, x86_machine_set_linuxboot_randomness,
+        NULL, NULL);
+    object_class_property_set_description(oc, X86_MACHINE_LINUXBOOT_RANDOMNESS,
+        "Pass random number seed to -kernel Linux image");
+
     object_class_property_add(oc, X86_MACHINE_PIC, "OnOffAuto",
                               x86_machine_get_pic,
                               x86_machine_set_pic,
include/hw/i386/pc.h +0 -3
index 8435733bd6..9cc3f5d338 100644
@@ -128,9 +128,6 @@ struct PCMachineClass {
 
     /* create kvmclock device even when KVM PV features are not exposed */
     bool kvmclock_create_always;
-
-    /* skip passing an rng seed for legacy machines */
-    bool legacy_no_rng_seed;
 };
 
 #define TYPE_PC_MACHINE "generic-pc-machine"
include/hw/i386/x86.h +3 -2
index 62fa5774f8..d7a2eb6f1c 100644
@@ -70,6 +70,7 @@ struct X86MachineState {
     OnOffAuto acpi;
     OnOffAuto pit;
     OnOffAuto pic;
+    OnOffAuto linuxboot_randomness;
 
     char *oem_id;
     char *oem_table_id;
@@ -94,6 +95,7 @@ struct X86MachineState {
 #define X86_MACHINE_OEM_ID           "x-oem-id"
 #define X86_MACHINE_OEM_TABLE_ID     "x-oem-table-id"
 #define X86_MACHINE_BUS_LOCK_RATELIMIT  "bus-lock-ratelimit"
+#define X86_MACHINE_LINUXBOOT_RANDOMNESS "x-linuxboot-randomness"
 
 #define TYPE_X86_MACHINE   MACHINE_TYPE_NAME("x86")
 OBJECT_DECLARE_TYPE(X86MachineState, X86MachineClass, X86_MACHINE)
@@ -126,8 +128,7 @@ void x86_bios_rom_init(MachineState *ms, const char *default_firmware,
 void x86_load_linux(X86MachineState *x86ms,
                     FWCfgState *fw_cfg,
                     int acpi_data_size,
-                    bool pvh_enabled,
-                    bool legacy_no_rng_seed);
+                    bool pvh_enabled);
 
 bool x86_machine_is_smm_enabled(const X86MachineState *x86ms);
 bool x86_machine_is_acpi_enabled(const X86MachineState *x86ms);
Signature · 1 line
2.37.1
#1 lore raw
Quoted 158 lines · Paolo Bonzini

OVMF does not support Linux setup_data and it is not clear how to fix this, so disable the support for the random number seed for the 7.1 release. Using a property allows shipping the code even if it is disabled by default. The property name has "x-" prepended because the implementation might change in the future; migration from future versions to QEMU 7.1 is only guaranteed to work if the property is left to its default of "off". At the time the property is enabled by default, the "x-" can be removed.

Using a property has other advantages in general: it makes it possible to use the normal compat property mechanism instead of ad hoc code, and it avoids parameter proliferation in x86_load_linux.

---
 hw/i386/microvm.c     |  2 +-
 hw/i386/pc.c          |  4 ++--
 hw/i386/pc_piix.c     |  2 +-
 hw/i386/pc_q35.c      |  2 +-
 hw/i386/x86.c         | 33 +++++++++++++++++++++++++++++----
 include/hw/i386/pc.h  |  3 ---
 include/hw/i386/x86.h |  5 +++--
 7 files changed, 37 insertions(+), 14 deletions(-)
hw/i386/microvm.c +1 -1
index 7fe8cce03e..dc929727dc 100644
@@ -332,7 +332,7 @@ static void microvm_memory_init(MicrovmMachineState *mms)
     rom_set_fw(fw_cfg);
 
     if (machine->kernel_filename != NULL) {
-        x86_load_linux(x86ms, fw_cfg, 0, true, false);
+        x86_load_linux(x86ms, fw_cfg, 0, true);
     }
 
     if (mms->option_roms) {
hw/i386/pc.c +2 -2
index 7280c02ce3..4518f3c546 100644
@@ -796,7 +796,7 @@ void xen_load_linux(PCMachineState *pcms)
     rom_set_fw(fw_cfg);
 
     x86_load_linux(x86ms, fw_cfg, pcmc->acpi_data_size,
-                   pcmc->pvh_enabled, pcmc->legacy_no_rng_seed);
+                   pcmc->pvh_enabled);
     for (i = 0; i < nb_option_roms; i++) {
         assert(!strcmp(option_rom[i].name, "linuxboot.bin") ||
                !strcmp(option_rom[i].name, "linuxboot_dma.bin") ||
@@ -1118,7 +1118,7 @@ void pc_memory_init(PCMachineState *pcms,
 
     if (linux_boot) {
         x86_load_linux(x86ms, fw_cfg, pcmc->acpi_data_size,
-                       pcmc->pvh_enabled, pcmc->legacy_no_rng_seed);
+                       pcmc->pvh_enabled);
     }
 
     for (i = 0; i < nb_option_roms; i++) {
hw/i386/pc_piix.c +1 -1
index a5c65c1c35..1526b7e3fd 100644
@@ -447,10 +447,10 @@ DEFINE_I440FX_MACHINE(v7_1, "pc-i440fx-7.1", NULL,
 static void pc_i440fx_7_0_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
+
     pc_i440fx_7_1_machine_options(m);
     m->alias = NULL;
     m->is_default = false;
-    pcmc->legacy_no_rng_seed = true;
     pcmc->enforce_amd_1tb_hole = false;
     compat_props_add(m->compat_props, hw_compat_7_0, hw_compat_7_0_len);
     compat_props_add(m->compat_props, pc_compat_7_0, pc_compat_7_0_len);
hw/i386/pc_q35.c +1 -1
index 3a35193ff7..c5b38edc65 100644
@@ -384,9 +384,9 @@ DEFINE_Q35_MACHINE(v7_1, "pc-q35-7.1", NULL,
 static void pc_q35_7_0_machine_options(MachineClass *m)
 {
     PCMachineClass *pcmc = PC_MACHINE_CLASS(m);
+
     pc_q35_7_1_machine_options(m);
     m->alias = NULL;
-    pcmc->legacy_no_rng_seed = true;
     pcmc->enforce_amd_1tb_hole = false;
     compat_props_add(m->compat_props, hw_compat_7_0, hw_compat_7_0_len);
     compat_props_add(m->compat_props, pc_compat_7_0, pc_compat_7_0_len);
hw/i386/x86.c +22 -4
index 050eedc0c8..01bad1972b 100644
@@ -60,6 +60,8 @@
 #include CONFIG_DEVICES
 #include "kvm/kvm_i386.h"
 
+#define RNG_SEED_LENGTH 32
+
 /* Physical Address of PVH entry point read from kernel ELF NOTE */
 static size_t pvh_start_addr;
 
@@ -767,8 +769,7 @@ static bool load_elfboot(const char *kernel_filename,
 void x86_load_linux(X86MachineState *x86ms,
                     FWCfgState *fw_cfg,
                     int acpi_data_size,
-                    bool pvh_enabled,
-                    bool legacy_no_rng_seed)
+                    bool pvh_enabled)
 {
     bool linuxboot_dma_enabled = X86_MACHINE_GET_CLASS(x86ms)->fwcfg_dma_enabled;
     uint16_t protocol;
@@ -786,7 +787,6 @@ void x86_load_linux(X86MachineState *x86ms,
     const char *dtb_filename = machine->dtb;
     const char *kernel_cmdline = machine->kernel_cmdline;
     SevKernelLoaderContext sev_load_ctx = {};
-    enum { RNG_SEED_LENGTH = 32 };
 
     /* Align to 16 bytes as a paranoia measure */
     cmdline_size = (strlen(kernel_cmdline) + 16) & ~15;
@@ -1076,7 +1076,8 @@ void x86_load_linux(X86MachineState *x86ms,
         load_image_size(dtb_filename, setup_data->data, dtb_size);
     }
 
-    if (!legacy_no_rng_seed) {
+    if (x86ms->linuxboot_randomness != ON_OFF_AUTO_OFF &&
+        (protocol >= 0x209 || x86ms->linuxboot_randomness == ON_OFF_AUTO_ON)) {
         setup_data_offset = QEMU_ALIGN_UP(kernel_size, 16);
         kernel_size = setup_data_offset + sizeof(struct setup_data) + RNG_SEED_LENGTH;
         kernel = g_realloc(kernel, kernel_size);
@@ -1237,6 +1238,23 @@ static void x86_machine_set_smm(Object *obj, Visitor *v, const char *name,
     visit_type_OnOffAuto(v, name, &x86ms->smm, errp);
 }
 
+static void x86_machine_get_linuxboot_randomness(Object *obj, Visitor *v, const char *name,
+                                           void *opaque, Error **errp)
+{
+    X86MachineState *x86ms = X86_MACHINE(obj);
+    OnOffAuto linuxboot_randomness = x86ms->linuxboot_randomness;
+
+    visit_type_OnOffAuto(v, name, &linuxboot_randomness, errp);
+}
+
+static void x86_machine_set_linuxboot_randomness(Object *obj, Visitor *v, const char *name,
+                                           void *opaque, Error **errp)
+{
+    X86MachineState *x86ms = X86_MACHINE(obj);
+
+    visit_type_OnOffAuto(v, name, &x86ms->linuxboot_randomness, errp);
+}
+
 bool x86_machine_is_acpi_enabled(const X86MachineState *x86ms)
 {
     if (x86ms->acpi == ON_OFF_AUTO_OFF) {

hw/i386/x86.c static void x86_machine_initfn(Object *obj) · line 1411

Quoted 7 lines
hw/i386/x86.c +1 -0
@@ -1387,6 +1405,7 @@ static void x86_machine_initfn(Object *obj)
     x86ms->acpi = ON_OFF_AUTO_AUTO;
     x86ms->pit = ON_OFF_AUTO_AUTO;
     x86ms->pic = ON_OFF_AUTO_AUTO;
+    x86ms->linuxboot_randomness = ON_OFF_AUTO_OFF;
     x86ms->pci_irq_mask = ACPI_BUILD_PCI_IRQS;
     x86ms->oem_id = g_strndup(ACPI_BUILD_APPNAME6, 6);
     x86ms->oem_table_id = g_strndup(ACPI_BUILD_APPNAME8, 8);

This is a weird thing to do in that there's no way to make it auto now. And in that case, let's just make it a simple boolean property for now?

Quoted 59 lines
hw/i386/x86.c +6 -0
@@ -1426,6 +1445,12 @@ static void x86_machine_class_init(ObjectClass *oc, void *data)
     object_class_property_set_description(oc, X86_MACHINE_PIT,
         "Enable i8254 PIT");
 
+    object_class_property_add(oc, X86_MACHINE_LINUXBOOT_RANDOMNESS, "OnOffAuto",
+        x86_machine_get_linuxboot_randomness, x86_machine_set_linuxboot_randomness,
+        NULL, NULL);
+    object_class_property_set_description(oc, X86_MACHINE_LINUXBOOT_RANDOMNESS,
+        "Pass random number seed to -kernel Linux image");
+
     object_class_property_add(oc, X86_MACHINE_PIC, "OnOffAuto",
                               x86_machine_get_pic,
                               x86_machine_set_pic,
include/hw/i386/pc.h +0 -3
index 8435733bd6..9cc3f5d338 100644
@@ -128,9 +128,6 @@ struct PCMachineClass {
 
     /* create kvmclock device even when KVM PV features are not exposed */
     bool kvmclock_create_always;
-
-    /* skip passing an rng seed for legacy machines */
-    bool legacy_no_rng_seed;
 };
 
 #define TYPE_PC_MACHINE "generic-pc-machine"
include/hw/i386/x86.h +3 -2
index 62fa5774f8..d7a2eb6f1c 100644
@@ -70,6 +70,7 @@ struct X86MachineState {
     OnOffAuto acpi;
     OnOffAuto pit;
     OnOffAuto pic;
+    OnOffAuto linuxboot_randomness;
 
     char *oem_id;
     char *oem_table_id;
@@ -94,6 +95,7 @@ struct X86MachineState {
 #define X86_MACHINE_OEM_ID           "x-oem-id"
 #define X86_MACHINE_OEM_TABLE_ID     "x-oem-table-id"
 #define X86_MACHINE_BUS_LOCK_RATELIMIT  "bus-lock-ratelimit"
+#define X86_MACHINE_LINUXBOOT_RANDOMNESS "x-linuxboot-randomness"
 
 #define TYPE_X86_MACHINE   MACHINE_TYPE_NAME("x86")
 OBJECT_DECLARE_TYPE(X86MachineState, X86MachineClass, X86_MACHINE)
@@ -126,8 +128,7 @@ void x86_bios_rom_init(MachineState *ms, const char *default_firmware,
 void x86_load_linux(X86MachineState *x86ms,
                     FWCfgState *fw_cfg,
                     int acpi_data_size,
-                    bool pvh_enabled,
-                    bool legacy_no_rng_seed);
+                    bool pvh_enabled);
 
 bool x86_machine_is_smm_enabled(const X86MachineState *x86ms);
 bool x86_machine_is_acpi_enabled(const X86MachineState *x86ms);
Signature · 1 line
2.37.1
#2 lore raw

Il mer 10 ago 2022, 19:06 Michael S. Tsirkin <[email protected]> ha scritto:

Quoted 12 lines

hw/i386/x86.c static void x86_machine_initfn(Object *obj) · line 1411

Quoted 8 lines
hw/i386/x86.c +1 -0
@@ -1387,6 +1405,7 @@ static void x86_machine_initfn(Object *obj)
     x86ms->acpi = ON_OFF_AUTO_AUTO;
     x86ms->pit = ON_OFF_AUTO_AUTO;
     x86ms->pic = ON_OFF_AUTO_AUTO;
+    x86ms->linuxboot_randomness = ON_OFF_AUTO_OFF;
     x86ms->pci_irq_mask = ACPI_BUILD_PCI_IRQS;
     x86ms->oem_id = g_strndup(ACPI_BUILD_APPNAME6, 6);
     x86ms->oem_table_id = g_strndup(ACPI_BUILD_APPNAME8, 8);

This is a weird thing to do in that there's no way to make it auto now.

Sure, -M x-linuxboot-randomness=auto works. And making it already on/off/auto will limit future patches to the injection logic rather than the QOM boilerplate.

Paolo

And in that case, let's just make it a simple boolean property for now?

Quoted 68 lines

Review static void x86_machine_class_init(ObjectClass

Quoted 2 lines
(quoted diff) +0 -0
@@ -1426,6 +1445,12 @@ static void x86_machine_class_init(ObjectClass

*oc, void *data)

hw/i386/x86.c static void x86_machine_class_init(ObjectClass *oc, void *data)

Quoted 4 lines
hw/i386/x86.c +1 -0
     object_class_property_set_description(oc, X86_MACHINE_PIT,
         "Enable i8254 PIT");
 
+    object_class_property_add(oc, X86_MACHINE_LINUXBOOT_RANDOMNESS,

"OnOffAuto",

Review static void x86_machine_class_init(ObjectClass · line 1449

Quoted 1 line
(quoted diff) +1 -0
+        x86_machine_get_linuxboot_randomness,

x86_machine_set_linuxboot_randomness,

Review static void x86_machine_class_init(ObjectClass · line 1451

Quoted 2 lines
(quoted diff) +2 -0
+        NULL, NULL);
+    object_class_property_set_description(oc,

X86_MACHINE_LINUXBOOT_RANDOMNESS,

include/hw/i386/pc.h struct PCMachineClass { · line 129

Quoted 12 lines
hw/i386/x86.c +2 -0
+        "Pass random number seed to -kernel Linux image");
+
     object_class_property_add(oc, X86_MACHINE_PIC, "OnOffAuto",
                               x86_machine_get_pic,
                               x86_machine_set_pic,
include/hw/i386/pc.h +0 -0
index 8435733bd6..9cc3f5d338 100644
@@ -128,9 +128,6 @@ struct PCMachineClass {
 
     /* create kvmclock device even when KVM PV features are not exposed

*/

include/hw/i386/x86.h void x86_bios_rom_init(MachineState *ms, const char

Quoted 28 lines
include/hw/i386/pc.h +0 -3
     bool kvmclock_create_always;
-
-    /* skip passing an rng seed for legacy machines */
-    bool legacy_no_rng_seed;
 };
 
 #define TYPE_PC_MACHINE "generic-pc-machine"
include/hw/i386/x86.h +2 -0
index 62fa5774f8..d7a2eb6f1c 100644
@@ -70,6 +70,7 @@ struct X86MachineState {
     OnOffAuto acpi;
     OnOffAuto pit;
     OnOffAuto pic;
+    OnOffAuto linuxboot_randomness;
 
     char *oem_id;
     char *oem_table_id;
@@ -94,6 +95,7 @@ struct X86MachineState {
 #define X86_MACHINE_OEM_ID           "x-oem-id"
 #define X86_MACHINE_OEM_TABLE_ID     "x-oem-table-id"
 #define X86_MACHINE_BUS_LOCK_RATELIMIT  "bus-lock-ratelimit"
+#define X86_MACHINE_LINUXBOOT_RANDOMNESS "x-linuxboot-randomness"
 
 #define TYPE_X86_MACHINE   MACHINE_TYPE_NAME("x86")
 OBJECT_DECLARE_TYPE(X86MachineState, X86MachineClass, X86_MACHINE)
@@ -126,8 +128,7 @@ void x86_bios_rom_init(MachineState *ms, const char

*default_firmware,

Quoted 11 lines
include/hw/i386/x86.h +1 -3
 void x86_load_linux(X86MachineState *x86ms,
                     FWCfgState *fw_cfg,
                     int acpi_data_size,
-                    bool pvh_enabled,
-                    bool legacy_no_rng_seed);
+                    bool pvh_enabled);
 
 bool x86_machine_is_smm_enabled(const X86MachineState *x86ms);
 bool x86_machine_is_acpi_enabled(const X86MachineState *x86ms);
--

2.37.1

Reviewed-by
#3 lore raw
Quoted 17 lines · Paolo Bonzini

Il mer 10 ago 2022, 19:06 Michael S. Tsirkin <[email protected]> ha scritto:

hw/i386/x86.c static void x86_machine_initfn(Object *obj) · line 1411

Quoted 8 lines
hw/i386/x86.c +1 -0
@@ -1387,6 +1405,7 @@ static void x86_machine_initfn(Object *obj)
       x86ms->acpi = ON_OFF_AUTO_AUTO;
       x86ms->pit = ON_OFF_AUTO_AUTO;
       x86ms->pic = ON_OFF_AUTO_AUTO;
+    x86ms->linuxboot_randomness = ON_OFF_AUTO_OFF;
       x86ms->pci_irq_mask = ACPI_BUILD_PCI_IRQS;
       x86ms->oem_id = g_strndup(ACPI_BUILD_APPNAME6, 6);
       x86ms->oem_table_id = g_strndup(ACPI_BUILD_APPNAME8, 8);

This is a weird thing to do in that there's no way to make it auto now.

Quoted 5 lines

Sure, -M x-linuxboot-randomness=auto works. And making it already on/off/auto will limit future patches to the injection logic rather than the QOM boilerplate.

Paolo

Hmm. It's unusual that auto is not the same as "no value at all". But I guess there's no rule saying that can't be the case. OK then.

Quoted 70 lines
    And in that case, let's just make it a simple boolean property for now?

    > @@ -1426,6 +1445,12 @@ static void x86_machine_class_init(ObjectClass
    *oc, void *data)
    >      object_class_property_set_description(oc, X86_MACHINE_PIT,
    >          "Enable i8254 PIT");
    > 
    > +    object_class_property_add(oc, X86_MACHINE_LINUXBOOT_RANDOMNESS,
    "OnOffAuto",
    > +        x86_machine_get_linuxboot_randomness,
    x86_machine_set_linuxboot_randomness,
    > +        NULL, NULL);
    > +    object_class_property_set_description(oc,
    X86_MACHINE_LINUXBOOT_RANDOMNESS,
    > +        "Pass random number seed to -kernel Linux image");
    > +
    >      object_class_property_add(oc, X86_MACHINE_PIC, "OnOffAuto",
    >                                x86_machine_get_pic,
    >                                x86_machine_set_pic,
    > diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
    > index 8435733bd6..9cc3f5d338 100644
    > --- a/include/hw/i386/pc.h
    > +++ b/include/hw/i386/pc.h
    > @@ -128,9 +128,6 @@ struct PCMachineClass {
    > 
    >      /* create kvmclock device even when KVM PV features are not exposed
    */
    >      bool kvmclock_create_always;
    > -
    > -    /* skip passing an rng seed for legacy machines */
    > -    bool legacy_no_rng_seed;
    >  };
    > 
    >  #define TYPE_PC_MACHINE "generic-pc-machine"
    > diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h
    > index 62fa5774f8..d7a2eb6f1c 100644
    > --- a/include/hw/i386/x86.h
    > +++ b/include/hw/i386/x86.h
    > @@ -70,6 +70,7 @@ struct X86MachineState {
    >      OnOffAuto acpi;
    >      OnOffAuto pit;
    >      OnOffAuto pic;
    > +    OnOffAuto linuxboot_randomness;
    > 
    >      char *oem_id;
    >      char *oem_table_id;
    > @@ -94,6 +95,7 @@ struct X86MachineState {
    >  #define X86_MACHINE_OEM_ID           "x-oem-id"
    >  #define X86_MACHINE_OEM_TABLE_ID     "x-oem-table-id"
    >  #define X86_MACHINE_BUS_LOCK_RATELIMIT  "bus-lock-ratelimit"
    > +#define X86_MACHINE_LINUXBOOT_RANDOMNESS "x-linuxboot-randomness"
    > 
    >  #define TYPE_X86_MACHINE   MACHINE_TYPE_NAME("x86")
    >  OBJECT_DECLARE_TYPE(X86MachineState, X86MachineClass, X86_MACHINE)
    > @@ -126,8 +128,7 @@ void x86_bios_rom_init(MachineState *ms, const char
    *default_firmware,
    >  void x86_load_linux(X86MachineState *x86ms,
    >                      FWCfgState *fw_cfg,
    >                      int acpi_data_size,
    > -                    bool pvh_enabled,
    > -                    bool legacy_no_rng_seed);
    > +                    bool pvh_enabled);
    > 
    >  bool x86_machine_is_smm_enabled(const X86MachineState *x86ms);
    >  bool x86_machine_is_acpi_enabled(const X86MachineState *x86ms);
    > --
    > 2.37.1