s390x/ipl: Try to detect Linux vs non Linux for initial IPL PSW
PATCH v3 1/1 s390x/ipl: Try to detect Linux vs non Linux for initial IPL PSW
Right now the IPL device always starts from address 0x10000 (the usual Linux entry point). To run other guests (e.g. test programs) it is useful to use the IPL PSW from address 0. We can use the Linux magic at 0x10008 to decide.
---v2->v3:
- check for iplpsw to avoid assert on file errors
- use 4 bytes at 4 instead of 8 bytes at 0v1->v2:
- use LINUX_MAGIC_ADDR define
- use assert for valid iplpsw pointer
- add endianess conversion
hw/s390x/ipl.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +18 -1
@@ -29,6 +29,7 @@#include "exec/exec-all.h" #define KERN_IMAGE_START 0x010000UL +#define LINUX_MAGIC_ADDR 0x010008UL#define KERN_PARM_AREA 0x010480UL#define INITRD_START 0x800000UL#define INITRD_PARM_START 0x010408UL
@@ -105,7 +106,9 @@ static uint64_t bios_translate_addr(void *opaque, uint64_t srcaddr)static void s390_ipl_realize (DeviceState *dev,Error **errp) {S390IPLState *ipl =S390_IPL (dev); -uint64_t pentry =KERN_IMAGE_START ; +uint32_t *iplpsw; +uint64_t pentry; +char *magic;int kernel_size;Error *err =NULL ;
@@ -157,6 +160,20 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp) NULL, 1, EM_S390, 0, 0);if (kernel_size <0 ) { kernel_size =load_image_targphys (ipl->kernel,0 , ram_size); +/* if this is Linux use KERN_IMAGE_START */ + magic =rom_ptr (LINUX_MAGIC_ADDR ); +if (magic && !memcmp (magic,"S390EP" ,6 )) { + pentry =KERN_IMAGE_START ; + }else { +/* if not Linux use the IPL PSW */ + iplpsw =rom_ptr (4 ); +if (iplpsw) { + pentry =be32_to_cpu (*iplpsw) &0x7fffffffUL ; + }else { +error_setg (&err,"Could not get IPL PSW" ); + goto error; + } + } }if (kernel_size <0 ) {error_setg (&err,"could not load kernel '%s'" , ipl->kernel);
Signature · 1 line
2.17.0
Quoted 10 lines · Christian Borntraeger
Right now the IPL device always starts from address
0x10000(the usual Linux entry point). To run other guests (e.g. test programs) it is useful to use the IPL PSW from address 0. We can use the Linux magic at0x10008to decide.Signed-off-by Christian Borntraeger <[email protected]>---
v2->v3:
- check for iplpsw to avoid assert on file errors
- use 4 bytes at 4 instead of 8 bytes at 0
I trust you that this is the right thing to do :)
Quoted 52 lines
v1->v2:
- useLINUX_MAGIC_ADDRdefine
- use assert for valid iplpsw pointer
- add endianess conversionhw/s390x/ipl.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)hw/s390x/ipl.c +18
-1@@ -29,6 +29,7 @@#include "exec/exec-all.h" #define KERN_IMAGE_START 0x010000UL +#define LINUX_MAGIC_ADDR 0x010008UL#define KERN_PARM_AREA 0x010480UL#define INITRD_START 0x800000UL#define INITRD_PARM_START 0x010408UL@@ -105,7 +106,9 @@ static uint64_t bios_translate_addr(void *opaque, uint64_t srcaddr)static void s390_ipl_realize (DeviceState *dev,Error **errp) {S390IPLState *ipl =S390_IPL (dev); -uint64_t pentry =KERN_IMAGE_START ; +uint32_t *iplpsw; +uint64_t pentry; +char *magic;int kernel_size;Error *err =NULL ;@@ -157,6 +160,20 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp) NULL, 1, EM_S390, 0, 0);if (kernel_size <0 ) { kernel_size =load_image_targphys (ipl->kernel,0 , ram_size); +/* if this is Linux use KERN_IMAGE_START */ + magic =rom_ptr (LINUX_MAGIC_ADDR ); +if (magic && !memcmp (magic,"S390EP" ,6 )) { + pentry =KERN_IMAGE_START ; + }else { +/* if not Linux use the IPL PSW */ + iplpsw =rom_ptr (4 ); +if (iplpsw) { + pentry =be32_to_cpu (*iplpsw) &0x7fffffffUL ; + }else { +error_setg (&err,"Could not get IPL PSW" ); + goto error; + } + } }if (kernel_size <0 ) {error_setg (&err,"could not load kernel '%s'" , ipl->kernel);
Signature · 3 lines
Thanks, David / dhildenb
Quoted 52 lines · Christian Borntraeger
Right now the IPL device always starts from address
0x10000(the usual Linux entry point). To run other guests (e.g. test programs) it is useful to use the IPL PSW from address 0. We can use the Linux magic at0x10008to decide.Signed-off-by Christian Borntraeger <[email protected]>---
v2->v3:
- check for iplpsw to avoid assert on file errors
- use 4 bytes at 4 instead of 8 bytes at 0v1->v2:
- useLINUX_MAGIC_ADDRdefine
- use assert for valid iplpsw pointer
- add endianess conversionhw/s390x/ipl.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)hw/s390x/ipl.c +11
-1@@ -29,6 +29,7 @@#include "exec/exec-all.h" #define KERN_IMAGE_START 0x010000UL +#define LINUX_MAGIC_ADDR 0x010008UL#define KERN_PARM_AREA 0x010480UL#define INITRD_START 0x800000UL#define INITRD_PARM_START 0x010408UL@@ -105,7 +106,9 @@ static uint64_t bios_translate_addr(void *opaque, uint64_t srcaddr)static void s390_ipl_realize (DeviceState *dev,Error **errp) {S390IPLState *ipl =S390_IPL (dev); -uint64_t pentry =KERN_IMAGE_START ; +uint32_t *iplpsw; +uint64_t pentry; +char *magic;int kernel_size;Error *err =NULL ;@@ -157,6 +160,20 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp) NULL, 1, EM_S390, 0, 0);if (kernel_size <0 ) { kernel_size =load_image_targphys (ipl->kernel,0 , ram_size); +/* if this is Linux use KERN_IMAGE_START */ + magic =rom_ptr (LINUX_MAGIC_ADDR ); +if (magic && !memcmp (magic,"S390EP" ,6 )) { + pentry =KERN_IMAGE_START ; + }else { +/* if not Linux use the IPL PSW */ + iplpsw =rom_ptr (4 );
hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 179
Quoted 10 lines
hw/s390x/ipl.c +7
-0+if (iplpsw) { + pentry =be32_to_cpu (*iplpsw) &0x7fffffffUL ; + }else { +error_setg (&err,"Could not get IPL PSW" ); + goto error; + } + } }if (kernel_size <0 ) {error_setg (&err,"could not load kernel '%s'" , ipl->kernel);
Quoted 30 lines · On Tue, 12 Jun 2018 12:04:48 +0200 Christian Borntraeger…
Right now the IPL device always starts from address
0x10000(the usual Linux entry point). To run other guests (e.g. test programs) it is useful to use the IPL PSW from address 0. We can use the Linux magic at0x10008to decide.Signed-off-by Christian Borntraeger <[email protected]>---
v2->v3:
- check for iplpsw to avoid assert on file errors
- use 4 bytes at 4 instead of 8 bytes at 0v1->v2:
- useLINUX_MAGIC_ADDRdefine
- use assert for valid iplpsw pointer
- add endianess conversionhw/s390x/ipl.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)hw/s390x/ipl.c +1
-0@@ -29,6 +29,7 @@#include "exec/exec-all.h" #define KERN_IMAGE_START 0x010000UL +#define LINUX_MAGIC_ADDR 0x010008UL#define KERN_PARM_AREA 0x010480UL#define INITRD_START 0x800000UL#define INITRD_PARM_START 0x010408UL
hw/s390x/ipl.c static uint64_t bios_translate_addr(void *opaque, uint64_t srcaddr) · line 109
Quoted 5 lines
hw/s390x/ipl.c +1
-1@@ -105,7 +106,9 @@ static uint64_t bios_translate_addr(void *opaque, uint64_t srcaddr)static void s390_ipl_realize (DeviceState *dev,Error **errp) {S390IPLState *ipl =S390_IPL (dev); -uint64_t pentry =KERN_IMAGE_START ; +uint32_t *iplpsw;
In case you respin: Can this be ipl_psw, please?
Quoted 6 lines
hw/s390x/ipl.c +2
-0+uint64_t pentry; +char *magic;int kernel_size;Error *err =NULL ;
hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 168
Quoted 9 lines
hw/s390x/ipl.c +6
-0@@ -157,6 +160,20 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp) NULL, 1, EM_S390, 0, 0);if (kernel_size <0 ) { kernel_size =load_image_targphys (ipl->kernel,0 , ram_size); +/* if this is Linux use KERN_IMAGE_START */ + magic =rom_ptr (LINUX_MAGIC_ADDR ); +if (magic && !memcmp (magic,"S390EP" ,6 )) { + pentry =KERN_IMAGE_START ; + }else { +/* if not Linux use the IPL PSW */
"use the address of the IPL PSW"?
hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 179
Quoted 11 lines
hw/s390x/ipl.c +8
-0+ iplpsw =rom_ptr (4 ); +if (iplpsw) { + pentry =be32_to_cpu (*iplpsw) &0x7fffffffUL ; + }else { +error_setg (&err,"Could not get IPL PSW" ); + goto error; + } + } }if (kernel_size <0 ) {error_setg (&err,"could not load kernel '%s'" , ipl->kernel);
Is this ever reached now? In any case, it might make sense to move this up, as the "could not load kernel 'plahh'" message seems more useful than "Could not get IPL PSW"...
Also, further below we copy ipl->cmdline if we think we're dealing with a Linux image. Would it make sense to explicitly check for the Linux magic there as well? (Separate patch, of course.)
Can/should netboot do a similar check? It uses KERN_IMAGE_START unconditionally if it wasn't an ELF file.
Quoted 27 lines · Cornelia Huck
Quoted 24 lines · On Tue, 12 Jun 2018 12:04:48 +0200 Christian Borntraeger…
Right now the IPL device always starts from address
0x10000(the usual Linux entry point). To run other guests (e.g. test programs) it is useful to use the IPL PSW from address 0. We can use the Linux magic at0x10008to decide.Signed-off-by Christian Borntraeger <[email protected]>---
v2->v3:
- check for iplpsw to avoid assert on file errors
- use 4 bytes at 4 instead of 8 bytes at 0v1->v2:
- useLINUX_MAGIC_ADDRdefine
- use assert for valid iplpsw pointer
- add endianess conversionhw/s390x/ipl.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)hw/s390x/ipl.c +0
-0@@ -29,6 +29,7 @@#include "exec/exec-all.h"
Quoted 13 lines
hw/s390x/ipl.c static uint64_t bios_translate_addr(void *opaque, uint64_t srcaddr) · line 109
Quoted 11 lines
hw/s390x/ipl.c +2
-1#define KERN_IMAGE_START 0x010000UL +#define LINUX_MAGIC_ADDR 0x010008UL#define KERN_PARM_AREA 0x010480UL#define INITRD_START 0x800000UL#define INITRD_PARM_START 0x010408UL@@ -105,7 +106,9 @@ static uint64_t bios_translate_addr(void *opaque, uint64_t srcaddr)static void s390_ipl_realize (DeviceState *dev,Error **errp) {S390IPLState *ipl =S390_IPL (dev); -uint64_t pentry =KERN_IMAGE_START ; +uint32_t *iplpsw;In case you respin: Can this be
ipl_psw, please?
sure.
Quoted 6 lines
Quoted 6 lines
hw/s390x/ipl.c +2
-0+uint64_t pentry; +char *magic;int kernel_size;Error *err =NULL ;
Quoted 12 lines
hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 168
Quoted 10 lines
hw/s390x/ipl.c +6
-0@@ -157,6 +160,20 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp) NULL, 1, EM_S390, 0, 0);if (kernel_size <0 ) { kernel_size =load_image_targphys (ipl->kernel,0 , ram_size); +/* if this is Linux use KERN_IMAGE_START */ + magic =rom_ptr (LINUX_MAGIC_ADDR ); +if (magic && !memcmp (magic,"S390EP" ,6 )) { + pentry =KERN_IMAGE_START ; + }else { +/* if not Linux use the IPL PSW */ "use the address of the IPL PSW"?
Well we use the IPL PSW (and we need the address to get that) See the * before iplpsw.
Quoted 13 lines
hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 179
Quoted 12 lines
hw/s390x/ipl.c +8
-0+ iplpsw =rom_ptr (4 ); +if (iplpsw) { + pentry =be32_to_cpu (*iplpsw) &0x7fffffffUL ; + }else { +error_setg (&err,"Could not get IPL PSW" ); + goto error; + } + } }if (kernel_size <0 ) {error_setg (&err,"could not load kernel '%s'" , ipl->kernel);
Quoted 1 line
Is this ever reached now? In any case, it might make sense to move this
Hmm, Right. If kernel_size < 0 then magic and ipl_psw should be NULL and we error out early
Quoted 9 lines
up, as the "could not load kernel 'plahh'" message seems more useful than "Could not get IPL PSW"...
Also, further below we copy
ipl->cmdlineif we think we're dealing with a Linux image. Would it make sense to explicitly check for the Linux magic there as well? (Separate patch, of course.)Can/should netboot do a similar check? It uses
KERN_IMAGE_STARTunconditionally if it wasn't an ELF file.
I think we already changed that there (I asked for that change).