qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: jrossi@linux.ibm.com, qemu-devel@nongnu.org, qemu-s390x@nongnu.org
Cc: frankja@linux.ibm.com
Subject: Re: [PATCH v4 08/19] pc-bios/s390-ccw: Remove panics from ECKD IPL path
Date: Thu, 17 Oct 2024 10:01:27 +0200	[thread overview]
Message-ID: <d7c663e5-e18b-4fce-a0eb-b6e10229bf45@redhat.com> (raw)
In-Reply-To: <20241017014748.829029-9-jrossi@linux.ibm.com>

On 17/10/2024 03.47, 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/bootmap.h |   1 +
>   pc-bios/s390-ccw/bootmap.c | 193 +++++++++++++++++++++++++------------
>   2 files changed, 135 insertions(+), 59 deletions(-)
> 
> diff --git a/pc-bios/s390-ccw/bootmap.h b/pc-bios/s390-ccw/bootmap.h
> index 09f4e6fb40..271dbabbc3 100644
> --- a/pc-bios/s390-ccw/bootmap.h
> +++ b/pc-bios/s390-ccw/bootmap.h
> @@ -16,6 +16,7 @@
>   
>   typedef uint64_t block_number_t;
>   #define NULL_BLOCK_NR 0xffffffffffffffffULL
> +#define ERROR_BLOCK_NR 0xfffffffffffffffeULL
>   
>   #define FREE_SPACE_FILLER '\xAA'
>   
> diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c
> index 5477cfe228..dd04bb3384 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 ERROR_BLOCK_NR;
> +    }
>   
>       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 NULL_BLOCK_NR;
>               }
>   
>               /* 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 NULL_BLOCK_NR;

Shouldn't that be a "return ERROR_BLOCK_NR" instead?

> +            }
>   
>               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 ERROR_BLOCK_NR;
> +                }
>                   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 ERROR_BLOCK_NR;
> +                }
>                   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 ERROR_BLOCK_NR;
> +            }
>   
>               *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 != ERROR_BLOCK_NR && block_nr != NULL_BLOCK_NR);
> +
> +        if (block_nr == ERROR_BLOCK_NR) {
> +            return ldipl ? 0 : -EIO;
> +        }

Mostly a matter of style, but if you move the if-statement into the while 
loop, you don't have to check for ERROR_BLOCK_NR in the while condition again.

>       }
>   
>       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;
>   }
...
> @@ -787,12 +859,15 @@ static void load_iso_bc_entry(IsoBcSection *load)
>       uint32_t blks_to_load = bswap16(s.sector_count) >> ET_SECTOR_SHIFT;
>       long real_size = iso_get_file_size(bswap32(s.load_rba));
>   
> -    if (real_size) {
> +    if (real_size > 0) {
>           /* Round up blocks to load */
>           blks_to_load = (real_size + ISO_SECTOR_SIZE - 1) / ISO_SECTOR_SIZE;
>           puts("ISO boot image size verified");
>       } else {
>           puts("ISO boot image size could not be verified");
> +        if (real_size < 0) {
> +            return;
> +        }
>       }

Ah, here's the fix for the problem that I complained about in the previous 
patch :-) ... looks like you've squashed it into the wrong patch.

  Thomas




  reply	other threads:[~2024-10-17  8:02 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-17  1:47 [PATCH v4 00/19] s390x: Add Full Boot Order Support jrossi
2024-10-17  1:47 ` [PATCH v4 01/19] hw/s390x/ipl: Provide more memory to the s390-ccw.img firmware jrossi
2024-10-17  1:47 ` [PATCH v4 02/19] pc-bios/s390-ccw: Use the libc from SLOF and remove sclp prints jrossi
2024-10-17  1:47 ` [PATCH v4 03/19] pc-bios/s390-ccw: Link the netboot code into the main s390-ccw.img binary jrossi
2024-10-17  1:47 ` [PATCH v4 04/19] hw/s390x: Remove the possibility to load the s390-netboot.img binary jrossi
2024-10-17  1:47 ` [PATCH v4 05/19] pc-bios/s390-ccw: Merge netboot.mak into the main Makefile jrossi
2024-10-17  1:47 ` [PATCH v4 06/19] docs/system/s390x/bootdevices: Update the documentation about network booting jrossi
2024-10-17  1:47 ` [PATCH v4 07/19] pc-bios/s390-ccw: Remove panics from ISO IPL path jrossi
2024-10-17  7:38   ` Thomas Huth
2024-10-17  1:47 ` [PATCH v4 08/19] pc-bios/s390-ccw: Remove panics from ECKD " jrossi
2024-10-17  8:01   ` Thomas Huth [this message]
2024-10-17  1:47 ` [PATCH v4 09/19] pc-bios/s390-ccw: Remove panics from SCSI " jrossi
2024-10-17 10:28   ` Thomas Huth
2024-10-17  1:47 ` [PATCH v4 10/19] pc-bios/s390-ccw: Remove panics from DASD " jrossi
2024-10-17  1:47 ` [PATCH v4 11/19] pc-bios/s390-ccw: Remove panics from Netboot " jrossi
2024-10-17 10:33   ` Thomas Huth
2024-10-17  1:47 ` [PATCH v4 12/19] pc-bios/s390-ccw: Enable failed IPL to return after error jrossi
2024-10-17  1:47 ` [PATCH v4 13/19] include/hw/s390x: Add include files for common IPL structs jrossi
2024-10-17  1:47 ` [PATCH v4 14/19] s390x: Add individual loadparm assignment to CCW device jrossi
2024-10-17  1:47 ` [PATCH v4 15/19] hw/s390x: Build an IPLB for each boot device jrossi
2024-10-17  1:47 ` [PATCH v4 16/19] s390x: Rebuild IPLB for SCSI device directly from DIAG308 jrossi
2024-10-17 11:27   ` Thomas Huth
2024-10-17  1:47 ` [PATCH v4 17/19] pc-bios/s390x: Enable multi-device boot loop jrossi
2024-10-17 11:41   ` Thomas Huth
2024-10-17  1:47 ` [PATCH v4 18/19] docs/system: Update documentation for s390x IPL jrossi
2024-10-17  1:47 ` [PATCH v4 19/19] tests/qtest: Add s390x boot order tests to cdrom-test.c jrossi
2024-10-17 11:51   ` Thomas Huth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d7c663e5-e18b-4fce-a0eb-b6e10229bf45@redhat.com \
    --to=thuth@redhat.com \
    --cc=frankja@linux.ibm.com \
    --cc=jrossi@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).