Skip to contentSkip to conversation

s390-ccw.img: s390-ccw.img fixes

PATCH Applied Jens Freimann 4 participants 9 messages Jun 18, 2014 – Jun 23, 2014

lore
Share & tools
lore
#0 lore raw

cover s390-ccw.img: s390-ccw.img fixes

Conny, Christian, Alex,

here's three bios bugfixes and an update for the binary. Patch 1 lets us boot with big inital ramdisks, Patch 2 introduces a subsystem reset to make sure start with a clean state. Patch 3 fixes parsing of the SCSI bootmap.

regards
Jens

Christian Borntraeger (1):
pc-bios/s390-ccw: do a subsystem reset before running the guest

David Hildenbrand (1):
pc-bios/s390-ccw: virtio_load_direct() can't load max number of
sectors

Eugene (jno) Dvurechenski (1):
pc-bios/s390-ccw: fix for fragmented SCSI bootmap

Jens Freimann (1):
pc-bios/s390-ccw: update s390-ccw.img binary

 pc-bios/s390-ccw.img       | Bin 9336 -> 9432 bytes
 pc-bios/s390-ccw/bootmap.c |  82 ++++++++++++++++++++++++++++++++++++++++-----
 pc-bios/s390-ccw/virtio.c  |   2 +-
 3 files changed, 75 insertions(+), 9 deletions(-)
Signature · 1 line
1.8.5.5
#1 lore raw

PATCH 1/4 pc-bios/s390-ccw: virtio_load_direct() can't load max number of sectors

From: David Hildenbrand <[email protected]>

The number of sectors to read is given by the last 16 bit of rec_list2. 1 is added in order to get to the real number of sectors to read (0x0000 -> read 1 block). For now, the maximum number (0xffff) led to 0 sectors being read.

This fixes a bug where a large initrd (62MB) could not be ipled anymore.

---
 pc-bios/s390-ccw/virtio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
pc-bios/s390-ccw/virtio.c +1 -1
index a46914d..bbb3c4f 100644
@@ -240,7 +240,7 @@ unsigned long virtio_load_direct(ulong rec_list1, ulong rec_list2,
 {
     u8 status;
     int sec = rec_list1;
-    int sec_num = (((rec_list2 >> 32)+ 1) & 0xffff);
+    int sec_num = ((rec_list2 >> 32) & 0xffff) + 1;
     int sec_len = rec_list2 >> 48;
     ulong addr = (ulong)load_addr;
 
Signature · 1 line
1.8.5.5
#2 lore raw

PATCH 2/4 pc-bios/s390-ccw: do a subsystem reset before running the guest

In reply to Jens Freimann

From: Christian Borntraeger <[email protected]>

The loader BIOS has already activated several devices. Let's do a subsystem reset before jumping into the guest. As there is no direct way of doing so, we use diagnose 308 to bring the system in a defined state. This is similar to what kdump on s390 uses. We have to define a small trampoline function that restores the low bytes to whatever the bootmap has written there.

---
 pc-bios/s390-ccw/bootmap.c | 55 +++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 47 insertions(+), 8 deletions(-)
pc-bios/s390-ccw/bootmap.c +47 -8
index 53a460d..c07553b 100644
@@ -58,6 +58,52 @@ struct mbr {
 /* Scratch space */
 static uint8_t sec[SECTOR_SIZE] __attribute__((__aligned__(SECTOR_SIZE)));
 
+typedef struct ResetInfo {
+    uint32_t ipl_mask;
+    uint32_t ipl_addr;
+    uint32_t ipl_continue;
+} ResetInfo;
+
+ResetInfo save;
+
+static void jump_to_IPL_2(void)
+{
+    ResetInfo *current = 0;
+
+    void (*ipl)(void) = (void *) (uint64_t) current->ipl_continue;
+    debug_print_addr("set IPL addr to", ipl);
+
+    /* Ensure the guest output starts fresh */
+    sclp_print("\n");
+
+    *current = save;
+    ipl(); /* should not return */
+}
+
+static void jump_to_IPL_code(uint64_t address)
+{
+    /*
+     * The IPL PSW is at address 0. We also must not overwrite the
+     * content of non-BIOS memory after we loaded the guest, so we
+     * save the original content and restore it in jump_to_IPL_2.
+     */
+    ResetInfo *current = 0;
+
+    save = *current;
+    current->ipl_addr = (uint32_t) (uint64_t) &jump_to_IPL_2;
+    current->ipl_continue = address & 0x7fffffff;
+
+    /*
+     * HACK ALERT.
+     * We use the load normal reset to keep r15 unchanged. jump_to_IPL_2
+     * can then use r15 as its stack pointer.
+     */
+    asm volatile("lghi 1,1\n\t"
+                 "diag 1,1,0x308\n\t"
+                 : : : "1", "memory");
+    virtio_panic("\n! IPL returns !\n");
+}
+
 /* Check for ZIPL magic. Returns 0 if not matched. */
 static int zipl_magic(uint8_t *ptr)
 {
@@ -123,7 +169,6 @@ static int zipl_run(struct scsi_blockptr *pte)
 {
     struct component_header *header;
     struct component_entry *entry;
-    void (*ipl)(void);
     uint8_t tmp_sec[SECTOR_SIZE];
 
     virtio_read(pte->blockno, tmp_sec);
@@ -157,14 +202,8 @@ static int zipl_run(struct scsi_blockptr *pte)
         goto fail;
     }
 
-    /* Ensure the guest output starts fresh */
-    sclp_print("\n");
-
-    /* And run the OS! */
-    ipl = (void*)(entry->load_address & 0x7fffffff);
-    debug_print_addr("set IPL addr to", ipl);
     /* should not return */
-    ipl();
+    jump_to_IPL_code(entry->load_address);
 
     return 0;
 
Signature · 1 line
1.8.5.5
#3 lore raw

PATCH 3/4 pc-bios/s390-ccw: fix for fragmented SCSI bootmap

In reply to Jens Freimann

From: "Eugene (jno) Dvurechenski" <[email protected]>

We need to interpret the last entry of the bootmap with zero block count as "continuation pointer".
The "last entry" is being detected by pre-filling of the scratch space with known values and respective look-ahead.

---
 pc-bios/s390-ccw/bootmap.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
pc-bios/s390-ccw/bootmap.c +27 -0
index c07553b..5ee3fcb 100644
@@ -118,10 +118,26 @@ static int zipl_magic(uint8_t *ptr)
     return 1;
 }
 
+#define FREE_SPACE_FILLER '\xAA'
+
+static inline bool unused_space(const void *p, unsigned int size)
+{
+    int i;
+    const unsigned char *m = p;
+
+    for (i = 0; i < size; i++) {
+        if (m[i] != FREE_SPACE_FILLER) {
+            return false;
+        }
+    }
+    return true;
+}
+
 static int zipl_load_segment(struct component_entry *entry)
 {
     const int max_entries = (SECTOR_SIZE / sizeof(struct scsi_blockptr));
     struct scsi_blockptr *bprs = (void*)sec;
+    const int bprs_size = sizeof(sec);
     uint64_t blockno;
     long address;
     int i;
@@ -133,6 +149,7 @@ static int zipl_load_segment(struct component_entry *entry)
     debug_print_int("addr", address);
 
     do {
+        memset(bprs, FREE_SPACE_FILLER, bprs_size);
         if (virtio_read(blockno, (uint8_t *)bprs)) {
             debug_print_int("failed reading bprs at", blockno);
             goto fail;
@@ -150,6 +167,16 @@ static int zipl_load_segment(struct component_entry *entry)
             if (i == (max_entries - 1))
                 break;
 
+            if (bprs[i].blockct == 0 && unused_space(&bprs[i + 1],
+                sizeof(struct scsi_blockptr))) {
+                /* This is a "continue" pointer.
+                 * This ptr is the last one in the current script section.
+                 * I.e. the next ptr must point to the unused memory area.
+                 * The blockno is not zero, so the upper loop must continue
+                 * reading next section of BPRS.
+                 */
+                break;
+            }
             address = virtio_load_direct(cur_desc[0], cur_desc[1], 0,
                                          (void*)address);
             if (address == -1)
Signature · 1 line
1.8.5.5
#4 lore raw

Re: [Qemu-devel] [PATCH 3/4] pc-bios/s390-ccw: fix for fragmented SCSI bootmap

pc-bios/s390-ccw/bootmap.c static int zipl_magic(uint8_t *ptr) · line 125

Quoted 3 lines · Jens Freimann
pc-bios/s390-ccw/bootmap.c +3 -0
+static inline bool unused_space(const void *p, unsigned int size)
+{
+    int i;

s390-ccw.h has a def for size_t (well, it's just "long"). So, we can use a bit more "gentile" version:

+static inline bool unused_space(const void *p, size_t size) +{
+ size_t i;

Signature · 5 lines
Best Regards,
Eugene "jno" Dvurechenski
zLinux (KVM) Development - Software Engineer
IBM Russia - Science & Technology Center
phone: +7 (495) 660 8940 ext. 1021

begin:vcard
fn:Eugene Dvurechenski
n:Dvurechenski;Eugene
org:IBM Systems & Technology Group;IBM S&T Center, Russia adr:;;Obrucheva st., bld.30/1, E2V, floor 4;Moscow;;117485;Russia email;internet:[email protected]
title:Software Engineer
tel;work:+7 (495) 660 8940 ext. 1021
tel;cell:+7 (903) 790-07-49
x-mozilla-html:FALSE
url:http://fsw.su/
version:2.1
end:vcard

#5 lore raw

Re: [Qemu-devel] [PATCH 3/4] pc-bios/s390-ccw: fix for fragmented SCSI bootmap

Quoted 12 lines · On Wed, 18 Jun 2014 16:53:15 +0400 "Eugene \"jno\" Dvurechenski"…

pc-bios/s390-ccw/bootmap.c static int zipl_magic(uint8_t *ptr) · line 125

Quoted 3 lines · Jens Freimann
pc-bios/s390-ccw/bootmap.c +3 -0
+static inline bool unused_space(const void *p, unsigned int size)
+{
+    int i;

s390-ccw.h has a def for size_t (well, it's just "long"). So, we can use a bit more "gentile" version:

Review

Quoted 3 lines
(quoted diff) +3 -0
+static inline bool unused_space(const void *p, size_t size)
+{
+    size_t i;

Let's stick with the posted version for now. We can do further cleanup of the bios code later on.

#6 lore raw

PATCH 4/4 pc-bios/s390-ccw: update s390-ccw.img binary

In reply to Jens Freimann

Update s390-ccw.img to match with latest fixes

---
 pc-bios/s390-ccw.img | Bin 9336 -> 9432 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
pc-bios/s390-ccw.img binary +0 -0
index f6223e77c2aacfa86652d63b773dc05eca55570d..1c7f7640fc0c5f2505c4f1114a21b3b712852dbc 100644
GIT binary patch
Signature · 1 line
1.8.5.5
Reviewed-by on the v1 series
#7 lore raw
In reply to Jens Freimann
Quoted 6 lines · Jens Freimann

Conny, Christian, Alex,

here's three bios bugfixes and an update for the binary. Patch 1 lets us boot with big inital ramdisks, Patch 2 introduces a subsystem reset to make sure start with a clean state. Patch 3 fixes parsing of the SCSI bootmap.

Nasty :).

Alex

#8 lore raw
In reply to Jens Freimann
Quoted 21 lines · On Wed, 18 Jun 2014 14:16:43 +0200 Jens Freimann <[email protected]>…

Conny, Christian, Alex,

here's three bios bugfixes and an update for the binary. Patch 1 lets us boot with big inital ramdisks, Patch 2 introduces a subsystem reset to make sure start with a clean state. Patch 3 fixes parsing of the SCSI bootmap.

regards
Jens

Christian Borntraeger (1):
pc-bios/s390-ccw: do a subsystem reset before running the guest

David Hildenbrand (1):
pc-bios/s390-ccw: virtio_load_direct() can't load max number of
sectors

Eugene (jno) Dvurechenski (1):
pc-bios/s390-ccw: fix for fragmented SCSI bootmap

Quoted 8 lines

Jens Freimann (1):
pc-bios/s390-ccw: update s390-ccw.img binary

 pc-bios/s390-ccw.img       | Bin 9336 -> 9432 bytes
 pc-bios/s390-ccw/bootmap.c |  82 ++++++++++++++++++++++++++++++++++++++++-----
 pc-bios/s390-ccw/virtio.c  |   2 +-
 3 files changed, 75 insertions(+), 9 deletions(-)

Thanks, applied to my s390-next branch.