Skip to contentSkip to conversation

fix assertion failures when using Xen

PATCH In review Paul Durrant 6 participants 18 messages Jun 24, 2020 – Jul 2, 2020

lore
Share & tools
lore
#0 lore raw

cover fix assertion failures when using Xen

From: Paul Durrant <[email protected]>

Paul Durrant (2):
xen: fix legacy 'xen-sysdev' and 'xen-backend' bus types
xen: cleanup unrealized flash devices

 hw/i386/pc_piix.c           | 9 ++++++---
 hw/i386/pc_sysfw.c          | 2 +-
 hw/xen/xen-legacy-backend.c | 4 ++--
 include/hw/i386/pc.h        | 1 +
 4 files changed, 10 insertions(+), 6 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 xen: fix legacy 'xen-sysdev' and 'xen-backend' bus types

From: Paul Durrant <[email protected]>

'xen-sysdev' plugs into the 'System' bus type, not 'xen-sysbus. That bus type is what 'xen-backend' plugs into.
'xen-sysdev' is drived form 'sys-bus-device' so the bus type need not be overridden. 'xen-backend' is derived from 'device', which plugs into the generic 'bus' type, so its bus type should be overridden to 'xen-sysbus'.

Without this patch, the following assertion will fail:

qemu-system-i386: hw/core/qdev.c:102: qdev_set_parent_bus: Assertion `dc->bus_type && object_dynamic_cast(OBJECT(bus), dc->bus_type)' failed.

Fixes 81cb05732efb ("qdev: Assert devices are plugged into a bus that can take them")

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

---
 hw/xen/xen-legacy-backend.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/xen/xen-legacy-backend.c +2 -2
index 2335ee2e65..c5c75c0064 100644
@@ -789,11 +789,12 @@ static void xendev_class_init(ObjectClass *klass, void *data)
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
     /* xen-backend devices can be plugged/unplugged dynamically */
     dc->user_creatable = true;
+    dc->bus_type = TYPE_XENSYSBUS;
 }
 
 static const TypeInfo xendev_type_info = {
     .name          = TYPE_XENBACKEND,
-    .parent        = TYPE_XENSYSDEV,
+    .parent        = TYPE_DEVICE,
     .class_init    = xendev_class_init,
     .instance_size = sizeof(struct XenLegacyDevice),
 };
@@ -824,7 +825,6 @@ static void xen_sysdev_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     device_class_set_props(dc, xen_sysdev_properties);
-    dc->bus_type = TYPE_XENSYSBUS;
 }
 
 static const TypeInfo xensysdev_info = {
Signature · 1 line
2.20.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] xen: fix legacy 'xen-sysdev' and 'xen-backend' bus types

Quoted 44 lines · Paul Durrant

From: Paul Durrant <[email protected]>

'xen-sysdev' plugs into the 'System' bus type, not 'xen-sysbus. That bus type is what 'xen-backend' plugs into.
'xen-sysdev' is drived form 'sys-bus-device' so the bus type need not be overridden. 'xen-backend' is derived from 'device', which plugs into the generic 'bus' type, so its bus type should be overridden to 'xen-sysbus'.

Without this patch, the following assertion will fail:

qemu-system-i386: hw/core/qdev.c:102: qdev_set_parent_bus: Assertion `dc->bus_type && object_dynamic_cast(OBJECT(bus), dc->bus_type)' failed.

Fixes 81cb05732efb ("qdev: Assert devices are plugged into a bus that can take them")

---
Cc: Stefano Stabellini <[email protected]>
Cc: Anthony Perard <[email protected]>

---
 hw/xen/xen-legacy-backend.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/xen/xen-legacy-backend.c +2 -1
index 2335ee2e65..c5c75c0064 100644
@@ -789,11 +789,12 @@ static void xendev_class_init(ObjectClass *klass, void *data)
     set_bit(DEVICE_CATEGORY_MISC, dc->categories);
     /* xen-backend devices can be plugged/unplugged dynamically */
     dc->user_creatable = true;
+    dc->bus_type = TYPE_XENSYSBUS;
 }
 
 static const TypeInfo xendev_type_info = {
     .name          = TYPE_XENBACKEND,
-    .parent        = TYPE_XENSYSDEV,
+    .parent        = TYPE_DEVICE,
     .class_init    = xendev_class_init,
     .instance_size = sizeof(struct XenLegacyDevice),
 };

hw/xen/xen-legacy-backend.c static void xen_sysdev_class_init(ObjectClass *klass, void *data) · line 830

Quoted 7 lines
hw/xen/xen-legacy-backend.c +0 -1
@@ -824,7 +825,6 @@ static void xen_sysdev_class_init(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     device_class_set_props(dc, xen_sysdev_properties);
-    dc->bus_type = TYPE_XENSYSBUS;
 }
 
 static const TypeInfo xensysdev_info = {
#3 lore raw

PATCH 2/2 xen: cleanup unrealized flash devices

In reply to Paul Durrant

From: Paul Durrant <[email protected]>

The generic pc_machine_initfn() calls pc_system_flash_create() which creates 'system.flash0' and 'system.flash1' devices. These devices are then realized by pc_system_flash_map() which is called from pc_system_firmware_init() which itself is called via pc_memory_init(). The latter however is not called when xen_enable() is true and hence the following assertion fails:

qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
Assertion `dev->realized' failed

These flash devices are unneeded when using Xen so this patch avoids the assertion by simply removing them using pc_system_flash_cleanup_unused().

Fixes ebc29e1beab0 ("pc: Support firmware configuration with -blockdev")

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>

---
 hw/i386/pc_piix.c    | 9 ++++++---
 hw/i386/pc_sysfw.c   | 2 +-
 include/hw/i386/pc.h | 1 +
 3 files changed, 8 insertions(+), 4 deletions(-)
hw/i386/pc_piix.c +6 -3
index 1497d0e4ae..977d40afb8 100644
@@ -186,9 +186,12 @@ static void pc_init1(MachineState *machine,
     if (!xen_enabled()) {
         pc_memory_init(pcms, system_memory,
                        rom_memory, &ram_memory);
-    } else if (machine->kernel_filename != NULL) {
-        /* For xen HVM direct kernel boot, load linux here */
-        xen_load_linux(pcms);
+    } else {
+        pc_system_flash_cleanup_unused(pcms);
+        if (machine->kernel_filename != NULL) {
+            /* For xen HVM direct kernel boot, load linux here */
+            xen_load_linux(pcms);
+        }
     }
 
     gsi_state = pc_gsi_create(&x86ms->gsi, pcmc->pci_enabled);
hw/i386/pc_sysfw.c +1 -1
index ec2a3b3e7e..0ff47a4b59 100644
@@ -108,7 +108,7 @@ void pc_system_flash_create(PCMachineState *pcms)
     }
 }
 
-static void pc_system_flash_cleanup_unused(PCMachineState *pcms)
+void pc_system_flash_cleanup_unused(PCMachineState *pcms)
 {
     char *prop_name;
     int i;
include/hw/i386/pc.h +1 -0
index e6135c34d6..497f2b7ab7 100644
@@ -187,6 +187,7 @@ int cmos_get_fd_drive_type(FloppyDriveType fd0);
 
 /* pc_sysfw.c */
 void pc_system_flash_create(PCMachineState *pcms);
+void pc_system_flash_cleanup_unused(PCMachineState *pcms);
 void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory);
 
 /* acpi-build.c */
Signature · 1 line
2.20.1
Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 11 lines · Paul Durrant

From: Paul Durrant <[email protected]>

The generic pc_machine_initfn() calls pc_system_flash_create() which creates 'system.flash0' and 'system.flash1' devices. These devices are then realized by pc_system_flash_map() which is called from pc_system_firmware_init() which itself is called via pc_memory_init(). The latter however is not called when xen_enable() is true and hence the following assertion fails:

qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
Assertion `dev->realized' failed

Quoted 7 lines

These flash devices are unneeded when using Xen so this patch avoids the assertion by simply removing them using pc_system_flash_cleanup_unused().

Fixes ebc29e1beab0 ("pc: Support firmware configuration with -blockdev")

I think I would add:

Fixes dfe8c79c4468 ("qdev: Assert onboard devices all get realized properly")

as this is the first commit where the unrealized flash devices are an issue.

Signature · 1 line
Anthony PERARD
#5 lore raw

RE: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 29 lines

-----Original Message-----
From: Anthony PERARD <[email protected]>
Sent: 30 June 2020 16:09
To: Paul Durrant <[email protected]>
Cc: [email protected]; [email protected]; Eduardo Habkost <[email protected]>; Michael S. Tsirkin <[email protected]>; Paul Durrant <[email protected]>; Jason Andryuk <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 11 lines · Paul Durrant

From: Paul Durrant <[email protected]>

The generic pc_machine_initfn() calls pc_system_flash_create() which creates 'system.flash0' and 'system.flash1' devices. These devices are then realized by pc_system_flash_map() which is called from pc_system_firmware_init() which itself is called via pc_memory_init(). The latter however is not called when xen_enable() is true and hence the following assertion fails:

qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
Assertion `dev->realized' failed

Quoted 7 lines

These flash devices are unneeded when using Xen so this patch avoids the assertion by simply removing them using pc_system_flash_cleanup_unused().

Fixes ebc29e1beab0 ("pc: Support firmware configuration with -blockdev")
Quoted 8 lines

I think I would add:

Fixes dfe8c79c4468 ("qdev: Assert onboard devices all get realized properly")

as this is the first commit where the unrealized flash devices are an issue.

OK.

Paul

Quoted 3 lines

--
Anthony PERARD

#6 lore raw

Re: [PATCH 2/2] xen: cleanup unrealized flash devices

In reply to Anthony PERARD
Quoted 20 lines · Anthony PERARD
Quoted 11 lines · Paul Durrant

From: Paul Durrant <[email protected]>

The generic pc_machine_initfn() calls pc_system_flash_create() which creates 'system.flash0' and 'system.flash1' devices. These devices are then realized by pc_system_flash_map() which is called from pc_system_firmware_init() which itself is called via pc_memory_init(). The latter however is not called when xen_enable() is true and hence the following assertion fails:

qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
Assertion `dev->realized' failed

Quoted 7 lines

These flash devices are unneeded when using Xen so this patch avoids the assertion by simply removing them using pc_system_flash_cleanup_unused().

Fixes ebc29e1beab0 ("pc: Support firmware configuration with -blockdev")
Quoted 8 lines

I think I would add:

Fixes dfe8c79c4468 ("qdev: Assert onboard devices all get realized properly")

as this is the first commit where the unrealized flash devices are an issue.

They were an issue before, but commit dfe8c79c4468 turned the minor issue into a crash bug. No objections.

#7 lore raw

Re: [PATCH 2/2] xen: cleanup unrealized flash devices

In reply to Paul Durrant
Quoted 35 lines · Paul Durrant

From: Paul Durrant <[email protected]>

The generic pc_machine_initfn() calls pc_system_flash_create() which creates 'system.flash0' and 'system.flash1' devices. These devices are then realized by pc_system_flash_map() which is called from pc_system_firmware_init() which itself is called via pc_memory_init(). The latter however is not called when xen_enable() is true and hence the following assertion fails:

qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
Assertion `dev->realized' failed

These flash devices are unneeded when using Xen so this patch avoids the assertion by simply removing them using pc_system_flash_cleanup_unused().

Fixes ebc29e1beab0 ("pc: Support firmware configuration with -blockdev")

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>

---
 hw/i386/pc_piix.c    | 9 ++++++---
 hw/i386/pc_sysfw.c   | 2 +-
 include/hw/i386/pc.h | 1 +
 3 files changed, 8 insertions(+), 4 deletions(-)
hw/i386/pc_piix.c +0 -0
index 1497d0e4ae..977d40afb8 100644

hw/i386/pc_piix.c static void pc_init1(MachineState *machine, · line 190

Quoted 8 lines
hw/i386/pc_piix.c +2 -3
@@ -186,9 +186,12 @@ static void pc_init1(MachineState *machine,
     if (!xen_enabled()) {
         pc_memory_init(pcms, system_memory,
                        rom_memory, &ram_memory);
-    } else if (machine->kernel_filename != NULL) {
-        /* For xen HVM direct kernel boot, load linux here */
-        xen_load_linux(pcms);
+    } else {
+        pc_system_flash_cleanup_unused(pcms);

TIL pc_system_flash_cleanup_unused().

What about restricting at the source?

-- >8 --

hw/i386/pc.c +17 -15
@@ -1004,24 +1004,26 @@ void pc_memory_init(PCMachineState *pcms,
                                     &machine->device_memory->mr);
     }
 
-    /* Initialize PC system firmware */
-    pc_system_firmware_init(pcms, rom_memory);
-
-    option_rom_mr = g_malloc(sizeof(*option_rom_mr));
-    memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
-                           &error_fatal);
-    if (pcmc->pci_enabled) {
-        memory_region_set_readonly(option_rom_mr, true);
-    }
-    memory_region_add_subregion_overlap(rom_memory,
-                                        PC_ROM_MIN_VGA,
-                                        option_rom_mr,
-                                        1);
-
     fw_cfg = fw_cfg_arch_create(machine,
                                 x86ms->boot_cpus, x86ms->apic_id_limit);
 
-    rom_set_fw(fw_cfg);
+    /* Initialize PC system firmware */
+    if (!xen_enabled()) {
+        pc_system_firmware_init(pcms, rom_memory);
+
+        option_rom_mr = g_malloc(sizeof(*option_rom_mr));
+        memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
+                               &error_fatal);
+        if (pcmc->pci_enabled) {
+            memory_region_set_readonly(option_rom_mr, true);
+        }
+        memory_region_add_subregion_overlap(rom_memory,
+                                            PC_ROM_MIN_VGA,
+                                            option_rom_mr,
+                                            1);
+
+        rom_set_fw(fw_cfg);
+    }
 
     if (pcmc->has_reserved_memory && machine->device_memory->base) {
         uint64_t *val = g_malloc(sizeof(*val));

---

Quoted 33 lines
hw/i386/pc_piix.c +4 -0
+        if (machine->kernel_filename != NULL) {
+            /* For xen HVM direct kernel boot, load linux here */
+            xen_load_linux(pcms);
+        }
     }
 
     gsi_state = pc_gsi_create(&x86ms->gsi, pcmc->pci_enabled);
hw/i386/pc_sysfw.c +1 -1
index ec2a3b3e7e..0ff47a4b59 100644
@@ -108,7 +108,7 @@ void pc_system_flash_create(PCMachineState *pcms)
     }
 }
 
-static void pc_system_flash_cleanup_unused(PCMachineState *pcms)
+void pc_system_flash_cleanup_unused(PCMachineState *pcms)
 {
     char *prop_name;
     int i;
include/hw/i386/pc.h +1 -0
index e6135c34d6..497f2b7ab7 100644
@@ -187,6 +187,7 @@ int cmos_get_fd_drive_type(FloppyDriveType fd0);
 
 /* pc_sysfw.c */
 void pc_system_flash_create(PCMachineState *pcms);
+void pc_system_flash_cleanup_unused(PCMachineState *pcms);
 void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory);
 
 /* acpi-build.c */
#8 lore raw

RE: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 56 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 16:26
To: Paul Durrant <[email protected]>; [email protected]; [email protected]
Cc: Eduardo Habkost <[email protected]>; Michael S. Tsirkin <[email protected]>; Paul Durrant <[email protected]>; Jason Andryuk <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 35 lines · Paul Durrant

From: Paul Durrant <[email protected]>

The generic pc_machine_initfn() calls pc_system_flash_create() which creates 'system.flash0' and 'system.flash1' devices. These devices are then realized by pc_system_flash_map() which is called from pc_system_firmware_init() which itself is called via pc_memory_init(). The latter however is not called when xen_enable() is true and hence the following assertion fails:

qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
Assertion `dev->realized' failed

These flash devices are unneeded when using Xen so this patch avoids the assertion by simply removing them using pc_system_flash_cleanup_unused().

Fixes ebc29e1beab0 ("pc: Support firmware configuration with -blockdev")

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>

---
 hw/i386/pc_piix.c    | 9 ++++++---
 hw/i386/pc_sysfw.c   | 2 +-
 include/hw/i386/pc.h | 1 +
 3 files changed, 8 insertions(+), 4 deletions(-)
hw/i386/pc_piix.c +0 -0
index 1497d0e4ae..977d40afb8 100644

hw/i386/pc_piix.c static void pc_init1(MachineState *machine, · line 190

Quoted 8 lines
hw/i386/pc_piix.c +2 -3
@@ -186,9 +186,12 @@ static void pc_init1(MachineState *machine,
     if (!xen_enabled()) {
         pc_memory_init(pcms, system_memory,
                        rom_memory, &ram_memory);
-    } else if (machine->kernel_filename != NULL) {
-        /* For xen HVM direct kernel boot, load linux here */
-        xen_load_linux(pcms);
+    } else {
+        pc_system_flash_cleanup_unused(pcms);

TIL pc_system_flash_cleanup_unused().

Quoted 2 lines

What about restricting at the source?

And leave the devices in place? They are not relevant for Xen, so why not clean up?

Paul

Quoted 80 lines

-- >8 --

hw/i386/pc.c +17 -16
@@ -1004,24 +1004,26 @@ void pc_memory_init(PCMachineState *pcms,
                                     &machine->device_memory->mr);
     }
 
-    /* Initialize PC system firmware */
-    pc_system_firmware_init(pcms, rom_memory);
-
-    option_rom_mr = g_malloc(sizeof(*option_rom_mr));
-    memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
-                           &error_fatal);
-    if (pcmc->pci_enabled) {
-        memory_region_set_readonly(option_rom_mr, true);
-    }
-    memory_region_add_subregion_overlap(rom_memory,
-                                        PC_ROM_MIN_VGA,
-                                        option_rom_mr,
-                                        1);
-
     fw_cfg = fw_cfg_arch_create(machine,
                                 x86ms->boot_cpus, x86ms->apic_id_limit);
 
-    rom_set_fw(fw_cfg);
+    /* Initialize PC system firmware */
+    if (!xen_enabled()) {
+        pc_system_firmware_init(pcms, rom_memory);
+
+        option_rom_mr = g_malloc(sizeof(*option_rom_mr));
+        memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
+                               &error_fatal);
+        if (pcmc->pci_enabled) {
+            memory_region_set_readonly(option_rom_mr, true);
+        }
+        memory_region_add_subregion_overlap(rom_memory,
+                                            PC_ROM_MIN_VGA,
+                                            option_rom_mr,
+                                            1);
+
+        rom_set_fw(fw_cfg);
+    }
 
     if (pcmc->has_reserved_memory && machine->device_memory->base) {
         uint64_t *val = g_malloc(sizeof(*val));
---
Quoted 34 lines
hw/i386/pc_piix.c +4 -0
+        if (machine->kernel_filename != NULL) {
+            /* For xen HVM direct kernel boot, load linux here */
+            xen_load_linux(pcms);
+        }
     }
 
     gsi_state = pc_gsi_create(&x86ms->gsi, pcmc->pci_enabled);
hw/i386/pc_sysfw.c +1 -1
index ec2a3b3e7e..0ff47a4b59 100644
@@ -108,7 +108,7 @@ void pc_system_flash_create(PCMachineState *pcms)
     }
 }
 
-static void pc_system_flash_cleanup_unused(PCMachineState *pcms)
+void pc_system_flash_cleanup_unused(PCMachineState *pcms)
 {
     char *prop_name;
     int i;
include/hw/i386/pc.h +1 -0
index e6135c34d6..497f2b7ab7 100644
@@ -187,6 +187,7 @@ int cmos_get_fd_drive_type(FloppyDriveType fd0);
 
 /* pc_sysfw.c */
 void pc_system_flash_create(PCMachineState *pcms);
+void pc_system_flash_cleanup_unused(PCMachineState *pcms);
 void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory);
 
 /* acpi-build.c */
#9 lore raw

Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 56 lines · Paul Durrant
Quoted 56 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 16:26
To: Paul Durrant <[email protected]>; [email protected]; [email protected]
Cc: Eduardo Habkost <[email protected]>; Michael S. Tsirkin <[email protected]>; Paul Durrant <[email protected]>; Jason Andryuk <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 35 lines · Paul Durrant

From: Paul Durrant <[email protected]>

The generic pc_machine_initfn() calls pc_system_flash_create() which creates 'system.flash0' and 'system.flash1' devices. These devices are then realized by pc_system_flash_map() which is called from pc_system_firmware_init() which itself is called via pc_memory_init(). The latter however is not called when xen_enable() is true and hence the following assertion fails:

qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
Assertion `dev->realized' failed

These flash devices are unneeded when using Xen so this patch avoids the assertion by simply removing them using pc_system_flash_cleanup_unused().

Fixes ebc29e1beab0 ("pc: Support firmware configuration with -blockdev")

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>

---
 hw/i386/pc_piix.c    | 9 ++++++---
 hw/i386/pc_sysfw.c   | 2 +-
 include/hw/i386/pc.h | 1 +
 3 files changed, 8 insertions(+), 4 deletions(-)
hw/i386/pc_piix.c +0 -0
index 1497d0e4ae..977d40afb8 100644

hw/i386/pc_piix.c static void pc_init1(MachineState *machine, · line 190

Quoted 8 lines
hw/i386/pc_piix.c +2 -3
@@ -186,9 +186,12 @@ static void pc_init1(MachineState *machine,
     if (!xen_enabled()) {
         pc_memory_init(pcms, system_memory,
                        rom_memory, &ram_memory);
-    } else if (machine->kernel_filename != NULL) {
-        /* For xen HVM direct kernel boot, load linux here */
-        xen_load_linux(pcms);
+    } else {
+        pc_system_flash_cleanup_unused(pcms);

TIL pc_system_flash_cleanup_unused().

Quoted 4 lines
Quoted 2 lines

What about restricting at the source?

And leave the devices in place? They are not relevant for Xen, so why not clean up?

No, I meant to not create them in the first place, instead of create+destroy.

Anyway what you did works, so I don't have any problem.

Quoted 85 lines

Paul

Quoted 80 lines

-- >8 --

hw/i386/pc.c +17 -16
@@ -1004,24 +1004,26 @@ void pc_memory_init(PCMachineState *pcms,
                                     &machine->device_memory->mr);
     }
 
-    /* Initialize PC system firmware */
-    pc_system_firmware_init(pcms, rom_memory);
-
-    option_rom_mr = g_malloc(sizeof(*option_rom_mr));
-    memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
-                           &error_fatal);
-    if (pcmc->pci_enabled) {
-        memory_region_set_readonly(option_rom_mr, true);
-    }
-    memory_region_add_subregion_overlap(rom_memory,
-                                        PC_ROM_MIN_VGA,
-                                        option_rom_mr,
-                                        1);
-
     fw_cfg = fw_cfg_arch_create(machine,
                                 x86ms->boot_cpus, x86ms->apic_id_limit);
 
-    rom_set_fw(fw_cfg);
+    /* Initialize PC system firmware */
+    if (!xen_enabled()) {
+        pc_system_firmware_init(pcms, rom_memory);
+
+        option_rom_mr = g_malloc(sizeof(*option_rom_mr));
+        memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
+                               &error_fatal);
+        if (pcmc->pci_enabled) {
+            memory_region_set_readonly(option_rom_mr, true);
+        }
+        memory_region_add_subregion_overlap(rom_memory,
+                                            PC_ROM_MIN_VGA,
+                                            option_rom_mr,
+                                            1);
+
+        rom_set_fw(fw_cfg);
+    }
 
     if (pcmc->has_reserved_memory && machine->device_memory->base) {
         uint64_t *val = g_malloc(sizeof(*val));
---
Quoted 34 lines
hw/i386/pc_piix.c +4 -0
+        if (machine->kernel_filename != NULL) {
+            /* For xen HVM direct kernel boot, load linux here */
+            xen_load_linux(pcms);
+        }
     }
 
     gsi_state = pc_gsi_create(&x86ms->gsi, pcmc->pci_enabled);
hw/i386/pc_sysfw.c +1 -1
index ec2a3b3e7e..0ff47a4b59 100644
@@ -108,7 +108,7 @@ void pc_system_flash_create(PCMachineState *pcms)
     }
 }
 
-static void pc_system_flash_cleanup_unused(PCMachineState *pcms)
+void pc_system_flash_cleanup_unused(PCMachineState *pcms)
 {
     char *prop_name;
     int i;
include/hw/i386/pc.h +1 -0
index e6135c34d6..497f2b7ab7 100644
@@ -187,6 +187,7 @@ int cmos_get_fd_drive_type(FloppyDriveType fd0);
 
 /* pc_sysfw.c */
 void pc_system_flash_create(PCMachineState *pcms);
+void pc_system_flash_cleanup_unused(PCMachineState *pcms);
 void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory);
 
 /* acpi-build.c */
#10 lore raw

Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 57 lines · Philippe Mathieu-Daudé
Quoted 56 lines · Paul Durrant
Quoted 56 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 16:26
To: Paul Durrant <[email protected]>; [email protected]; [email protected]
Cc: Eduardo Habkost <[email protected]>; Michael S. Tsirkin <[email protected]>; Paul Durrant <[email protected]>; Jason Andryuk <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 35 lines · Paul Durrant

From: Paul Durrant <[email protected]>

The generic pc_machine_initfn() calls pc_system_flash_create() which creates 'system.flash0' and 'system.flash1' devices. These devices are then realized by pc_system_flash_map() which is called from pc_system_firmware_init() which itself is called via pc_memory_init(). The latter however is not called when xen_enable() is true and hence the following assertion fails:

qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
Assertion `dev->realized' failed

These flash devices are unneeded when using Xen so this patch avoids the assertion by simply removing them using pc_system_flash_cleanup_unused().

Fixes ebc29e1beab0 ("pc: Support firmware configuration with -blockdev")

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>

---
 hw/i386/pc_piix.c    | 9 ++++++---
 hw/i386/pc_sysfw.c   | 2 +-
 include/hw/i386/pc.h | 1 +
 3 files changed, 8 insertions(+), 4 deletions(-)
hw/i386/pc_piix.c +0 -0
index 1497d0e4ae..977d40afb8 100644

hw/i386/pc_piix.c static void pc_init1(MachineState *machine, · line 190

Quoted 8 lines
hw/i386/pc_piix.c +2 -3
@@ -186,9 +186,12 @@ static void pc_init1(MachineState *machine,
     if (!xen_enabled()) {
         pc_memory_init(pcms, system_memory,
                        rom_memory, &ram_memory);
-    } else if (machine->kernel_filename != NULL) {
-        /* For xen HVM direct kernel boot, load linux here */
-        xen_load_linux(pcms);
+    } else {
+        pc_system_flash_cleanup_unused(pcms);

TIL pc_system_flash_cleanup_unused().

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

What about restricting at the source?

And leave the devices in place? They are not relevant for Xen, so why not clean up?

No, I meant to not create them in the first place, instead of create+destroy.

Better. Opinion, not demand :)

[...]

#11 lore raw

RE: [PATCH 2/2] xen: cleanup unrealized flash devices

In reply to Philippe Mathieu-Daudé
Quoted 69 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 18:27
To: [email protected]; [email protected]; [email protected]
Cc: 'Eduardo Habkost' <[email protected]>; 'Michael S. Tsirkin' <[email protected]>; 'Paul Durrant' <[email protected]>; 'Jason Andryuk' <[email protected]>; 'Paolo Bonzini' <[email protected]>; 'Richard Henderson' <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 59 lines · Paul Durrant
Quoted 58 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 16:26
To: Paul Durrant <[email protected]>; [email protected]; [email protected]
Cc: Eduardo Habkost <[email protected]>; Michael S. Tsirkin <[email protected]>; Paul Durrant <[email protected]>; Jason Andryuk <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 35 lines · Paul Durrant

From: Paul Durrant <[email protected]>

The generic pc_machine_initfn() calls pc_system_flash_create() which creates 'system.flash0' and 'system.flash1' devices. These devices are then realized by pc_system_flash_map() which is called from pc_system_firmware_init() which itself is called via pc_memory_init(). The latter however is not called when xen_enable() is true and hence the following assertion fails:

qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
Assertion `dev->realized' failed

These flash devices are unneeded when using Xen so this patch avoids the assertion by simply removing them using pc_system_flash_cleanup_unused().

Fixes ebc29e1beab0 ("pc: Support firmware configuration with -blockdev")

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>

---
 hw/i386/pc_piix.c    | 9 ++++++---
 hw/i386/pc_sysfw.c   | 2 +-
 include/hw/i386/pc.h | 1 +
 3 files changed, 8 insertions(+), 4 deletions(-)
hw/i386/pc_piix.c +0 -0
index 1497d0e4ae..977d40afb8 100644

hw/i386/pc_piix.c static void pc_init1(MachineState *machine, · line 190

Quoted 8 lines
hw/i386/pc_piix.c +2 -3
@@ -186,9 +186,12 @@ static void pc_init1(MachineState *machine,
     if (!xen_enabled()) {
         pc_memory_init(pcms, system_memory,
                        rom_memory, &ram_memory);
-    } else if (machine->kernel_filename != NULL) {
-        /* For xen HVM direct kernel boot, load linux here */
-        xen_load_linux(pcms);
+    } else {
+        pc_system_flash_cleanup_unused(pcms);

TIL pc_system_flash_cleanup_unused().

What about restricting at the source?

Quoted 6 lines
Quoted 1 line

And leave the devices in place? They are not relevant for Xen, so why not clean up?

No, I meant to not create them in the first place, instead of create+destroy.

Anyway what you did works, so I don't have any problem.

IIUC Jason originally tried restricting creation but encountered a problem because xen_enabled() would always return false at that point, because machine creation occurs before accelerators are initialized.

Paul

Quoted 88 lines
Quoted 85 lines

Paul

Quoted 80 lines

-- >8 --

hw/i386/pc.c +17 -16
@@ -1004,24 +1004,26 @@ void pc_memory_init(PCMachineState *pcms,
                                     &machine->device_memory->mr);
     }
 
-    /* Initialize PC system firmware */
-    pc_system_firmware_init(pcms, rom_memory);
-
-    option_rom_mr = g_malloc(sizeof(*option_rom_mr));
-    memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
-                           &error_fatal);
-    if (pcmc->pci_enabled) {
-        memory_region_set_readonly(option_rom_mr, true);
-    }
-    memory_region_add_subregion_overlap(rom_memory,
-                                        PC_ROM_MIN_VGA,
-                                        option_rom_mr,
-                                        1);
-
     fw_cfg = fw_cfg_arch_create(machine,
                                 x86ms->boot_cpus, x86ms->apic_id_limit);
 
-    rom_set_fw(fw_cfg);
+    /* Initialize PC system firmware */
+    if (!xen_enabled()) {
+        pc_system_firmware_init(pcms, rom_memory);
+
+        option_rom_mr = g_malloc(sizeof(*option_rom_mr));
+        memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
+                               &error_fatal);
+        if (pcmc->pci_enabled) {
+            memory_region_set_readonly(option_rom_mr, true);
+        }
+        memory_region_add_subregion_overlap(rom_memory,
+                                            PC_ROM_MIN_VGA,
+                                            option_rom_mr,
+                                            1);
+
+        rom_set_fw(fw_cfg);
+    }
 
     if (pcmc->has_reserved_memory && machine->device_memory->base) {
         uint64_t *val = g_malloc(sizeof(*val));
---
Quoted 34 lines
hw/i386/pc_piix.c +4 -0
+        if (machine->kernel_filename != NULL) {
+            /* For xen HVM direct kernel boot, load linux here */
+            xen_load_linux(pcms);
+        }
     }
 
     gsi_state = pc_gsi_create(&x86ms->gsi, pcmc->pci_enabled);
hw/i386/pc_sysfw.c +1 -1
index ec2a3b3e7e..0ff47a4b59 100644
@@ -108,7 +108,7 @@ void pc_system_flash_create(PCMachineState *pcms)
     }
 }
 
-static void pc_system_flash_cleanup_unused(PCMachineState *pcms)
+void pc_system_flash_cleanup_unused(PCMachineState *pcms)
 {
     char *prop_name;
     int i;
include/hw/i386/pc.h +1 -0
index e6135c34d6..497f2b7ab7 100644
@@ -187,6 +187,7 @@ int cmos_get_fd_drive_type(FloppyDriveType fd0);
 
 /* pc_sysfw.c */
 void pc_system_flash_create(PCMachineState *pcms);
+void pc_system_flash_cleanup_unused(PCMachineState *pcms);
 void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory);
 
 /* acpi-build.c */
#12 lore raw

Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 70 lines · Paul Durrant
Quoted 70 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 18:27
To: [email protected]; [email protected]; [email protected]
Cc: 'Eduardo Habkost' <[email protected]>; 'Michael S. Tsirkin' <[email protected]>; 'Paul Durrant' <[email protected]>; 'Jason Andryuk' <[email protected]>; 'Paolo Bonzini' <[email protected]>; 'Richard Henderson' <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 59 lines · Paul Durrant
Quoted 58 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 16:26
To: Paul Durrant <[email protected]>; [email protected]; [email protected]
Cc: Eduardo Habkost <[email protected]>; Michael S. Tsirkin <[email protected]>; Paul Durrant <[email protected]>; Jason Andryuk <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 35 lines · Paul Durrant

From: Paul Durrant <[email protected]>

The generic pc_machine_initfn() calls pc_system_flash_create() which creates 'system.flash0' and 'system.flash1' devices. These devices are then realized by pc_system_flash_map() which is called from pc_system_firmware_init() which itself is called via pc_memory_init(). The latter however is not called when xen_enable() is true and hence the following assertion fails:

qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
Assertion `dev->realized' failed

These flash devices are unneeded when using Xen so this patch avoids the assertion by simply removing them using pc_system_flash_cleanup_unused().

Fixes ebc29e1beab0 ("pc: Support firmware configuration with -blockdev")

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>

---
 hw/i386/pc_piix.c    | 9 ++++++---
 hw/i386/pc_sysfw.c   | 2 +-
 include/hw/i386/pc.h | 1 +
 3 files changed, 8 insertions(+), 4 deletions(-)
hw/i386/pc_piix.c +0 -0
index 1497d0e4ae..977d40afb8 100644

hw/i386/pc_piix.c static void pc_init1(MachineState *machine, · line 190

Quoted 8 lines
hw/i386/pc_piix.c +2 -3
@@ -186,9 +186,12 @@ static void pc_init1(MachineState *machine,
     if (!xen_enabled()) {
         pc_memory_init(pcms, system_memory,
                        rom_memory, &ram_memory);
-    } else if (machine->kernel_filename != NULL) {
-        /* For xen HVM direct kernel boot, load linux here */
-        xen_load_linux(pcms);
+    } else {
+        pc_system_flash_cleanup_unused(pcms);

TIL pc_system_flash_cleanup_unused().

What about restricting at the source?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

And leave the devices in place? They are not relevant for Xen, so why not clean up?

No, I meant to not create them in the first place, instead of create+destroy.

Anyway what you did works, so I don't have any problem.

IIUC Jason originally tried restricting creation but encountered a problem because xen_enabled() would always return false at that point, because machine creation occurs before accelerators are initialized.

Correct. Quoting my previous email:
"""
Removing the call to pc_system_flash_create() from pc_machine_initfn() lets QEMU startup and run a Xen HVM again. xen_enabled() doesn't work there since accelerators have not been initialized yes, I guess? """

If you want to remove the creation in the first place, then I have two questions. Why does pc_system_flash_create()/pc_pflash_create() get called so early creating the pflash devices? Why aren't they just created as needed in pc_system_flash_map()?

Regards,
Jason

Quoted 92 lines

Paul

Quoted 88 lines
Quoted 85 lines

Paul

Quoted 80 lines

-- >8 --

hw/i386/pc.c +17 -16
@@ -1004,24 +1004,26 @@ void pc_memory_init(PCMachineState *pcms,
                                     &machine->device_memory->mr);
     }
 
-    /* Initialize PC system firmware */
-    pc_system_firmware_init(pcms, rom_memory);
-
-    option_rom_mr = g_malloc(sizeof(*option_rom_mr));
-    memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
-                           &error_fatal);
-    if (pcmc->pci_enabled) {
-        memory_region_set_readonly(option_rom_mr, true);
-    }
-    memory_region_add_subregion_overlap(rom_memory,
-                                        PC_ROM_MIN_VGA,
-                                        option_rom_mr,
-                                        1);
-
     fw_cfg = fw_cfg_arch_create(machine,
                                 x86ms->boot_cpus, x86ms->apic_id_limit);
 
-    rom_set_fw(fw_cfg);
+    /* Initialize PC system firmware */
+    if (!xen_enabled()) {
+        pc_system_firmware_init(pcms, rom_memory);
+
+        option_rom_mr = g_malloc(sizeof(*option_rom_mr));
+        memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
+                               &error_fatal);
+        if (pcmc->pci_enabled) {
+            memory_region_set_readonly(option_rom_mr, true);
+        }
+        memory_region_add_subregion_overlap(rom_memory,
+                                            PC_ROM_MIN_VGA,
+                                            option_rom_mr,
+                                            1);
+
+        rom_set_fw(fw_cfg);
+    }
 
     if (pcmc->has_reserved_memory && machine->device_memory->base) {
         uint64_t *val = g_malloc(sizeof(*val));
---
Quoted 34 lines
hw/i386/pc_piix.c +4 -0
+        if (machine->kernel_filename != NULL) {
+            /* For xen HVM direct kernel boot, load linux here */
+            xen_load_linux(pcms);
+        }
     }
 
     gsi_state = pc_gsi_create(&x86ms->gsi, pcmc->pci_enabled);
hw/i386/pc_sysfw.c +1 -1
index ec2a3b3e7e..0ff47a4b59 100644
@@ -108,7 +108,7 @@ void pc_system_flash_create(PCMachineState *pcms)
     }
 }
 
-static void pc_system_flash_cleanup_unused(PCMachineState *pcms)
+void pc_system_flash_cleanup_unused(PCMachineState *pcms)
 {
     char *prop_name;
     int i;
include/hw/i386/pc.h +1 -0
index e6135c34d6..497f2b7ab7 100644
@@ -187,6 +187,7 @@ int cmos_get_fd_drive_type(FloppyDriveType fd0);
 
 /* pc_sysfw.c */
 void pc_system_flash_create(PCMachineState *pcms);
+void pc_system_flash_cleanup_unused(PCMachineState *pcms);
 void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory);
 
 /* acpi-build.c */
#13 lore raw

Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 78 lines · Jason Andryuk
Quoted 77 lines · Paul Durrant
Quoted 76 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 18:27
To: [email protected]; [email protected]; [email protected]
Cc: 'Eduardo Habkost' <[email protected]>; 'Michael S. Tsirkin' <[email protected]>; 'Paul Durrant' <[email protected]>; 'Jason Andryuk' <[email protected]>; 'Paolo Bonzini' <[email protected]>; 'Richard Henderson' <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 56 lines · Paul Durrant
Quoted 56 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 16:26
To: Paul Durrant <[email protected]>; [email protected]; [email protected]
Cc: Eduardo Habkost <[email protected]>; Michael S. Tsirkin <[email protected]>; Paul Durrant <[email protected]>; Jason Andryuk <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 35 lines · Paul Durrant

From: Paul Durrant <[email protected]>

The generic pc_machine_initfn() calls pc_system_flash_create() which creates 'system.flash0' and 'system.flash1' devices. These devices are then realized by pc_system_flash_map() which is called from pc_system_firmware_init() which itself is called via pc_memory_init(). The latter however is not called when xen_enable() is true and hence the following assertion fails:

qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
Assertion `dev->realized' failed

These flash devices are unneeded when using Xen so this patch avoids the assertion by simply removing them using pc_system_flash_cleanup_unused().

Fixes ebc29e1beab0 ("pc: Support firmware configuration with -blockdev")

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>

---
 hw/i386/pc_piix.c    | 9 ++++++---
 hw/i386/pc_sysfw.c   | 2 +-
 include/hw/i386/pc.h | 1 +
 3 files changed, 8 insertions(+), 4 deletions(-)
hw/i386/pc_piix.c +0 -0
index 1497d0e4ae..977d40afb8 100644

hw/i386/pc_piix.c static void pc_init1(MachineState *machine, · line 190

Quoted 8 lines
hw/i386/pc_piix.c +2 -3
@@ -186,9 +186,12 @@ static void pc_init1(MachineState *machine,
     if (!xen_enabled()) {
         pc_memory_init(pcms, system_memory,
                        rom_memory, &ram_memory);
-    } else if (machine->kernel_filename != NULL) {
-        /* For xen HVM direct kernel boot, load linux here */
-        xen_load_linux(pcms);
+    } else {
+        pc_system_flash_cleanup_unused(pcms);

TIL pc_system_flash_cleanup_unused().

Quoted 4 lines
Quoted 2 lines

What about restricting at the source?

And leave the devices in place? They are not relevant for Xen, so why not clean up?

No, I meant to not create them in the first place, instead of create+destroy.

Anyway what you did works, so I don't have any problem.

Quoted 7 lines
Quoted 1 line

IIUC Jason originally tried restricting creation but encountered a problem because xen_enabled() would always return false at that point, because machine creation occurs before accelerators are initialized.

Correct. Quoting my previous email:
"""
Removing the call to pc_system_flash_create() from pc_machine_initfn() lets QEMU startup and run a Xen HVM again. xen_enabled() doesn't work there since accelerators have not been initialized yes, I guess?

Ah, I missed that. You pointed at the bug here :)

I think pc_system_flash_create() shouldn't be called in init() but realize().

Quoted 103 lines

"""

If you want to remove the creation in the first place, then I have two questions. Why does pc_system_flash_create()/pc_pflash_create() get called so early creating the pflash devices? Why aren't they just created as needed in pc_system_flash_map()?

Regards,
Jason

Quoted 92 lines

Paul

Quoted 88 lines
Quoted 85 lines

Paul

Quoted 80 lines

-- >8 --

hw/i386/pc.c +17 -16
@@ -1004,24 +1004,26 @@ void pc_memory_init(PCMachineState *pcms,
                                     &machine->device_memory->mr);
     }
 
-    /* Initialize PC system firmware */
-    pc_system_firmware_init(pcms, rom_memory);
-
-    option_rom_mr = g_malloc(sizeof(*option_rom_mr));
-    memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
-                           &error_fatal);
-    if (pcmc->pci_enabled) {
-        memory_region_set_readonly(option_rom_mr, true);
-    }
-    memory_region_add_subregion_overlap(rom_memory,
-                                        PC_ROM_MIN_VGA,
-                                        option_rom_mr,
-                                        1);
-
     fw_cfg = fw_cfg_arch_create(machine,
                                 x86ms->boot_cpus, x86ms->apic_id_limit);
 
-    rom_set_fw(fw_cfg);
+    /* Initialize PC system firmware */
+    if (!xen_enabled()) {
+        pc_system_firmware_init(pcms, rom_memory);
+
+        option_rom_mr = g_malloc(sizeof(*option_rom_mr));
+        memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
+                               &error_fatal);
+        if (pcmc->pci_enabled) {
+            memory_region_set_readonly(option_rom_mr, true);
+        }
+        memory_region_add_subregion_overlap(rom_memory,
+                                            PC_ROM_MIN_VGA,
+                                            option_rom_mr,
+                                            1);
+
+        rom_set_fw(fw_cfg);
+    }
 
     if (pcmc->has_reserved_memory && machine->device_memory->base) {
         uint64_t *val = g_malloc(sizeof(*val));
---
Quoted 34 lines
hw/i386/pc_piix.c +4 -0
+        if (machine->kernel_filename != NULL) {
+            /* For xen HVM direct kernel boot, load linux here */
+            xen_load_linux(pcms);
+        }
     }
 
     gsi_state = pc_gsi_create(&x86ms->gsi, pcmc->pci_enabled);
hw/i386/pc_sysfw.c +1 -1
index ec2a3b3e7e..0ff47a4b59 100644
@@ -108,7 +108,7 @@ void pc_system_flash_create(PCMachineState *pcms)
     }
 }
 
-static void pc_system_flash_cleanup_unused(PCMachineState *pcms)
+void pc_system_flash_cleanup_unused(PCMachineState *pcms)
 {
     char *prop_name;
     int i;
include/hw/i386/pc.h +1 -0
index e6135c34d6..497f2b7ab7 100644
@@ -187,6 +187,7 @@ int cmos_get_fd_drive_type(FloppyDriveType fd0);
 
 /* pc_sysfw.c */
 void pc_system_flash_create(PCMachineState *pcms);
+void pc_system_flash_cleanup_unused(PCMachineState *pcms);
 void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory);
 
 /* acpi-build.c */
#14 lore raw

Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 87 lines · Philippe Mathieu-Daudé
Quoted 78 lines · Jason Andryuk
Quoted 77 lines · Paul Durrant
Quoted 76 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 18:27
To: [email protected]; [email protected]; [email protected]
Cc: 'Eduardo Habkost' <[email protected]>; 'Michael S. Tsirkin' <[email protected]>; 'Paul Durrant' <[email protected]>; 'Jason Andryuk' <[email protected]>; 'Paolo Bonzini' <[email protected]>; 'Richard Henderson' <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 56 lines · Paul Durrant
Quoted 56 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 16:26
To: Paul Durrant <[email protected]>; [email protected]; [email protected]
Cc: Eduardo Habkost <[email protected]>; Michael S. Tsirkin <[email protected]>; Paul Durrant <[email protected]>; Jason Andryuk <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 35 lines · Paul Durrant

From: Paul Durrant <[email protected]>

The generic pc_machine_initfn() calls pc_system_flash_create() which creates 'system.flash0' and 'system.flash1' devices. These devices are then realized by pc_system_flash_map() which is called from pc_system_firmware_init() which itself is called via pc_memory_init(). The latter however is not called when xen_enable() is true and hence the following assertion fails:

qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
Assertion `dev->realized' failed

These flash devices are unneeded when using Xen so this patch avoids the assertion by simply removing them using pc_system_flash_cleanup_unused().

Fixes ebc29e1beab0 ("pc: Support firmware configuration with -blockdev")

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>

---
 hw/i386/pc_piix.c    | 9 ++++++---
 hw/i386/pc_sysfw.c   | 2 +-
 include/hw/i386/pc.h | 1 +
 3 files changed, 8 insertions(+), 4 deletions(-)
hw/i386/pc_piix.c +0 -0
index 1497d0e4ae..977d40afb8 100644

hw/i386/pc_piix.c static void pc_init1(MachineState *machine, · line 190

Quoted 8 lines
hw/i386/pc_piix.c +2 -3
@@ -186,9 +186,12 @@ static void pc_init1(MachineState *machine,
     if (!xen_enabled()) {
         pc_memory_init(pcms, system_memory,
                        rom_memory, &ram_memory);
-    } else if (machine->kernel_filename != NULL) {
-        /* For xen HVM direct kernel boot, load linux here */
-        xen_load_linux(pcms);
+    } else {
+        pc_system_flash_cleanup_unused(pcms);

TIL pc_system_flash_cleanup_unused().

Quoted 4 lines
Quoted 2 lines

What about restricting at the source?

And leave the devices in place? They are not relevant for Xen, so why not clean up?

No, I meant to not create them in the first place, instead of create+destroy.

Anyway what you did works, so I don't have any problem.

Quoted 7 lines
Quoted 1 line

IIUC Jason originally tried restricting creation but encountered a problem because xen_enabled() would always return false at that point, because machine creation occurs before accelerators are initialized.

Correct. Quoting my previous email:
"""
Removing the call to pc_system_flash_create() from pc_machine_initfn() lets QEMU startup and run a Xen HVM again. xen_enabled() doesn't work there since accelerators have not been initialized yes, I guess?

Quoted 4 lines

Ah, I missed that. You pointed at the bug here :)

I think pc_system_flash_create() shouldn't be called in init() but realize().

Hmm this is a MachineClass, not qdev, so no realize().

In softmmu/vl.c we have:

4152 configure_accelerators(argv[0]);
....
4327 if (!xen_enabled()) { // so xen_enable() is working
4328 /* On 32-bit hosts, QEMU is limited by virtual address space */
4329 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
4330 error_report("at most 2047 MB RAM can be simulated");
4331 exit(1);
4332 }
4333 }
....
4348 machine_run_board_init(current_machine);

which calls in hw/core/machine.c:

1089 void machine_run_board_init(MachineState *machine) 1090 {
1091 MachineClass *machine_class = MACHINE_GET_CLASS(machine);
....
1138 machine_class->init(machine);
1139 }

         -> pc_machine_class_init()

This should come after:

         -> pc_machine_initfn()

            -> pc_system_flash_create(pcms)
Quoted 105 lines
Quoted 104 lines

"""

If you want to remove the creation in the first place, then I have two questions. Why does pc_system_flash_create()/pc_pflash_create() get called so early creating the pflash devices? Why aren't they just created as needed in pc_system_flash_map()?

Regards,
Jason

Quoted 92 lines

Paul

Quoted 88 lines
Quoted 85 lines

Paul

Quoted 80 lines

-- >8 --

hw/i386/pc.c +17 -16
@@ -1004,24 +1004,26 @@ void pc_memory_init(PCMachineState *pcms,
                                     &machine->device_memory->mr);
     }
 
-    /* Initialize PC system firmware */
-    pc_system_firmware_init(pcms, rom_memory);
-
-    option_rom_mr = g_malloc(sizeof(*option_rom_mr));
-    memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
-                           &error_fatal);
-    if (pcmc->pci_enabled) {
-        memory_region_set_readonly(option_rom_mr, true);
-    }
-    memory_region_add_subregion_overlap(rom_memory,
-                                        PC_ROM_MIN_VGA,
-                                        option_rom_mr,
-                                        1);
-
     fw_cfg = fw_cfg_arch_create(machine,
                                 x86ms->boot_cpus, x86ms->apic_id_limit);
 
-    rom_set_fw(fw_cfg);
+    /* Initialize PC system firmware */
+    if (!xen_enabled()) {
+        pc_system_firmware_init(pcms, rom_memory);
+
+        option_rom_mr = g_malloc(sizeof(*option_rom_mr));
+        memory_region_init_ram(option_rom_mr, NULL, "pc.rom", PC_ROM_SIZE,
+                               &error_fatal);
+        if (pcmc->pci_enabled) {
+            memory_region_set_readonly(option_rom_mr, true);
+        }
+        memory_region_add_subregion_overlap(rom_memory,
+                                            PC_ROM_MIN_VGA,
+                                            option_rom_mr,
+                                            1);
+
+        rom_set_fw(fw_cfg);
+    }
 
     if (pcmc->has_reserved_memory && machine->device_memory->base) {
         uint64_t *val = g_malloc(sizeof(*val));
---
Quoted 34 lines
hw/i386/pc_piix.c +4 -0
+        if (machine->kernel_filename != NULL) {
+            /* For xen HVM direct kernel boot, load linux here */
+            xen_load_linux(pcms);
+        }
     }
 
     gsi_state = pc_gsi_create(&x86ms->gsi, pcmc->pci_enabled);
hw/i386/pc_sysfw.c +1 -1
index ec2a3b3e7e..0ff47a4b59 100644
@@ -108,7 +108,7 @@ void pc_system_flash_create(PCMachineState *pcms)
     }
 }
 
-static void pc_system_flash_cleanup_unused(PCMachineState *pcms)
+void pc_system_flash_cleanup_unused(PCMachineState *pcms)
 {
     char *prop_name;
     int i;
include/hw/i386/pc.h +1 -0
index e6135c34d6..497f2b7ab7 100644
@@ -187,6 +187,7 @@ int cmos_get_fd_drive_type(FloppyDriveType fd0);
 
 /* pc_sysfw.c */
 void pc_system_flash_create(PCMachineState *pcms);
+void pc_system_flash_cleanup_unused(PCMachineState *pcms);
 void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory);
 
 /* acpi-build.c */
#15 lore raw

Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 119 lines · Philippe Mathieu-Daudé
Quoted 87 lines · Philippe Mathieu-Daudé
Quoted 78 lines · Jason Andryuk
Quoted 77 lines · Paul Durrant
Quoted 76 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 18:27
To: [email protected]; [email protected]; [email protected]
Cc: 'Eduardo Habkost' <[email protected]>; 'Michael S. Tsirkin' <[email protected]>; 'Paul Durrant' <[email protected]>; 'Jason Andryuk' <[email protected]>; 'Paolo Bonzini' <[email protected]>; 'Richard Henderson' <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 56 lines · Paul Durrant
Quoted 56 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 16:26
To: Paul Durrant <[email protected]>; [email protected]; [email protected]
Cc: Eduardo Habkost <[email protected]>; Michael S. Tsirkin <[email protected]>; Paul Durrant <[email protected]>; Jason Andryuk <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 35 lines · Paul Durrant

From: Paul Durrant <[email protected]>

The generic pc_machine_initfn() calls pc_system_flash_create() which creates 'system.flash0' and 'system.flash1' devices. These devices are then realized by pc_system_flash_map() which is called from pc_system_firmware_init() which itself is called via pc_memory_init(). The latter however is not called when xen_enable() is true and hence the following assertion fails:

qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
Assertion `dev->realized' failed

These flash devices are unneeded when using Xen so this patch avoids the assertion by simply removing them using pc_system_flash_cleanup_unused().

Fixes ebc29e1beab0 ("pc: Support firmware configuration with -blockdev")

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>

---
 hw/i386/pc_piix.c    | 9 ++++++---
 hw/i386/pc_sysfw.c   | 2 +-
 include/hw/i386/pc.h | 1 +
 3 files changed, 8 insertions(+), 4 deletions(-)
hw/i386/pc_piix.c +0 -0
index 1497d0e4ae..977d40afb8 100644

hw/i386/pc_piix.c static void pc_init1(MachineState *machine, · line 190

Quoted 8 lines
hw/i386/pc_piix.c +2 -3
@@ -186,9 +186,12 @@ static void pc_init1(MachineState *machine,
     if (!xen_enabled()) {
         pc_memory_init(pcms, system_memory,
                        rom_memory, &ram_memory);
-    } else if (machine->kernel_filename != NULL) {
-        /* For xen HVM direct kernel boot, load linux here */
-        xen_load_linux(pcms);
+    } else {
+        pc_system_flash_cleanup_unused(pcms);

TIL pc_system_flash_cleanup_unused().

Quoted 4 lines
Quoted 2 lines

What about restricting at the source?

And leave the devices in place? They are not relevant for Xen, so why not clean up?

No, I meant to not create them in the first place, instead of create+destroy.

Anyway what you did works, so I don't have any problem.

Quoted 7 lines
Quoted 1 line

IIUC Jason originally tried restricting creation but encountered a problem because xen_enabled() would always return false at that point, because machine creation occurs before accelerators are initialized.

Correct. Quoting my previous email:
"""
Removing the call to pc_system_flash_create() from pc_machine_initfn() lets QEMU startup and run a Xen HVM again. xen_enabled() doesn't work there since accelerators have not been initialized yes, I guess?

Quoted 4 lines

Ah, I missed that. You pointed at the bug here :)

I think pc_system_flash_create() shouldn't be called in init() but realize().

Hmm this is a MachineClass, not qdev, so no realize().

In softmmu/vl.c we have:

4152 configure_accelerators(argv[0]);
....
4327 if (!xen_enabled()) { // so xen_enable() is working
4328 /* On 32-bit hosts, QEMU is limited by virtual address space */
4329 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
4330 error_report("at most 2047 MB RAM can be simulated");
4331 exit(1);
4332 }
4333 }
....
4348 machine_run_board_init(current_machine);

which calls in hw/core/machine.c:

1089 void machine_run_board_init(MachineState *machine) 1090 {
1091 MachineClass *machine_class = MACHINE_GET_CLASS(machine);
....
1138 machine_class->init(machine);
1139 }

Quoted 7 lines
         -> pc_machine_class_init()

This should come after:

         -> pc_machine_initfn()

            -> pc_system_flash_create(pcms)

Sorry, I'm not following the flow you want.

The xen_enabled() call in vl.c may always fail. Or at least in most common Xen usage. Xen HVMs are started with machine xenfv and don't specify an accelerator. You need to process the xenfv default machine opts to process "accel=xen". Actually, I don't know how the accelerator initialization works, but xen_accel_class_init() needs to be called to set ac->allowed = &xen_allowed. xen_allowed is the return value of xen_enabled() and the accelerator initialization must toggle it.

Regards,
Jason

#16 lore raw

Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 121 lines · Jason Andryuk
Quoted 120 lines · Philippe Mathieu-Daudé
Quoted 87 lines · Philippe Mathieu-Daudé
Quoted 78 lines · Jason Andryuk
Quoted 77 lines · Paul Durrant
Quoted 76 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 18:27
To: [email protected]; [email protected]; [email protected]
Cc: 'Eduardo Habkost' <[email protected]>; 'Michael S. Tsirkin' <[email protected]>; 'Paul Durrant' <[email protected]>; 'Jason Andryuk' <[email protected]>; 'Paolo Bonzini' <[email protected]>; 'Richard Henderson' <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 56 lines · Paul Durrant
Quoted 56 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 16:26
To: Paul Durrant <[email protected]>; [email protected]; [email protected]
Cc: Eduardo Habkost <[email protected]>; Michael S. Tsirkin <[email protected]>; Paul Durrant <[email protected]>; Jason Andryuk <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 35 lines · Paul Durrant

From: Paul Durrant <[email protected]>

The generic pc_machine_initfn() calls pc_system_flash_create() which creates 'system.flash0' and 'system.flash1' devices. These devices are then realized by pc_system_flash_map() which is called from pc_system_firmware_init() which itself is called via pc_memory_init(). The latter however is not called when xen_enable() is true and hence the following assertion fails:

qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
Assertion `dev->realized' failed

These flash devices are unneeded when using Xen so this patch avoids the assertion by simply removing them using pc_system_flash_cleanup_unused().

Fixes ebc29e1beab0 ("pc: Support firmware configuration with -blockdev")

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>

---
 hw/i386/pc_piix.c    | 9 ++++++---
 hw/i386/pc_sysfw.c   | 2 +-
 include/hw/i386/pc.h | 1 +
 3 files changed, 8 insertions(+), 4 deletions(-)
hw/i386/pc_piix.c +0 -0
index 1497d0e4ae..977d40afb8 100644

hw/i386/pc_piix.c static void pc_init1(MachineState *machine, · line 190

Quoted 8 lines
hw/i386/pc_piix.c +2 -3
@@ -186,9 +186,12 @@ static void pc_init1(MachineState *machine,
     if (!xen_enabled()) {
         pc_memory_init(pcms, system_memory,
                        rom_memory, &ram_memory);
-    } else if (machine->kernel_filename != NULL) {
-        /* For xen HVM direct kernel boot, load linux here */
-        xen_load_linux(pcms);
+    } else {
+        pc_system_flash_cleanup_unused(pcms);

TIL pc_system_flash_cleanup_unused().

Quoted 4 lines
Quoted 2 lines

What about restricting at the source?

And leave the devices in place? They are not relevant for Xen, so why not clean up?

No, I meant to not create them in the first place, instead of create+destroy.

Anyway what you did works, so I don't have any problem.

Quoted 7 lines
Quoted 1 line

IIUC Jason originally tried restricting creation but encountered a problem because xen_enabled() would always return false at that point, because machine creation occurs before accelerators are initialized.

Correct. Quoting my previous email:
"""
Removing the call to pc_system_flash_create() from pc_machine_initfn() lets QEMU startup and run a Xen HVM again. xen_enabled() doesn't work there since accelerators have not been initialized yes, I guess?

Quoted 4 lines

Ah, I missed that. You pointed at the bug here :)

I think pc_system_flash_create() shouldn't be called in init() but realize().

Hmm this is a MachineClass, not qdev, so no realize().

In softmmu/vl.c we have:

4152 configure_accelerators(argv[0]);
....
4327 if (!xen_enabled()) { // so xen_enable() is working
4328 /* On 32-bit hosts, QEMU is limited by virtual address space */
4329 if (ram_size > (2047 << 20) && HOST_LONG_BITS == 32) {
4330 error_report("at most 2047 MB RAM can be simulated");
4331 exit(1);
4332 }
4333 }
....
4348 machine_run_board_init(current_machine);

which calls in hw/core/machine.c:

1089 void machine_run_board_init(MachineState *machine) 1090 {
1091 MachineClass *machine_class = MACHINE_GET_CLASS(machine);
....
1138 machine_class->init(machine);
1139 }

         -> pc_machine_class_init()
Quoted 7 lines
Quoted 5 lines

This should come after:

         -> pc_machine_initfn()

            -> pc_system_flash_create(pcms)

Sorry, I'm not following the flow you want.

Well, I was simply trying to understand what was wrong, and what we should fix so you don't have to create flash devices then destroy them when using Xen.

I already said Paul patch is OK and gave my R-b to it.

Quoted 9 lines

The xen_enabled() call in vl.c may always fail. Or at least in most common Xen usage. Xen HVMs are started with machine xenfv and don't specify an accelerator. You need to process the xenfv default machine opts to process "accel=xen". Actually, I don't know how the accelerator initialization works, but xen_accel_class_init() needs to be called to set ac->allowed = &xen_allowed. xen_allowed is the return value of xen_enabled() and the accelerator initialization must toggle it.

Since you are happy how this current works, I'm also fine with it, I won't investigate further.

Regards,

Phil.

#17 lore raw

Re: [PATCH 2/2] xen: cleanup unrealized flash devices

In reply to Jason Andryuk
Quoted 87 lines · Jason Andryuk
Quoted 70 lines · Paul Durrant
Quoted 70 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 18:27
To: [email protected]; [email protected]; [email protected]
Cc: 'Eduardo Habkost' <[email protected]>; 'Michael S. Tsirkin' <[email protected]>; 'Paul Durrant' <[email protected]>; 'Jason Andryuk' <[email protected]>; 'Paolo Bonzini' <[email protected]>; 'Richard Henderson' <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 59 lines · Paul Durrant
Quoted 58 lines

-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: 30 June 2020 16:26
To: Paul Durrant <[email protected]>; [email protected]; [email protected]
Cc: Eduardo Habkost <[email protected]>; Michael S. Tsirkin <[email protected]>; Paul Durrant <[email protected]>; Jason Andryuk <[email protected]>; Paolo Bonzini <[email protected]>; Richard Henderson <[email protected]>
Subject: Re: [PATCH 2/2] xen: cleanup unrealized flash devices

Quoted 35 lines · Paul Durrant

From: Paul Durrant <[email protected]>

The generic pc_machine_initfn() calls pc_system_flash_create() which creates 'system.flash0' and 'system.flash1' devices. These devices are then realized by pc_system_flash_map() which is called from pc_system_firmware_init() which itself is called via pc_memory_init(). The latter however is not called when xen_enable() is true and hence the following assertion fails:

qemu-system-i386: hw/core/qdev.c:439: qdev_assert_realized_properly:
Assertion `dev->realized' failed

These flash devices are unneeded when using Xen so this patch avoids the assertion by simply removing them using pc_system_flash_cleanup_unused().

Fixes ebc29e1beab0 ("pc: Support firmware configuration with -blockdev")

---
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: "Michael S. Tsirkin" <[email protected]>
Cc: Marcel Apfelbaum <[email protected]>

---
 hw/i386/pc_piix.c    | 9 ++++++---
 hw/i386/pc_sysfw.c   | 2 +-
 include/hw/i386/pc.h | 1 +
 3 files changed, 8 insertions(+), 4 deletions(-)
hw/i386/pc_piix.c +0 -0
index 1497d0e4ae..977d40afb8 100644

hw/i386/pc_piix.c static void pc_init1(MachineState *machine, · line 190

Quoted 8 lines
hw/i386/pc_piix.c +2 -3
@@ -186,9 +186,12 @@ static void pc_init1(MachineState *machine,
     if (!xen_enabled()) {
         pc_memory_init(pcms, system_memory,
                        rom_memory, &ram_memory);
-    } else if (machine->kernel_filename != NULL) {
-        /* For xen HVM direct kernel boot, load linux here */
-        xen_load_linux(pcms);
+    } else {
+        pc_system_flash_cleanup_unused(pcms);

TIL pc_system_flash_cleanup_unused().

What about restricting at the source?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

And leave the devices in place? They are not relevant for Xen, so why not clean up?

No, I meant to not create them in the first place, instead of create+destroy.

Anyway what you did works, so I don't have any problem.

IIUC Jason originally tried restricting creation but encountered a problem because xen_enabled() would always return false at that point, because machine creation occurs before accelerators are initialized.

Correct. Quoting my previous email:
"""
Removing the call to pc_system_flash_create() from pc_machine_initfn() lets QEMU startup and run a Xen HVM again. xen_enabled() doesn't work there since accelerators have not been initialized yes, I guess? """

Quoted 4 lines

If you want to remove the creation in the first place, then I have two questions. Why does pc_system_flash_create()/pc_pflash_create() get called so early creating the pflash devices? Why aren't they just created as needed in pc_system_flash_map()?

commit ebc29e1beab02646702c8cb9a1d29b68f72ad503

pc: Support firmware configuration with -blockdev

[...]

Properties need to be created in .instance_init() methods. For PC machines, that's pc_machine_initfn(). To make alias properties work, we need to create the onboard flash devices there, too. [...]

For context, read the entire commit message. If you have questions then, don't hesitate to ask them here.