[PATCH v3 08/19] pc-bios/s390-ccw: Remove panics from ECKD IPL path

jrossi@linux.ibm.com posted 19 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH v3 08/19] pc-bios/s390-ccw: Remove panics from ECKD IPL path
Posted by jrossi@linux.ibm.com 1 month, 2 weeks ago
From: Jared Rossi <jrossi@linux.ibm.com>

Remove panic-on-error from ECKD block device IPL specific functions so that
error recovery may be possible in the future.

Functions that would previously panic now provide a return code.

Signed-off-by: Jared Rossi <jrossi@linux.ibm.com>
---
 pc-bios/s390-ccw/s390-ccw.h |   1 +
 pc-bios/s390-ccw/bootmap.c  | 183 ++++++++++++++++++++++++------------
 2 files changed, 126 insertions(+), 58 deletions(-)

diff --git a/pc-bios/s390-ccw/s390-ccw.h b/pc-bios/s390-ccw/s390-ccw.h
index cbd92f3671..7516e96a14 100644
--- a/pc-bios/s390-ccw/s390-ccw.h
+++ b/pc-bios/s390-ccw/s390-ccw.h
@@ -31,6 +31,7 @@ typedef unsigned long long u64;
 #define EBUSY   2
 #define ENODEV  3
 #define EINVAL  4
+#define ENOENT  5
 
 #ifndef MIN
 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c
index 7984de62fe..266b38c034 100644
--- a/pc-bios/s390-ccw/bootmap.c
+++ b/pc-bios/s390-ccw/bootmap.c
@@ -145,14 +145,17 @@ static block_number_t load_eckd_segments(block_number_t blk, bool ldipl,
     bool more_data;
 
     memset(_bprs, FREE_SPACE_FILLER, sizeof(_bprs));
-    read_block(blk, bprs, "BPRS read failed");
+    if (virtio_read(blk, bprs)) {
+        puts("BPRS read failed");
+        return -EIO;
+    }
 
     do {
         more_data = false;
         for (j = 0;; j++) {
             block_nr = gen_eckd_block_num(&bprs[j].xeckd, ldipl);
             if (is_null_block_number(block_nr)) { /* end of chunk */
-                break;
+                return -ENOENT;
             }
 
             /* we need the updated blockno for the next indirect entry
@@ -163,15 +166,20 @@ static block_number_t load_eckd_segments(block_number_t blk, bool ldipl,
             }
 
             /* List directed pointer does not store block size */
-            IPL_assert(ldipl || block_size_ok(bprs[j].xeckd.bptr.size),
-                       "bad chunk block size");
+            if (!ldipl && !block_size_ok(bprs[j].xeckd.bptr.size)) {
+                puts("Bad chunk block size");
+                return -EIO;
+            }
 
             if (!eckd_valid_address(&bprs[j].xeckd, ldipl)) {
                 /*
                  * If an invalid address is found during LD-IPL then break and
-                 * retry as CCW
+                 * retry as CCW-IPL, otherwise abort on error
                  */
-                IPL_assert(ldipl, "bad chunk ECKD addr");
+                if (!ldipl) {
+                    puts("Bad chunk ECKD address");
+                    return -EIO;
+                }
                 break;
             }
 
@@ -189,7 +197,10 @@ static block_number_t load_eckd_segments(block_number_t blk, bool ldipl,
                  * I.e. the next ptr must point to the unused memory area
                  */
                 memset(_bprs, FREE_SPACE_FILLER, sizeof(_bprs));
-                read_block(block_nr, bprs, "BPRS continuation read failed");
+                if (virtio_read(block_nr, bprs)) {
+                    puts("BPRS continuation read failed");
+                    return -EIO;
+                }
                 more_data = true;
                 break;
             }
@@ -198,7 +209,10 @@ static block_number_t load_eckd_segments(block_number_t blk, bool ldipl,
              * to memory (address).
              */
             rc = virtio_read_many(block_nr, (void *)(*address), count + 1);
-            IPL_assert(rc == 0, "code chunk read failed");
+            if (rc != 0) {
+                puts("Code chunk read failed");
+                return -EIO;
+            }
 
             *address += (count + 1) * virtio_get_block_size();
         }
@@ -232,7 +246,10 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
 
     /* Get Stage1b data */
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(s1b_block_nr, s1b, "Cannot read stage1b boot loader");
+    if (virtio_read(s1b_block_nr, s1b)) {
+        puts("Cannot read stage1b boot loader");
+        return -EIO;
+    }
 
     memset(_s2, FREE_SPACE_FILLER, sizeof(_s2));
 
@@ -244,7 +261,10 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
             break;
         }
 
-        read_block(cur_block_nr, s2_cur_blk, "Cannot read stage2 boot loader");
+        if (virtio_read(cur_block_nr, s2_cur_blk)) {
+            puts("Cannot read stage2 boot loader");
+            return -EIO;
+        }
 
         if (find_zipl_boot_menu_banner(&banner_offset)) {
             /*
@@ -252,8 +272,10 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
              * possibility of menu data spanning multiple blocks.
              */
             if (prev_block_nr) {
-                read_block(prev_block_nr, s2_prev_blk,
-                           "Cannot read stage2 boot loader");
+                if (virtio_read(prev_block_nr, s2_prev_blk)) {
+                    puts("Cannot read stage2 boot loader");
+                    return -EIO;
+                }
             }
 
             if (i + 1 < STAGE2_BLK_CNT_MAX) {
@@ -261,8 +283,10 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
             }
 
             if (next_block_nr && !is_null_block_number(next_block_nr)) {
-                read_block(next_block_nr, s2_next_blk,
-                           "Cannot read stage2 boot loader");
+                if (virtio_read(next_block_nr, s2_next_blk)) {
+                    puts("Cannot read stage2 boot loader");
+                    return -EIO;
+                }
             }
 
             return menu_get_zipl_boot_index(s2_cur_blk + banner_offset);
@@ -275,7 +299,7 @@ static int eckd_get_boot_menu_index(block_number_t s1b_block_nr)
     return 0;
 }
 
-static void run_eckd_boot_script(block_number_t bmt_block_nr,
+static int run_eckd_boot_script(block_number_t bmt_block_nr,
                                  block_number_t s1b_block_nr)
 {
     int i;
@@ -292,17 +316,28 @@ static void run_eckd_boot_script(block_number_t bmt_block_nr,
     }
 
     debug_print_int("loadparm", loadparm);
-    IPL_assert(loadparm < MAX_BOOT_ENTRIES, "loadparm value greater than"
-               " maximum number of boot entries allowed");
+    if (loadparm >= MAX_BOOT_ENTRIES) {
+        puts("loadparm value greater than max number of boot entries allowed");
+        return -EINVAL;
+    }
 
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(bmt_block_nr, sec, "Cannot read Boot Map Table");
+    if (virtio_read(bmt_block_nr, sec)) {
+        puts("Cannot read Boot Map Table");
+        return -EIO;
+    }
 
     block_nr = gen_eckd_block_num(&bmt->entry[loadparm].xeckd, ldipl);
-    IPL_assert(block_nr != -1, "Cannot find Boot Map Table Entry");
+    if (block_nr == NULL_BLOCK_NR) {
+        puts("Cannot find Boot Map Table Entry");
+        return -EIO;
+    }
 
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(block_nr, sec, "Cannot read Boot Map Script");
+    if (virtio_read(block_nr, sec)) {
+        puts("Cannot read Boot Map Script");
+        return -EIO;
+    }
 
     for (i = 0; bms->entry[i].type == BOOT_SCRIPT_LOAD ||
                 bms->entry[i].type == BOOT_SCRIPT_SIGNATURE; i++) {
@@ -317,21 +352,28 @@ static void run_eckd_boot_script(block_number_t bmt_block_nr,
 
         do {
             block_nr = load_eckd_segments(block_nr, ldipl, &address);
-        } while (block_nr != -1);
+        } while (block_nr >= 0);
+
+        if (block_nr != -ENOENT && block_nr < 0) {
+            return ldipl ? 0 : -EIO;
+        }
     }
 
     if (ldipl && bms->entry[i].type != BOOT_SCRIPT_EXEC) {
         /* Abort LD-IPL and retry as CCW-IPL */
-        return;
+        return 0;
     }
 
-    IPL_assert(bms->entry[i].type == BOOT_SCRIPT_EXEC,
-               "Unknown script entry type");
+    if (bms->entry[i].type != BOOT_SCRIPT_EXEC) {
+        puts("Unknown script entry type");
+        return -EINVAL;
+    }
     write_reset_psw(bms->entry[i].address.load_address); /* no return */
     jump_to_IPL_code(0); /* no return */
+    return 1;
 }
 
-static void ipl_eckd_cdl(void)
+static int ipl_eckd_cdl(void)
 {
     XEckdMbr *mbr;
     EckdCdlIpl2 *ipl2 = (void *)sec;
@@ -342,20 +384,23 @@ static void ipl_eckd_cdl(void)
     puts("CDL");
 
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(1, ipl2, "Cannot read IPL2 record at block 1");
+    if (virtio_read(1, ipl2)) {
+        puts("Cannot read IPL2 record at block 1");
+        return -EIO;
+    }
 
     mbr = &ipl2->mbr;
     if (!magic_match(mbr, ZIPL_MAGIC)) {
         puts("No zIPL section in IPL2 record.");
-        return;
+        return 0;
     }
     if (!block_size_ok(mbr->blockptr.xeckd.bptr.size)) {
         puts("Bad block size in zIPL section of IPL2 record.");
-        return;
+        return 0;
     }
     if (mbr->dev_type != DEV_TYPE_ECKD) {
         puts("Non-ECKD device type in zIPL section of IPL2 record.");
-        return;
+        return 0;
     }
 
     /* save pointer to Boot Map Table */
@@ -365,19 +410,21 @@ static void ipl_eckd_cdl(void)
     s1b_block_nr = eckd_block_num(&ipl2->stage1.seek[0].chs);
 
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(2, vlbl, "Cannot read Volume Label at block 2");
+    if (virtio_read(2, vlbl)) {
+        puts("Cannot read Volume Label at block 2");
+        return -EIO;
+    }
     if (!magic_match(vlbl->key, VOL1_MAGIC)) {
         puts("Invalid magic of volume label block.");
-        return;
+        return 0;
     }
     if (!magic_match(vlbl->f.key, VOL1_MAGIC)) {
         puts("Invalid magic of volser block.");
-        return;
+        return 0;
     }
     print_volser(vlbl->f.volser);
 
-    run_eckd_boot_script(bmt_block_nr, s1b_block_nr);
-    /* no return */
+    return run_eckd_boot_script(bmt_block_nr, s1b_block_nr);
 }
 
 static void print_eckd_ldl_msg(ECKD_IPL_mode_t mode)
@@ -403,7 +450,7 @@ static void print_eckd_ldl_msg(ECKD_IPL_mode_t mode)
     print_volser(vlbl->volser);
 }
 
-static void ipl_eckd_ldl(ECKD_IPL_mode_t mode)
+static int ipl_eckd_ldl(ECKD_IPL_mode_t mode)
 {
     block_number_t bmt_block_nr, s1b_block_nr;
     EckdLdlIpl1 *ipl1 = (void *)sec;
@@ -415,10 +462,13 @@ static void ipl_eckd_ldl(ECKD_IPL_mode_t mode)
     /* DO NOT read BootMap pointer (only one, xECKD) at block #2 */
 
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(0, sec, "Cannot read block 0 to grab boot info.");
+    if (virtio_read(0, sec)) {
+        puts("Cannot read block 0 to grab boot info.");
+        return -EIO;
+    }
     if (mode == ECKD_LDL_UNLABELED) {
         if (!magic_match(ipl1->bip.magic, ZIPL_MAGIC)) {
-            return; /* not applicable layout */
+            return 0; /* not applicable layout */
         }
         puts("unlabeled LDL.");
     }
@@ -430,8 +480,7 @@ static void ipl_eckd_ldl(ECKD_IPL_mode_t mode)
     /* save pointer to Stage1b Data */
     s1b_block_nr = eckd_block_num(&ipl1->stage1.seek[0].chs);
 
-    run_eckd_boot_script(bmt_block_nr, s1b_block_nr);
-    /* no return */
+    return run_eckd_boot_script(bmt_block_nr, s1b_block_nr);
 }
 
 static block_number_t eckd_find_bmt(ExtEckdBlockPtr *ptr)
@@ -441,11 +490,14 @@ static block_number_t eckd_find_bmt(ExtEckdBlockPtr *ptr)
     BootRecord *br;
 
     blockno = gen_eckd_block_num(ptr, 0);
-    read_block(blockno, tmp_sec, "Cannot read boot record");
+    if (virtio_read(blockno, tmp_sec)) {
+        puts("Cannot read boot record");
+        return -EIO;
+    }
     br = (BootRecord *)tmp_sec;
     if (!magic_match(br->magic, ZIPL_MAGIC)) {
         /* If the boot record is invalid, return and try CCW-IPL instead */
-        return NULL_BLOCK_NR;
+        return 0;
     }
 
     return gen_eckd_block_num(&br->pgt.xeckd, 1);
@@ -470,7 +522,7 @@ static void print_eckd_msg(void)
     printf("%s", msg);
 }
 
-static void ipl_eckd(void)
+static int ipl_eckd(void)
 {
     IplVolumeLabel *vlbl = (void *)sec;
     LDL_VTOC *vtoc = (void *)sec;
@@ -480,7 +532,10 @@ static void ipl_eckd(void)
 
     /* Block 2 can contain either the CDL VOL1 label or the LDL VTOC */
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-    read_block(2, vlbl, "Cannot read block 2");
+    if (virtio_read(2, vlbl)) {
+        puts("Cannot read block 2");
+        return -EIO;
+    }
 
     /*
      * First check for a list-directed-format pointer which would
@@ -490,34 +545,46 @@ static void ipl_eckd(void)
         ldipl_bmt = eckd_find_bmt((ExtEckdBlockPtr *)&vlbl->f.br);
         if (ldipl_bmt) {
             puts("List-Directed");
-            /* LD-IPL does not use the S1B bock, just make it NULL */
-            run_eckd_boot_script(ldipl_bmt, NULL_BLOCK_NR);
-            /* Only return in error, retry as CCW-IPL */
+            /*
+             * LD-IPL does not use the S1B bock, just make it NULL_BLOCK_NR.
+             * In some failure cases retry IPL before aborting.
+             */
+            if (run_eckd_boot_script(ldipl_bmt, NULL_BLOCK_NR)) {
+                return -EIO;
+            }
+            /* Non-fatal error, retry as CCW-IPL */
             printf("Retrying IPL ");
             print_eckd_msg();
         }
         memset(sec, FREE_SPACE_FILLER, sizeof(sec));
-        read_block(2, vtoc, "Cannot read block 2");
+        if (virtio_read(2, vtoc)) {
+            puts("Cannot read block 2");
+            return -EIO;
+        }
     }
 
     /* Not list-directed */
     if (magic_match(vtoc->magic, VOL1_MAGIC)) {
-        ipl_eckd_cdl(); /* may return in error */
+        if (ipl_eckd_cdl()) {
+            return 1;
+        }
     }
 
     if (magic_match(vtoc->magic, CMS1_MAGIC)) {
-        ipl_eckd_ldl(ECKD_CMS); /* no return */
+        return ipl_eckd_ldl(ECKD_CMS);
     }
     if (magic_match(vtoc->magic, LNX1_MAGIC)) {
-        ipl_eckd_ldl(ECKD_LDL); /* no return */
+        return ipl_eckd_ldl(ECKD_LDL);
     }
 
-    ipl_eckd_ldl(ECKD_LDL_UNLABELED); /* it still may return */
+    if (ipl_eckd_ldl(ECKD_LDL_UNLABELED)) {
+        return 1;
+    }
     /*
      * Ok, it is not a LDL by any means.
      * It still might be a CDL with zero record keys for IPL1 and IPL2
      */
-    ipl_eckd_cdl();
+    return ipl_eckd_cdl();
 }
 
 /***********************************************************************
@@ -907,7 +974,7 @@ static bool has_iso_signature(void)
  * Bus specific IPL sequences
  */
 
-static void zipl_load_vblk(void)
+static int zipl_load_vblk(void)
 {
     int blksize = virtio_get_block_size();
 
@@ -916,7 +983,7 @@ static void zipl_load_vblk(void)
             virtio_assume_iso9660();
         }
         if (ipl_iso_el_torito()) {
-            return;
+            return 0;
         }
     }
 
@@ -924,21 +991,21 @@ static void zipl_load_vblk(void)
         puts("Using guessed DASD geometry.");
         virtio_assume_eckd();
     }
-    ipl_eckd();
+    return ipl_eckd();
 }
 
-static void zipl_load_vscsi(void)
+static int zipl_load_vscsi(void)
 {
     if (virtio_get_block_size() == VIRTIO_ISO_BLOCK_SIZE) {
         /* Is it an ISO image in non-CD drive? */
         if (ipl_iso_el_torito()) {
-            return;
+            return 0;
         }
     }
 
     puts("Using guessed DASD geometry.");
     virtio_assume_eckd();
-    ipl_eckd();
+    return ipl_eckd();
 }
 
 /***********************************************************************
-- 
2.45.1
Re: [PATCH v3 08/19] pc-bios/s390-ccw: Remove panics from ECKD IPL path
Posted by Thomas Huth 1 month, 2 weeks ago
On 08/10/2024 03.15, jrossi@linux.ibm.com wrote:
> From: Jared Rossi <jrossi@linux.ibm.com>
> 
> Remove panic-on-error from ECKD block device IPL specific functions so that
> error recovery may be possible in the future.
> 
> Functions that would previously panic now provide a return code.
> 
> Signed-off-by: Jared Rossi <jrossi@linux.ibm.com>
> ---
>   pc-bios/s390-ccw/s390-ccw.h |   1 +
>   pc-bios/s390-ccw/bootmap.c  | 183 ++++++++++++++++++++++++------------
>   2 files changed, 126 insertions(+), 58 deletions(-)
> 
> diff --git a/pc-bios/s390-ccw/s390-ccw.h b/pc-bios/s390-ccw/s390-ccw.h
> index cbd92f3671..7516e96a14 100644
> --- a/pc-bios/s390-ccw/s390-ccw.h
> +++ b/pc-bios/s390-ccw/s390-ccw.h
> @@ -31,6 +31,7 @@ typedef unsigned long long u64;
>   #define EBUSY   2
>   #define ENODEV  3
>   #define EINVAL  4
> +#define ENOENT  5
>   
>   #ifndef MIN
>   #define MIN(a, b) (((a) < (b)) ? (a) : (b))
> diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c
> index 7984de62fe..266b38c034 100644
> --- a/pc-bios/s390-ccw/bootmap.c
> +++ b/pc-bios/s390-ccw/bootmap.c
> @@ -145,14 +145,17 @@ static block_number_t load_eckd_segments(block_number_t blk, bool ldipl,
>       bool more_data;
>   
>       memset(_bprs, FREE_SPACE_FILLER, sizeof(_bprs));
> -    read_block(blk, bprs, "BPRS read failed");
> +    if (virtio_read(blk, bprs)) {
> +        puts("BPRS read failed");
> +        return -EIO;
> +    }

load_eckd_segments() returns a value of type block_number_t which is an 
unsigned type, so returning a negative error value will likely not work as 
expected...

...
> @@ -317,21 +352,28 @@ static void run_eckd_boot_script(block_number_t bmt_block_nr,
>   
>           do {
>               block_nr = load_eckd_segments(block_nr, ldipl, &address);
> -        } while (block_nr != -1);
> +        } while (block_nr >= 0);

... for example here: block_nr is also of type block_number_t, so the while 
condition is also true for "negative" error codes.

> +        if (block_nr != -ENOENT && block_nr < 0) {

"block_nr < 0" likely also always evaluates to "false".

> +            return ldipl ? 0 : -EIO;
> +        }
>       }
>   
>       if (ldipl && bms->entry[i].type != BOOT_SCRIPT_EXEC) {
>           /* Abort LD-IPL and retry as CCW-IPL */
> -        return;
> +        return 0;
>       }
>   
> -    IPL_assert(bms->entry[i].type == BOOT_SCRIPT_EXEC,
> -               "Unknown script entry type");
> +    if (bms->entry[i].type != BOOT_SCRIPT_EXEC) {
> +        puts("Unknown script entry type");
> +        return -EINVAL;
> +    }
>       write_reset_psw(bms->entry[i].address.load_address); /* no return */
>       jump_to_IPL_code(0); /* no return */
> +    return 1;
>   }
...
> @@ -441,11 +490,14 @@ static block_number_t eckd_find_bmt(ExtEckdBlockPtr *ptr)
>       BootRecord *br;
>   
>       blockno = gen_eckd_block_num(ptr, 0);
> -    read_block(blockno, tmp_sec, "Cannot read boot record");
> +    if (virtio_read(blockno, tmp_sec)) {
> +        puts("Cannot read boot record");
> +        return -EIO;

Same problem here: Returning a negative error code via unsigned 
block_number_t ....

...
> @@ -490,34 +545,46 @@ static void ipl_eckd(void)
>           ldipl_bmt = eckd_find_bmt((ExtEckdBlockPtr *)&vlbl->f.br);
>           if (ldipl_bmt) {

... will cause trouble here.

>               puts("List-Directed");
> -            /* LD-IPL does not use the S1B bock, just make it NULL */
> -            run_eckd_boot_script(ldipl_bmt, NULL_BLOCK_NR);
> -            /* Only return in error, retry as CCW-IPL */
> +            /*
> +             * LD-IPL does not use the S1B bock, just make it NULL_BLOCK_NR.
> +             * In some failure cases retry IPL before aborting.
> +             */
> +            if (run_eckd_boot_script(ldipl_bmt, NULL_BLOCK_NR)) {
> +                return -EIO;
> +            }
> +            /* Non-fatal error, retry as CCW-IPL */
>               printf("Retrying IPL ");
>               print_eckd_msg();
>           }
>           memset(sec, FREE_SPACE_FILLER, sizeof(sec));
> -        read_block(2, vtoc, "Cannot read block 2");
> +        if (virtio_read(2, vtoc)) {
> +            puts("Cannot read block 2");
> +            return -EIO;
> +        }
>       }
>   
>       /* Not list-directed */
>       if (magic_match(vtoc->magic, VOL1_MAGIC)) {
> -        ipl_eckd_cdl(); /* may return in error */
> +        if (ipl_eckd_cdl()) {
> +            return 1;
> +        }
>       }
>   
>       if (magic_match(vtoc->magic, CMS1_MAGIC)) {
> -        ipl_eckd_ldl(ECKD_CMS); /* no return */
> +        return ipl_eckd_ldl(ECKD_CMS);
>       }
>       if (magic_match(vtoc->magic, LNX1_MAGIC)) {
> -        ipl_eckd_ldl(ECKD_LDL); /* no return */
> +        return ipl_eckd_ldl(ECKD_LDL);
>       }
>   
> -    ipl_eckd_ldl(ECKD_LDL_UNLABELED); /* it still may return */
> +    if (ipl_eckd_ldl(ECKD_LDL_UNLABELED)) {
> +        return 1;
> +    }
>       /*
>        * Ok, it is not a LDL by any means.
>        * It still might be a CDL with zero record keys for IPL1 and IPL2
>        */
> -    ipl_eckd_cdl();
> +    return ipl_eckd_cdl();
>   }

  Thomas
Re: [PATCH v3 08/19] pc-bios/s390-ccw: Remove panics from ECKD IPL path
Posted by Jared Rossi 1 month, 2 weeks ago

On 10/9/24 6:53 AM, Thomas Huth wrote:
> On 08/10/2024 03.15, jrossi@linux.ibm.com wrote:
>> [snip...]
>
> load_eckd_segments() returns a value of type block_number_t which is 
> an unsigned type, so returning a negative error value will likely not 
> work as expected...
>
> ...
>> @@ -317,21 +352,28 @@ static void run_eckd_boot_script(block_number_t 
>> bmt_block_nr,
>>             do {
>>               block_nr = load_eckd_segments(block_nr, ldipl, &address);
>> -        } while (block_nr != -1);
>> +        } while (block_nr >= 0);
> [snip...]

There already exists a special block number defined in bootmap.h, 
NULL_BLOCK_NR 0xffffffffffffffffULL. Therefore I would propose simply 
adding another as ERROR_BLOCK_NR 0xfffffffffffffffeULL.

ERROR_BLOCK_NR would replace the negative error codes and NULL_BLOCK_NR 
would represent expected end of chunk.  Does this seem reasonable?

     Jared


Re: [PATCH v3 08/19] pc-bios/s390-ccw: Remove panics from ECKD IPL path
Posted by Thomas Huth 1 month, 2 weeks ago
On 10/10/2024 03.37, Jared Rossi wrote:
> 
> 
> On 10/9/24 6:53 AM, Thomas Huth wrote:
>> On 08/10/2024 03.15, jrossi@linux.ibm.com wrote:
>>> [snip...]
>>
>> load_eckd_segments() returns a value of type block_number_t which is an 
>> unsigned type, so returning a negative error value will likely not work as 
>> expected...
>>
>> ...
>>> @@ -317,21 +352,28 @@ static void run_eckd_boot_script(block_number_t 
>>> bmt_block_nr,
>>>             do {
>>>               block_nr = load_eckd_segments(block_nr, ldipl, &address);
>>> -        } while (block_nr != -1);
>>> +        } while (block_nr >= 0);
>> [snip...]
> 
> There already exists a special block number defined in bootmap.h, 
> NULL_BLOCK_NR 0xffffffffffffffffULL. Therefore I would propose simply adding 
> another as ERROR_BLOCK_NR 0xfffffffffffffffeULL.
> 
> ERROR_BLOCK_NR would replace the negative error codes and NULL_BLOCK_NR 
> would represent expected end of chunk.  Does this seem reasonable?

Sounds like a good idea.

Alternatively, you could do casting to signed long here and there, but 
that's ugly, too.

  Thomas