Skip to contentSkip to conversation

S390x KVM support v2

PATCH In review Alexander Graf 4 participants 21 messages Oct 21, 2009 – Oct 22, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

cover S390x KVM support v2

While S390x was one of the first targets that were supported by KVM it always lacked qemu system emulation support.

In order to change that sad fact, I figured I'd just take on the task myself, taking kuli (http://www.ibm.com/developerworks/linux/linux390/kuli.html),
Documentation/s390/kvm.txt and lguest as starting points to write a clean, qemu'ish S390x Virtio machine emulation.

So now you can run Linux VMs on Linux on z/VM on LPAR on zSeries!

This is the resulting code. Please comment on things you like and also on the ones you don't :-).

The patchset is based on Uli's S390x userspace emulation patches. There's not really that much shared functionality, but I didn't want to reimplement the configure wheels. So make sure to have his patches applied first.

Please only run S390x system virtualization using io threads. S390x has very few intercepts and even less that actually reach userspace. So you'll end up with a non-responsive VM without a dedicated IO thread.

Use: $ ./configure --target-list=s390x-softmmu --enable-io-thread

Currently only -kernel, -initrd and friends work. Booting from a real dasd device is not supported.

Also to actually run this code you need a patch for an ugly bug in the kernel module that Carsten sent a patch to on the ML.

I verified that the userspace actually works on a 2.6.27 (SLES11) kernel, so if it doesn't work on current git, please tell me! I'm too afraid that I might end up in a 3270 terminal to update the kernel on my z/VM instance :-).

v1 -> v2:

- use new kvm_run variables
- use DO_UPCAST
- add bridge device for "info qtree"

Alexander Graf (9):
Export function for VA defined ram allocation
Add KVM support for S390x
Add support for S390x system emulation
Add S390x virtio machine bus
Add S390x virtio machine description
S390 GDB stub
Implement early printk in virtio-console
Set default console to virtio on S390x
Move mp_state to CPU_COMMON

 Makefile.target          |    2 +
 configure                |    4 +-
 cpu-common.h             |    1 +
 cpu-defs.h               |    1 +
 exec.c                   |   15 ++-
 gdbstub.c                |   52 ++++++
 hw/s390-virtio-bus.c     |  384 ++++++++++++++++++++++++++++++++++++++
 hw/s390-virtio-bus.h     |   64 +++++++
 hw/s390-virtio.c         |  244 ++++++++++++++++++++++++
 hw/virtio-console.c      |    7 +
 hw/virtio-console.h      |    2 +
 target-i386/cpu.h        |    1 -
 target-s390x/cpu.h       |   86 +++++++++-
 target-s390x/exec.h      |    5 +
 target-s390x/helper.c    |   26 +++-
 target-s390x/kvm.c       |  457 ++++++++++++++++++++++++++++++++++++++++++++++
 target-s390x/machine.c   |   30 +++
 target-s390x/op_helper.c |   53 ++++++
 vl.c                     |   26 +++
 19 files changed, 1452 insertions(+), 8 deletions(-)
 create mode 100644 hw/s390-virtio-bus.c
 create mode 100644 hw/s390-virtio-bus.h
 create mode 100644 hw/s390-virtio.c
 create mode 100644 target-s390x/kvm.c
 create mode 100644 target-s390x/machine.c
#1 lore raw

PATCH 1/9 Export function for VA defined ram allocation

S390 requires vmas for guests to be < 256 GB. So we need to directly export mmaps "try to use this vma as start address" feature to not accidently get over that limit.

---
 cpu-common.h |    1 +
 exec.c       |   15 +++++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)
cpu-common.h +1 -0
index 6302372..ecaf9e3 100644
@@ -30,6 +30,7 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr,
 
 ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr);
 ram_addr_t qemu_ram_alloc(ram_addr_t);
+ram_addr_t _qemu_ram_alloc(ram_addr_t size, void *map_at);
 void qemu_ram_free(ram_addr_t addr);
 /* This should only be used for ram local to a device.  */
 void *qemu_get_ram_ptr(ram_addr_t addr);
exec.c +13 -2
index 076d26b..36c26cd 100644
@@ -2404,14 +2404,20 @@ void qemu_unregister_coalesced_mmio(target_phys_addr_t addr, ram_addr_t size)
         kvm_uncoalesce_mmio_region(addr, size);
 }
 
-ram_addr_t qemu_ram_alloc(ram_addr_t size)
+ram_addr_t _qemu_ram_alloc(ram_addr_t size, void *map_at)
 {
     RAMBlock *new_block;
 
     size = TARGET_PAGE_ALIGN(size);
     new_block = qemu_malloc(sizeof(*new_block));
 
-    new_block->host = qemu_vmalloc(size);
+    if (map_at) {
+        new_block->host = mmap(map_at, size, PROT_EXEC|PROT_READ|PROT_WRITE,
+                               MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+
+    } else {
+        new_block->host = qemu_vmalloc(size);
+    }
 #ifdef MADV_MERGEABLE
     madvise(new_block->host, size, MADV_MERGEABLE);
 #endif
@@ -2434,6 +2440,11 @@ ram_addr_t qemu_ram_alloc(ram_addr_t size)
     return new_block->offset;
 }
 
+ram_addr_t qemu_ram_alloc(ram_addr_t size)
+{
+    return _qemu_ram_alloc(size, NULL);
+}
+
 void qemu_ram_free(ram_addr_t addr)
 {
     /* TODO: implement this.  */
Signature · 1 line
1.6.0.2
#2 lore raw

PATCH 2/9 Add KVM support for S390x

S390x was one of the first platforms that received support for KVM back in the day. Unfortunately until now there hasn't been a qemu implementation that would enable users to actually run guests.

So let's include support for KVM S390x in qemu!

---

v1 -> v2:

- use new generic psw fields in kvm_run

---
 configure          |    4 +-
 target-s390x/kvm.c |  457 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 460 insertions(+), 1 deletions(-)
 create mode 100644 target-s390x/kvm.c
configure +3 -1
index b93fc34..e81492a 100755
@@ -1342,6 +1342,8 @@ EOF
             kvm_cflags="$kvm_cflags -I$kerneldir/arch/x86/include"
 	elif test "$cpu" = "ppc" -a -d "$kerneldir/arch/powerpc/include" ; then
 	    kvm_cflags="$kvm_cflags -I$kerneldir/arch/powerpc/include"
+	elif test "$cpu" = "s390x" -a -d "$kerneldir/arch/s390/include" ; then
+	    kvm_cflags="$kvm_cflags -I$kerneldir/arch/s390/include"
         elif test -d "$kerneldir/arch/$cpu/include" ; then
             kvm_cflags="$kvm_cflags -I$kerneldir/arch/$cpu/include"
       fi
@@ -2306,7 +2308,7 @@ case "$target_arch2" in
     fi
 esac
 case "$target_arch2" in
-  i386|x86_64|ppcemb|ppc|ppc64)
+  i386|x86_64|ppcemb|ppc|ppc64|s390x)
     # Make sure the target and host cpus are compatible
     if test "$kvm" = "yes" -a "$target_softmmu" = "yes" -a \
       \( "$target_arch2" = "$cpu" -o \
target-s390x/kvm.c new file +457 -0

457 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#3 lore raw

PATCH 3/9 Add support for S390x system emulation

Right now only S390x Linux userspace emulation is supported. Let's enable the basics for system emulation so we can run virtual machines with KVM!

---
 target-s390x/cpu.h       |   86 ++++++++++++++++++++++++++++++++++++++++++++-
 target-s390x/exec.h      |    5 +++
 target-s390x/helper.c    |   26 +++++++++++++-
 target-s390x/machine.c   |   30 ++++++++++++++++
 target-s390x/op_helper.c |   53 ++++++++++++++++++++++++++++
 5 files changed, 196 insertions(+), 4 deletions(-)
 create mode 100644 target-s390x/machine.c
target-s390x/cpu.h +84 -2
index 93b09cd..c5ba7c3 100644
@@ -30,8 +30,7 @@
 
 #include "softfloat.h"
 
-#define NB_MMU_MODES 2 // guess
-#define MMU_USER_IDX 0 // guess
+#define NB_MMU_MODES 2
 
 typedef union FPReg {
     struct {
@@ -77,12 +76,28 @@ static inline void cpu_clone_regs(CPUState *env, target_ulong newsp)
 }
 #endif
 
+#define MMU_MODE0_SUFFIX _kernel
+#define MMU_MODE1_SUFFIX _user
+#define MMU_USER_IDX 1
+static inline int cpu_mmu_index (CPUState *env)
+{
+    /* XXX: Currently we don't implement virtual memory */
+    return 0;
+}
+
+
 CPUS390XState *cpu_s390x_init(const char *cpu_model);
 void s390x_translate_init(void);
 int cpu_s390x_exec(CPUS390XState *s);
 void cpu_s390x_close(CPUS390XState *s);
 void do_interrupt (CPUState *env);
 
+#ifndef CONFIG_USER_ONLY
+extern int s390_virtio_hypercall(CPUState *env);
+extern void kvm_s390_virtio_irq(CPUState *env, int config_change, uint64_t token);
+extern CPUState *s390_cpu_addr2state(uint16_t cpu_addr);
+#endif
+
 /* you can call this signal handler from your SIGBUS and SIGSEGV
    signal handlers to inform the virtual CPU of exceptions. non zero
    is returned if the signal was handled by the virtual CPU.  */
@@ -129,4 +144,71 @@ static inline void cpu_get_tb_cpu_state(CPUState* env, target_ulong *pc,
     *cs_base = 0;
     *flags = env->psw.mask; // guess
 }
+
+/* Program Status Word.  */
+#define S390_PSWM_REGNUM 0
+#define S390_PSWA_REGNUM 1
+/* General Purpose Registers.  */
+#define S390_R0_REGNUM 2
+#define S390_R1_REGNUM 3
+#define S390_R2_REGNUM 4
+#define S390_R3_REGNUM 5
+#define S390_R4_REGNUM 6
+#define S390_R5_REGNUM 7
+#define S390_R6_REGNUM 8
+#define S390_R7_REGNUM 9
+#define S390_R8_REGNUM 10
+#define S390_R9_REGNUM 11
+#define S390_R10_REGNUM 12
+#define S390_R11_REGNUM 13
+#define S390_R12_REGNUM 14
+#define S390_R13_REGNUM 15
+#define S390_R14_REGNUM 16
+#define S390_R15_REGNUM 17
+/* Access Registers.  */
+#define S390_A0_REGNUM 18
+#define S390_A1_REGNUM 19
+#define S390_A2_REGNUM 20
+#define S390_A3_REGNUM 21
+#define S390_A4_REGNUM 22
+#define S390_A5_REGNUM 23
+#define S390_A6_REGNUM 24
+#define S390_A7_REGNUM 25
+#define S390_A8_REGNUM 26
+#define S390_A9_REGNUM 27
+#define S390_A10_REGNUM 28
+#define S390_A11_REGNUM 29
+#define S390_A12_REGNUM 30
+#define S390_A13_REGNUM 31
+#define S390_A14_REGNUM 32
+#define S390_A15_REGNUM 33
+/* Floating Point Control Word.  */
+#define S390_FPC_REGNUM 34
+/* Floating Point Registers.  */
+#define S390_F0_REGNUM 35
+#define S390_F1_REGNUM 36
+#define S390_F2_REGNUM 37
+#define S390_F3_REGNUM 38
+#define S390_F4_REGNUM 39
+#define S390_F5_REGNUM 40
+#define S390_F6_REGNUM 41
+#define S390_F7_REGNUM 42
+#define S390_F8_REGNUM 43
+#define S390_F9_REGNUM 44
+#define S390_F10_REGNUM 45
+#define S390_F11_REGNUM 46
+#define S390_F12_REGNUM 47
+#define S390_F13_REGNUM 48
+#define S390_F14_REGNUM 49
+#define S390_F15_REGNUM 50
+/* Total.  */
+#define S390_NUM_REGS 51
+
+/* Pseudo registers -- PC and condition code.  */
+#define S390_PC_REGNUM S390_NUM_REGS
+#define S390_CC_REGNUM (S390_NUM_REGS+1)
+#define S390_NUM_PSEUDO_REGS 2
+#define S390_NUM_TOTAL_REGS (S390_NUM_REGS+2)
+
+
 #endif
target-s390x/exec.h +5 -0
index 5198359..13dc7dd 100644
@@ -22,9 +22,14 @@
 
 register struct CPUS390XState *env asm(AREG0);
 
+#include "config.h"
 #include "cpu.h"
 #include "exec-all.h"
 
+#if !defined(CONFIG_USER_ONLY)
+#include "softmmu_exec.h"
+#endif /* !defined(CONFIG_USER_ONLY) */
+
 static inline int cpu_has_work(CPUState *env)
 {
     return env->interrupt_request & CPU_INTERRUPT_HARD; // guess
target-s390x/helper.c +24 -2
index 5407c62..d98d603 100644
@@ -27,6 +27,9 @@
 #include "gdbstub.h"
 #include "qemu-common.h"
 
+#include <linux/kvm.h>
+#include "kvm.h"
+
 CPUS390XState *cpu_s390x_init(const char *cpu_model)
 {
     CPUS390XState *env;
@@ -61,13 +64,13 @@ int cpu_s390x_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
     return 1;
 }
 
+#endif /* CONFIG_USER_ONLY */
+
 target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
 {
     return addr;
 }
 
-#endif /* CONFIG_USER_ONLY */
-
 void cpu_reset(CPUS390XState *env)
 {
     if (qemu_loglevel_mask(CPU_LOG_RESET)) {
@@ -79,3 +82,22 @@ void cpu_reset(CPUS390XState *env)
     /* FIXME: reset vector? */
     tlb_flush(env, 1);
 }
+
+#ifndef CONFIG_USER_ONLY
+
+int cpu_s390x_handle_mmu_fault (CPUState *env, target_ulong address, int rw,
+                                int mmu_idx, int is_softmmu)
+{
+    target_ulong phys;
+    int prot;
+
+    /* XXX: implement mmu */
+
+    phys = address;
+    prot = PAGE_READ | PAGE_WRITE;
+
+    return tlb_set_page(env, address & TARGET_PAGE_MASK,
+                        phys & TARGET_PAGE_MASK, prot,
+                        mmu_idx, is_softmmu);
+}
+#endif /* CONFIG_USER_ONLY */
target-s390x/machine.c new file +30 -0
new file mode 100644
index 0000000..3e79be6
@@ -0,0 +1,30 @@
+/*
+ * QEMU S390x machine definitions
+ *
+ * Copyright (c) 2009 Alexander Graf <[email protected]>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "hw/hw.h"
+#include "hw/boards.h"
+
+void cpu_save(QEMUFile *f, void *opaque)
+{
+}
+
+int cpu_load(QEMUFile *f, void *opaque, int version_id)
+{
+    return 0;
+}
target-s390x/op_helper.c +53 -0

56 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#4 lore raw

PATCH 4/9 Add S390x virtio machine bus

On S390x we don't want to go through the hassle of emulating real existing hardware, because we don't need to for running Linux.

So let's instead implement a machine that is 100% based on VirtIO which we fortunately implement already.

This patch implements the bus that is the groundwork for such an S390x virtio machine.

---

v1 -> v2:

- use DO_UPCAST
- add bridge device for "info qtree"

---
 Makefile.target      |    2 +
 hw/s390-virtio-bus.c |  384 ++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/s390-virtio-bus.h |   64 +++++++++
 3 files changed, 450 insertions(+), 0 deletions(-)
 create mode 100644 hw/s390-virtio-bus.c
 create mode 100644 hw/s390-virtio-bus.h
Makefile.target +2 -0
index 8d146c5..ef72867 100644
@@ -294,6 +294,8 @@ obj-sh4-y += ide/core.o ide/mmio.o
 obj-m68k-y = an5206.o mcf5206.o mcf_uart.o mcf_intc.o mcf5208.o mcf_fec.o
 obj-m68k-y += m68k-semi.o dummy_m68k.o
 
+obj-s390x-y = s390-virtio-bus.o
+
 main.o vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
 vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
hw/s390-virtio-bus.c new file +384 -0

384 lines not on this page · raw message

hw/s390-virtio-bus.h new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#5 lore raw

PATCH 5/9 Add S390x virtio machine description

In order to use the new S390x virtio bus we just introduced, we also need a machine description that sets up the machine according to our PV specification.

Let's add that machine description and be happy!

---
 Makefile.target  |    2 +-
 hw/s390-virtio.c |  244 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 245 insertions(+), 1 deletions(-)
 create mode 100644 hw/s390-virtio.c
Makefile.target +1 -1
index ef72867..524be43 100644
@@ -294,7 +294,7 @@ obj-sh4-y += ide/core.o ide/mmio.o
 obj-m68k-y = an5206.o mcf5206.o mcf_uart.o mcf_intc.o mcf5208.o mcf_fec.o
 obj-m68k-y += m68k-semi.o dummy_m68k.o
 
-obj-s390x-y = s390-virtio-bus.o
+obj-s390x-y = s390-virtio-bus.o s390-virtio.o 
 
 main.o vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 
hw/s390-virtio.c new file +244 -0

244 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#6 lore raw

PATCH 6/9 S390 GDB stub

In order to debug funny kernel breakages it's always good to have a working gdb stub around.

While Uli's patches don't include one one, I needed one that's at least good enough for 'bt' and some variable examinations during early bootup.

So here it is - the absolute basics to get the qemu gdb stub running with s390x targets.

---
 gdbstub.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)
gdbstub.c +52 -0
index 315f606..49f6fe3 100644
@@ -1348,6 +1348,55 @@ static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n)
 
     return 8;
 }
+#elif defined (TARGET_S390X)
+
+#define NUM_CORE_REGS S390_NUM_TOTAL_REGS
+
+static int cpu_gdb_read_register(CPUState *env, uint8_t *mem_buf, int n)
+{
+    switch (n) {
+        case S390_PSWM_REGNUM: GET_REGL(env->psw.mask); break;
+        case S390_PSWA_REGNUM: GET_REGL(env->psw.addr); break;
+        case S390_R0_REGNUM ... S390_R15_REGNUM:
+            GET_REGL(env->regs[n-S390_R0_REGNUM]); break;
+        case S390_A0_REGNUM ... S390_A15_REGNUM:
+            GET_REG32(env->aregs[n-S390_A0_REGNUM]); break;
+        case S390_FPC_REGNUM: GET_REG32(env->fpc); break;
+        case S390_F0_REGNUM ... S390_F15_REGNUM:
+            /* XXX */
+            break;
+        case S390_PC_REGNUM: GET_REGL(env->psw.addr); break;
+        case S390_CC_REGNUM: GET_REG32(env->cc); break;
+    }
+
+    return 0;
+}
+
+static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n)
+{
+    target_ulong tmpl;
+    uint32_t tmp32;
+    int r = 8;
+    tmpl = ldtul_p(mem_buf);
+    tmp32 = ldl_p(mem_buf);
+
+    switch (n) {
+        case S390_PSWM_REGNUM: env->psw.mask = tmpl; break;
+        case S390_PSWA_REGNUM: env->psw.addr = tmpl; break;
+        case S390_R0_REGNUM ... S390_R15_REGNUM:
+            env->regs[n-S390_R0_REGNUM] = tmpl; break;
+        case S390_A0_REGNUM ... S390_A15_REGNUM:
+            env->aregs[n-S390_A0_REGNUM] = tmp32; r=4; break;
+        case S390_FPC_REGNUM: env->fpc = tmp32; r=4; break;
+        case S390_F0_REGNUM ... S390_F15_REGNUM:
+            /* XXX */
+            break;
+        case S390_PC_REGNUM: env->psw.addr = tmpl; break;
+        case S390_CC_REGNUM: env->cc = tmp32; r=4; break;
+    }
+
+    return r;
+}
 #else
 
 #define NUM_CORE_REGS 0
@@ -1616,6 +1665,9 @@ static void gdb_set_cpu_pc(GDBState *s, target_ulong pc)
     s->c_cpu->pc = pc;
 #elif defined (TARGET_ALPHA)
     s->c_cpu->pc = pc;
+#elif defined (TARGET_S390X)
+    cpu_synchronize_state(s->c_cpu);
+    s->c_cpu->psw.addr = pc;
 #endif
 }
 
Signature · 1 line
1.6.0.2
#7 lore raw

PATCH 7/9 Implement early printk in virtio-console

On our S390x Virtio machine we don't have anywhere to display early printks on, because we don't know about VGA or serial ports.

So instead we just forward everything to the virtio console that we created anyways.

---
 hw/virtio-console.c |    7 +++++++
 hw/virtio-console.h |    2 ++
 2 files changed, 9 insertions(+), 0 deletions(-)
hw/virtio-console.c +7 -0
index 57f8f89..cd6cf20 100644
@@ -105,6 +105,13 @@ static void vcon_event(void *opaque, int event)
     /* we will ignore any event for the time being */
 }
 
+void virtio_console_print_early(VirtIODevice *vdev, uint8_t *buf)
+{
+    VirtIOConsole *s = to_virtio_console(vdev);
+
+    qemu_chr_write(s->chr, buf, strlen((char*)buf));
+}
+
 static void virtio_console_save(QEMUFile *f, void *opaque)
 {
     VirtIOConsole *s = opaque;
hw/virtio-console.h +2 -0
index 84d0717..f3ccc3c 100644
@@ -16,4 +16,6 @@
 /* The ID for virtio console */
 #define VIRTIO_ID_CONSOLE 3
 
+void virtio_console_print_early(VirtIODevice *vdev, uint8_t *buf);
+
 #endif
Signature · 1 line
1.6.0.2
#8 lore raw

PATCH 8/9 Set default console to virtio on S390x

All "normal" system emulation targets in qemu I'm aware of display output on either VGA or serial output.

Our S390x virtio machine doesn't have such kind of legacy hardware. So instead we need to default to a virtio console.

I'm not particularly proud of this patch. It would be a lot better to have something in the machine description that tells us about the default terminal.

---
 vl.c |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
vl.c +26 -0
index eb2744e..e7f1504 100644
@@ -4818,6 +4818,20 @@ int main(int argc, char **argv, char **envp)
     cyls = heads = secs = 0;
     translation = BIOS_ATA_TRANSLATION_AUTO;
 
+#ifdef TARGET_S390X
+    for(i = 0; i < MAX_SERIAL_PORTS; i++)
+        serial_devices[i] = NULL;
+    serial_device_index = 0;
+
+    for(i = 0; i < MAX_PARALLEL_PORTS; i++)
+        parallel_devices[i] = NULL;
+    parallel_device_index = 0;
+
+    virtio_consoles[0] = "mon:stdio";
+    for(i = 1; i < MAX_VIRTIO_CONSOLES; i++)
+        virtio_consoles[i] = NULL;
+    virtio_console_index = 0;
+#else
     serial_devices[0] = "vc:80Cx24C";
     for(i = 1; i < MAX_SERIAL_PORTS; i++)
         serial_devices[i] = NULL;
@@ -4831,6 +4845,7 @@ int main(int argc, char **argv, char **envp)
     for(i = 0; i < MAX_VIRTIO_CONSOLES; i++)
         virtio_consoles[i] = NULL;
     virtio_console_index = 0;
+#endif
 
     monitor_devices[0] = "vc:80Cx24C";
     for (i = 1; i < MAX_MONITOR_DEVICES; i++) {
@@ -5709,6 +5724,17 @@ int main(int argc, char **argv, char **envp)
                 break;
             }
         }
+        for (i = 0; i < MAX_VIRTIO_CONSOLES; i++) {
+            const char *devname = virtio_consoles[i];
+            if (devname && !strcmp(devname,"mon:stdio")) {
+                monitor_devices[0] = NULL;
+                break;
+            } else if (devname && !strcmp(devname,"stdio")) {
+                monitor_devices[0] = NULL;
+                virtio_consoles[i] = "mon:stdio";
+                break;
+            }
+        }
     }
 
     if (nb_numa_nodes > 0) {
Signature · 1 line
1.6.0.2
#9 lore raw

PATCH 9/9 Move mp_state to CPU_COMMON

MP State is implemented in the generic code, so let's move the variable it accesses to generic code as well.

Still unbreaks PPC and now even S390x w/ KVM.

---
 cpu-defs.h        |    1 +
 target-i386/cpu.h |    1 -
 2 files changed, 1 insertions(+), 1 deletions(-)
cpu-defs.h +1 -0
index 95068b5..ad804e6 100644
@@ -197,6 +197,7 @@ typedef struct CPUWatchpoint {
     const char *cpu_model_str;                                          \
     struct KVMState *kvm_state;                                         \
     struct kvm_run *kvm_run;                                            \
+    uint32_t mp_state;                                                  \
     int kvm_fd;
 
 #endif
target-i386/cpu.h +0 -1
index 5929d28..8d0c2a9 100644
@@ -692,7 +692,6 @@ typedef struct CPUX86State {
 
     /* For KVM */
     uint64_t interrupt_bitmap[256 / 64];
-    uint32_t mp_state;
 
     /* in order to simplify APIC support, we leave this pointer to the
        user */
Signature · 1 line
1.6.0.2
#10 lore raw

Re: [Qemu-devel] [PATCH 1/9] Export function for VA defined ram allocation

In reply to Alexander Graf
Quoted 15 lines · Alexander Graf

S390 requires vmas for guests to be < 256 GB. So we need to directly export mmaps "try to use this vma as start address" feature to not accidently get over that limit.

---
 cpu-common.h |    1 +
 exec.c       |   15 +++++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)
cpu-common.h +0 -0
index 6302372..ecaf9e3 100644

cpu-common.h static inline void cpu_register_physical_memory(target_phys_addr_t start_addr, · line 34

Quoted 5 lines
cpu-common.h +1 -0
@@ -30,6 +30,7 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr,
 
 ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr);
 ram_addr_t qemu_ram_alloc(ram_addr_t);
+ram_addr_t _qemu_ram_alloc(ram_addr_t size, void *map_at);
 

I don't like this interface very much. Couldn't the fact that we need a va starting at 0 for s390 kvm be hidden behind the existing qemu_ram_alloc?

Regards,

Anthony Liguori

#11 lore raw

Re: [Qemu-devel] [PATCH 1/9] Export function for VA defined ram allocation

Quoted 11 lines · Anthony Liguori
Quoted 10 lines · Alexander Graf

S390 requires vmas for guests to be < 256 GB. So we need to directly export mmaps "try to use this vma as start address" feature to not accidently get over that limit.

---
cpu-common.h | 1 +
exec.c | 15 +++++++++++++--

2 files changed, 14 insertions(+), 2 deletions(-)
Quoted 12 lines

cpu-common.h static inline void cpu_register_physical_memory · line 34

Quoted 10 lines
cpu-common.h +1 -0
index 6302372..ecaf9e3 100644
@@ -30,6 +30,7 @@ static inline void cpu_register_physical_memory 
 (target_phys_addr_t start_addr,
 ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr);
 ram_addr_t qemu_ram_alloc(ram_addr_t);
+ram_addr_t _qemu_ram_alloc(ram_addr_t size, void *map_at);
 

I don't like this interface very much. Couldn't the fact that we need a va starting at 0 for s390 kvm be hidden behind the existing qemu_ram_alloc?

We don't need a va starting at 0. We need a max va ending < 256 GB.

Carsten did mention in a previous mail that he has getting rid of that limitation on his todo list, but for now that's what we have. As soon as the kvm module is updated to support arbitrary addresses we can just revert this patch and be happy.

For the time being all we need to check is that nobody else uses _qemu_ram_alloc, so we really can revert it safely then.

Alex

#12 lore raw

Re: [Qemu-devel] [PATCH 1/9] Export function for VA defined ram allocation

Quoted 27 lines · Alexander Graf
Quoted 11 lines · Anthony Liguori
Quoted 10 lines · Alexander Graf

S390 requires vmas for guests to be < 256 GB. So we need to directly export mmaps "try to use this vma as start address" feature to not accidently get over that limit.

---
cpu-common.h | 1 +
exec.c | 15 +++++++++++++--

2 files changed, 14 insertions(+), 2 deletions(-)
Quoted 12 lines

cpu-common.h static inline void · line 34

Quoted 10 lines
cpu-common.h +1 -0
index 6302372..ecaf9e3 100644
@@ -30,6 +30,7 @@ static inline void 
 cpu_register_physical_memory(target_phys_addr_t start_addr,
 ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr);
 ram_addr_t qemu_ram_alloc(ram_addr_t);
+ram_addr_t _qemu_ram_alloc(ram_addr_t size, void *map_at);
 

I don't like this interface very much. Couldn't the fact that we need a va starting at 0 for s390 kvm be hidden behind the existing qemu_ram_alloc?

Quoted 5 lines

We don't need a va starting at 0. We need a max va ending < 256 GB.

Carsten did mention in a previous mail that he has getting rid of that limitation on his todo list, but for now that's what we have. As soon as the kvm module is updated to support arbitrary addresses we can just revert this patch and be happy.

For the time being all we need to check is that nobody else uses _qemu_ram_alloc, so we really can revert it safely then.

Couldn't we just as easily put the check in qemu_ram_alloc under a TARGET_S390 && kvm_enabled()?

That's far better than introducing a function who's only name difference is an underscore.

Regards,

Anthony Liguori

Quoted 1 line

Alex

#13 lore raw

Re: [Qemu-devel] [PATCH 1/9] Export function for VA defined ram allocation

Quoted 30 lines · Anthony Liguori
Quoted 29 lines · Alexander Graf
Quoted 11 lines · Anthony Liguori
Quoted 10 lines · Alexander Graf

S390 requires vmas for guests to be < 256 GB. So we need to directly export mmaps "try to use this vma as start address" feature to not accidently get over that limit.

---
cpu-common.h | 1 +
exec.c | 15 +++++++++++++--

2 files changed, 14 insertions(+), 2 deletions(-)
Quoted 12 lines

cpu-common.h static inline void cpu_register_physical_memory · line 34

Quoted 10 lines
cpu-common.h +1 -0
index 6302372..ecaf9e3 100644
@@ -30,6 +30,7 @@ static inline void cpu_register_physical_memory 
 (target_phys_addr_t start_addr,
 ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr);
 ram_addr_t qemu_ram_alloc(ram_addr_t);
+ram_addr_t _qemu_ram_alloc(ram_addr_t size, void *map_at);
 

I don't like this interface very much. Couldn't the fact that we need a va starting at 0 for s390 kvm be hidden behind the existing qemu_ram_alloc?

We don't need a va starting at 0. We need a max va ending < 256 GB.

Quoted 7 lines
Quoted 3 lines

Carsten did mention in a previous mail that he has getting rid of that limitation on his todo list, but for now that's what we have. As soon as the kvm module is updated to support arbitrary addresses we can just revert this patch and be happy.

For the time being all we need to check is that nobody else uses _qemu_ram_alloc, so we really can revert it safely then.

Couldn't we just as easily put the check in qemu_ram_alloc under a TARGET_S390 && kvm_enabled()?

That's far better than introducing a function who's only name difference is an underscore.

So you would prefer a special #ifdef for s390 in generic code over a specifically for this purpose exported function?

Well, you're the boss. I like the special function better, but whatever you say.

Alex

#14 lore raw

Re: [Qemu-devel] [PATCH 1/9] Export function for VA defined ram allocation

Quoted 3 lines · Alexander Graf

So you would prefer a special #ifdef for s390 in generic code over a specifically for this purpose exported function?

Well, you're the boss. I like the special function better, but whatever you say.

How is someone supposed to figure out what _qemu_ram_alloc is for? Nothing in your patch really indicates that.

However, an ugly #ifdef immediately tells someone, oh, s390 kvm needs this terrible hack, so let's keep bugging those guys to eliminate the need for that.

Regards,

Anthony Liguori

Quoted 2 lines

Alex

#15 lore raw

Re: [Qemu-devel] [PATCH 1/9] Export function for VA defined ram allocation

Quoted 8 lines · Anthony Liguori
Quoted 3 lines · Alexander Graf

So you would prefer a special #ifdef for s390 in generic code over a specifically for this purpose exported function?

Well, you're the boss. I like the special function better, but whatever you say.

How is someone supposed to figure out what _qemu_ram_alloc is for? Nothing in your patch really indicates that.

However, an ugly #ifdef immediately tells someone, oh, s390 kvm needs this terrible hack, so let's keep bugging those guys to eliminate the need for that.

Alright :-). Any other complaints? If not I'd spin up v3.

Alex

#16 lore raw

Re: [Qemu-devel] [PATCH 1/9] Export function for VA defined ram allocation

Quoted 6 lines · Alexander Graf
Quoted 3 lines · Anthony Liguori
Quoted 2 lines · Alexander Graf

So you would prefer a special #ifdef for s390 in generic code over a specifically for this purpose exported function?

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Well, you're the boss. I like the special function better, but whatever you say.

How is someone supposed to figure out what _qemu_ram_alloc is for? Nothing in your patch really indicates that.

However, an ugly #ifdef immediately tells someone, oh, s390 kvm needs this terrible hack, so let's keep bugging those guys to eliminate the need for that.

Alright :-). Any other complaints? If not I'd spin up v3.

Nope.

Regards,

Anthony Liguori

Quoted 2 lines

Alex

#17 lore raw

[Qemu-devel] Re: [PATCH 1/9] Export function for VA defined ram allocation

In reply to Anthony Liguori
Quoted 7 lines · Anthony Liguori
Quoted 5 lines · Alexander Graf

So you would prefer a special #ifdef for s390 in generic code over a specifically for this purpose exported function?

Well, you're the boss. I like the special function better, but whatever you say.

Quoted 6 lines

How is someone supposed to figure out what _qemu_ram_alloc is for? Nothing in your patch really indicates that.

However, an ugly #ifdef immediately tells someone, oh, s390 kvm needs this terrible hack, so let's keep bugging those guys to eliminate the need for that.

What about this:

-ram_addr_t qemu_ram_alloc(ram_addr_t size) +ram_addr_t qemu_ram_alloc_at(ram_addr_t size, void *map_at)

 {
     RAMBlock *new_block;

     size = TARGET_PAGE_ALIGN(size);
     new_block = qemu_malloc(sizeof(*new_block));

- new_block->host = qemu_vmalloc(size);
+ if (map_at) {
+ new_block->host = map_at;
+ } else {
+ new_block->host = qemu_vmalloc(size);
+ }

 #ifdef MADV_MERGEABLE
     madvise(new_block->host, size, MADV_MERGEABLE);

#endif

and calling mmap where you're currently calling _qemu_ram_alloc?

Paolo

#18 lore raw

[Qemu-devel] Re: [PATCH 1/9] Export function for VA defined ram allocation

Quoted 20 lines · Paolo Bonzini

What about this:

(quoted diff) +6 -2
-ram_addr_t qemu_ram_alloc(ram_addr_t size)
+ram_addr_t qemu_ram_alloc_at(ram_addr_t size, void *map_at)
 {
     RAMBlock *new_block;
 
     size = TARGET_PAGE_ALIGN(size);
     new_block = qemu_malloc(sizeof(*new_block));
 
-    new_block->host = qemu_vmalloc(size);
+    if (map_at) {
+        new_block->host = map_at;
+    } else {
+        new_block->host = qemu_vmalloc(size);
+    }
 #ifdef MADV_MERGEABLE
     madvise(new_block->host, size, MADV_MERGEABLE);
 #endif
Quoted 1 line

and calling mmap where you're currently calling _qemu_ram_alloc?

I'm not sure. It's definitely better but I don't think we really want machines to decide whether their memory is allocated generally speaking. That's the advantage of hiding behind qemu_ram_alloc().

Another way to look at this is that it's roughly the same problem as qemu-kvm's -mem-path. -mem-path doesn't really address subregions though. In order to support shared memory regions, I think it necessary to be able to say something like, ram region XX..YY should be tied to this mmap()'d region. Either way, these operations should be transparent to the caller of qemu_ram_alloc().

I didn't want to suggest solving the larger problem because I didn't want to bog down an otherwise reasonable series.

Regards,

Anthony Liguori

Quoted 1 line

Paolo

#19 lore raw

Re: [Qemu-devel] [PATCH 1/9] Export function for VA defined ram allocation

In reply to Anthony Liguori
Quoted 1 line · Anthony Liguori

However, an ugly #ifdef immediately tells someone, oh, s390 kvm needs this terrible hack, so let's keep bugging those guys to eliminate the need for that.

/me moves cleaning up memslot handling a little further up the prio list. I fear it still won't make it to queue head in the near future, but I'll see what I can do.