s390x/kvm: add support to change the IPL device in guest
cover s390x/kvm: add support to change the IPL device in guest
Cornelia, Alex, Christian,
these patches add support to chane the IPL device from within the guest.
Jens
Fan Zhang (4):
s390x/ipl: always load the bios for ccw machine s390x/ipl: support diagnose 308 subcodes 5 and 6 s390x/ipl: drop reipl parameters on resets s390x/ipl: make s390x ipl device aware of migration
hw/s390x/ipl.c | 233 +++++++++++++++++++++++++++++++++------------ hw/s390x/ipl.h | 25 +++++ hw/s390x/s390-virtio-ccw.c | 2 +- hw/s390x/s390-virtio.c | 8 +- hw/s390x/s390-virtio.h | 3 +- target-s390x/kvm.c | 3 +- target-s390x/misc_helper.c | 33 ++++++- 7 files changed, 240 insertions(+), 67 deletions(-) create mode 100644 hw/s390x/ipl.h
Signature · 1 line
2.1.4
PATCH 1/4 s390x/ipl: always load the bios for ccw machine
From: Fan Zhang <[email protected]>
We will need bios support in order to be able to support selecting a different boot device via diagnose 308 in the ccw machine, so let's make the bios mandatory for the ccw machine.
--- hw/s390x/ipl.c | 105 +++++++++++++++++++++++++-------------------- hw/s390x/s390-virtio-ccw.c | 2 +- hw/s390x/s390-virtio.c | 6 ++- hw/s390x/s390-virtio.h | 3 +- 4 files changed, 66 insertions(+), 50 deletions(-)
hw/s390x/ipl.c +59 -46
@@ -50,6 +50,8 @@ typedef struct S390IPLState {/*< private >*/ SysBusDevice parent_obj;uint64_t start_addr; +uint64_t bios_start_addr; +bool enforce_bios;/*< public >*/ char *kernel;
@@ -65,11 +67,14 @@ static int s390_ipl_init(SysBusDevice *dev)uint64_t pentry =KERN_IMAGE_START ;int kernel_size; -if (!ipl->kernel) { -int bios_size; -char *bios_filename; +int bios_size; +char *bios_filename; -/* Load zipl bootloader */ +/* +* Always load the bios if it was enforced, +* even if an external kernel has been defined. +*/ +if (!ipl->kernel || ipl->enforce_bios) {if (bios_name ==NULL ) { bios_name = ipl->firmware; }
@@ -79,12 +84,12 @@ static int s390_ipl_init(SysBusDevice *dev)hw_error ("could not find stage1 bootloader\n" ); } - bios_size =load_elf (bios_filename,NULL ,NULL , &ipl->start_addr,NULL , -NULL ,1 ,ELF_MACHINE ,0 ); + bios_size =load_elf (bios_filename,NULL ,NULL , &ipl->bios_start_addr, +NULL ,NULL ,1 ,ELF_MACHINE ,0 );if (bios_size <0 ) { bios_size =load_image_targphys (bios_filename,ZIPL_IMAGE_START ,4096 ); - ipl->start_addr =ZIPL_IMAGE_START ; + ipl->bios_start_addr =ZIPL_IMAGE_START ;if (bios_size >4096 ) {hw_error ("stage1 bootloader is > 4k\n" ); }
@@ -94,52 +99,59 @@ static int s390_ipl_init(SysBusDevice *dev)if (bios_size ==-1 ) {hw_error ("could not load bootloader '%s'\n" , bios_name); } -return 0 ; - } - kernel_size =load_elf (ipl->kernel,NULL ,NULL , &pentry,NULL , -NULL ,1 ,ELF_MACHINE ,0 ); -if (kernel_size <0 ) { - kernel_size =load_image_targphys (ipl->kernel,0 , ram_size); - } -if (kernel_size <0 ) { -fprintf (stderr,"could not load kernel '%s'\n" , ipl->kernel); -return -1 ; - } -/* -* Is it a Linux kernel (starting at 0x10000)? If yes, we fill in the -* kernel parameters here as well. Note: For old kernels (up to 3.2) -* we can not rely on the ELF entry point - it was 0x800 (the SALIPL -* loader) and it won't work. For this case we force it to 0x10000, too. -*/ -if (pentry ==KERN_IMAGE_START || pentry ==0x800 ) { - ipl->start_addr =KERN_IMAGE_START ; -/* Overwrite parameters in the kernel image, which are "rom" */ -strcpy (rom_ptr (KERN_PARM_AREA ), ipl->cmdline); - }else { - ipl->start_addr = pentry; +/* default boot target is the bios */ + ipl->start_addr = ipl->bios_start_addr; } -if (ipl->initrd) { -ram_addr_t initrd_offset; -int initrd_size; - - initrd_offset =INITRD_START ; -while (kernel_size +0x100000 > initrd_offset) { - initrd_offset +=0x100000 ; +if (ipl->kernel) { + kernel_size =load_elf (ipl->kernel,NULL ,NULL , &pentry,NULL , +NULL ,1 ,ELF_MACHINE ,0 ); +if (kernel_size <0 ) { + kernel_size =load_image_targphys (ipl->kernel,0 , ram_size); + } +if (kernel_size <0 ) { +fprintf (stderr,"could not load kernel '%s'\n" , ipl->kernel); +return -1 ; } - initrd_size =load_image_targphys (ipl->initrd, initrd_offset, - ram_size - initrd_offset); -if (initrd_size ==-1 ) { -fprintf (stderr,"qemu: could not load initrd '%s'\n" , ipl->initrd); -exit (1 ); +/* +* Is it a Linux kernel (starting at 0x10000)? If yes, we fill in the +* kernel parameters here as well. Note: For old kernels (up to 3.2) +* we can not rely on the ELF entry point - it was 0x800 (the SALIPL +* loader) and it won't work. For this case we force it to 0x10000, too. +*/ +if (pentry ==KERN_IMAGE_START || pentry ==0x800 ) { + ipl->start_addr =KERN_IMAGE_START ; +/* Overwrite parameters in the kernel image, which are "rom" */ +strcpy (rom_ptr (KERN_PARM_AREA ), ipl->cmdline); + }else { + ipl->start_addr = pentry; } -/* we have to overwrite values in the kernel image, which are "rom" */ -stq_p (rom_ptr (INITRD_PARM_START ), initrd_offset); -stq_p (rom_ptr (INITRD_PARM_SIZE ), initrd_size); - } +if (ipl->initrd) { +ram_addr_t initrd_offset; +int initrd_size; + + initrd_offset =INITRD_START ; +while (kernel_size +0x100000 > initrd_offset) { + initrd_offset +=0x100000 ; + } + initrd_size =load_image_targphys (ipl->initrd, initrd_offset, + ram_size - initrd_offset); +if (initrd_size ==-1 ) { +fprintf (stderr,"qemu: could not load initrd '%s'\n" , + ipl->initrd); +exit (1 ); + } +/* +* we have to overwrite values in the kernel image, +* which are "rom" +*/ +stq_p (rom_ptr (INITRD_PARM_START ), initrd_offset); +stq_p (rom_ptr (INITRD_PARM_SIZE ), initrd_size); + } + }return 0 ; }
@@ -148,6 +160,7 @@ static Property s390_ipl_properties[] = {DEFINE_PROP_STRING ("initrd" , S390IPLState, initrd),DEFINE_PROP_STRING ("cmdline" , S390IPLState, cmdline),DEFINE_PROP_STRING ("firmware" , S390IPLState, firmware), +DEFINE_PROP_BOOL ("enforce_bios" , S390IPLState, enforce_bios, false), DEFINE_PROP_END_OF_LIST(), };
hw/s390x/s390-virtio-ccw.c +1 -1
@@ -126,7 +126,7 @@ static void ccw_init(MachineState *machine) css_bus =virtual_css_bus_init ();s390_sclp_init ();s390_init_ipl_dev (machine->kernel_filename, machine->kernel_cmdline, - machine->initrd_filename,"s390-ccw.img" ); + machine->initrd_filename,"s390-ccw.img" , true);s390_flic_init (); dev =qdev_create (NULL ,TYPE_S390_PCI_HOST_BRIDGE );
hw/s390x/s390-virtio.c +4 -2
@@ -128,7 +128,8 @@ static void s390_virtio_register_hcalls(void)void s390_init_ipl_dev (const char *kernel_filename,const char *kernel_cmdline,const char *initrd_filename, -const char *firmware) +const char *firmware, +bool enforce_bios) {DeviceState *dev;
@@ -141,6 +142,7 @@ void s390_init_ipl_dev(const char *kernel_filename, }qdev_prop_set_string (dev,"cmdline" , kernel_cmdline);qdev_prop_set_string (dev,"firmware" , firmware); +qdev_prop_set_bit (dev,"enforce_bios" , enforce_bios);qdev_init_nofail (dev); }
@@ -221,7 +223,7 @@ static void s390_init(MachineState *machine) s390_bus =s390_virtio_bus_init (&my_ram_size);s390_sclp_init ();s390_init_ipl_dev (machine->kernel_filename, machine->kernel_cmdline, - machine->initrd_filename,ZIPL_FILENAME ); + machine->initrd_filename,ZIPL_FILENAME , false);s390_flic_init ();/* register hypercalls */
hw/s390x/s390-virtio.h +2 -1
@@ -26,7 +26,8 @@ void s390_init_cpus(const char *cpu_model, uint8_t *storage_keys);void s390_init_ipl_dev (const char *kernel_filename,const char *kernel_cmdline,const char *initrd_filename, -const char *firmware); +const char *firmware, +bool enforce_bios);void s390_create_virtio_net (BusState *bus,const char *name);void s390_nmi (NMIState *n,int cpu_index,Error **errp);#endif
Signature · 1 line
2.1.4
PATCH 2/4 s390x/ipl: support diagnose 308 subcodes 5 and 6
In reply to Jens FreimannFrom: Fan Zhang <[email protected]>
To support dynamically updating the IPL device from inside the KVM guest on the s390 platform, DIAG 308 instruction is intercepted in QEMU to handle the request.
Subcode 5 allows to specify a new boot device, which is saved for later in the s390_ipl device. This also allows to switch from an external kernel to a boot device.
Subcode 6 retrieves boot device configuration that has been previously set.
--- hw/s390x/ipl.c | 87 ++++++++++++++++++++++++++++++++++++++-------- hw/s390x/ipl.h | 24 +++++++++++++ hw/s390x/s390-virtio.c | 2 ++ target-s390x/misc_helper.c | 33 ++++++++++++++++-- 4 files changed, 129 insertions(+), 17 deletions(-) create mode 100644 hw/s390x/ipl.h
hw/s390x/ipl.c +72 -15
@@ -18,6 +18,7 @@#include "hw/sysbus.h" #include "hw/s390x/virtio-ccw.h" #include "hw/s390x/css.h" +#include "ipl.h" #define KERN_IMAGE_START 0x010000UL#define KERN_PARM_AREA 0x010480UL
@@ -52,12 +53,17 @@ typedef struct S390IPLState {uint64_t start_addr;uint64_t bios_start_addr;bool enforce_bios; +IplParameterBlock iplb; +bool iplb_valid;/*< public >*/ char *kernel;char *initrd;char *cmdline;char *firmware; +uint8_t cssid; +uint8_t ssid; +uint16_t devno; } S390IPLState;
@@ -164,6 +170,69 @@ static Property s390_ipl_properties[] = { DEFINE_PROP_END_OF_LIST(), }; +/* +* In addition to updating the iplstate, this function returns: +* - 0 if system was ipled with external kernel +* - -1 if no valid boot device was found +* - ccw id of the boot device otherwise +*/ +static uint64_t s390_update_iplstate (CPUS390XState *env,S390IPLState *ipl) +{ +DeviceState *dev_st; + +if (ipl->iplb_valid) { + ipl->cssid =0 ; + ipl->ssid =0 ; + ipl->devno = ipl->iplb.devno; + goto out; + } + +if (ipl->kernel) { +return 0 ; + } + + dev_st =get_boot_device (0 ); +if (dev_st) { +VirtioCcwDevice *ccw_dev = (VirtioCcwDevice *)object_dynamic_cast ( +OBJECT (qdev_get_parent_bus (dev_st)->parent), +TYPE_VIRTIO_CCW_DEVICE ); +if (ccw_dev) { + ipl->cssid = ccw_dev->sch->cssid; + ipl->ssid = ccw_dev->sch->ssid; + ipl->devno = ccw_dev->sch->devno; + goto out; + } + } + +return -1 ; +out: +return ipl->cssid <<24 | ipl->ssid <<16 | ipl->devno; +} + +int s390_ipl_update_diag308 (IplParameterBlock *iplb) +{ +S390IPLState *ipl; + + ipl =S390_IPL (object_resolve_path (TYPE_S390_IPL ,NULL )); +if (ipl) { + ipl->iplb = *iplb; + ipl->iplb_valid = true; +return 0 ; + } +return -1 ; +} + +IplParameterBlock *s390_ipl_get_iplb (void ) +{ +S390IPLState *ipl; + + ipl =S390_IPL (object_resolve_path (TYPE_S390_IPL ,NULL )); +if (!ipl || !ipl->iplb_valid) { +return NULL ; + } +return &ipl->iplb; +} +static void s390_ipl_reset (DeviceState *dev) {S390IPLState *ipl =S390_IPL (dev);
@@ -173,21 +242,9 @@ static void s390_ipl_reset(DeviceState *dev) env->psw.addr = ipl->start_addr; env->psw.mask =IPL_PSW_MASK ; -if (!ipl->kernel) { -/* Tell firmware, if there is a preferred boot device */ - env->regs[7 ] =-1 ; -DeviceState *dev_st =get_boot_device (0 ); -if (dev_st) { -VirtioCcwDevice *ccw_dev = (VirtioCcwDevice *)object_dynamic_cast ( -OBJECT (qdev_get_parent_bus (dev_st)->parent), -TYPE_VIRTIO_CCW_DEVICE ); - -if (ccw_dev) { - env->regs[7 ] = ccw_dev->sch->cssid <<24 | - ccw_dev->sch->ssid <<16 | - ccw_dev->sch->devno; - } - } +if (!ipl->kernel || ipl->iplb_valid) { + env->psw.addr = ipl->bios_start_addr; + env->regs[7 ] =s390_update_iplstate (env, ipl); }s390_cpu_set_state (CPU_STATE_OPERATING , cpu);
hw/s390x/ipl.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* s390 IPL device +* +* Copyright 2015 IBM Corp. +* Author(s): Zhang Fan <[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 HW_S390_IPL_H +#define HW_S390_IPL_H + +typedef struct IplParameterBlock { +uint8_t reserved1[110 ]; +uint16_t devno; +uint8_t reserved2[88 ]; +}IplParameterBlock ; + +int s390_ipl_update_diag308 (IplParameterBlock *iplb); +IplParameterBlock *s390_ipl_get_iplb (void ); + +#endif
hw/s390x/s390-virtio.c +2 -0
@@ -143,6 +143,8 @@ void s390_init_ipl_dev(const char *kernel_filename,qdev_prop_set_string (dev,"cmdline" , kernel_cmdline);qdev_prop_set_string (dev,"firmware" , firmware);qdev_prop_set_bit (dev,"enforce_bios" , enforce_bios); +object_property_add_child (qdev_get_machine (),"s390-ipl" , +OBJECT (dev),NULL );qdev_init_nofail (dev); }
target-s390x/misc_helper.c +31 -2
@@ -25,6 +25,7 @@#include <string.h> #include "sysemu/kvm.h" #include "qemu/timer.h" +#include "exec/address-spaces.h" #ifdef CONFIG_KVM #include <linux/kvm.h> #endif
@@ -34,6 +35,7 @@#include "sysemu/cpus.h" #include "sysemu/sysemu.h" #include "hw/s390x/ebcdic.h" +#include "hw/s390x/ipl.h" #endif /* #define DEBUG_HELPER */
@@ -151,12 +153,15 @@ static int load_normal_reset(S390CPU *cpu)return 0 ; } +#define DIAG_308_RC_OK 0x0001#define DIAG_308_RC_NO_CONF 0x0102#define DIAG_308_RC_INVALID 0x0402 +void handle_diag_308 (CPUS390XState *env,uint64_t r1,uint64_t r3) {uint64_t addr = env->regs[r1];uint64_t subcode = env->regs[r3]; +IplParameterBlock *iplb;if (env->psw.mask &PSW_MASK_PSTATE ) {program_interrupt (env,PGM_PRIVILEGED ,ILEN_LATER_INC );
@@ -180,14 +185,38 @@ void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3)program_interrupt (env,PGM_SPECIFICATION ,ILEN_LATER_INC );return ; } - env->regs[r1+1 ] =DIAG_308_RC_INVALID ; +if (!address_space_access_valid (&address_space_memory, addr, +sizeof (IplParameterBlock), false)) { +program_interrupt (env,PGM_ADDRESSING ,ILEN_LATER_INC ); +return ; + } + iplb =g_malloc0 (sizeof (struct IplParameterBlock )); +cpu_physical_memory_read (addr, iplb,sizeof (struct IplParameterBlock )); +if (!s390_ipl_update_diag308 (iplb)) { + env->regs[r1 +1 ] =DIAG_308_RC_OK ; + }else { + env->regs[r1 +1 ] =DIAG_308_RC_INVALID ; + } +g_free (iplb);return ;case 6 :if ((r1 &1 ) || (addr &0x0fffULL )) {program_interrupt (env,PGM_SPECIFICATION ,ILEN_LATER_INC );return ; } - env->regs[r1+1 ] =DIAG_308_RC_NO_CONF ; +if (!address_space_access_valid (&address_space_memory, addr, +sizeof (IplParameterBlock), true)) { +program_interrupt (env,PGM_ADDRESSING ,ILEN_LATER_INC ); +return ; + } + iplb =s390_ipl_get_iplb (); +if (iplb) { +cpu_physical_memory_write (addr, iplb, +sizeof (struct IplParameterBlock )); + env->regs[r1 +1 ] =DIAG_308_RC_OK ; + }else { + env->regs[r1 +1 ] =DIAG_308_RC_NO_CONF ; + }return ;default :hw_error ("Unhandled diag308 subcode %" PRIx64, subcode);
Signature · 1 line
2.1.4
PATCH 3/4 s390x/ipl: drop reipl parameters on resets
In reply to Jens FreimannFrom: Fan Zhang <[email protected]>
Whenever a reboot initiated by the guest is done, the reipl parameters should remain valid. The disk configured by the guest is to be used for ipl'ing. External reboot/reset request (e.g. via virsh reset guest) should completely reset the guest to the initial state, and therefore also reset the reipl parameters, resulting in an ipl behaviour of the initially configured guest. This could be an external kernel or a disk.
--- hw/s390x/ipl.c | 15 +++++++++++++++ hw/s390x/ipl.h | 1 + target-s390x/kvm.c | 3 ++- 3 files changed, 18 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +15 -0
@@ -55,6 +55,7 @@ typedef struct S390IPLState {bool enforce_bios;IplParameterBlock iplb;bool iplb_valid; +bool reipl_requested;/*< public >*/ char *kernel;
@@ -233,6 +234,15 @@ IplParameterBlock *s390_ipl_get_iplb(void)return &ipl->iplb; } +void s390_reipl_request (void ) +{ +S390IPLState *ipl; + + ipl =S390_IPL (object_resolve_path (TYPE_S390_IPL ,NULL )); + ipl->reipl_requested = true; +qemu_system_reset_request (); +} +static void s390_ipl_reset (DeviceState *dev) {S390IPLState *ipl =S390_IPL (dev);
@@ -242,6 +252,11 @@ static void s390_ipl_reset(DeviceState *dev) env->psw.addr = ipl->start_addr; env->psw.mask =IPL_PSW_MASK ; +if (!ipl->reipl_requested) { + ipl->iplb_valid = false; + } + ipl->reipl_requested = false; +if (!ipl->kernel || ipl->iplb_valid) { env->psw.addr = ipl->bios_start_addr; env->regs[7 ] =s390_update_iplstate (env, ipl);
hw/s390x/ipl.h +1 -0
@@ -20,5 +20,6 @@ typedef struct IplParameterBlock {int s390_ipl_update_diag308 (IplParameterBlock *iplb);IplParameterBlock *s390_ipl_get_iplb (void ); +void s390_reipl_request (void );#endif
target-s390x/kvm.c +2 -1
@@ -42,6 +42,7 @@#include "qapi-event.h" #include "hw/s390x/s390-pci-inst.h" #include "hw/s390x/s390-pci-bus.h" +#include "hw/s390x/ipl.h" /* #define DEBUG_KVM */
@@ -1397,7 +1398,7 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) ret =handle_intercept (cpu);break ;case KVM_EXIT_S390_RESET : -qemu_system_reset_request (); +s390_reipl_request ();break ;case KVM_EXIT_S390_TSCH : ret =handle_tsch (cpu);
Signature · 1 line
2.1.4
PATCH 4/4 s390x/ipl: make s390x ipl device aware of migration
In reply to Jens FreimannFrom: Fan Zhang <[email protected]>
We have to migrate the reipl parameters, so a reboot on the migrated machine will behave just like on the origin. Otherwise, the reipl parameters configured by the guest would be lost.
--- hw/s390x/ipl.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
hw/s390x/ipl.c +28 -0
@@ -67,6 +67,33 @@ typedef struct S390IPLState {uint16_t devno; } S390IPLState; +static const VMStateDescription vmstate_iplb = { + .name ="ipl/iplb" , + .version_id =0 , + .minimum_version_id =0 , + .fields = (VMStateField []) { +VMSTATE_UINT8_ARRAY (reserved1, IplParameterBlock,110 ), +VMSTATE_UINT16 (devno, IplParameterBlock), +VMSTATE_UINT8_ARRAY (reserved2, IplParameterBlock,88 ), +VMSTATE_END_OF_LIST () + } +}; + +static const VMStateDescription vmstate_ipl = { + .name ="ipl" , + .version_id =0 , + .minimum_version_id =0 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (start_addr, S390IPLState), +VMSTATE_UINT64 (bios_start_addr, S390IPLState), +VMSTATE_STRUCT (iplb, S390IPLState,0 , vmstate_iplb, IplParameterBlock), +VMSTATE_BOOL (iplb_valid, S390IPLState), +VMSTATE_UINT8 (cssid, S390IPLState), +VMSTATE_UINT8 (ssid, S390IPLState), +VMSTATE_UINT16 (devno, S390IPLState), +VMSTATE_END_OF_LIST () + } +};static int s390_ipl_init (SysBusDevice *dev) {
@@ -273,6 +300,7 @@ static void s390_ipl_class_init(ObjectClass *klass, void *data) k->init = s390_ipl_init; dc->props = s390_ipl_properties; dc->reset = s390_ipl_reset; + dc->vmsd = &vmstate_ipl; }static const TypeInfo s390_ipl_info = {
Signature · 1 line
2.1.4
Am 12.02.2015 um 18:02 schrieb Jens Freimann:
Quoted 13 lines
Cornelia, Alex, Christian,
these patches add support to chane the IPL device from within the guest.
Jens
Fan Zhang (4):
s390x/ipl: always load the bios for ccw machine s390x/ipl: support diagnose 308 subcodes 5 and 6 s390x/ipl: drop reipl parameters on resets s390x/ipl: make s390x ipl device aware of migration
Quoted 10 lines
hw/s390x/ipl.c | 233 +++++++++++++++++++++++++++++++++------------ hw/s390x/ipl.h | 25 +++++ hw/s390x/s390-virtio-ccw.c | 2 +- hw/s390x/s390-virtio.c | 8 +- hw/s390x/s390-virtio.h | 3 +- target-s390x/kvm.c | 3 +- target-s390x/misc_helper.c | 33 ++++++- 7 files changed, 240 insertions(+), 67 deletions(-) create mode 100644 hw/s390x/ipl.h
Thanks
Tested and applied to s390/queue
- /sys/firmware/reipl/ works
- lsreipl works
- using a slightly fixed chreipl works
- data is keep during managedsave/restore
- switch from external kernel to disk also works