Skip to contentSkip to conversation

Remove hardcoded xen-platform device initialization (v3)

PATCH In review Paul Durrant 2 participants 11 messages Jun 18, 2013

lore
Share & tools
lore
#0 lore raw

cover Remove hardcoded xen-platform device initialization (v3)

Because of concerns over backwards compatibility and a suggestion that xenfv should be retired in favour of using the pc machine type I have re- worked my original patch into 2 patches:

[PATCH 1/2] Allow use of pc machine type (accel=xen) for Xen HVM [PATCH 2/2] Move hardcoded initialization of xen-platform device.

Application of both these patches allows alternative pc machine types to be used with the accel=xen option, but preserves the hardcoded creation of the xen-platform device only for machine type xenfv.

v3:
- Add test for xen_enabled() that went missing in v2

#1 lore raw

PATCH 1/2 Allow use of pc machine type (accel=xen) for Xen HVM domains.

Xen HVM domains normally spawn QEMU with a dedicated xenfv machine type. The initialization code for this machine type can easily be pulled into the generic pc initialization code and guarded with a test for whether the xen accelerator options is specified, which is more consistent with the way other accelerators are used.

---
 hw/i386/pc_piix.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/i386/pc_piix.c +5 -3
index d618570..7bbb59a 100644
@@ -1,3 +1,4 @@
+
 /*
  * QEMU PC System Emulator
  *
@@ -91,6 +92,10 @@ static void pc_init1(MemoryRegion *system_memory,
     DeviceState *icc_bridge;
     FWCfgState *fw_cfg = NULL;
 
+    if (xen_enabled() && xen_hvm_init() != 0) {
+        hw_error("xen hardware virtual machine initialisation failed");
+    }
+
     icc_bridge = qdev_create(NULL, TYPE_ICC_BRIDGE);
     object_property_add_child(qdev_get_machine(), "icc-bridge",
                               OBJECT(icc_bridge), NULL);
@@ -320,9 +325,6 @@ static void pc_init_isa(QEMUMachineInitArgs *args)
 #ifdef CONFIG_XEN
 static void pc_xen_hvm_init(QEMUMachineInitArgs *args)
 {
-    if (xen_hvm_init() != 0) {
-        hw_error("xen hardware virtual machine initialisation failed");
-    }
     pc_init_pci(args);
 }
 #endif
Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 1/2 Allow use of pc machine type (accel=xen) for Xen HVM domains.

In reply to Paul Durrant

Xen HVM domains normally spawn QEMU with a dedicated xenfv machine type. The initialization code for this machine type can easily be pulled into the generic pc initialization code and guarded with a test for whether the xen accelerator options is specified, which is more consistent with the way other accelerators are used.

---
 hw/i386/pc_piix.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/i386/pc_piix.c +5 -3
index d618570..7bbb59a 100644
@@ -1,3 +1,4 @@
+
 /*
  * QEMU PC System Emulator
  *
@@ -91,6 +92,10 @@ static void pc_init1(MemoryRegion *system_memory,
     DeviceState *icc_bridge;
     FWCfgState *fw_cfg = NULL;
 
+    if (xen_enabled() && xen_hvm_init() != 0) {
+        hw_error("xen hardware virtual machine initialisation failed");
+    }
+
     icc_bridge = qdev_create(NULL, TYPE_ICC_BRIDGE);
     object_property_add_child(qdev_get_machine(), "icc-bridge",
                               OBJECT(icc_bridge), NULL);
@@ -320,9 +325,6 @@ static void pc_init_isa(QEMUMachineInitArgs *args)
 #ifdef CONFIG_XEN
 static void pc_xen_hvm_init(QEMUMachineInitArgs *args)
 {
-    if (xen_hvm_init() != 0) {
-        hw_error("xen hardware virtual machine initialisation failed");
-    }
     pc_init_pci(args);
 }
 #endif
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] Allow use of pc machine type (accel=xen) for Xen HVM domains.

Am 18.06.2013 11:59, schrieb Paul Durrant:

Quoted 16 lines

Xen HVM domains normally spawn QEMU with a dedicated xenfv machine type. The initialization code for this machine type can easily be pulled into the generic pc initialization code and guarded with a test for whether the xen accelerator options is specified, which is more consistent with the way other accelerators are used.

---
 hw/i386/pc_piix.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/i386/pc_piix.c +0 -0
index d618570..7bbb59a 100644

hw/i386/pc_piix.c line 4

Quoted 4 lines
hw/i386/pc_piix.c +1 -0
@@ -1,3 +1,4 @@
+
 /*
  * QEMU PC System Emulator
  *

Unrelated whitespace change, please drop this hunk.

hw/i386/pc_piix.c static void pc_init1(MemoryRegion *system_memory, · line 96

Quoted 6 lines
hw/i386/pc_piix.c +2 -0
@@ -91,6 +92,10 @@ static void pc_init1(MemoryRegion *system_memory,
     DeviceState *icc_bridge;
     FWCfgState *fw_cfg = NULL;
 
+    if (xen_enabled() && xen_hvm_init() != 0) {
+        hw_error("xen hardware virtual machine initialisation failed");

I see this is just a code movement, but maybe consider replacing that with an fprintf()+exit(1)? Xen does not have any CPUs AFAIU and they wouldn't be initialized at that point anyway, so hw_error() is not much more than an fprintf()+abort().

Regards,
Andreas

Quoted 15 lines
hw/i386/pc_piix.c +2 -3
+    }
+
     icc_bridge = qdev_create(NULL, TYPE_ICC_BRIDGE);
     object_property_add_child(qdev_get_machine(), "icc-bridge",
                               OBJECT(icc_bridge), NULL);
@@ -320,9 +325,6 @@ static void pc_init_isa(QEMUMachineInitArgs *args)
 #ifdef CONFIG_XEN
 static void pc_xen_hvm_init(QEMUMachineInitArgs *args)
 {
-    if (xen_hvm_init() != 0) {
-        hw_error("xen hardware virtual machine initialisation failed");
-    }
     pc_init_pci(args);
 }
 #endif
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#4 lore raw

Re: [Qemu-devel] [PATCH 1/2] Allow use of pc machine type (accel=xen) for Xen HVM domains.

In reply to Paul Durrant

Am 18.06.2013 11:59, schrieb Paul Durrant:

Quoted 16 lines

Xen HVM domains normally spawn QEMU with a dedicated xenfv machine type. The initialization code for this machine type can easily be pulled into the generic pc initialization code and guarded with a test for whether the xen accelerator options is specified, which is more consistent with the way other accelerators are used.

---
 hw/i386/pc_piix.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
hw/i386/pc_piix.c +0 -0
index d618570..7bbb59a 100644

hw/i386/pc_piix.c line 4

Quoted 4 lines
hw/i386/pc_piix.c +1 -0
@@ -1,3 +1,4 @@
+
 /*
  * QEMU PC System Emulator
  *

Unrelated whitespace change, please drop this hunk.

hw/i386/pc_piix.c static void pc_init1(MemoryRegion *system_memory, · line 96

Quoted 6 lines
hw/i386/pc_piix.c +2 -0
@@ -91,6 +92,10 @@ static void pc_init1(MemoryRegion *system_memory,
     DeviceState *icc_bridge;
     FWCfgState *fw_cfg = NULL;
 
+    if (xen_enabled() && xen_hvm_init() != 0) {
+        hw_error("xen hardware virtual machine initialisation failed");

I see this is just a code movement, but maybe consider replacing that with an fprintf()+exit(1)? Xen does not have any CPUs AFAIU and they wouldn't be initialized at that point anyway, so hw_error() is not much more than an fprintf()+abort().

Regards,
Andreas

Quoted 15 lines
hw/i386/pc_piix.c +2 -3
+    }
+
     icc_bridge = qdev_create(NULL, TYPE_ICC_BRIDGE);
     object_property_add_child(qdev_get_machine(), "icc-bridge",
                               OBJECT(icc_bridge), NULL);
@@ -320,9 +325,6 @@ static void pc_init_isa(QEMUMachineInitArgs *args)
 #ifdef CONFIG_XEN
 static void pc_xen_hvm_init(QEMUMachineInitArgs *args)
 {
-    if (xen_hvm_init() != 0) {
-        hw_error("xen hardware virtual machine initialisation failed");
-    }
     pc_init_pci(args);
 }
 #endif
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#5 lore raw

Re: [Qemu-devel] [PATCH 1/2] Allow use of pc machine type (accel=xen) for Xen HVM domains.

Quoted 21 lines

-----Original Message-----
From: Andreas Färber [mailto:[email protected]]
Sent: 18 June 2013 11:29
To: Paul Durrant
Cc: [email protected]; [email protected]; Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH 1/2] Allow use of pc machine type (accel=xen) for Xen HVM domains.

Am 18.06.2013 11:59, schrieb Paul Durrant:

Quoted 1 line

Xen HVM domains normally spawn QEMU with a dedicated xenfv machine

type. The

Quoted 10 lines

initialization code for this machine type can easily be pulled into the generic pc initialization code and guarded with a test for whether the xen accelerator options is specified, which is more consistent with the way other accelerators are used.

---
 hw/i386/pc_piix.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
Quoted 12 lines

hw/i386/pc_piix.c line 4

Quoted 9 lines
hw/i386/pc_piix.c +1 -0
index d618570..7bbb59a 100644
@@ -1,3 +1,4 @@
+
 /*
  * QEMU PC System Emulator
  *

Unrelated whitespace change, please drop this hunk.

Ok.

Quoted 5 lines

hw/i386/pc_piix.c static void pc_init1(MemoryRegion

Quoted 1 line
hw/i386/pc_piix.c +0 -0
@@ -91,6 +92,10 @@ static void pc_init1(MemoryRegion

*system_memory,

Quoted 3 lines
hw/i386/pc_piix.c +0 -0
     DeviceState *icc_bridge;
     FWCfgState *fw_cfg = NULL;
 
Quoted 8 lines

hw/i386/pc_piix.c static void pc_init1(MemoryRegion *system_memory, · line 96

Quoted 2 lines
hw/i386/pc_piix.c +2 -0
+    if (xen_enabled() && xen_hvm_init() != 0) {
+        hw_error("xen hardware virtual machine initialisation failed");

I see this is just a code movement, but maybe consider replacing that with an fprintf()+exit(1)? Xen does not have any CPUs AFAIU and they wouldn't be initialized at that point anyway, so hw_error() is not much more than an fprintf()+abort().

If that's preferred I can do that, but it makes it less apparent that this patch is just code movement.

Paul

#6 lore raw

Re: [Qemu-devel] [PATCH 1/2] Allow use of pc machine type (accel=xen) for Xen HVM domains.

In reply to Andreas Färber
Quoted 21 lines

-----Original Message-----
From: Andreas Färber [mailto:[email protected]]
Sent: 18 June 2013 11:29
To: Paul Durrant
Cc: [email protected]; [email protected]; Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH 1/2] Allow use of pc machine type (accel=xen) for Xen HVM domains.

Am 18.06.2013 11:59, schrieb Paul Durrant:

Quoted 1 line

Xen HVM domains normally spawn QEMU with a dedicated xenfv machine

type. The

Quoted 10 lines

initialization code for this machine type can easily be pulled into the generic pc initialization code and guarded with a test for whether the xen accelerator options is specified, which is more consistent with the way other accelerators are used.

---
 hw/i386/pc_piix.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
Quoted 12 lines

hw/i386/pc_piix.c line 4

Quoted 9 lines
hw/i386/pc_piix.c +1 -0
index d618570..7bbb59a 100644
@@ -1,3 +1,4 @@
+
 /*
  * QEMU PC System Emulator
  *

Unrelated whitespace change, please drop this hunk.

Ok.

Quoted 5 lines

hw/i386/pc_piix.c static void pc_init1(MemoryRegion

Quoted 1 line
hw/i386/pc_piix.c +0 -0
@@ -91,6 +92,10 @@ static void pc_init1(MemoryRegion

*system_memory,

Quoted 3 lines
hw/i386/pc_piix.c +0 -0
     DeviceState *icc_bridge;
     FWCfgState *fw_cfg = NULL;
 
Quoted 8 lines

hw/i386/pc_piix.c static void pc_init1(MemoryRegion *system_memory, · line 96

Quoted 2 lines
hw/i386/pc_piix.c +2 -0
+    if (xen_enabled() && xen_hvm_init() != 0) {
+        hw_error("xen hardware virtual machine initialisation failed");

I see this is just a code movement, but maybe consider replacing that with an fprintf()+exit(1)? Xen does not have any CPUs AFAIU and they wouldn't be initialized at that point anyway, so hw_error() is not much more than an fprintf()+abort().

If that's preferred I can do that, but it makes it less apparent that this patch is just code movement.

Paul

#7 lore raw

PATCH 2/2 Move hardcoded initialization of xen-platform device.

In reply to Paul Durrant

Creation of the xen-platform device is currently hardcoded into machine type pc's initialization code, guarded by a test for the whether the xen accelerator is enabled. This patch moves the creation of xen-platform into the initialization code of the xenfv machine type. This maintains backwards compatibility for that machine type but allows more flexibility if another machine type is used with Xen HVM domains.

---
 hw/i386/pc_piix.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
hw/i386/pc_piix.c +6 -3
index 7bbb59a..8dd487e 100644
@@ -179,9 +179,6 @@ static void pc_init1(MemoryRegion *system_memory,
     pc_register_ferr_irq(gsi[13]);
 
     pc_vga_init(isa_bus, pci_enabled ? pci_bus : NULL);
-    if (xen_enabled()) {
-        pci_create_simple(pci_bus, -1, "xen-platform");
-    }
 
     /* init basic PC hardware */
     pc_basic_device_init(isa_bus, gsi, &rtc_state, &floppy, xen_enabled());
@@ -325,7 +322,13 @@ static void pc_init_isa(QEMUMachineInitArgs *args)
 #ifdef CONFIG_XEN
 static void pc_xen_hvm_init(QEMUMachineInitArgs *args)
 {
+    PCIBus *bus;
+
     pc_init_pci(args);
+
+    bus = pci_find_root_bus(0);
+    if (bus != NULL)
+        pci_create_simple(bus, -1, "xen-platform");
 }
 #endif
 
Signature · 1 line
1.7.10.4
#8 lore raw

PATCH 2/2 Move hardcoded initialization of xen-platform device.

In reply to Paul Durrant

Creation of the xen-platform device is currently hardcoded into machine type pc's initialization code, guarded by a test for the whether the xen accelerator is enabled. This patch moves the creation of xen-platform into the initialization code of the xenfv machine type. This maintains backwards compatibility for that machine type but allows more flexibility if another machine type is used with Xen HVM domains.

---
 hw/i386/pc_piix.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
hw/i386/pc_piix.c +6 -3
index 7bbb59a..8dd487e 100644
@@ -179,9 +179,6 @@ static void pc_init1(MemoryRegion *system_memory,
     pc_register_ferr_irq(gsi[13]);
 
     pc_vga_init(isa_bus, pci_enabled ? pci_bus : NULL);
-    if (xen_enabled()) {
-        pci_create_simple(pci_bus, -1, "xen-platform");
-    }
 
     /* init basic PC hardware */
     pc_basic_device_init(isa_bus, gsi, &rtc_state, &floppy, xen_enabled());
@@ -325,7 +322,13 @@ static void pc_init_isa(QEMUMachineInitArgs *args)
 #ifdef CONFIG_XEN
 static void pc_xen_hvm_init(QEMUMachineInitArgs *args)
 {
+    PCIBus *bus;
+
     pc_init_pci(args);
+
+    bus = pci_find_root_bus(0);
+    if (bus != NULL)
+        pci_create_simple(bus, -1, "xen-platform");
 }
 #endif
 
Signature · 1 line
1.7.10.4
#9 lore raw

Re: [Qemu-devel] [PATCH 2/2] Move hardcoded initialization of xen-platform device.

Am 18.06.2013 11:59, schrieb Paul Durrant:

Quoted 27 lines

Creation of the xen-platform device is currently hardcoded into machine type pc's initialization code, guarded by a test for the whether the xen accelerator is enabled. This patch moves the creation of xen-platform into the initialization code of the xenfv machine type. This maintains backwards compatibility for that machine type but allows more flexibility if another machine type is used with Xen HVM domains.

---
 hw/i386/pc_piix.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
hw/i386/pc_piix.c +0 -3
index 7bbb59a..8dd487e 100644
@@ -179,9 +179,6 @@ static void pc_init1(MemoryRegion *system_memory,
     pc_register_ferr_irq(gsi[13]);
 
     pc_vga_init(isa_bus, pci_enabled ? pci_bus : NULL);
-    if (xen_enabled()) {
-        pci_create_simple(pci_bus, -1, "xen-platform");
-    }
 
     /* init basic PC hardware */
     pc_basic_device_init(isa_bus, gsi, &rtc_state, &floppy, xen_enabled());

hw/i386/pc_piix.c static void pc_init_isa(QEMUMachineInitArgs *args) · line 331

Quoted 10 lines
hw/i386/pc_piix.c +6 -0
@@ -325,7 +322,13 @@ static void pc_init_isa(QEMUMachineInitArgs *args)
 #ifdef CONFIG_XEN
 static void pc_xen_hvm_init(QEMUMachineInitArgs *args)
 {
+    PCIBus *bus;
+
     pc_init_pci(args);
+
+    bus = pci_find_root_bus(0);
+    if (bus != NULL)
+        pci_create_simple(bus, -1, "xen-platform");

scripts/checkpatch.pl will complain about missing braces for if, but otherwise looks okay to me.

Andreas

Quoted 3 lines
hw/i386/pc_piix.c +0 -0
 }
 #endif
 
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#10 lore raw

Re: [Qemu-devel] [PATCH 2/2] Move hardcoded initialization of xen-platform device.

In reply to Paul Durrant

Am 18.06.2013 11:59, schrieb Paul Durrant:

Quoted 27 lines

Creation of the xen-platform device is currently hardcoded into machine type pc's initialization code, guarded by a test for the whether the xen accelerator is enabled. This patch moves the creation of xen-platform into the initialization code of the xenfv machine type. This maintains backwards compatibility for that machine type but allows more flexibility if another machine type is used with Xen HVM domains.

---
 hw/i386/pc_piix.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
hw/i386/pc_piix.c +0 -3
index 7bbb59a..8dd487e 100644
@@ -179,9 +179,6 @@ static void pc_init1(MemoryRegion *system_memory,
     pc_register_ferr_irq(gsi[13]);
 
     pc_vga_init(isa_bus, pci_enabled ? pci_bus : NULL);
-    if (xen_enabled()) {
-        pci_create_simple(pci_bus, -1, "xen-platform");
-    }
 
     /* init basic PC hardware */
     pc_basic_device_init(isa_bus, gsi, &rtc_state, &floppy, xen_enabled());

hw/i386/pc_piix.c static void pc_init_isa(QEMUMachineInitArgs *args) · line 331

Quoted 10 lines
hw/i386/pc_piix.c +6 -0
@@ -325,7 +322,13 @@ static void pc_init_isa(QEMUMachineInitArgs *args)
 #ifdef CONFIG_XEN
 static void pc_xen_hvm_init(QEMUMachineInitArgs *args)
 {
+    PCIBus *bus;
+
     pc_init_pci(args);
+
+    bus = pci_find_root_bus(0);
+    if (bus != NULL)
+        pci_create_simple(bus, -1, "xen-platform");

scripts/checkpatch.pl will complain about missing braces for if, but otherwise looks okay to me.

Andreas

Quoted 3 lines
hw/i386/pc_piix.c +0 -0
 }
 #endif
 
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg