Patchwork [02/15] xen: Add xen_machine_fv

login
register
mail settings
Submitter Stefano Stabellini
Date Aug. 12, 2010, 2:09 p.m.
Message ID <1281622202-3453-2-git-send-email-stefano.stabellini@eu.citrix.com>
Download mbox | patch
Permalink /patch/61601/
State New
Headers show

Comments

Stefano Stabellini - Aug. 12, 2010, 2:09 p.m.
From: Anthony PERARD <anthony.perard@citrix.com>

Add the Xen FV (Fully Virtualized) machine to Qemu;
this is groundwork to add Xen device model support in Qemu.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
 Makefile.target     |    3 +
 hw/xen_machine_fv.c |  156 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 159 insertions(+), 0 deletions(-)
 create mode 100644 hw/xen_machine_fv.c
Kevin Wolf - Aug. 16, 2010, 1:42 p.m.
Am 12.08.2010 16:09, schrieb stefano.stabellini@eu.citrix.com:
> From: Anthony PERARD <anthony.perard@citrix.com>
> 
> Add the Xen FV (Fully Virtualized) machine to Qemu;
> this is groundwork to add Xen device model support in Qemu.
> 
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

Why does this need its own machine type? Shouldn't an HVM machine really
look like a PC? And indeed most of this code looks like a (slightly
outdated) copy of pc_piix.c with !pci_enabled code paths removed.

Kevin
Stefano Stabellini - Aug. 16, 2010, 2:04 p.m.
On Mon, 16 Aug 2010, Kevin Wolf wrote:
> Am 12.08.2010 16:09, schrieb stefano.stabellini@eu.citrix.com:
> > From: Anthony PERARD <anthony.perard@citrix.com>
> > 
> > Add the Xen FV (Fully Virtualized) machine to Qemu;
> > this is groundwork to add Xen device model support in Qemu.
> > 
> > Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
> > Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
> 
> Why does this need its own machine type? Shouldn't an HVM machine really
> look like a PC? And indeed most of this code looks like a (slightly
> outdated) copy of pc_piix.c with !pci_enabled code paths removed.
 
The main reason is that we need some xen specific initializations, as you can
see from xen_init_fv.
But considering that we have been asked to remove target-xen and that
will cause a major refactoring of this series, xen_machine_fv could
change significantly in the next iterations anyway...
Kevin Wolf - Aug. 16, 2010, 2:13 p.m.
Am 16.08.2010 16:04, schrieb Stefano Stabellini:
> On Mon, 16 Aug 2010, Kevin Wolf wrote:
>> Am 12.08.2010 16:09, schrieb stefano.stabellini@eu.citrix.com:
>>> From: Anthony PERARD <anthony.perard@citrix.com>
>>>
>>> Add the Xen FV (Fully Virtualized) machine to Qemu;
>>> this is groundwork to add Xen device model support in Qemu.
>>>
>>> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
>>> Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
>>
>> Why does this need its own machine type? Shouldn't an HVM machine really
>> look like a PC? And indeed most of this code looks like a (slightly
>> outdated) copy of pc_piix.c with !pci_enabled code paths removed.
>  
> The main reason is that we need some xen specific initializations, as you can
> see from xen_init_fv.

Right, there are some more Xen specific things added later. However, the
main part of it is duplicated from pc_piix.c. I'm sure that with some
refactoring we could call these functions instead of copying and
modifying them. The problem with the latter is that they will inevitably
diverge even for changes that make sense for both.

I'm not even sure that the machine is the right place to do these Xen
specific initializations (expect for the Xen platform PCI device). As
far as I understand, the QEMUMachine is considered guest state whereas
most of these initializations concern host state.

> But considering that we have been asked to remove target-xen and that
> will cause a major refactoring of this series, xen_machine_fv could
> change significantly in the next iterations anyway...

Basically, the request to remove target-xen and my comment both aim in
the same direction, namely making Xen less special and integrate it
better in existing structures.

Kevin
Anthony Liguori - Aug. 16, 2010, 2:38 p.m.
On 08/16/2010 09:13 AM, Kevin Wolf wrote:
> Am 16.08.2010 16:04, schrieb Stefano Stabellini:
>    
>> On Mon, 16 Aug 2010, Kevin Wolf wrote:
>>      
>>> Am 12.08.2010 16:09, schrieb stefano.stabellini@eu.citrix.com:
>>>        
>>>> From: Anthony PERARD<anthony.perard@citrix.com>
>>>>
>>>> Add the Xen FV (Fully Virtualized) machine to Qemu;
>>>> this is groundwork to add Xen device model support in Qemu.
>>>>
>>>> Signed-off-by: Anthony PERARD<anthony.perard@citrix.com>
>>>> Signed-off-by: Stefano Stabellini<stefano.stabellini@eu.citrix.com>
>>>>          
>>> Why does this need its own machine type? Shouldn't an HVM machine really
>>> look like a PC? And indeed most of this code looks like a (slightly
>>> outdated) copy of pc_piix.c with !pci_enabled code paths removed.
>>>        
>>
>> The main reason is that we need some xen specific initializations, as you can
>> see from xen_init_fv.
>>      
> Right, there are some more Xen specific things added later. However, the
> main part of it is duplicated from pc_piix.c. I'm sure that with some
> refactoring we could call these functions instead of copying and
> modifying them. The problem with the latter is that they will inevitably
> diverge even for changes that make sense for both.
>
> I'm not even sure that the machine is the right place to do these Xen
> specific initializations (expect for the Xen platform PCI device). As
> far as I understand, the QEMUMachine is considered guest state whereas
> most of these initializations concern host state.
>    

To be honest, I think we'll need KVM, Xen, and QEMU specific machines.

The right default set of hardware for all three is different.

Going back to an old series of mine, they might share a MachineCore, but 
they'll ultimately need to be different machines.

Regards,

Anthony Liguori

>    
>> But considering that we have been asked to remove target-xen and that
>> will cause a major refactoring of this series, xen_machine_fv could
>> change significantly in the next iterations anyway...
>>      
> Basically, the request to remove target-xen and my comment both aim in
> the same direction, namely making Xen less special and integrate it
> better in existing structures.
>
> Kevin
>
>
Kevin Wolf - Aug. 16, 2010, 2:51 p.m.
Am 16.08.2010 16:38, schrieb Anthony Liguori:
> On 08/16/2010 09:13 AM, Kevin Wolf wrote:
>> Am 16.08.2010 16:04, schrieb Stefano Stabellini:
>>    
>>> On Mon, 16 Aug 2010, Kevin Wolf wrote:
>>>      
>>>> Am 12.08.2010 16:09, schrieb stefano.stabellini@eu.citrix.com:
>>>>        
>>>>> From: Anthony PERARD<anthony.perard@citrix.com>
>>>>>
>>>>> Add the Xen FV (Fully Virtualized) machine to Qemu;
>>>>> this is groundwork to add Xen device model support in Qemu.
>>>>>
>>>>> Signed-off-by: Anthony PERARD<anthony.perard@citrix.com>
>>>>> Signed-off-by: Stefano Stabellini<stefano.stabellini@eu.citrix.com>
>>>>>          
>>>> Why does this need its own machine type? Shouldn't an HVM machine really
>>>> look like a PC? And indeed most of this code looks like a (slightly
>>>> outdated) copy of pc_piix.c with !pci_enabled code paths removed.
>>>>        
>>>
>>> The main reason is that we need some xen specific initializations, as you can
>>> see from xen_init_fv.
>>>      
>> Right, there are some more Xen specific things added later. However, the
>> main part of it is duplicated from pc_piix.c. I'm sure that with some
>> refactoring we could call these functions instead of copying and
>> modifying them. The problem with the latter is that they will inevitably
>> diverge even for changes that make sense for both.
>>
>> I'm not even sure that the machine is the right place to do these Xen
>> specific initializations (expect for the Xen platform PCI device). As
>> far as I understand, the QEMUMachine is considered guest state whereas
>> most of these initializations concern host state.
>>    
> 
> To be honest, I think we'll need KVM, Xen, and QEMU specific machines.
> 
> The right default set of hardware for all three is different.

Right, I agree. This is why I put the exception for the platform device.
There are probably some more devices for which the same applies.

But these exceptions all about guest state. If qdev was finished, this
would be a matter of having a different configuration file, right?

This series, as I understand it, is adding much more to the Xen FV
machine. Things that are not about which devices a VM contains, but
about some implementation details of the host.

Kevin
Stefano Stabellini - Aug. 16, 2010, 3 p.m.
On Mon, 16 Aug 2010, Kevin Wolf wrote:
> Right, I agree. This is why I put the exception for the platform device.
> There are probably some more devices for which the same applies.
> 
> But these exceptions all about guest state. If qdev was finished, this
> would be a matter of having a different configuration file, right?
> 
> This series, as I understand it, is adding much more to the Xen FV
> machine. Things that are not about which devices a VM contains, but
> about some implementation details of the host.
 
We could probably move the mapcache initialization and the ioreq and
buffered ioreq page setup to another place, but apart from that the rest
is about emulated devices.
Anthony Liguori - Aug. 16, 2010, 3:07 p.m.
On 08/16/2010 09:51 AM, Kevin Wolf wrote:
> Am 16.08.2010 16:38, schrieb Anthony Liguori:
>    
>>
>> To be honest, I think we'll need KVM, Xen, and QEMU specific machines.
>>
>> The right default set of hardware for all three is different.
>>      
> Right, I agree. This is why I put the exception for the platform device.
> There are probably some more devices for which the same applies.
>
> But these exceptions all about guest state. If qdev was finished, this
> would be a matter of having a different configuration file, right?
>
> This series, as I understand it, is adding much more to the Xen FV
> machine. Things that are not about which devices a VM contains, but
> about some implementation details of the host.
>    

Yeah, but dropping the target-xen will probably fix most of that stuff.

Regards,

Anthony Liguori

> Kevin
>

Patch

diff --git a/Makefile.target b/Makefile.target
index 8a9c427..8fdc884 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -183,6 +183,9 @@  QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
 # xen backend driver support
 obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
 
+# xen full virtualized machine
+obj-$(CONFIG_XEN) += xen_machine_fv.o
+
 # USB layer
 obj-$(CONFIG_USB_OHCI) += usb-ohci.o
 
diff --git a/hw/xen_machine_fv.c b/hw/xen_machine_fv.c
new file mode 100644
index 0000000..8114460
--- /dev/null
+++ b/hw/xen_machine_fv.c
@@ -0,0 +1,156 @@ 
+/*
+ * QEMU Xen FV Machine
+ *
+ * Copyright (c) 2003-2007 Fabrice Bellard
+ * Copyright (c) 2007 Red Hat
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw.h"
+#include "pc.h"
+#include "pci.h"
+#include "usb-uhci.h"
+#include "net.h"
+#include "boards.h"
+#include "ide.h"
+#include "sysemu.h"
+
+#include "xen/hvm/hvm_info_table.h"
+
+#define MAX_IDE_BUS 2
+
+static void xen_init_fv(ram_addr_t ram_size,
+                        const char *boot_device,
+                        const char *kernel_filename,
+                        const char *kernel_cmdline,
+                        const char *initrd_filename,
+                        const char *cpu_model)
+{
+    int i;
+    ram_addr_t below_4g_mem_size, above_4g_mem_size = 0;
+    PCIBus *pci_bus;
+    PCII440FXState *i440fx_state;
+    int piix3_devfn = -1;
+    qemu_irq *cpu_irq;
+    qemu_irq *isa_irq;
+    qemu_irq *i8259;
+    qemu_irq *cmos_s3;
+    qemu_irq *smi_irq;
+    IsaIrqState *isa_irq_state;
+    DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
+    FDCtrl *floppy_controller;
+    BusState *idebus[MAX_IDE_BUS];
+    ISADevice *rtc_state;
+
+    CPUState *env;
+
+    /* Initialize a dummy CPU */
+    if (cpu_model == NULL) {
+#ifdef TARGET_X86_64
+        cpu_model = "qemu64";
+#else
+        cpu_model = "qemu32";
+#endif
+    }
+    env = cpu_init(cpu_model);
+    env->halted = 1;
+
+    cpu_irq = pc_allocate_cpu_irq();
+    i8259 = i8259_init(cpu_irq[0]);
+    isa_irq_state = qemu_mallocz(sizeof(*isa_irq_state));
+    isa_irq_state->i8259 = i8259;
+
+    isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
+
+    pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
+    isa_bus_irqs(isa_irq);
+
+    pc_register_ferr_irq(isa_reserve_irq(13));
+
+    pc_vga_init(pci_bus);
+
+    /* init basic PC hardware */
+    pc_basic_device_init(isa_irq, &floppy_controller, &rtc_state);
+
+    for(i = 0; i < nb_nics; i++) {
+        NICInfo *nd = &nd_table[i];
+
+        if (nd->model && strcmp(nd->model, "ne2k_isa") == 0)
+            pc_init_ne2k_isa(nd);
+        else
+            pci_nic_init_nofail(nd, "e1000", NULL);
+    }
+
+    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
+        fprintf(stderr, "qemu: too many IDE bus\n");
+        exit(1);
+    }
+
+    for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
+        hd[i] = drive_get(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
+    }
+
+    PCIDevice *dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
+    idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
+    idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
+
+    pc_audio_init(pci_bus, isa_irq);
+
+    if (ram_size >= 0xe0000000 ) {
+        above_4g_mem_size = ram_size - 0xe0000000;
+        below_4g_mem_size = 0xe0000000;
+    } else {
+        below_4g_mem_size = ram_size;
+    }
+    pc_cmos_init(below_4g_mem_size, above_4g_mem_size, boot_device,
+            idebus[0], idebus[1], floppy_controller, rtc_state);
+
+    if (usb_enabled) {
+        usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
+    }
+
+    if (acpi_enabled) {
+        cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
+        smi_irq = qemu_allocate_irqs(pc_acpi_smi_interrupt, first_cpu, 1);
+        piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
+                isa_reserve_irq(9), *cmos_s3, *smi_irq,
+                0);
+    }
+
+    if (i440fx_state) {
+        i440fx_init_memory_mappings(i440fx_state);
+    }
+
+    pc_pci_device_init(pci_bus);
+}
+
+static QEMUMachine xenfv_machine = {
+    .name = "xenfv",
+    .desc = "Xen Fully-virtualized PC",
+    .init = xen_init_fv,
+    .max_cpus = HVM_MAX_VCPUS,
+};
+
+static void xenfv_machine_init(void)
+{
+    qemu_register_machine(&xenfv_machine);
+}
+
+machine_init(xenfv_machine_init);