Skip to contentSkip to conversation

s390x/ipl: Try to detect Linux vs non Linux for initial IPL PSW

PATCH Superseded Christian Borntraeger 2 participants 4 messages May 8, 2018

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 hw/s390x/ipl.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +14 -1
index 150f6c0582..c0fed26f03 100644
@@ -104,7 +104,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;
+    uint64_t *iplpsw;
+    uint64_t pentry;
+    char *magic;
     int kernel_size;
     Error *err = NULL;
 
@@ -156,6 +158,17 @@ 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(0x10008);
+            if (magic && !memcmp(magic, "S390EP", 6)) {
+                pentry = KERN_IMAGE_START;
+            } else {
+                /* if not Linux use the IPL PSW */
+                iplpsw = rom_ptr(0);
+                if (iplpsw) {
+                    pentry = *iplpsw & 0x7fffffffUL;
+                }
+            }
         }
         if (kernel_size < 0) {
             error_setg(&err, "could not load kernel '%s'", ipl->kernel);
Signature · 1 line
2.14.2
#1 lore raw
Quoted 30 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 at 0x10008 to decide.

---
 hw/s390x/ipl.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +3 -1
index 150f6c0582..c0fed26f03 100644
@@ -104,7 +104,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;
+    uint64_t *iplpsw;
+    uint64_t pentry;
+    char *magic;
     int kernel_size;
     Error *err = NULL;
 
@@ -156,6 +158,17 @@ 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);

hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 170

Quoted 10 lines
hw/s390x/ipl.c +10 -0
+            /* if this is Linux use KERN_IMAGE_START */
+            magic = rom_ptr(0x10008);
+            if (magic && !memcmp(magic, "S390EP", 6)) {
+                pentry = KERN_IMAGE_START;
+            } else {
+                /* if not Linux use the IPL PSW */
+                iplpsw = rom_ptr(0);
+                if (iplpsw) {
+                    pentry = *iplpsw & 0x7fffffffUL;
+                }
else {
    error_report("Failed to determine entry point");
    exit(1);
}

?

Otherwise some version of GCC might complain that pentry is used uninitialized later.

Alternatively, use "assert(iplpsw)" instead of the "if (iplpws)" ?

hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 174

Quoted 5 lines
hw/s390x/ipl.c +1 -0
+            }
         }
         if (kernel_size < 0) {
             error_setg(&err, "could not load kernel '%s'", ipl->kernel);

Thomas

#2 lore raw
In reply to Christian Borntraeger
Quoted 29 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 at 0x10008 to decide.

---
 hw/s390x/ipl.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +3 -1
index 150f6c0582..c0fed26f03 100644
@@ -104,7 +104,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;
+    uint64_t *iplpsw;
+    uint64_t pentry;
+    char *magic;
     int kernel_size;
     Error *err = NULL;
 
@@ -156,6 +158,17 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp)
                                NULL, 1, EM_S390, 0, 0);
         if (kernel_size < 0) {

hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 169

Quoted 10 lines
hw/s390x/ipl.c +9 -0
             kernel_size = load_image_targphys(ipl->kernel, 0, ram_size);
+            /* if this is Linux use KERN_IMAGE_START */
+            magic = rom_ptr(0x10008);
+            if (magic && !memcmp(magic, "S390EP", 6)) {
+                pentry = KERN_IMAGE_START;
+            } else {
+                /* if not Linux use the IPL PSW */
+                iplpsw = rom_ptr(0);
+                if (iplpsw) {
+                    pentry = *iplpsw & 0x7fffffffUL;

This needs an endianess conversion I think.

#3 lore raw
In reply to Christian Borntraeger
Quoted 29 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 at 0x10008 to decide.

---
 hw/s390x/ipl.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
hw/s390x/ipl.c +3 -1
index 150f6c0582..c0fed26f03 100644
@@ -104,7 +104,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;
+    uint64_t *iplpsw;
+    uint64_t pentry;
+    char *magic;
     int kernel_size;
     Error *err = NULL;
 
@@ -156,6 +158,17 @@ static void s390_ipl_realize(DeviceState *dev, Error **errp)
                                NULL, 1, EM_S390, 0, 0);
         if (kernel_size < 0) {

hw/s390x/ipl.c static void s390_ipl_realize(DeviceState *dev, Error **errp) · line 169

Quoted 10 lines
hw/s390x/ipl.c +9 -0
             kernel_size = load_image_targphys(ipl->kernel, 0, ram_size);
+            /* if this is Linux use KERN_IMAGE_START */
+            magic = rom_ptr(0x10008);
+            if (magic && !memcmp(magic, "S390EP", 6)) {
+                pentry = KERN_IMAGE_START;
+            } else {
+                /* if not Linux use the IPL PSW */
+                iplpsw = rom_ptr(0);
+                if (iplpsw) {
+                    pentry = *iplpsw & 0x7fffffffUL;

I forgot endianess conversion here.

Quoted 6 lines
hw/s390x/ipl.c +2 -0
+                }
+            }
         }
         if (kernel_size < 0) {
             error_setg(&err, "could not load kernel '%s'", ipl->kernel);