Skip to contentSkip to conversation

RFC: Xenner

PATCH In review Alexander Graf 10 participants 96 messages Nov 1, 2010 – Nov 2, 2010 Kbuild Page 2 of 2

lore
Share & tools
lore
#81 lore raw

Re: [Qemu-devel] [PATCH 31/40] xenner: libxc emu: xenstore

In reply to Alexander Graf
Quoted 50 lines · Alexander Graf

Xenner emulates parts of libxc, so we can not use the real xen infrastructure when running xen pv guests without xen.

This patch adds support for emulation of xenstored.

---
 hw/xenner_guest_store.c |  494 +++++++++++++++++++++++++++++++++ hw/xenner_libxenstore.c |  709 +++++++++++++++++++++++++++++++++++++++++++++++

 2 files changed, 1203 insertions(+), 0 deletions(-)

 create mode 100644 hw/xenner_guest_store.c
 create mode 100644 hw/xenner_libxenstore.c

hw/xenner_guest_store.c new file +31 -0
new file mode 100644
index 0000000..c067275
@@ -0,0 +1,494 @@
+/*
+ *  Copyright (C) 2005 Rusty Russell IBM Corporation
+ *  Copyright (C) Red Hat 2007
+ *  Copyright (C) Novell Inc. 2010
+ *
+ *  Author(s): Gerd Hoffmann <[email protected]>
+ *             Alexander Graf <[email protected]>
+ *
+ *  Xenner emulation -- guest interface to xenstore
+ *
+ *  tools/xenstore/xenstored_domain.c equivalent, some code is from there.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; under version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "xen.h"
+#include "xen_interfaces.h"
+#include "xenner.h"
+#include "qemu-char.h"
+
+/* ------------------------------------------------------------- */

hw/xenner_guest_store.c line 41

Quoted 10 lines
hw/xenner_guest_store.c new file +10 -0
+
+static target_phys_addr_t xen_store_mfn;
+
+static struct xs_handle *xs_guest;
+static char xs_buf[1024];
+static char xs_len;
+static int debug = 0;
+
+static int evtchndev;
+static evtchn_port_t evtchnport;

A lot of static state. Couldn't this be wrapped inside a structure, which is then passed around?

#82 lore raw

PATCH 32/40 xenner: emudev

In reply to Alexander Graf

Xenner uses its own special PV device to communicate between qemu and the guest xenner kernel. This patch implements that device.

---
 hw/xenner_emudev.c |  107 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/xenner_emudev.h |  108 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 215 insertions(+), 0 deletions(-)
 create mode 100644 hw/xenner_emudev.c
 create mode 100644 hw/xenner_emudev.h
hw/xenner_emudev.c new file +107 -0
new file mode 100644
index 0000000..dea617e
@@ -0,0 +1,107 @@
+/*
+ *  Copyright (C) Red Hat 2007
+ *  Copyright (C) Novell Inc. 2010
+ *
+ *  Author(s): Gerd Hoffmann <[email protected]>
+ *             Alexander Graf <[email protected]>
+ *
+ *  Xenner communication device
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; under version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <inttypes.h>
+
+#include "xenner_emudev.h"
+
+void emudev_write_entry(struct emudev_state *e, uint32_t value)
+{
+    e->entry = value;
+}
+
+void emudev_write_value(struct emudev_state *e, uint32_t value)
+{
+    uint16_t type, index;
+    int high_32;
+
+    type = e->entry >> 16;
+    high_32 = type & EMUDEV_CONF_HIGH_32;
+    type &= ~EMUDEV_CONF_HIGH_32;
+    index = e->entry & 0xffff;
+    switch (type) {
+    case EMUDEV_CONF_GRANT_TABLE_PFNS:
+        if (index < EMUDEV_CONF_GRANT_TABLE_COUNT)
+            e->gnttab[index] = value;
+        break;
+    case EMUDEV_CONF_EVTCHN_TO_PIN:
+        if (index < EMUDEV_CONF_EVTCHN_TO_PIN_COUNT)
+            e->evtchn[index] = value;
+        break;
+    case EMUDEV_CONF_COMMAND_RESULT:
+        if (index < EMUDEV_CONF_COMMAND_RESULT_COUNT)
+            e->result[index] = value;
+        break;
+    default:
+        if (type >= EMUDEV_CONF_SIMPLE_COUNT) {
+            break;
+        }
+        if (high_32) {
+            e->config[type] = (e->config[type] & 0x00000000ffffffffULL)
+                            | ((uint64_t)value << 32);
+        } else {
+            e->config[type] = (e->config[type] & 0xffffffff00000000ULL)
+                            | ((uint64_t)value);
+        }
+        break;
+    }
+}
+
+uint32_t emudev_read_value(struct emudev_state *e)
+{
+    uint16_t type, index;
+    int high_32;
+    uint64_t r = -1;
+
+    type = e->entry >> 16;
+    high_32 = type & EMUDEV_CONF_HIGH_32;
+    type &= ~EMUDEV_CONF_HIGH_32;
+    index = e->entry & 0xffff;
+    switch (type) {
+    case EMUDEV_CONF_GRANT_TABLE_PFNS:
+        if (index < EMUDEV_CONF_GRANT_TABLE_COUNT) {
+            r = e->gnttab[index];
+        }
+        break;
+    case EMUDEV_CONF_EVTCHN_TO_PIN:
+        if (index < EMUDEV_CONF_EVTCHN_TO_PIN_COUNT) {
+            r = e->evtchn[index];
+        }
+        break;
+    case EMUDEV_CONF_COMMAND_RESULT:
+        if (index < EMUDEV_CONF_COMMAND_RESULT_COUNT) {
+            r = e->result[index];
+        }
+        break;
+    default:
+        if (type < EMUDEV_CONF_SIMPLE_COUNT) {
+            r = e->config[type];
+        }
+        break;
+    }
+
+    if (high_32) {
+        return (uint32_t)(r >> 32);
+    }
+
+    return (uint32_t)r;
+}
hw/xenner_emudev.h new file +108 -0

108 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#83 lore raw

PATCH 33/40 xenner: core

In reply to Alexander Graf

This patch adds generic xenner functionality to qemu.

---
 hw/xenner.h      |   52 +++++++++++++
 hw/xenner_core.c |  224 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 276 insertions(+), 0 deletions(-)
 create mode 100644 hw/xenner.h
 create mode 100644 hw/xenner_core.c
hw/xenner.h new file +52 -0
new file mode 100644
index 0000000..241dc4c
@@ -0,0 +1,52 @@
+/*
+ *  Copyright (C) Red Hat 2007
+ *  Copyright (C) Novell Inc. 2010
+ *
+ *  Author(s): Gerd Hoffmann <[email protected]>
+ *             Alexander Graf <[email protected]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; under version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu-common.h"
+
+/* xenner_core.c */
+struct xenner_emu_file {
+    const char *filename;
+    int        pages;
+    void       *blob;
+};
+
+void *xenner_mfn_to_ptr(xen_pfn_t pfn);
+void *xenner_get_grant_table(int index);
+void *xenner_get_vminfo(void);
+uint64_t xenner_get_config(uint32_t reg);
+uint32_t xenner_get_evtchn_pin(uint32_t reg);
+void xenner_set_config(uint32_t reg, uint64_t value);
+int xenner_load_emu_file(struct xenner_emu_file *f);
+int xenner_guest_evtchn_alloc(void);
+int xenner_guest_evtchn_release(int port);
+int xenner_core_init(int evt);
+
+/* xenner_guest_store.c */
+void xenner_guest_store_setup(uint64_t guest_mfn, evtchn_port_t guest_evtchn);
+void xenner_guest_store_reset(void);
+
+/* xenner_pv.c */
+int xenner_init_pv(const char *kernel_filename,
+                   const char *kernel_cmdline,
+                   const char *initrd_filename);
+
+int xenner_domain_build_pv(const char *kernel,
+                           const char *initrd,
+                           const char *cmdline);
hw/xenner_core.c new file +224 -0

224 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#84 lore raw

Re: [Qemu-devel] [PATCH 33/40] xenner: core

Quoted 259 lines · Alexander Graf

This patch adds generic xenner functionality to qemu.

---
 hw/xenner.h      |   52 +++++++++++++
 hw/xenner_core.c |  224 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 276 insertions(+), 0 deletions(-)
 create mode 100644 hw/xenner.h
 create mode 100644 hw/xenner_core.c
hw/xenner.h new file +52 -0
new file mode 100644
index 0000000..241dc4c
@@ -0,0 +1,52 @@
+/*
+ *  Copyright (C) Red Hat 2007
+ *  Copyright (C) Novell Inc. 2010
+ *
+ *  Author(s): Gerd Hoffmann <[email protected]>
+ *             Alexander Graf <[email protected]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; under version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu-common.h"
+
+/* xenner_core.c */
+struct xenner_emu_file {
+    const char *filename;
+    int        pages;
+    void       *blob;
+};
+
+void *xenner_mfn_to_ptr(xen_pfn_t pfn);
+void *xenner_get_grant_table(int index);
+void *xenner_get_vminfo(void);
+uint64_t xenner_get_config(uint32_t reg);
+uint32_t xenner_get_evtchn_pin(uint32_t reg);
+void xenner_set_config(uint32_t reg, uint64_t value);
+int xenner_load_emu_file(struct xenner_emu_file *f);
+int xenner_guest_evtchn_alloc(void);
+int xenner_guest_evtchn_release(int port);
+int xenner_core_init(int evt);
+
+/* xenner_guest_store.c */
+void xenner_guest_store_setup(uint64_t guest_mfn, evtchn_port_t guest_evtchn);
+void xenner_guest_store_reset(void);
+
+/* xenner_pv.c */
+int xenner_init_pv(const char *kernel_filename,
+                   const char *kernel_cmdline,
+                   const char *initrd_filename);
+
+int xenner_domain_build_pv(const char *kernel,
+                           const char *initrd,
+                           const char *cmdline);
hw/xenner_core.c new file +185 -0
new file mode 100644
index 0000000..53a9a75
@@ -0,0 +1,224 @@
+/*
+ *  Copyright (C) Red Hat 2007
+ *  Copyright (C) Novell Inc. 2010
+ *
+ *  Author(s): Gerd Hoffmann <[email protected]>
+ *             Alexander Graf <[email protected]>
+ *
+ *  Xenner Core
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; under version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "hw.h"
+#include "isa.h"
+#include "sysemu.h"
+#include "xen.h"
+#include "xen_interfaces.h"
+#include "xenner.h"
+#include "xenner_emudev.h"
+#include "loader.h"
+
+/* #define DEBUG */
+
+static int guest_evtchndev;
+static struct emudev_state xen_emudev;
+
+/* ------------------------------------------------------------- */
+
+static void do_emudev_command(uint16_t cmd, uint16_t arg)
+{
+    switch (cmd) {
+    case EMUDEV_CMD_NOP:
+        /* nop vmexit */
+        break;
+    case EMUDEV_CMD_WRITE_CHAR:
+#ifdef DEBUG
+        fprintf(stderr, "%c", arg);
+#endif
+        break;
+    case EMUDEV_CMD_CONFIGURATION_DONE:
+        /* emu finisted initial EMUDEV_CONF_* setup */
+        break;
+    case EMUDEV_CMD_EVTCHN_ALLOC:
+        if (arg < EMUDEV_CONF_COMMAND_RESULT_COUNT) {
+            xen_emudev.result[arg] = xenner_guest_evtchn_alloc();
+        }
+        break;
+    case EMUDEV_CMD_EVTCHN_SEND:
+        xc_evtchn.notify(guest_evtchndev, arg);
+        break;
+    case EMUDEV_CMD_GUEST_SHUTDOWN:
+        switch (arg) {
+        case SHUTDOWN_poweroff:
+            fprintf(stderr, "xenner emudev: guest poweroff -> powerdown\n");
+            qemu_system_powerdown_request();
+            break;
+        case SHUTDOWN_reboot:
+            fprintf(stderr, "xenner emudev: guest reboot -> reset\n");
+            qemu_system_reset_request();
+            vm_stop(0);
+            break;
+        case SHUTDOWN_suspend:
+            fprintf(stderr, "xenner emudev: guest suspend -> stop vm\n");
+            vm_stop(0);
+            break;
+        case SHUTDOWN_crash:
+            fprintf(stderr, "xenner emudev: guest crash -> reset\n");
+            vm_stop(0);
+            qemu_system_reset_request();
+            break;
+        }
+        break;
+    default:
+        fprintf(stderr, "xenner emudev: cmd 0x%04x arg 0x%04x\n", cmd, arg);
+    }
+}
+
+static void xenner_port_write(void *opaque, uint32_t addr, uint32_t val)
+{
+    uint16_t cmd, arg;
+
+    switch (addr) {
+    case EMUDEV_REG_CONF_ENTRY:
+        emudev_write_entry(&xen_emudev, val);
+        break;
+    case EMUDEV_REG_CONF_VALUE:
+        emudev_write_value(&xen_emudev, val);
+        break;
+    case EMUDEV_REG_COMMAND:
+        cmd = val >> 16;
+        arg = val & 0xffff;
+        do_emudev_command(cmd, arg);
+        break;
+    default:
+        fprintf(stderr, "io: %s, addr 0x%" PRIx16 " value 0x%" PRIx32 "\n",
+                __FUNCTION__, addr, val);
+        break;
+    }
+}
+
+static uint32_t xenner_port_read(void *opaque, uint32_t addr)
+{
+    uint32_t val;
+
+    switch (addr) {
+    case EMUDEV_REG_CONF_VALUE:
+        val = emudev_read_value(&xen_emudev);
+        break;
+    default:
+        fprintf(stderr, "io: %s, addr 0x%" PRIx16 "\n", __FUNCTION__, addr);
+        val = 0xffffffff;
+        break;
+    }
+    return val;
+}
+
+/* ------------------------------------------------------------- */
+
+void *xenner_mfn_to_ptr(xen_pfn_t pfn)
+{
+    ram_addr_t offset;
+
+    offset = cpu_get_physical_page_desc(pfn << PAGE_SHIFT);
+    return qemu_get_ram_ptr(offset);
+}
+
+void *xenner_get_grant_table(int index)
+{
+    uint32_t pfn;
+
+    if (index > EMUDEV_CONF_GRANT_TABLE_COUNT) {
+        return NULL;
+    }
+    pfn = xen_emudev.gnttab[index];
+    if (!pfn) {
+        return NULL;
+    }
+    return xenner_mfn_to_ptr(pfn);
+}
+
+void *xenner_get_vminfo(void)
+{
+    uint32_t pfn;
+
+    pfn = xen_emudev.config[EMUDEV_CONF_VMINFO_PFN];
+    if (!pfn) {
+        return NULL;
+    }
+    return xenner_mfn_to_ptr(pfn);
+}
+
+uint64_t xenner_get_config(uint32_t reg)
+{
+    return xen_emudev.config[reg];
+}
+
+uint32_t xenner_get_evtchn_pin(uint32_t reg)
+{
+    return xen_emudev.evtchn[reg];
+}
+
+void xenner_set_config(uint32_t reg, uint64_t value)
+{
+    xen_emudev.config[reg] = value;
+}
+
+/* ------------------------------------------------------------- */
+
+int xenner_load_emu_file(struct xenner_emu_file *f)
+{
+    int r;
+
+    /* Fetch size */
+    r = get_image_size(f->filename);
+    if (r <= 0) {

hw/xenner_core.c line 195

Quoted 10 lines
hw/xenner_core.c new file +10 -0
+        fprintf(stderr, "can't find %s\n", f->filename);
+        return -1;
+    }
+
+    /* Allocate memory */
+    f->pages = (r + PAGE_SIZE - 1) / PAGE_SIZE;
+    f->blob = qemu_mallocz(f->pages * PAGE_SIZE);
+    if (!f->blob) {
+        return -1;
+    }

qemu_mallocz doesn't return NULL

Quoted 30 lines
hw/xenner_core.c new file +29 -0
+
+    /* Load image */
+    r = load_image(f->filename, f->blob);
+
+    return r;
+}
+
+/* ------------------------------------------------------------- */
+
+int xenner_guest_evtchn_alloc(void)
+{
+    return xc_evtchn.bind_unbound_port(guest_evtchndev, 0);
+}
+
+int xenner_guest_evtchn_release(int port)
+{
+    return xc_evtchn.unbind(guest_evtchndev, port);
+}
+
+int xenner_core_init(int evt)
+{
+    guest_evtchndev = evt;
+    xc_evtchn.domid(guest_evtchndev, xen_domid);
+
+    register_ioport_write(EMUDEV_REG_BASE, 16, 4, xenner_port_write, NULL);
+    register_ioport_read(EMUDEV_REG_BASE, 16, 4, xenner_port_read, NULL);
+
+    return 0;
+}
Signature · 1 line
mailto:[email protected]
#85 lore raw

PATCH 34/40 xenner: PV machine

In reply to Alexander Graf

The same as Xen has a PV machine to do all the initialization of devices, we have one for xenner. This patch implements said machine description.

---
 hw/xenner_pv.c |  135 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 135 insertions(+), 0 deletions(-)
 create mode 100644 hw/xenner_pv.c
hw/xenner_pv.c new file +135 -0
new file mode 100644
index 0000000..6350075
@@ -0,0 +1,135 @@
+/*
+ *  Copyright (C) Red Hat 2007
+ *  Copyright (C) Novell Inc. 2010
+ *
+ *  Author(s): Gerd Hoffmann <[email protected]>
+ *             Alexander Graf <[email protected]>
+ *
+ *  Xenner PV machine
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; under version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/mman.h>
+
+#include <xen/io/protocols.h>
+
+#include "hw.h"
+#include "pc.h"
+#include "kvm.h"
+#include "sysemu.h"
+#include "qemu-char.h"
+#include "xen_backend.h"
+#include "xen_interfaces.h"
+#include "xen_domainbuild.h"
+#include "xenner.h"
+#include "xenner_emudev.h"
+#include "loader.h"
+#include "elf.h"
+#include "apic.h"
+#include "sysbus.h"
+
+/* ------------------------------------------------------------- */
+
+/* convert megabytes to pages and back */
+#define MB_TO_PG(x) (x << 8)
+#define PG_TO_MB(x) (x >> 8)
+
+#define addr_to_frame(addr)    ((addr) >> PAGE_SHIFT)
+#define frame_to_addr(frame)   ((frame) << PAGE_SHIFT)
+#define addr_offset(addr)      ((addr) & ~PAGE_MASK)
+
+static int       guest_evtchndev;
+
+/* ------------------------------------------------------------- */
+
+static IsaIrqState *isa_irq_state;
+
+static void ioapic_init(IsaIrqState *isa_irq_state)
+{
+    DeviceState *dev;
+    SysBusDevice *d;
+    unsigned int i;
+
+    dev = qdev_create(NULL, "ioapic");
+    qdev_init_nofail(dev);
+    d = sysbus_from_qdev(dev);
+    sysbus_mmio_map(d, 0, 0xfec00000);
+
+    for (i = 0; i < IOAPIC_NUM_PINS; i++) {
+        isa_irq_state->ioapic[i] = qdev_get_gpio_in(dev, i);
+    }
+}
+
+static void xenner_request_irq(void *opaque, int irq, int level)
+{
+}
+
+static int xenner_setup_irqs(void)
+{
+    qemu_irq *isa_irq;
+    qemu_irq *cpu_irq;
+
+    cpu_irq = qemu_allocate_irqs(xenner_request_irq, NULL, 1);
+    isa_irq_state = qemu_mallocz(sizeof(*isa_irq_state));
+    isa_irq_state->i8259 = i8259_init(cpu_irq[0]);
+    ioapic_init(isa_irq_state);
+    isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
+
+    isa_bus_new(NULL);
+    isa_bus_irqs(isa_irq);
+
+    return 0;
+}
+
+static void guest_evtchn_event(void *opaque)
+{
+    evtchn_port_t port;
+    int pin;
+
+    port = xc_evtchn.pending(guest_evtchndev);
+    if ((int)port < 0 || port > EMUDEV_CONF_EVTCHN_TO_PIN_COUNT) {
+        return;
+    }
+    xc_evtchn.unmask(guest_evtchndev, port);
+    pin = xenner_get_evtchn_pin(port);
+    qemu_set_irq(isa_irq_state->ioapic[pin], 1);
+}
+
+int xenner_init_pv(const char *kernel_filename,
+                   const char *kernel_cmdline,
+                   const char *initrd_filename)
+{
+    ram_addr_t ram_addr;
+    ram_addr_t boot_addr;
+
+    pc_cpus_init(NULL);
+
+    ram_addr = qemu_ram_alloc(NULL, "pc.ram", ram_size);
+    cpu_register_physical_memory(0, ram_size, ram_addr);
+
+    boot_addr = qemu_ram_alloc(NULL, "xenner.trampoline", 0x1000);
+    cpu_register_physical_memory(0xfffff000, 0x1000, boot_addr);
+
+    guest_evtchndev = xc_evtchn.open();
+    xenner_core_init(guest_evtchndev);
+    qemu_set_fd_handler(xc_evtchn.fd(guest_evtchndev),
+                        guest_evtchn_event, NULL, NULL);
+
+    xenner_setup_irqs();
+
+    xenner_domain_build_pv(kernel_filename, initrd_filename,
+                           kernel_cmdline);
+
+    return 0;
+}
Signature · 1 line
1.6.0.2
#86 lore raw

PATCH 35/40 xenner: Domain Builder

In reply to Alexander Graf

The traditional Xen way of loading a kernel and initial data structures into the guest's memory is by calling libxc functions. We want to be able to run without libxc dependencies though, so we need an alternative.

This patch implements a full domain builder for xenner. It loads the guest kernel, sets up basic memory layouts and saves everything off for the pv communication device between xenner and qemu.

---
 hw/xenner_dom_builder.c |  406 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 406 insertions(+), 0 deletions(-)
 create mode 100644 hw/xenner_dom_builder.c
hw/xenner_dom_builder.c new file +406 -0
new file mode 100644
index 0000000..b4d55dd
@@ -0,0 +1,406 @@
+/*
+ *  Copyright (C) Red Hat 2007
+ *  Copyright (C) Novell Inc. 2010
+ *
+ *  Author(s): Gerd Hoffmann <[email protected]>
+ *             Alexander Graf <[email protected]>
+ *
+ *  Xenner Domain Builder
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; under version 2 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/mman.h>
+
+#include <xen/io/protocols.h>
+
+#include "hw.h"
+#include "pc.h"
+#include "kvm.h"
+#include "sysemu.h"
+#include "qemu-char.h"
+#include "xen_backend.h"
+#include "xen_interfaces.h"
+#include "xen_domainbuild.h"
+#include "xenner.h"
+#include "xenner_emudev.h"
+#include "loader.h"
+#include "elf.h"
+#include "apic.h"
+
+#define XEN_ELFNOTE_INFO            0
+#define XEN_ELFNOTE_ENTRY           1
+#define XEN_ELFNOTE_HYPERCALL_PAGE  2
+#define XEN_ELFNOTE_VIRT_BASE       3
+#define XEN_ELFNOTE_PADDR_OFFSET    4
+#define XEN_ELFNOTE_XEN_VERSION     5
+#define XEN_ELFNOTE_GUEST_OS        6
+#define XEN_ELFNOTE_GUEST_VERSION   7
+#define XEN_ELFNOTE_LOADER          8
+#define XEN_ELFNOTE_PAE_MODE        9
+#define XEN_ELFNOTE_FEATURES       10
+#define XEN_ELFNOTE_BSD_SYMTAB     11
+#define XEN_ELFNOTE_HV_START_LOW   12
+#define XEN_ELFNOTE_L1_MFN_VALID   13
+#define XEN_ELFNOTE_SUSPEND_CANCEL 14
+#define XEN_ELFNOTE_INIT_P2M       15
+
+
+typedef struct DomParams {
+    uint64_t virt_hypercall;
+    uint64_t virt_base;
+    uint64_t virt_entry;
+    int pae;
+    int bits;
+} DomParams;
+
+#define MEGABYTE        (uint64_t)0x100000ULL
+#define MB_TO_PG(x)     (MEGABYTE * x / TARGET_PAGE_SIZE)
+#define PG_TO_MB(x)     (x * TARGET_PAGE_SIZE / MEGABYTE)
+
+static uint64_t note_numeric(uint8_t *desc, uint32_t desc_len)
+{
+    uint64_t r = 0;
+
+    switch (desc_len) {
+        case sizeof(uint8_t):
+            r = *desc;
+            break;
+        case sizeof(uint16_t):
+            r = lduw_p(desc);
+            break;
+        case sizeof(uint32_t):
+            r = ldl_p(desc);
+            break;
+        case sizeof(uint64_t):
+            r = ldq_p(desc);
+            break;
+    }
+
+    return r;
+}
+
+static void dombuild_note(void *opaque, uint8_t *name, uint32_t name_len,
+                          uint8_t *desc, uint32_t desc_len, uint32_t type)
+{
+    DomParams *params = (DomParams *)opaque;
+
+    if (name_len != 4) {
+        return;
+    }
+
+    if (!((name[0] == 'X') && (name[1] == 'e') && (name[2] == 'n'))) {
+        return;
+    }
+
+    switch (type) {
+        case XEN_ELFNOTE_HYPERCALL_PAGE:
+            params->virt_hypercall = note_numeric(desc, desc_len);
+            break;
+        case XEN_ELFNOTE_VIRT_BASE:
+            params->virt_base = note_numeric(desc, desc_len);
+            break;
+        case XEN_ELFNOTE_ENTRY:
+            params->virt_entry = note_numeric(desc, desc_len);
+            break;
+        case XEN_ELFNOTE_PAE_MODE:
+            params->pae = !strncmp((char*)desc, "yes", desc_len);
+            break;
+    }
+}
+
+static void dombuild_xen_guest_key(DomParams *params, char *key, char *value)
+{
+    if (!strncmp(key, "HYPERCALL_PAGE", strlen("HYPERCALL_PAGE"))) {
+        params->virt_hypercall = (strtoull(value, NULL, 0) << PAGE_SHIFT) +
+                                 params->virt_base;
+    }
+
+    if (!strncmp(key, "VIRT_BASE", strlen("VIRT_BASE"))) {
+        params->virt_base = strtoull(value, NULL, 0);
+    }
+
+    if (!strncmp(key, "VIRT_ENTRY", strlen("VIRT_ENTRY"))) {
+        params->virt_entry = strtoull(value, NULL, 0);
+    }
+
+    if (!strncmp(key, "PAE", strlen("PAE"))) {
+        params->pae = !strncmp(value, "yes", 3);
+    }
+}
+
+static void dombuild_section(void *opaque, uint8_t *_name, uint32_t len,
+                             uint8_t *_content)
+{
+    DomParams *params = (DomParams *)opaque;
+    char *entry, *next_entry;
+    char *name = (void*)_name;
+    char *content = (void*)_content;
+
+    if (strlen(name) != strlen("__xen_guest")) {
+        return;
+    }
+
+    if (strncmp(name, "__xen_guest", strlen("__xen_guest"))) {
+        return;
+    }
+
+    /* Example contents of section __xen_guest (without line break):
+     *
+     * GUEST_OS=Mini-OS,XEN_VER=xen-3.0,VIRT_BASE=0x0,ELF_PADDR_OFFSET=0x0,
+     * HYPERCALL_PAGE=0x2,LOADER=generic
+     *
+     */
+
+    entry = (char *)content;
+    while (entry) {
+        char *comma, *equalsign, *key, *value;
+
+        comma = strchr(entry, ',');
+        if (comma) {
+            *comma = '\0';
+            next_entry = comma + 1;
+        } else {
+            next_entry = NULL;
+        }
+
+        /* entry now contains KEY=VALUE */
+        equalsign = strchr(entry, '=');
+        if (equalsign) {
+            /* well-formed entry */
+
+            *equalsign = '\0';
+            key = entry;
+            value = equalsign + 1;
+
+            dombuild_xen_guest_key(params, key, value);
+        }
+
+        /* process next entry */
+        entry = next_entry;
+    }
+}
+
+static uint64_t mfn_to_pfn(uint64_t mfn, uint64_t mfn_guest)
+{
+    return mfn - mfn_guest;
+}
+
+static uint64_t dombuild_translate(void *opaque, uint64_t addr)
+{
+    xen_pfn_t *offset = opaque;
+
+    /* offset the kernel into physical memory */
+    addr += *offset * PAGE_SIZE;
+
+    return addr;
+}
+
+static void dombuild_header_notify(void *opaque, void *header, int bits)
+{
+    DomParams *params = opaque;
+
+    params->bits = bits;
+}
+
+
+static void xenner_cpu_reset(void *opaque)
+{
+    uint8_t boot_buf[] = { 0xea, 0x00, 0x00, 0x00, 0x00 };
+
+    /* install the stage0 boot loader */
+    cpu_physical_memory_rw(0xfffffff0, boot_buf, sizeof(boot_buf), 1);
+}
+
+int xenner_domain_build_pv(const char *kernel,
+                           const char *initrd,
+                           const char *cmdline)
+{
+    const char *emu_file;
+    xen_pfn_t pg_total, pg_emu, pg_m2p, pg_guest;
+    xen_pfn_t mfn_emu, mfn_m2p, mfn_guest;
+    uint64_t emu_entry, emu_low, emu_high;
+    int emu_size;
+    DomParams dom_params;
+    uint64_t elf_entry;
+    uint64_t elf_low, elf_high;
+    int kernel_size;
+    ElfHandlers handlers = elf_default_handlers;
+    target_phys_addr_t cur_addr;
+    int long_mode;
+    int console_evtchn, xenstore_evtchn;
+    uint64_t console_mfn, xenstore_mfn, start_info_pfn;
+    uint64_t init_pt_pfn, cmdline_pfn = 0, initrd_len = 0;
+    uint64_t mfn_list_pfn;
+
+    pg_total = ram_size / PAGE_SIZE;
+    pg_emu   = MB_TO_PG(4);
+    pg_m2p   = MB_TO_PG(4);
+    /* every page entry occupies one long */
+    while (pg_m2p < pg_total / (sizeof(target_phys_addr_t) * 8)) {
+        pg_m2p += MB_TO_PG(2);
+    }
+    mfn_guest  = pg_emu + pg_m2p;
+
+    memset(&dom_params, 0, sizeof(DomParams));
+    handlers.note_fn = dombuild_note;
+    handlers.note_opaque = &dom_params;
+    handlers.section_fn = dombuild_section;
+    handlers.section_opaque = &dom_params;
+    handlers.translate_fn = dombuild_translate;
+    handlers.translate_opaque = &mfn_guest;
+    handlers.header_notify_fn = dombuild_header_notify;
+    handlers.header_notify_opaque = &dom_params;
+    kernel_size = load_elf(kernel, &handlers, &elf_entry,
+                           &elf_low, &elf_high, 0, ELF_MACHINE, 0);
+    if (kernel_size < 0) {
+        fprintf(stderr, "Error while loading elf kernel\n");
+        exit(1);
+    }
+
+#if 0
+    printf("virt base: %#lx\n", dom_params.virt_base);
+    printf("virt hypercall: %#lx\n", dom_params.virt_hypercall);
+    printf("virt entry: %#lx\n", dom_params.virt_entry);
+    printf("guest bitness: %d%s\n", dom_params.bits,
+           dom_params.pae ? " pae" : "");
+#endif
+
+    cur_addr = (elf_high + 0x100000) & ~0xfffffULL;
+
+    if (initrd) {
+        int r;
+
+        xenner_set_config(EMUDEV_CONF_PFN_INITRD,
+                          mfn_to_pfn(cur_addr >> PAGE_SHIFT, mfn_guest));
+
+        r = load_image_targphys(initrd, cur_addr, 0);
+        cur_addr += r;
+        initrd_len = r;
+
+        if (r < 0) {
+            fprintf(stderr, "failed to load initrd\n");
+            exit(1);
+        }
+    }
+
+    /* memory setup */
+    if (dom_params.bits == 64) {
+        /* 64bit */
+        emu_file = "xenner64.elf";
+        long_mode = 1;
+    } else if (dom_params.pae) {
+        /* 32bit, PAE */
+        if (pg_total > MB_TO_PG(16384)) {
+            pg_total = MB_TO_PG(16384);
+        }
+        emu_file = "xenner32-pae.elf";
+        long_mode = 0;
+    } else {
+        /* 32bit, non-PAE */
+        if (pg_total > MB_TO_PG(4096)) {
+            pg_total = MB_TO_PG(4096);
+        }
+        emu_file = "xenner32.elf";
+        long_mode = 0;
+    }
+
+    mfn_emu    = 0;
+    mfn_m2p    = pg_emu;
+    pg_guest   = pg_total - mfn_guest;
+
+    emu_file = qemu_find_file(QEMU_FILE_TYPE_BIOS, emu_file);
+    emu_size = load_elf(emu_file, NULL, &emu_entry, &emu_low, &emu_high,
+                        0, ELF_MACHINE, 0);
+
+    if (emu_size < 0) {
+        fprintf(stderr, "Couldn't load xenner image\n");
+        exit(1);
+    }
+
+    cur_addr = (cur_addr + (PAGE_SIZE - 1)) & PAGE_MASK;
+
+    mfn_list_pfn = mfn_to_pfn(cur_addr >> PAGE_SHIFT, mfn_guest);
+    cur_addr += (pg_guest * (long_mode ? 8 : 4) + ~PAGE_MASK) & PAGE_MASK;
+
+    start_info_pfn = mfn_to_pfn(cur_addr >> PAGE_SHIFT, mfn_guest);
+    cur_addr += PAGE_SIZE;
+
+    console_mfn = (cur_addr >> PAGE_SHIFT);
+    cur_addr += PAGE_SIZE;
+
+    xenstore_mfn = (cur_addr >> PAGE_SHIFT);
+    cur_addr += PAGE_SIZE;
+
+    if (cmdline) {
+        cpu_physical_memory_rw(cur_addr, (void*)cmdline, strlen(cmdline) + 1, 1);
+        cmdline_pfn = mfn_to_pfn(cur_addr >> PAGE_SHIFT, mfn_guest);
+        cur_addr += PAGE_SIZE;
+    }
+
+    cur_addr = (cur_addr + ((4 * 1024 * 1024) - 1)) & ~((4 * 1024 * 1024) - 1);
+
+    init_pt_pfn = mfn_to_pfn(cur_addr >> PAGE_SHIFT, mfn_guest);
+    cur_addr += PAGE_SIZE * 100;
+
+    xenner_set_config(EMUDEV_CONF_MFN_CONSOLE,     console_mfn);
+    xenner_set_config(EMUDEV_CONF_MFN_XENSTORE,    xenstore_mfn);
+    xenner_set_config(EMUDEV_CONF_PFN_START_INFO,  start_info_pfn);
+    xenner_set_config(EMUDEV_CONF_PFN_INIT_PT,     init_pt_pfn);
+    xenner_set_config(EMUDEV_CONF_PFN_MFN_LIST,    mfn_list_pfn);
+    xenner_set_config(EMUDEV_CONF_PV_VIRT_ENTRY,   dom_params.virt_entry);
+    xenner_set_config(EMUDEV_CONF_PV_VIRT_BASE,    dom_params.virt_base);
+    xenner_set_config(EMUDEV_CONF_HYPERCALL_PAGE,  dom_params.virt_hypercall);
+
+    xenner_set_config(EMUDEV_CONF_DEBUG_LEVEL,      0);
+    xenner_set_config(EMUDEV_CONF_EMU_START_PFN,    mfn_emu);
+    xenner_set_config(EMUDEV_CONF_EMU_PAGE_COUNT,   pg_emu);
+    xenner_set_config(EMUDEV_CONF_M2P_START_PFN,    mfn_m2p);
+    xenner_set_config(EMUDEV_CONF_M2P_PAGE_COUNT,   pg_m2p);
+    xenner_set_config(EMUDEV_CONF_GUEST_START_PFN,  mfn_guest);
+    xenner_set_config(EMUDEV_CONF_TOTAL_PAGE_COUNT, pg_total);
+    xenner_set_config(EMUDEV_CONF_GUEST_PAGE_COUNT, pg_guest);
+    xenner_set_config(EMUDEV_CONF_NR_VCPUS,         smp_cpus);
+
+    xenner_set_config(EMUDEV_CONF_INITRD_LEN,       initrd_len);
+    xenner_set_config(EMUDEV_CONF_PFN_CMDLINE,      cmdline_pfn);
+
+    /* guest setup */
+
+    console_evtchn  = xenner_guest_evtchn_alloc();
+    xenstore_evtchn = xenner_guest_evtchn_alloc();
+
+    xenner_set_config(EMUDEV_CONF_EVTCH_CONSOLE,    console_evtchn);
+    xenner_set_config(EMUDEV_CONF_EVTCH_XENSTORE,   xenstore_evtchn);
+
+    /* default frontent protocol */
+    if (long_mode) {
+        xen_protocol = XEN_IO_PROTO_ABI_X86_32;
+    } else {
+        xen_protocol = XEN_IO_PROTO_ABI_X86_32;
+    }
+
+    xenstore_domain_init1(kernel, initrd, cmdline);
+    xenstore_domain_init2(xenstore_evtchn,
+                          xenstore_mfn,
+                          console_evtchn,
+                          console_mfn);
+
+    xenner_guest_store_setup(xenstore_mfn,
+                             xenstore_evtchn);
+
+    qemu_register_reset(xenner_cpu_reset, NULL);
+    xenner_cpu_reset(NULL);
+
+    return 0;
+}
Signature · 1 line
1.6.0.2
#87 lore raw

[Qemu-devel] Re: [PATCH 35/40] xenner: Domain Builder

Quoted 9 lines · Alexander Graf

The traditional Xen way of loading a kernel and initial data structures into the guest's memory is by calling libxc functions. We want to be able to run without libxc dependencies though, so we need an alternative.

This patch implements a full domain builder for xenner. It loads the guest kernel, sets up basic memory layouts and saves everything off for the pv communication device between xenner and qemu.

What about 36 to 40? :)

Paolo

#88 lore raw

[Qemu-devel] Re: [PATCH 35/40] xenner: Domain Builder

Quoted 5 lines · Paolo Bonzini
Quoted 4 lines · Alexander Graf

The traditional Xen way of loading a kernel and initial data structures into the guest's memory is by calling libxc functions. We want to be able to run without libxc dependencies though, so we need an alternative.

Quoted 7 lines
Quoted 5 lines

This patch implements a full domain builder for xenner. It loads the guest kernel, sets up basic memory layouts and saves everything off for the pv communication device between xenner and qemu.

What about 36 to 40? :)

What about them? :) Didn't they make it to the ML?

Alex

#89 lore raw

[Qemu-devel] Re: [PATCH 35/40] xenner: Domain Builder

Quoted 12 lines · Alexander Graf
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Alexander Graf

The traditional Xen way of loading a kernel and initial data structures into the guest's memory is by calling libxc functions. We want to be able to run without libxc dependencies though, so we need an alternative.

This patch implements a full domain builder for xenner. It loads the guest kernel, sets up basic memory layouts and saves everything off for the pv communication device between xenner and qemu.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

What about 36 to 40? :)

What about them? :) Didn't they make it to the ML?

http://patchwork.ozlabs.org/project/qemu-devel/list/ seems to agree with me they didn't. :)

Paolo

#90 lore raw

[Qemu-devel] Re: [PATCH 35/40] xenner: Domain Builder

Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Alexander Graf
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Alexander Graf

The traditional Xen way of loading a kernel and initial data structures into the guest's memory is by calling libxc functions. We want to be able to run without libxc dependencies though, so we need an alternative.

This patch implements a full domain builder for xenner. It loads the guest kernel, sets up basic memory layouts and saves everything off for the pv communication device between xenner and qemu.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

What about 36 to 40? :)

What about them? :) Didn't they make it to the ML?

http://patchwork.ozlabs.org/project/qemu-devel/list/ seems to agree with me they didn't. :)

Alright, I resent 36-40 with the (hopefully) correct reply-to header :). The binary blob mail just bounced though, apparently it's too big. So for that, please grab it from my git tree :).

Alex

#91 lore raw
In reply to Alexander Graf
Quoted 17 lines · Alexander Graf

Some of you might remember Gerd's xenner project. The basic motivation is to run Xen PV guests in KVM with the normal KVM architecture.

In order to achieve this, Xenner contains of two pieces:

1) Xenner Qemu pieces
2) Xenner guest kernel

Part 1 is partially in qemu already. The xen support framework that Gerd pushed a while back can be used just as well for xenner. Some parts like a special PV device to communicate with xenner and, mechanisms to instantiate a VM and replacements for xen infrastructure are provided in patches here.

Part 2 is a completely self-contained piece of code. The xenner guest kernel runs in the VM's CPL0 context. It translates guest hypercalls to hardware calls that KVM implements, like CR3 modifications or LAPIC accesses.

Quoted 7 lines

This patch set tries to revive Gerd's code by integrating as much as possible into the qemu code base. My ultimate goal is to isolate the qemu xenner code well enough to be able to run an i386 xen pv guest with tcg on powerpc.

I'm sending this set out in the hope to receive feedback. Do you think this is a good idea? Can you spot some glitches in the code that I overlooked? See the list below for things I'm aware of to be broken.

I forgot to mention the git repo this is also available at:

git://repo.or.cz/qemu/agraf.git xenner-v0

That makes it a lot easier to try out :).

Alex

#92 lore raw

PATCH 36/40 xen: only create dummy env when necessary

In reply to Alexander Graf

For native Xen machines, we need to create a dummy env so qemu always has something to work on.

When using xenner however, we don't want that dummy env but create real envs instead.

---
 hw/xen_machine_pv.c |   22 ++++++++++++++--------
 1 files changed, 14 insertions(+), 8 deletions(-)
hw/xen_machine_pv.c +14 -8
index b94d6e9..6f2666d 100644
@@ -30,16 +30,9 @@
 #include "xen_domainbuild.h"
 #include "blockdev.h"
 
-static void xen_init_pv(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)
+static void create_dummy_env(const char *cpu_model)
 {
     CPUState *env;
-    DriveInfo *dinfo;
-    int i;
 
     /* Initialize a dummy CPU */
     if (cpu_model == NULL) {
@@ -51,6 +44,17 @@ static void xen_init_pv(ram_addr_t ram_size,
     }
     env = cpu_init(cpu_model);
     env->halted = 1;
+}
+
+static void xen_init_pv(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)
+{
+    DriveInfo *dinfo;
+    int i;
 
     /* Initialize backend core & drivers */
     if (xen_be_init() != 0) {
@@ -60,9 +64,11 @@ static void xen_init_pv(ram_addr_t ram_size,
 
     switch (xen_mode) {
     case XEN_ATTACH:
+        create_dummy_env(cpu_model);
         /* nothing to do, xend handles everything */
         break;
     case XEN_CREATE:
+        create_dummy_env(cpu_model);
         if (xen_domain_build_pv(kernel_filename, initrd_filename,
                                 kernel_cmdline) < 0) {
             fprintf(stderr, "xen pv domain creation failed\n");
Signature · 1 line
1.6.0.2
#93 lore raw

PATCH 38/40 xenner: integrate into build system

In reply to Alexander Graf

Now that we have all the pieces in place, let's integrate into the build system.

---
 Makefile        |    6 ++++++
 Makefile.target |   16 ++++++++++++++--
 configure       |   21 +++++++++++++++++++--
 3 files changed, 39 insertions(+), 4 deletions(-)
Makefile +6 -0
index 3df202c..17b10bf 100644
@@ -96,6 +96,12 @@ recurse-all: $(SUBDIR_RULES) $(ROMSUBDIR_RULES)
 
 audio/audio.o audio/fmodaudio.o: QEMU_CFLAGS += $(FMOD_CFLAGS)
 
+# xen backend driver support (shared by xen+xenner)
+ifneq ($(CONFIG_XEN)$(CONFIG_XENNER),)
+  obj-y += xen_backend.o xen_devconfig.o
+  obj-y += xen_console.o xenfb.o xen_disk.o xen_nic.o
+endif
+
 QEMU_CFLAGS+=$(CURL_CFLAGS)
 
 ui/cocoa.o: ui/cocoa.m
Makefile.target +14 -2
index c48cbcc..9dc97b6 100644
@@ -182,8 +182,20 @@ QEMU_CFLAGS += $(VNC_SASL_CFLAGS)
 QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
 QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
 
-# xen backend driver support
-obj-$(CONFIG_XEN) += xen_machine_pv.o xen_domainbuild.o
+# xen bits shared by xenner+xen
+ifneq ($(CONFIG_XEN)$(CONFIG_XENNER),)
+  obj-y += xen_machine_pv.o xen_interfaces.o
+endif
+
+# xen support
+obj-$(CONFIG_XEN) += xen_domainbuild.o
+
+# xenner support
+obj-$(CONFIG_XENNER) += xenner_core.o xenner_emudev.o xenner_guest_store.o
+obj-$(CONFIG_XENNER) += xenner_pv.o
+obj-$(CONFIG_XENNER) += xenner_libxc_evtchn.o xenner_libxc_gnttab.o xenner_libxc_if.o
+obj-$(CONFIG_XENNER) += xenner_libxenstore.o
+obj-$(CONFIG_XENNER) += xenner_dom_builder.o
 
 # USB layer
 obj-$(CONFIG_USB_OHCI) += usb-ohci.o
configure +19 -2
index f62c1fe..4d08220 100755
@@ -285,6 +285,7 @@ vnc_jpeg=""
 vnc_png=""
 vnc_thread="no"
 xen=""
+xenner=""
 linux_aio=""
 attr=""
 vhost_net=""
@@ -632,6 +633,10 @@ for opt do
   ;;
   --enable-xen) xen="yes"
   ;;
+  --disable-xenner) xenner="no"
+  ;;
+  --enable-xenner) xenner="yes"
+  ;;
   --disable-brlapi) brlapi="no"
   ;;
   --enable-brlapi) brlapi="yes"
@@ -868,6 +873,8 @@ echo "                           (affects only QEMU, not qemu-img)"
 echo "  --enable-mixemu          enable mixer emulation"
 echo "  --disable-xen            disable xen backend driver support"
 echo "  --enable-xen             enable xen backend driver support"
+echo "  --disable-xenner         disable xenner (xen emulation) support"
+echo "  --enable-xenner          enable xenner (xen emulation) support"
 echo "  --disable-brlapi         disable BrlAPI"
 echo "  --enable-brlapi          enable BrlAPI"
 echo "  --disable-vnc-tls        disable TLS encryption for VNC server"
@@ -1134,9 +1141,10 @@ else
 fi
 
 ##########################################
-# xen probe
+# probe for xen libs and includes
+# note: xenner included here for now as it needs the headers too.
 
-if test "$xen" != "no" ; then
+if test "$xen" != "no" -o "$xenner" != "no"; then
   xen_libs="-lxenstore -lxenctrl -lxenguest"
   cat > $TMPC <<EOF
 #include <xenctrl.h>
@@ -1145,12 +1153,17 @@ int main(void) { xs_daemon_open(); xc_interface_open(); return 0; }
 EOF
   if compile_prog "" "$xen_libs" ; then
     xen=yes
+    xenner=yes
     libs_softmmu="$xen_libs $libs_softmmu"
   else
     if test "$xen" = "yes" ; then
       feature_not_found "xen"
     fi
+    if test "$xenner" = "yes" ; then
+      feature_not_found "xenner"
+    fi
     xen=no
+    xenner=no
   fi
 fi
 
@@ -2314,6 +2327,7 @@ if test -n "$sparc_cpu"; then
     echo "Target Sparc Arch $sparc_cpu"
 fi
 echo "xen support       $xen"
+echo "xenner support    $xenner"
 echo "brlapi support    $brlapi"
 echo "bluez  support    $bluez"
 echo "Documentation     $docs"
@@ -2886,6 +2900,9 @@ case "$target_arch2" in
     if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then
       echo "CONFIG_XEN=y" >> $config_target_mak
     fi
+    if test "$xenner" = "yes" -a "$target_softmmu" = "yes" ; then
+      echo "CONFIG_XENNER=y" >> $config_target_mak
+    fi
 esac
 case "$target_arch2" in
   i386|x86_64|ppcemb|ppc|ppc64|s390x)
Signature · 1 line
1.6.0.2
#94 lore raw

PATCH 39/40 xenner: integrate into xen pv machine

In reply to Alexander Graf

For native Xen support, we already have a xen machine description. This one doesn't really know too much about xenner yet though, so we need to teach it.

This patch adds support for xenner in the xen pv machine description.

---
 hw/xen_backend.h    |    1 +
 hw/xen_machine_pv.c |   16 ++++++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)
hw/xen_backend.h +1 -0
index f53a742..f6fc5f3 100644
@@ -2,6 +2,7 @@
 #define QEMU_HW_XEN_BACKEND_H 1
 
 #include "xen_common.h"
+#include "xen_redirect.h"
 #include "sysemu.h"
 #include "net.h"
 #include "qdev.h"
hw/xen_machine_pv.c +14 -2
index 6f2666d..6611011 100644
@@ -29,6 +29,7 @@
 #include "xen_backend.h"
 #include "xen_domainbuild.h"
 #include "blockdev.h"
+#include "xenner.h"
 
 static void create_dummy_env(const char *cpu_model)
 {
@@ -57,12 +58,14 @@ static void xen_init_pv(ram_addr_t ram_size,
     int i;
 
     /* Initialize backend core & drivers */
+    xen_interfaces_init();
     if (xen_be_init() != 0) {
         fprintf(stderr, "%s: xen backend core setup failed\n", __FUNCTION__);
         exit(1);
     }
 
     switch (xen_mode) {
+#ifdef CONFIG_XEN
     case XEN_ATTACH:
         create_dummy_env(cpu_model);
         /* nothing to do, xend handles everything */
@@ -75,9 +78,18 @@ static void xen_init_pv(ram_addr_t ram_size,
             exit(1);
         }
         break;
+#endif
+#ifdef CONFIG_XENNER
     case XEN_EMULATE:
-        fprintf(stderr, "xen emulation not implemented (yet)\n");
-        exit(1);
+        if (xenner_init_pv(kernel_filename, kernel_cmdline,
+                           initrd_filename) < 0) {
+            fprintf(stderr, "xenner pv domain creation failed\n");
+            exit(1);
+        }
+        break;
+#endif
+    default:
+        /* not reached, xen_interfaces_init() catches this already */
         break;
     }
 
Signature · 1 line
1.6.0.2
#95 lore raw

PATCH 40/40 xen: add sysrq support

In reply to Alexander Graf

Sending sys-requests on Xen is different from the usual keyboard based ways. For xen, we need to add a xenstored node which the guest pulls the sysrq information from.

This patch implements said interface by introducing a new human monitor command to use it. It's purely optional.

---
 hmp-commands.hx      |   24 ++++++++++++++++++++++++
 hw/xen.h             |    2 ++
 hw/xen_domainbuild.c |    8 ++++++++
 monitor.c            |    8 ++++++++
 4 files changed, 42 insertions(+), 0 deletions(-)
hmp-commands.hx +24 -0
index 81999aa..40fdd00 100644
@@ -436,6 +436,30 @@ This command is useful to send keys that your graphical user interface
 intercepts at low level, such as @code{ctrl-alt-f1} in X Window.
 ETEXI
 
+#if defined(CONFIG_XEN) || defined(CONFIG_XENNER)
+    {
+        .name       = "xen_sysrq",
+        .args_type  = "string:s",
+        .params     = "key",
+        .help       = "send sysrq to the Xen VM",
+        .mhandler.cmd = do_xen_sysrq,
+    },
+#endif
+
+STEXI
+@item xen_sysrq @var{key}
+@findex xen_sysrq
+
+Send @var{key} as sys-request to the Xen VM. This is the equivalent to
+alt-print-@var{key} in normal Linux guests. Example:
+@example
+xen_sysrq s
+@end example
+
+Please keep in mind that this is the only way of sending sys-requests to
+Xen PV machines. The usual alt-print-@var{key} way does not work.
+ETEXI
+
     {
         .name       = "system_reset",
         .args_type  = "",
hw/xen.h +2 -0
index 780dcf7..f2ac576 100644
@@ -18,4 +18,6 @@ enum xen_mode {
 extern uint32_t xen_domid;
 extern enum xen_mode xen_mode;
 
+void xen_sysrq(const char *sysrq);
+
 #endif /* QEMU_HW_XEN_H */
hw/xen_domainbuild.c +8 -0
index 7f1fd66..49962db 100644
@@ -211,6 +211,14 @@ static int xen_domain_watcher(void)
     _exit(0);
 }
 
+void xen_sysrq(const char *sysrq)
+{
+    void *dom;
+
+    dom = xs_get_domain_path(xenstore, xen_domid);
+    xenstore_write_str(dom, "control/sysrq", sysrq);
+}
+
 /* normal cleanup */
 static void xen_domain_cleanup(void)
 {
monitor.c +8 -0
index 61607c5..99aae01 100644
@@ -30,6 +30,7 @@
 #include "hw/pci.h"
 #include "hw/watchdog.h"
 #include "hw/loader.h"
+#include "hw/xen.h"
 #include "gdbstub.h"
 #include "net.h"
 #include "net/slirp.h"
@@ -1639,6 +1640,13 @@ static void release_keys(void *opaque)
     }
 }
 
+#if defined(CONFIG_XEN) || defined(CONFIG_XENNER)
+static void do_xen_sysrq(Monitor *mon, const QDict *qdict)
+{
+    xen_sysrq(strdup(qdict_get_str(qdict, "string")));
+}
+#endif
+
 static void do_sendkey(Monitor *mon, const QDict *qdict)
 {
     char keyname_buf[16];
Signature · 1 line
1.6.0.2