pc-bios: s390x: fix corner cases in booting from ECKD
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
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.
--- pc-bios/s390-ccw/bootmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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;
Signature · 1 line
2.25.4
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=0x7fe18000and the magic value "zIPL" is located at0x7fe18ffc-0x7fe18fff.Fixes ba831b25262a ("s390-ccw: read stage2 boot loader data to find menu")Reviewed-by Collin Walling <[email protected]>Signed-off-by Marc Hartmayer <[email protected]>--- pc-bios/s390-ccw/bootmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)pc-bios/s390-ccw/bootmap.c +0
-0
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
-0if (magic_match (s2_cur_blk + i,ZIPL_MAGIC_EBCDIC )) { *offset = i;return true;
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=0x7fe18000and the magic value "zIPL" is located at0x7fe18ffc-0x7fe18fff.Fixes ba831b25262a ("s390-ccw: read stage2 boot loader data to find menu")Reviewed-by Collin Walling <[email protected]>Signed-off-by Marc Hartmayer <[email protected]>--- pc-bios/s390-ccw/bootmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)pc-bios/s390-ccw/bootmap.c +0
-0@@ -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_SIZEinstead 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
-0if (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
Re: [PATCH 1/3] pc-bios/s390-ccw: fix off-by-one error
In reply to Marc HartmayerQuoted 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=0x7fe18000and the magic value "zIPL" is located at0x7fe18ffc-0x7fe18fff.Fixes ba831b25262a ("s390-ccw: read stage2 boot loader data to find menu")Reviewed-by Collin Walling <[email protected]>Signed-off-by Marc Hartmayer <[email protected]>--- pc-bios/s390-ccw/bootmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)pc-bios/s390-ccw/bootmap.c +0
-0
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:
PATCH 2/3 pc-bios/s390-ccw: break loop if a null block number is reached
In reply to Marc HartmayerBreak 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.
--- pc-bios/s390-ccw/bootmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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 ; }
Signature · 1 line
2.25.4
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_nris 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")Reviewed-by Collin Walling <[email protected]>Signed-off-by Marc Hartmayer <[email protected]>--- pc-bios/s390-ccw/bootmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)pc-bios/s390-ccw/bootmap.c +0
-0
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
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_nris 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")Reviewed-by Collin Walling <[email protected]>Signed-off-by Marc Hartmayer <[email protected]>--- pc-bios/s390-ccw/bootmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)pc-bios/s390-ccw/bootmap.c +0
-0pc-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 ; }Reviewed-by Thomas Huth <[email protected]>
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
PATCH 3/3 pc-bios/s390-ccw: Update s390-ccw.img bios binary
In reply to Marc HartmayerContains 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
Signature · 1 line
2.25.4