Skip to contentSkip to conversation

pc-bios: s390x: fix corner cases in booting from ECKD

PATCH In review Marc Hartmayer 3 participants 9 messages Sep 24, 2020

lore
Share & tools
lore
#0 lore raw

cover pc-bios: s390x: fix corner cases in booting from ECKD

The first patch fixes the scan for the string "zIPL" (which is used to detect the start of the boot menu banner) in find_zipl_boot_menu_banner. The second patch fixes the bug of not booting the default entry if no zipl boot menu data was found.

For everybody's convenience there is a branch:
https://gitlab.com/mhartmay/qemu/-/tree/bios_fixes

Marc Hartmayer (3):
pc-bios/s390-ccw: fix off-by-one error pc-bios/s390-ccw: break loop if a null block number is reached pc-bios/s390-ccw: Update s390-ccw.img bios binary

 pc-bios/s390-ccw.img       | Bin 42608 -> 42608 bytes
 pc-bios/s390-ccw/bootmap.c |   4 ++--
 2 files changed, 2 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.4
#1 lore raw

PATCH 1/3 pc-bios/s390-ccw: fix off-by-one error

This error takes effect when the magic value "zIPL" is located at the end of a block. For example if s2_cur_blk = 0x7fe18000 and the magic value "zIPL" is located at 0x7fe18ffc - 0x7fe18fff.

Fixes ba831b25262a ("s390-ccw: read stage2 boot loader data to find menu")
---
 pc-bios/s390-ccw/bootmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
pc-bios/s390-ccw/bootmap.c +1 -1
index 97205674e59a..0d29dceaa3cc 100644
@@ -163,7 +163,7 @@ static bool find_zipl_boot_menu_banner(int *offset)
     int i;
 
     /* Menu banner starts with "zIPL" */
-    for (i = 0; i < virtio_get_block_size() - 4; i++) {
+    for (i = 0; i < virtio_get_block_size() - 3; i++) {
         if (magic_match(s2_cur_blk + i, ZIPL_MAGIC_EBCDIC)) {
             *offset = i;
             return true;
Signature · 1 line
2.25.4
#2 lore raw

Re: [PATCH 1/3] pc-bios/s390-ccw: fix off-by-one error

Hi Marc,

Quoted 16 lines · Marc Hartmayer

This error takes effect when the magic value "zIPL" is located at the end of a block. For example if s2_cur_blk = 0x7fe18000 and the magic value "zIPL" is located at 0x7fe18ffc - 0x7fe18fff.

Fixes ba831b25262a ("s390-ccw: read stage2 boot loader data to find menu")
---
 pc-bios/s390-ccw/bootmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
pc-bios/s390-ccw/bootmap.c +0 -0
index 97205674e59a..0d29dceaa3cc 100644

pc-bios/s390-ccw/bootmap.c static bool find_zipl_boot_menu_banner(int *offset) · line 166

Quoted 5 lines
pc-bios/s390-ccw/bootmap.c +1 -1
@@ -163,7 +163,7 @@ static bool find_zipl_boot_menu_banner(int *offset)
     int i;
 
     /* Menu banner starts with "zIPL" */
-    for (i = 0; i < virtio_get_block_size() - 4; i++) {
+    for (i = 0; i < virtio_get_block_size() - 3; i++) {

Easier to review as:

       for (i = 0; i <= virtio_get_block_size() - 4; i++) {

Even easier defining ZIPL_MAGIC_SIZE instead of the magic '4'.

Quoted 4 lines
pc-bios/s390-ccw/bootmap.c +0 -0
         if (magic_match(s2_cur_blk + i, ZIPL_MAGIC_EBCDIC)) {
             *offset = i;
             return true;
#3 lore raw

Re: [PATCH 1/3] pc-bios/s390-ccw: fix off-by-one error

Quoted 21 lines · Philippe Mathieu-Daudé

Hi Marc,

Quoted 18 lines · Marc Hartmayer

This error takes effect when the magic value "zIPL" is located at the end of a block. For example if s2_cur_blk = 0x7fe18000 and the magic value "zIPL" is located at 0x7fe18ffc - 0x7fe18fff.

Fixes ba831b25262a ("s390-ccw: read stage2 boot loader data to find menu")
---
 pc-bios/s390-ccw/bootmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
pc-bios/s390-ccw/bootmap.c +0 -0
index 97205674e59a..0d29dceaa3cc 100644
@@ -163,7 +163,7 @@ static bool find_zipl_boot_menu_banner(int *offset)
     int i;
 
Quoted 7 lines

pc-bios/s390-ccw/bootmap.c static bool find_zipl_boot_menu_banner(int *offset) · line 166

Quoted 3 lines
pc-bios/s390-ccw/bootmap.c +1 -1
     /* Menu banner starts with "zIPL" */
-    for (i = 0; i < virtio_get_block_size() - 4; i++) {
+    for (i = 0; i < virtio_get_block_size() - 3; i++) {

Easier to review as:

       for (i = 0; i <= virtio_get_block_size() - 4; i++) {

Yep.

Quoted 2 lines

Even easier defining ZIPL_MAGIC_SIZE instead of the magic '4'.

I thought about adding such a macro as well. Makes even more sense with your proposed change.

Quoted 6 lines
Quoted 5 lines
pc-bios/s390-ccw/bootmap.c +0 -0
         if (magic_match(s2_cur_blk + i, ZIPL_MAGIC_EBCDIC)) {
             *offset = i;
             return true;
Signature · 8 lines
Kind regards / Beste Grüße
   Marc Hartmayer

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Gregor Pillen 
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
Reviewed-by on v1 1/3
#4 lore raw

Re: [PATCH 1/3] pc-bios/s390-ccw: fix off-by-one error

In reply to Marc Hartmayer
Quoted 16 lines · Marc Hartmayer

This error takes effect when the magic value "zIPL" is located at the end of a block. For example if s2_cur_blk = 0x7fe18000 and the magic value "zIPL" is located at 0x7fe18ffc - 0x7fe18fff.

Fixes ba831b25262a ("s390-ccw: read stage2 boot loader data to find menu")
---
 pc-bios/s390-ccw/bootmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
pc-bios/s390-ccw/bootmap.c +0 -0
index 97205674e59a..0d29dceaa3cc 100644

pc-bios/s390-ccw/bootmap.c static bool find_zipl_boot_menu_banner(int *offset) · line 169

Quoted 8 lines
pc-bios/s390-ccw/bootmap.c +1 -1
@@ -163,7 +163,7 @@ static bool find_zipl_boot_menu_banner(int *offset)
     int i;
 
     /* Menu banner starts with "zIPL" */
-    for (i = 0; i < virtio_get_block_size() - 4; i++) {
+    for (i = 0; i < virtio_get_block_size() - 3; i++) {
         if (magic_match(s2_cur_blk + i, ZIPL_MAGIC_EBCDIC)) {
             *offset = i;
             return true;

I agree with Philippe, i <= virtio_get_block_size() - 4 would be a little bit nicer. Anyway:

#5 lore raw

PATCH 2/3 pc-bios/s390-ccw: break loop if a null block number is reached

In reply to Marc Hartmayer

Break the loop if cur_block_nr is a null block number because this means that the end of chunk is reached. In this case we will try to boot the default entry.

Fixes ba831b25262a ("s390-ccw: read stage2 boot loader data to find menu")
---
 pc-bios/s390-ccw/bootmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
pc-bios/s390-ccw/bootmap.c +1 -1
index 0d29dceaa3cc..08f16c5595a3 100644
@@ -192,7 +192,7 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
     for (i = 0; i < STAGE2_BLK_CNT_MAX; i++) {
         cur_block_nr = eckd_block_num(&s1b->seek[i].chs);
 
-        if (!cur_block_nr) {
+        if (!cur_block_nr || is_null_block_number(cur_block_nr)) {
             break;
         }
 
Signature · 1 line
2.25.4
Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH 2/3] pc-bios/s390-ccw: break loop if a null block number is reached

Quoted 16 lines · Marc Hartmayer

Break the loop if cur_block_nr is a null block number because this means that the end of chunk is reached. In this case we will try to boot the default entry.

Fixes ba831b25262a ("s390-ccw: read stage2 boot loader data to find menu")
---
 pc-bios/s390-ccw/bootmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
pc-bios/s390-ccw/bootmap.c +0 -0
index 0d29dceaa3cc..08f16c5595a3 100644

pc-bios/s390-ccw/bootmap.c static int eckd_get_boot_menu_index(block_number_t s1b_block_nr) · line 197

Quoted 7 lines
pc-bios/s390-ccw/bootmap.c +1 -1
@@ -192,7 +192,7 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
     for (i = 0; i < STAGE2_BLK_CNT_MAX; i++) {
         cur_block_nr = eckd_block_num(&s1b->seek[i].chs);
 
-        if (!cur_block_nr) {
+        if (!cur_block_nr || is_null_block_number(cur_block_nr)) {
             break;
         }

I'll queue the two patches on my s390-ccw bios branch. Just let me know if you'd like to have the "< ... - 3" changed into "<= ... - 4" in the first patch, I can tweak it directly if you like.

Thomas

#7 lore raw

Re: [PATCH 2/3] pc-bios/s390-ccw: break loop if a null block number is reached

Quoted 27 lines · Thomas Huth
Quoted 16 lines · Marc Hartmayer

Break the loop if cur_block_nr is a null block number because this means that the end of chunk is reached. In this case we will try to boot the default entry.

Fixes ba831b25262a ("s390-ccw: read stage2 boot loader data to find menu")
---
 pc-bios/s390-ccw/bootmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
pc-bios/s390-ccw/bootmap.c +0 -0
index 0d29dceaa3cc..08f16c5595a3 100644

pc-bios/s390-ccw/bootmap.c static int eckd_get_boot_menu_index(block_number_t s1b_block_nr) · line 197

Quoted 7 lines
pc-bios/s390-ccw/bootmap.c +1 -1
@@ -192,7 +192,7 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
     for (i = 0; i < STAGE2_BLK_CNT_MAX; i++) {
         cur_block_nr = eckd_block_num(&s1b->seek[i].chs);
 
-        if (!cur_block_nr) {
+        if (!cur_block_nr || is_null_block_number(cur_block_nr)) {
             break;
         }
Quoted 3 lines

I'll queue the two patches on my s390-ccw bios branch. Just let me know if you'd like to have the "< ... - 3" changed into "<= ... - 4" in the first patch, I can tweak it directly if you like.

Yes, please change it to <= … - 4. Thanks!

Quoted 3 lines

Thomas

Signature · 8 lines
Kind regards / Beste Grüße
   Marc Hartmayer

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Gregor Pillen 
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294
#8 lore raw

PATCH 3/3 pc-bios/s390-ccw: Update s390-ccw.img bios binary

In reply to Marc Hartmayer

Contains the fixes "pc-bios/s390-ccw: fix off-by-one error" and "pc-bios/s390-ccw: break loop if a null block number is reached".

---
 pc-bios/s390-ccw.img | Bin 42608 -> 42608 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
pc-bios/s390-ccw.img binary +0 -0
index 3074686a8c7448d943aa62f810d88d3e92865ef3..d166774ece9e2a3cd1d89e02acfffb68b370a363 100644
GIT binary patch
Signature · 1 line
2.25.4