Skip to contentSkip to conversation

s390: ipl device and cpu reset handler

PATCH In review Jens Freimann 4 participants 15 messages Dec 7, 2012 – Dec 11, 2012

lore
Share & tools
lore
#0 lore raw

cover s390: ipl device and cpu reset handler

Hi Alex,

some s390 patches dealing with ipl device, CPU reset and a bugfix:

Patch 1 fixes a bug that overwrites the standard kernel command line Patch 2 is an initial patch towards the previously discussed ipl device.
More patches will follow soon.
Patch 3 adds a cpu reset handler. With this patch and the ipl device
we can reboot on s390

Christian Borntraeger (2):
s390: Fix empty kernel command line
s390: Move IPL code into a separate device

Jens Freimann (1):
s390: add cpu reset handler

 hw/s390-virtio.c       |   32 +++----------------
 hw/s390x/Makefile.objs |    1 +
 hw/s390x/ipl.c         |   80 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/s390x/ipl.h         |   34 ++++++++++++++++++++
 target-s390x/cpu.c     |   25 +++++++++++++++
 target-s390x/kvm.c     |   10 +++++-
 6 files changed, 154 insertions(+), 28 deletions(-)
 create mode 100644 hw/s390x/ipl.c
 create mode 100644 hw/s390x/ipl.h
#1 lore raw

PATCH 1/3 s390: Fix empty kernel command line

From: Christian Borntraeger <[email protected]>

Since commit 967c0da73a7b0da186baba6632301d83644a570c
vl.c: Avoid segfault when started with no arguments

the user can specify a kernel without a command line. Lets not overwrite the default command line with \0 in that case.

---
 hw/s390-virtio.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/s390-virtio.c +1 -1
index ca1bb09..d77871a 100644
@@ -290,7 +290,7 @@ static void s390_init(QEMUMachineInitArgs *args)
         stq_p(rom_ptr(INITRD_PARM_SIZE), initrd_size);
     }
 
-    if (rom_ptr(KERN_PARM_AREA)) {
+    if (rom_ptr(KERN_PARM_AREA) && strlen(kernel_cmdline)) {
         /* we have to overwrite values in the kernel image, which are "rom" */
         memcpy(rom_ptr(KERN_PARM_AREA), kernel_cmdline,
                strlen(kernel_cmdline) + 1);
Signature · 1 line
1.7.1
#6 lore raw

PATCH 2/3 s390: Move IPL code into a separate device

In reply to Jens Freimann

From: Christian Borntraeger <[email protected]>

Lets move the code to setup IPL for external kernel or via the zipl rom into a separate file. This allows to

- define a reboot handler, setting up the PSW appropriately
- enhance the boot code to IPL disks that contain a bootmap that was created with zipl under LPAR or z/VM (see additional patch) and thus disabling the bios code that only works for specifically prepared disks.
- reuse that code for several machines (e.g. virtio-ccw and virtio-s390)

---
 hw/s390-virtio.c       |   30 ++---------------
 hw/s390x/Makefile.objs |    1 +
 hw/s390x/ipl.c         |   80 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/s390x/ipl.h         |   34 ++++++++++++++++++++
 4 files changed, 119 insertions(+), 26 deletions(-)
 create mode 100644 hw/s390x/ipl.c
 create mode 100644 hw/s390x/ipl.h
hw/s390-virtio.c +4 -26
index d77871a..10a5fd7 100644
@@ -33,6 +33,7 @@
 
 #include "hw/s390-virtio-bus.h"
 #include "hw/s390x/sclp.h"
+#include "hw/s390x/ipl.h"
 
 //#define DEBUG_S390
 
@@ -48,17 +49,6 @@
 #define KVM_S390_VIRTIO_RESET           1
 #define KVM_S390_VIRTIO_SET_STATUS      2
 
-#define KERN_IMAGE_START                0x010000UL
-#define KERN_PARM_AREA                  0x010480UL
-#define INITRD_START                    0x800000UL
-#define INITRD_PARM_START               0x010408UL
-#define INITRD_PARM_SIZE                0x010410UL
-#define PARMFILE_START                  0x001000UL
-
-#define ZIPL_START			0x009000UL
-#define ZIPL_LOAD_ADDR			0x009000UL
-#define ZIPL_FILENAME			"s390-zipl.rom"
-
 #define MAX_BLK_DEVS                    10
 
 static VirtIOS390Bus *s390_bus;
@@ -185,6 +175,7 @@ static void s390_init(QEMUMachineInitArgs *args)
     /* get a BUS */
     s390_bus = s390_virtio_bus_init(&my_ram_size);
     s390_sclp_init();
+    s390_ipl_init();
 
     /* allocate RAM */
     memory_region_init_ram(ram, "s390.ram", my_ram_size);
@@ -225,11 +216,7 @@ static void s390_init(QEMUMachineInitArgs *args)
         tmp_env->storage_keys = storage_keys;
     }
 
-    /* One CPU has to run */
-    s390_add_running_cpu(env);
-
     if (kernel_filename) {
-
         kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, NULL,
                                NULL, 1, ELF_MACHINE, 0);
         if (kernel_size == -1UL) {
@@ -240,13 +227,6 @@ static void s390_init(QEMUMachineInitArgs *args)
                     kernel_filename);
             exit(1);
         }
-        /*
-         * we can not rely on the ELF entry point, since up to 3.2 this
-         * value was 0x800 (the SALIPL loader) and it wont work. For
-         * all (Linux) cases 0x10000 (KERN_IMAGE_START) should be fine.
-         */
-        env->psw.addr = KERN_IMAGE_START;
-        env->psw.mask = 0x0000000180000000ULL;
     } else {
         ram_addr_t bios_size = 0;
         char *bios_filename;
@@ -257,7 +237,7 @@ static void s390_init(QEMUMachineInitArgs *args)
         }
 
         bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
-        bios_size = load_image_targphys(bios_filename, ZIPL_LOAD_ADDR, 4096);
+        bios_size = load_image_targphys(bios_filename, ZIPL_IMAGE_START, 4096);
         g_free(bios_filename);
 
         if ((long)bios_size < 0) {
@@ -267,9 +247,6 @@ static void s390_init(QEMUMachineInitArgs *args)
         if (bios_size > 4096) {
             hw_error("stage1 bootloader is > 4k\n");
         }
-
-        env->psw.addr = ZIPL_START;
-        env->psw.mask = 0x0000000180000000ULL;
     }
 
     if (initrd_filename) {
@@ -352,3 +329,4 @@ static void s390_machine_init(void)
 }
 
 machine_init(s390_machine_init);
+
hw/s390x/Makefile.objs +1 -0
index 096dfcd..4a5a5d8 100644
@@ -4,3 +4,4 @@ obj-y := $(addprefix ../,$(obj-y))
 obj-y += sclp.o
 obj-y += event-facility.o
 obj-y += sclpquiesce.o sclpconsole.o
+obj-y += ipl.o
hw/s390x/ipl.c new file +80 -0

80 lines not on this page · raw message

hw/s390x/ipl.h new file +34 -0
new file mode 100644
index 0000000..214abbc
@@ -0,0 +1,34 @@
+/*
+ * ipl support
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Christian Borntraeger <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at your
+ * option) any later version.  See the COPYING file in the top-level directory.
+ *
+ */
+
+
+#ifndef S390_IPL_H
+#define S390_IPL_H
+
+#define KERN_IMAGE_START                0x010000UL
+#define KERN_PARM_AREA                  0x010480UL
+#define INITRD_START                    0x800000UL
+#define INITRD_PARM_START               0x010408UL
+#define INITRD_PARM_SIZE                0x010410UL
+#define PARMFILE_START                  0x001000UL
+#define ZIPL_FILENAME                   "s390-zipl.rom"
+#define ZIPL_IMAGE_START                0x009000UL
+#define IPL_PSW_MASK                    0x0000000180000000ULL
+
+/* starts the first cpu with the given address and a default psw mask */
+void s390_ipl_cpu(uint64_t pswaddr);
+
+/* Initialize the ipl code */
+void s390_ipl_init(void);
+
+#endif //S390_IPL_H
Signature · 1 line
1.7.1
#12 lore raw

PATCH 3/3 s390: add cpu reset handler

In reply to Jens Freimann

Add a CPU reset handler to have all CPUs in a PoP compliant state.

---
 target-s390x/cpu.c |   25 +++++++++++++++++++++++++
 target-s390x/kvm.c |   10 +++++++++-
 2 files changed, 34 insertions(+), 1 deletions(-)
target-s390x/cpu.c +25 -0
index 619b202..a601380 100644
@@ -4,6 +4,7 @@
  * Copyright (c) 2009 Ulrich Hecht
  * Copyright (c) 2011 Alexander Graf
  * Copyright (c) 2012 SUSE LINUX Products GmbH
+ * Copyright (c) 2012 IBM Corp.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,12 +19,35 @@
  * 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/lgpl-2.1.html>
+ * Contributions after 2012-12-07 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
+ *
  */
 
 #include "cpu.h"
+#include "hw/hw.h"
 #include "qemu-common.h"
 #include "qemu-timer.h"
 
+/* TODO: remove me, when reset over QOM tree is implemented */
+static void s390_cpu_machine_reset_cb(void *opaque)
+{
+    S390CPU *cpu = opaque;
+    CPUS390XState *env = &cpu->env;
+
+    memset(env->regs, 0, sizeof(env->regs));
+    memset(env->aregs, 0, sizeof(env->aregs));
+    memset(env->cregs, 0, sizeof(env->cregs));
+    memset(env->fregs, 0, sizeof(env->fregs));
+    /* architectured initial values for CR 0 and 14 */
+    env->cregs[0] = 0xE0UL;
+    env->cregs[14] = 0xC2000000UL;
+    env->psw.addr = 0;
+    /* set to z/Architecture mode */
+    env->psw.mask = 0x0000000180000000ULL;
+    env->psa = 0;
+    s390_del_running_cpu(env);
+}
 
 /* CPUClass::reset() */
 static void s390_cpu_reset(CPUState *s)
@@ -56,6 +80,7 @@ static void s390_cpu_initfn(Object *obj)
 
     cpu_exec_init(env);
 #if !defined(CONFIG_USER_ONLY)
+    qemu_register_reset(s390_cpu_machine_reset_cb, cpu);
     qemu_get_timedate(&tm, 0);
     env->tod_offset = TOD_UNIX_EPOCH +
                       (time2tod(mktimegm(&tm)) * 1000000000ULL);
target-s390x/kvm.c +9 -1
index 94de764..3969a49 100644
@@ -85,7 +85,15 @@ int kvm_arch_init_vcpu(CPUS390XState *env)
 
 void kvm_arch_reset_vcpu(CPUS390XState *env)
 {
-    /* FIXME: add code to reset vcpu. */
+    /* The initial reset call is needed here to reset in-kernel
+     * vcpu data that we can't access directly from QEMU
+     * (i.e. with older kernels which don't support sync_regs/ONE_REG).
+     * Before this ioctl cpu_synchronize_state() is called in common kvm
+     * code (kvm-all) */
+    if (kvm_vcpu_ioctl(env, KVM_S390_INITIAL_RESET, NULL)) {
+        perror("Can't reset vcpu\n");
+    }
+
 }
 
 int kvm_arch_put_registers(CPUS390XState *env, int level)
Signature · 1 line
1.7.1
#9 lore raw

PATCH 2/2 s390: enable ipl device for virtio-ccw

In reply to Christian Borntraeger

In case of virtio-ccw we also want to get a disk by its device id.

---
 hw/s390x/ipl-disk.c |    5 +++++
 1 file changed, 5 insertions(+)
hw/s390x/ipl-disk.c +5 -0
index 1aab32b..6a83d9c 100644
@@ -21,6 +21,7 @@
 #include <sysemu.h>
 #include "hw/loader.h"
 #include "hw/s390-virtio-bus.h"
+#include "hw/s390x/virtio-ccw.h"
 #include "hw/sysbus.h"
 #include "hw/s390x/ipl.h"
 #include "hw/s390x/ipl-disk.h"
@@ -435,6 +436,10 @@ static VirtIOBlkConf *getVirtIOBlkConf(DeviceState *dev, const char *id)
         VirtIOS390Device *s390dev;
         s390dev = DO_UPCAST(VirtIOS390Device, qdev, dev);
         blk = &s390dev->blk;
+    } else if (strcmp(dev->parent_bus->name, "virtio-ccw") == 0) {
+        VirtioCcwData *ccwdev;
+        ccwdev = DO_UPCAST(VirtioCcwData, qdev, dev);
+        blk = &ccwdev->blk;
     } else {
         error_report("s390-ipl: device '%s' is not a virtio device",
                      id ? id : "0");
Signature · 1 line
1.7.10.1
#7 lore raw

cover ipl device followup

In reply to Jens Freimann

Alex,

here is were the IPL device code would move into. Some rough edges are still there, but it can ipl almost anything that was zipled under LPAR/VM.

Christian Borntraeger (2):
s390: Add bootmap parsing to ipl device
s390: enable ipl device for virtio-ccw

 hw/s390x/Makefile.objs |    2 +-
 hw/s390x/ipl-disk.c    |  504 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/s390x/ipl-disk.h    |  104 ++++++++++
 hw/s390x/ipl.c         |   51 ++++-
 4 files changed, 659 insertions(+), 2 deletions(-)
 create mode 100644 hw/s390x/ipl-disk.c
 create mode 100644 hw/s390x/ipl-disk.h
Signature · 1 line
1.7.10.1
#8 lore raw

PATCH 1/2 s390: Add bootmap parsing to ipl device

The zipl bios code only works for specially prepared disks. This adds parsing of the on disk bootmap of disks that are zipled with a zipl under LPAR/zVM. Since all bootmaps are pretty similar the code is written in a way to not only fcp bootmaps (which are architectured and
also parsed by the firmware on real boxes) but also
- dasd bootmaps for eckd and fba, with new and old versions of zipl
- any kind of block size 512,1024,2048,4096
- bootmaps created with the SLES11 zipl (those understood by the "bios")

To make the behaviour consistent with old code, we have two ipl devices. A default one (no_user) that just boots the kernel or the bios and one that can be specified by the user with -device s390-ipl that also allows to trigger the bootmap parsing.

---
 hw/s390x/Makefile.objs |    2 +-
 hw/s390x/ipl-disk.c    |  499 ++++++++++++++++++++++++++++++++++++++++++++++++
 hw/s390x/ipl-disk.h    |  104 ++++++++++
 hw/s390x/ipl.c         |   51 ++++-
 4 files changed, 654 insertions(+), 2 deletions(-)
 create mode 100644 hw/s390x/ipl-disk.c
 create mode 100644 hw/s390x/ipl-disk.h
hw/s390x/Makefile.objs +1 -1
index 4a5a5d8..a4a7c5a 100644
@@ -4,4 +4,4 @@ obj-y := $(addprefix ../,$(obj-y))
 obj-y += sclp.o
 obj-y += event-facility.o
 obj-y += sclpquiesce.o sclpconsole.o
-obj-y += ipl.o
+obj-y += ipl.o ipl-disk.o
hw/s390x/ipl-disk.c new file +499 -0

499 lines not on this page · raw message

hw/s390x/ipl-disk.h new file +104 -0

104 lines not on this page · raw message

hw/s390x/ipl.c +50 -1

95 lines not on this page · raw message

Signature · 1 line
1.7.10.1
#13 lore raw

Re: [Qemu-devel] [PATCH 3/3] s390: add cpu reset handler

In reply to Jens Freimann

Am 07.12.2012 14:55, schrieb Jens Freimann:

Quoted 44 lines

Add a CPU reset handler to have all CPUs in a PoP compliant state.

---
 target-s390x/cpu.c |   25 +++++++++++++++++++++++++
 target-s390x/kvm.c |   10 +++++++++-
 2 files changed, 34 insertions(+), 1 deletions(-)
target-s390x/cpu.c +14 -0
index 619b202..a601380 100644
@@ -4,6 +4,7 @@
  * Copyright (c) 2009 Ulrich Hecht
  * Copyright (c) 2011 Alexander Graf
  * Copyright (c) 2012 SUSE LINUX Products GmbH
+ * Copyright (c) 2012 IBM Corp.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,12 +19,35 @@
  * 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/lgpl-2.1.html>
+ * Contributions after 2012-12-07 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
+ *
  */
 
 #include "cpu.h"
+#include "hw/hw.h"
 #include "qemu-common.h"
 #include "qemu-timer.h"
 
+/* TODO: remove me, when reset over QOM tree is implemented */
+static void s390_cpu_machine_reset_cb(void *opaque)
+{
+    S390CPU *cpu = opaque;
+    CPUS390XState *env = &cpu->env;
+
+    memset(env->regs, 0, sizeof(env->regs));
+    memset(env->aregs, 0, sizeof(env->aregs));
+    memset(env->cregs, 0, sizeof(env->cregs));

target-s390x/cpu.c line 50

Quoted 10 lines
target-s390x/cpu.c +10 -0
+    memset(env->fregs, 0, sizeof(env->fregs));
+    /* architectured initial values for CR 0 and 14 */
+    env->cregs[0] = 0xE0UL;
+    env->cregs[14] = 0xC2000000UL;
+    env->psw.addr = 0;
+    /* set to z/Architecture mode */
+    env->psw.mask = 0x0000000180000000ULL;
+    env->psa = 0;
+    s390_del_running_cpu(env);
+}

What's the connection between lack of reset over QOM tree and not calling the existing s390_cpu_reset() from s390_cpu_machine_reset_cb()? Are some CPUS390XState fields maybe misplaced?

Regards,
Andreas

Quoted 33 lines
target-s390x/cpu.c +1 -0
 /* CPUClass::reset() */
 static void s390_cpu_reset(CPUState *s)
@@ -56,6 +80,7 @@ static void s390_cpu_initfn(Object *obj)
 
     cpu_exec_init(env);
 #if !defined(CONFIG_USER_ONLY)
+    qemu_register_reset(s390_cpu_machine_reset_cb, cpu);
     qemu_get_timedate(&tm, 0);
     env->tod_offset = TOD_UNIX_EPOCH +
                       (time2tod(mktimegm(&tm)) * 1000000000ULL);
target-s390x/kvm.c +9 -1
index 94de764..3969a49 100644
@@ -85,7 +85,15 @@ int kvm_arch_init_vcpu(CPUS390XState *env)
 
 void kvm_arch_reset_vcpu(CPUS390XState *env)
 {
-    /* FIXME: add code to reset vcpu. */
+    /* The initial reset call is needed here to reset in-kernel
+     * vcpu data that we can't access directly from QEMU
+     * (i.e. with older kernels which don't support sync_regs/ONE_REG).
+     * Before this ioctl cpu_synchronize_state() is called in common kvm
+     * code (kvm-all) */
+    if (kvm_vcpu_ioctl(env, KVM_S390_INITIAL_RESET, NULL)) {
+        perror("Can't reset vcpu\n");
+    }
+
 }
 
 int kvm_arch_put_registers(CPUS390XState *env, int level)
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#14 lore raw

Re: [Qemu-devel] [PATCH 3/3] s390: add cpu reset handler

Quoted 51 lines · Andreas Färber

Am 07.12.2012 14:55, schrieb Jens Freimann:

Quoted 50 lines

Add a CPU reset handler to have all CPUs in a PoP compliant state.

---
 target-s390x/cpu.c |   25 +++++++++++++++++++++++++
 target-s390x/kvm.c |   10 +++++++++-
 2 files changed, 34 insertions(+), 1 deletions(-)
target-s390x/cpu.c +20 -0
index 619b202..a601380 100644
@@ -4,6 +4,7 @@
  * Copyright (c) 2009 Ulrich Hecht
  * Copyright (c) 2011 Alexander Graf
  * Copyright (c) 2012 SUSE LINUX Products GmbH
+ * Copyright (c) 2012 IBM Corp.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,12 +19,35 @@
  * 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/lgpl-2.1.html>
+ * Contributions after 2012-12-07 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
+ *
  */
 
 #include "cpu.h"
+#include "hw/hw.h"
 #include "qemu-common.h"
 #include "qemu-timer.h"
 
+/* TODO: remove me, when reset over QOM tree is implemented */
+static void s390_cpu_machine_reset_cb(void *opaque)
+{
+    S390CPU *cpu = opaque;
+    CPUS390XState *env = &cpu->env;
+
+    memset(env->regs, 0, sizeof(env->regs));
+    memset(env->aregs, 0, sizeof(env->aregs));
+    memset(env->cregs, 0, sizeof(env->cregs));
+    memset(env->fregs, 0, sizeof(env->fregs));
+    /* architectured initial values for CR 0 and 14 */
+    env->cregs[0] = 0xE0UL;
+    env->cregs[14] = 0xC2000000UL;
+    env->psw.addr = 0;
+    /* set to z/Architecture mode */
Quoted 8 lines

target-s390x/cpu.c line 50

Quoted 4 lines
target-s390x/cpu.c +4 -0
+    env->psw.mask = 0x0000000180000000ULL;
+    env->psa = 0;
+    s390_del_running_cpu(env);
+}

What's the connection between lack of reset over QOM tree and not calling the existing s390_cpu_reset() from s390_cpu_machine_reset_cb()? Are some CPUS390XState fields maybe misplaced?

Thanks for the review!

Calling cpu_reset from s390_cpu_machine_reset() has an undesired side-effect. By setting env->halted to zero we decrement our running cpu counter too often. The way it is implemented in this patch, it works in all cases, i.e. guest-triggered reboot, system_reset qmp command as well as system halt.

But I agree that it's not obvious why we do it this way. The running_cpus counter complicates things. Maybe I can come up with a nicer solution...

Jens

Quoted 42 lines

Regards,
Andreas

Quoted 33 lines
target-s390x/cpu.c +1 -0
 /* CPUClass::reset() */
 static void s390_cpu_reset(CPUState *s)
@@ -56,6 +80,7 @@ static void s390_cpu_initfn(Object *obj)
 
     cpu_exec_init(env);
 #if !defined(CONFIG_USER_ONLY)
+    qemu_register_reset(s390_cpu_machine_reset_cb, cpu);
     qemu_get_timedate(&tm, 0);
     env->tod_offset = TOD_UNIX_EPOCH +
                       (time2tod(mktimegm(&tm)) * 1000000000ULL);
target-s390x/kvm.c +9 -1
index 94de764..3969a49 100644
@@ -85,7 +85,15 @@ int kvm_arch_init_vcpu(CPUS390XState *env)
 
 void kvm_arch_reset_vcpu(CPUS390XState *env)
 {
-    /* FIXME: add code to reset vcpu. */
+    /* The initial reset call is needed here to reset in-kernel
+     * vcpu data that we can't access directly from QEMU
+     * (i.e. with older kernels which don't support sync_regs/ONE_REG).
+     * Before this ioctl cpu_synchronize_state() is called in common kvm
+     * code (kvm-all) */
+    if (kvm_vcpu_ioctl(env, KVM_S390_INITIAL_RESET, NULL)) {
+        perror("Can't reset vcpu\n");
+    }
+
 }
 
 int kvm_arch_put_registers(CPUS390XState *env, int level)
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Signature · 19 lines
Mit freundlichen Grüßen / Kind regards 

Jens Freimann 

-- 
IBM Linux Technology Center / Boeblingen lab
IBM Systems &Technology Group, Systems Software Development
-------------------------------------------------------------
IBM Deutschland
Schoenaicher Str 220
71032 Boeblingen
Phone: +49-7031-16 x1122
E-Mail: [email protected]
-------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
#2 lore raw

Re: [Qemu-devel] [PATCH 1/3] s390: Fix empty kernel command line

In reply to Jens Freimann
Quoted 19 lines · Jens Freimann

From: Christian Borntraeger <[email protected]>

Since commit 967c0da73a7b0da186baba6632301d83644a570c
vl.c: Avoid segfault when started with no arguments

the user can specify a kernel without a command line. Lets not overwrite the default command line with \0 in that case.

---
hw/s390-virtio.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
hw/s390-virtio.c +0 -0
index ca1bb09..d77871a 100644

hw/s390-virtio.c static void s390_init(QEMUMachineInitArgs *args) · line 293

Quoted 5 lines
hw/s390-virtio.c +1 -1
@@ -290,7 +290,7 @@ static void s390_init(QEMUMachineInitArgs *args)
        stq_p(rom_ptr(INITRD_PARM_SIZE), initrd_size);
    }
 
-    if (rom_ptr(KERN_PARM_AREA)) {
+    if (rom_ptr(KERN_PARM_AREA) && strlen(kernel_cmdline)) {

why strlen()? If no -append option was passed, kernel_cmdline should be NULL. If -append "" was passed, the user wants to command line to be overwritten with "\0".

Alex

#11 lore raw

Re: [Qemu-devel] [PATCH 2/3] s390: Move IPL code into a separate device

In reply to Jens Freimann
Quoted 12 lines · Jens Freimann

From: Christian Borntraeger <[email protected]>

Lets move the code to setup IPL for external kernel or via the zipl rom into a separate file. This allows to

- define a reboot handler, setting up the PSW appropriately
- enhance the boot code to IPL disks that contain a bootmap that was created with zipl under LPAR or z/VM (see additional patch) and thus disabling the bios code that only works for specifically prepared disks.
- reuse that code for several machines (e.g. virtio-ccw and virtio-s390)

Quoted 2 lines

Creating a separate device sounds like a good idea, but please do so consistently. Please move everything that relates to booting into the device, including -kernel.

Also, I don't think we need a "-default" ipl device. Just create a generic ipl device that controls booting.

Alex

Quoted 235 lines

---

hw/s390-virtio.c       |   30 ++---------------
hw/s390x/Makefile.objs |    1 +
hw/s390x/ipl.c         |   80 ++++++++++++++++++++++++++++++++++++++++++++++++
hw/s390x/ipl.h         |   34 ++++++++++++++++++++
4 files changed, 119 insertions(+), 26 deletions(-)

create mode 100644 hw/s390x/ipl.c
create mode 100644 hw/s390x/ipl.h

hw/s390-virtio.c +4 -26
index d77871a..10a5fd7 100644
@@ -33,6 +33,7 @@
 
 #include "hw/s390-virtio-bus.h"
 #include "hw/s390x/sclp.h"
+#include "hw/s390x/ipl.h"
 
 //#define DEBUG_S390
 
@@ -48,17 +49,6 @@
 #define KVM_S390_VIRTIO_RESET           1
 #define KVM_S390_VIRTIO_SET_STATUS      2
 
-#define KERN_IMAGE_START                0x010000UL
-#define KERN_PARM_AREA                  0x010480UL
-#define INITRD_START                    0x800000UL
-#define INITRD_PARM_START               0x010408UL
-#define INITRD_PARM_SIZE                0x010410UL
-#define PARMFILE_START                  0x001000UL
-
-#define ZIPL_START			0x009000UL
-#define ZIPL_LOAD_ADDR			0x009000UL
-#define ZIPL_FILENAME			"s390-zipl.rom"
-
 #define MAX_BLK_DEVS                    10
 
 static VirtIOS390Bus *s390_bus;
@@ -185,6 +175,7 @@ static void s390_init(QEMUMachineInitArgs *args)
    /* get a BUS */
    s390_bus = s390_virtio_bus_init(&my_ram_size);
    s390_sclp_init();
+    s390_ipl_init();
 
    /* allocate RAM */
    memory_region_init_ram(ram, "s390.ram", my_ram_size);
@@ -225,11 +216,7 @@ static void s390_init(QEMUMachineInitArgs *args)
        tmp_env->storage_keys = storage_keys;
    }
 
-    /* One CPU has to run */
-    s390_add_running_cpu(env);
-
    if (kernel_filename) {
-
        kernel_size = load_elf(kernel_filename, NULL, NULL, NULL, NULL,
                               NULL, 1, ELF_MACHINE, 0);
        if (kernel_size == -1UL) {
@@ -240,13 +227,6 @@ static void s390_init(QEMUMachineInitArgs *args)
                    kernel_filename);
            exit(1);
        }
-        /*
-         * we can not rely on the ELF entry point, since up to 3.2 this
-         * value was 0x800 (the SALIPL loader) and it wont work. For
-         * all (Linux) cases 0x10000 (KERN_IMAGE_START) should be fine.
-         */
-        env->psw.addr = KERN_IMAGE_START;
-        env->psw.mask = 0x0000000180000000ULL;
    } else {
        ram_addr_t bios_size = 0;
        char *bios_filename;
@@ -257,7 +237,7 @@ static void s390_init(QEMUMachineInitArgs *args)
        }
 
        bios_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name);
-        bios_size = load_image_targphys(bios_filename, ZIPL_LOAD_ADDR, 4096);
+        bios_size = load_image_targphys(bios_filename, ZIPL_IMAGE_START, 4096);
        g_free(bios_filename);
 
        if ((long)bios_size < 0) {
@@ -267,9 +247,6 @@ static void s390_init(QEMUMachineInitArgs *args)
        if (bios_size > 4096) {
            hw_error("stage1 bootloader is > 4k\n");
        }
-
-        env->psw.addr = ZIPL_START;
-        env->psw.mask = 0x0000000180000000ULL;
    }
 
    if (initrd_filename) {
@@ -352,3 +329,4 @@ static void s390_machine_init(void)
 }
 
 machine_init(s390_machine_init);
+
hw/s390x/Makefile.objs +0 -0
index 096dfcd..4a5a5d8 100644
@@ -4,3 +4,4 @@ obj-y := $(addprefix ../,$(obj-y))

obj-y += sclp.o
obj-y += event-facility.o
obj-y += sclpquiesce.o sclpconsole.o

hw/s390x/Makefile.objs +1 -0
+obj-y += ipl.o
hw/s390x/ipl.c new file +80 -0
new file mode 100644
index 0000000..1736fca
@@ -0,0 +1,80 @@
+/*
+ * bootloader support
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Christian Borntraeger <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at your
+ * option) any later version.  See the COPYING file in the top-level directory.
+ *
+ */
+
+#include <sysemu.h>
+#include "cpu.h"
+#include "hw/loader.h"
+#include "hw/sysbus.h"
+#include "hw/s390x/ipl.h"
+
+void s390_ipl_cpu(uint64_t pswaddr)
+{
+    CPUS390XState *env = qemu_get_cpu(0);
+    env->psw.addr = pswaddr;
+    env->psw.mask = IPL_PSW_MASK;
+    s390_add_running_cpu(env);
+}
+
+static int s390_ipl_default_init(SysBusDevice *dev)
+{
+    return 0;
+}
+
+static Property s390_ipl_properties[] = {
+        DEFINE_PROP_END_OF_LIST(),
+};
+
+static void s390_ipl_reset(DeviceState *dev)
+{
+    if (rom_ptr(KERN_IMAGE_START)) {
+        /*
+         * we can not rely on the ELF entry point, since up to 3.2 this
+         * value was 0x800 (the SALIPL loader) and it wont work. For
+         * all (Linux) cases 0x10000 (KERN_IMAGE_START) should be fine.
+         */
+        return s390_ipl_cpu(KERN_IMAGE_START);
+    }
+    return s390_ipl_cpu(ZIPL_IMAGE_START);
+}
+
+static void s390_ipl_default_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = s390_ipl_default_init;
+    dc->props = s390_ipl_properties;
+    dc->reset = s390_ipl_reset;
+    dc->no_user = 1;
+}
+
+static TypeInfo s390_ipl_default_info = {
+    .class_init = s390_ipl_default_class_init,
+    .parent = TYPE_SYS_BUS_DEVICE,
+    .name  = "s390-ipl-default",
+};
+
+static void s390_register_ipl(void)
+{
+    type_register_static(&s390_ipl_default_info);
+}
+
+type_init(s390_register_ipl)
+
+void s390_ipl_init(void)
+{
+    DeviceState *dev  = qdev_create(NULL, "s390-ipl-default");
+    qdev_init_nofail(dev);
+}
+
+
hw/s390x/ipl.h new file +34 -0
new file mode 100644
index 0000000..214abbc
@@ -0,0 +1,34 @@
+/*
+ * ipl support
+ *
+ * Copyright IBM, Corp. 2012
+ *
+ * Authors:
+ *  Christian Borntraeger <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or (at your
+ * option) any later version.  See the COPYING file in the top-level directory.
+ *
+ */
+
+
+#ifndef S390_IPL_H
+#define S390_IPL_H
+
+#define KERN_IMAGE_START                0x010000UL
+#define KERN_PARM_AREA                  0x010480UL
+#define INITRD_START                    0x800000UL
+#define INITRD_PARM_START               0x010408UL
+#define INITRD_PARM_SIZE                0x010410UL
+#define PARMFILE_START                  0x001000UL
+#define ZIPL_FILENAME                   "s390-zipl.rom"
+#define ZIPL_IMAGE_START                0x009000UL
+#define IPL_PSW_MASK                    0x0000000180000000ULL
+
+/* starts the first cpu with the given address and a default psw mask */
+void s390_ipl_cpu(uint64_t pswaddr);
+
+/* Initialize the ipl code */
+void s390_ipl_init(void);
+
+#endif //S390_IPL_H
Signature · 1 line
1.7.1
#10 lore raw

Re: [Qemu-devel] [RFC/PATCH 0/2] ipl device followup

In reply to Christian Borntraeger
Quoted 4 lines · Christian Borntraeger

Alex,

here is were the IPL device code would move into. Some rough edges are still there, but it can ipl almost anything that was zipled under LPAR/VM.

Please try and check how nicely this can be done if we would map a firmware blob into the guest address space. I still believe that we can handle all boot strapping cases from within guest context.

The great advantage would be that we get user interaction and consistent device state. And less code that runs under host privileges.

Alex

#3 lore raw

Re: [Qemu-devel] [PATCH 1/3] s390: Fix empty kernel command line

In reply to Alexander Graf
Quoted 25 lines · Alexander Graf
Quoted 22 lines · Jens Freimann

From: Christian Borntraeger <[email protected]>

Since commit 967c0da73a7b0da186baba6632301d83644a570c
vl.c: Avoid segfault when started with no arguments

the user can specify a kernel without a command line. Lets not overwrite the default command line with \0 in that case.

---
hw/s390-virtio.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
hw/s390-virtio.c +0 -0
index ca1bb09..d77871a 100644
@@ -290,7 +290,7 @@ static void s390_init(QEMUMachineInitArgs *args)
        stq_p(rom_ptr(INITRD_PARM_SIZE), initrd_size);
    }
 
Quoted 4 lines

hw/s390-virtio.c static void s390_init(QEMUMachineInitArgs *args) · line 293

Quoted 2 lines
hw/s390-virtio.c +1 -1
-    if (rom_ptr(KERN_PARM_AREA)) {
+    if (rom_ptr(KERN_PARM_AREA) && strlen(kernel_cmdline)) {

why strlen()? If no -append option was passed, kernel_cmdline should be NULL. If -append "" was passed, the user wants to command line to be overwritten with "\0".

Nope. kernel_cmdline is always a valid pointer.

vl.c:

[..]

    if (!kernel_cmdline) {
        kernel_cmdline = "";
    }

[..]

#4 lore raw

Re: [Qemu-devel] [PATCH 1/3] s390: Fix empty kernel command line

Quoted 31 lines · Christian Borntraeger
Quoted 25 lines · Alexander Graf
Quoted 22 lines · Jens Freimann

From: Christian Borntraeger <[email protected]>

Since commit 967c0da73a7b0da186baba6632301d83644a570c
vl.c: Avoid segfault when started with no arguments

the user can specify a kernel without a command line. Lets not overwrite the default command line with \0 in that case.

---
hw/s390-virtio.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
hw/s390-virtio.c +0 -0
index ca1bb09..d77871a 100644
@@ -290,7 +290,7 @@ static void s390_init(QEMUMachineInitArgs *args)
       stq_p(rom_ptr(INITRD_PARM_SIZE), initrd_size);
   }
 
Quoted 4 lines

hw/s390-virtio.c static void s390_init(QEMUMachineInitArgs *args) · line 293

Quoted 2 lines
hw/s390-virtio.c +1 -1
-    if (rom_ptr(KERN_PARM_AREA)) {
+    if (rom_ptr(KERN_PARM_AREA) && strlen(kernel_cmdline)) {

why strlen()? If no -append option was passed, kernel_cmdline should be NULL. If -append "" was passed, the user wants to command line to be overwritten with "\0".

Quoted 8 lines

Nope. kernel_cmdline is always a valid pointer.

vl.c:

[..]

   if (!kernel_cmdline) {
       kernel_cmdline = "";

}

Then that's on purpose. Either we change the default for everyone or not at all. But checking for "" only in the s390 machine sounds off.

Alex

#5 lore raw

Re: [Qemu-devel] [PATCH 1/3] s390: Fix empty kernel command line

Quoted 36 lines · Alexander Graf
Quoted 33 lines · Christian Borntraeger
Quoted 25 lines · Alexander Graf
Quoted 22 lines · Jens Freimann

From: Christian Borntraeger <[email protected]>

Since commit 967c0da73a7b0da186baba6632301d83644a570c
vl.c: Avoid segfault when started with no arguments

the user can specify a kernel without a command line. Lets not overwrite the default command line with \0 in that case.

---
hw/s390-virtio.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
hw/s390-virtio.c +0 -0
index ca1bb09..d77871a 100644
@@ -290,7 +290,7 @@ static void s390_init(QEMUMachineInitArgs *args)
       stq_p(rom_ptr(INITRD_PARM_SIZE), initrd_size);
   }
 
Quoted 4 lines

hw/s390-virtio.c static void s390_init(QEMUMachineInitArgs *args) · line 293

Quoted 2 lines
hw/s390-virtio.c +1 -1
-    if (rom_ptr(KERN_PARM_AREA)) {
+    if (rom_ptr(KERN_PARM_AREA) && strlen(kernel_cmdline)) {

why strlen()? If no -append option was passed, kernel_cmdline should be NULL. If -append "" was passed, the user wants to command line to be overwritten with "\0".

Nope. kernel_cmdline is always a valid pointer.

Quoted 8 lines
Quoted 6 lines

vl.c:

[..]

   if (!kernel_cmdline) {
       kernel_cmdline = "";

}

Then that's on purpose. Either we change the default for everyone or not at all. But checking for "" only in the s390 machine sounds off.

Ok, makes sense.