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 v5 15/19] hw/s390x: Build an IPLB for each boot device
Date: Tue, 22 Oct 2024 15:13:38 +0200	[thread overview]
Message-ID: <9891e2f8-c5b9-4bc6-84a3-dd0b49920cc6@redhat.com> (raw)
In-Reply-To: <20241020012953.1380075-16-jrossi@linux.ibm.com>

On 20/10/2024 03.29, jrossi@linux.ibm.com wrote:
> From: Jared Rossi <jrossi@linux.ibm.com>
> 
> Build an IPLB for any device with a bootindex (up to a maximum of 8 devices).
> 
> The IPLB chain is placed immediately before the BIOS in memory. Because this
> is not a fixed address, the location of the next IPLB and number of remaining
> boot devices is stored in the QIPL global variable for possible later access by
> the guest during IPL.
> 
> Signed-off-by: Jared Rossi <jrossi@linux.ibm.com>
> ---
...
> diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
> index 656996b500..ed152a9dd2 100644
> --- a/hw/s390x/ipl.c
> +++ b/hw/s390x/ipl.c
> @@ -56,6 +56,13 @@ static bool iplb_extended_needed(void *opaque)
>       return ipl->iplbext_migration;
>   }
>   
> +/* Place the IPLB chain immediately before the BIOS in memory */
> +static uint64_t find_iplb_chain_addr(uint64_t bios_addr, uint16_t count)
> +{
> +    return (bios_addr & TARGET_PAGE_MASK)
> +            - (count * sizeof(IplParameterBlock));
> +}
> +
>   static const VMStateDescription vmstate_iplb_extended = {
>       .name = "ipl/iplb_extended",
>       .version_id = 0,
> @@ -398,6 +405,17 @@ static CcwDevice *s390_get_ccw_device(DeviceState *dev_st, int *devtype)
>       return ccw_dev;
>   }
>   
> +static uint64_t s390_ipl_map_iplb_chain(IplParameterBlock *iplb_chain)
> +{
> +    S390IPLState *ipl = get_ipl_device();
> +    uint16_t count = ipl->qipl.chain_len;

I ran into problems when running the cdrom-test on my x86 laptop.

I think the above line needs to be changed into this to get it working on 
little endian hosts:

     uint16_t count = be16_to_cpu(ipl->qipl.chain_len)


> +    uint64_t len = sizeof(IplParameterBlock) * count;
> +    uint64_t chain_addr = find_iplb_chain_addr(ipl->bios_start_addr, count);
> +
> +    cpu_physical_memory_write(chain_addr, iplb_chain, len);
> +    return chain_addr;
> +}
> +
>   void s390_ipl_fmt_loadparm(uint8_t *loadparm, char *str, Error **errp)
>   {
>       int i;
> @@ -428,54 +446,51 @@ void s390_ipl_convert_loadparm(char *ascii_lp, uint8_t *ebcdic_lp)
>       }
>   }
>   
> -static bool s390_gen_initial_iplb(S390IPLState *ipl)
> +static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb)
>   {
> -    DeviceState *dev_st;
> +    S390IPLState *ipl = get_ipl_device();
>       CcwDevice *ccw_dev = NULL;
>       SCSIDevice *sd;
>       int devtype;
>       uint8_t *lp;
>   
> -    dev_st = get_boot_device(0);
> -    if (dev_st) {
> -        ccw_dev = s390_get_ccw_device(dev_st, &devtype);
> -    }
> -
>       /*
>        * Currently allow IPL only from CCW devices.
>        */
> +    ccw_dev = s390_get_ccw_device(dev_st, &devtype);
>       if (ccw_dev) {
>           lp = ccw_dev->loadparm;
>   
>           switch (devtype) {
>           case CCW_DEVTYPE_SCSI:
>               sd = SCSI_DEVICE(dev_st);
> -            ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN);
> -            ipl->iplb.blk0_len =
> +            iplb->len = cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN);
> +            iplb->blk0_len =
>                   cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN - S390_IPLB_HEADER_LEN);
> -            ipl->iplb.pbt = S390_IPL_TYPE_QEMU_SCSI;
> -            ipl->iplb.scsi.lun = cpu_to_be32(sd->lun);
> -            ipl->iplb.scsi.target = cpu_to_be16(sd->id);
> -            ipl->iplb.scsi.channel = cpu_to_be16(sd->channel);
> -            ipl->iplb.scsi.devno = cpu_to_be16(ccw_dev->sch->devno);
> -            ipl->iplb.scsi.ssid = ccw_dev->sch->ssid & 3;
> +            iplb->pbt = S390_IPL_TYPE_QEMU_SCSI;
> +            iplb->scsi.lun = cpu_to_be32(sd->lun);
> +            iplb->scsi.target = cpu_to_be16(sd->id);
> +            iplb->scsi.channel = cpu_to_be16(sd->channel);
> +            iplb->scsi.devno = cpu_to_be16(ccw_dev->sch->devno);
> +            iplb->scsi.ssid = ccw_dev->sch->ssid & 3;
>               break;
>           case CCW_DEVTYPE_VFIO:
> -            ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_CCW_LEN);
> -            ipl->iplb.pbt = S390_IPL_TYPE_CCW;
> -            ipl->iplb.ccw.devno = cpu_to_be16(ccw_dev->sch->devno);
> -            ipl->iplb.ccw.ssid = ccw_dev->sch->ssid & 3;
> +            iplb->len = cpu_to_be32(S390_IPLB_MIN_CCW_LEN);
> +            iplb->pbt = S390_IPL_TYPE_CCW;
> +            iplb->ccw.devno = cpu_to_be16(ccw_dev->sch->devno);
> +            iplb->ccw.ssid = ccw_dev->sch->ssid & 3;
>               break;
>           case CCW_DEVTYPE_VIRTIO_NET:
> +            /* The S390IPLState netboot is true if ANY IPLB may use netboot */
>               ipl->netboot = true;
>               /* Fall through to CCW_DEVTYPE_VIRTIO case */
>           case CCW_DEVTYPE_VIRTIO:
> -            ipl->iplb.len = cpu_to_be32(S390_IPLB_MIN_CCW_LEN);
> -            ipl->iplb.blk0_len =
> +            iplb->len = cpu_to_be32(S390_IPLB_MIN_CCW_LEN);
> +            iplb->blk0_len =
>                   cpu_to_be32(S390_IPLB_MIN_CCW_LEN - S390_IPLB_HEADER_LEN);
> -            ipl->iplb.pbt = S390_IPL_TYPE_CCW;
> -            ipl->iplb.ccw.devno = cpu_to_be16(ccw_dev->sch->devno);
> -            ipl->iplb.ccw.ssid = ccw_dev->sch->ssid & 3;
> +            iplb->pbt = S390_IPL_TYPE_CCW;
> +            iplb->ccw.devno = cpu_to_be16(ccw_dev->sch->devno);
> +            iplb->ccw.ssid = ccw_dev->sch->ssid & 3;
>               break;
>           }
>   
> @@ -484,8 +499,8 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl)
>               lp = S390_CCW_MACHINE(qdev_get_machine())->loadparm;
>           }
>   
> -        s390_ipl_convert_loadparm((char *)lp, ipl->iplb.loadparm);
> -        ipl->iplb.flags |= DIAG308_FLAGS_LP_VALID;
> +        s390_ipl_convert_loadparm((char *)lp, iplb->loadparm);
> +        iplb->flags |= DIAG308_FLAGS_LP_VALID;
>   
>           return true;
>       }
> @@ -493,6 +508,62 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl)
>       return false;
>   }
>   
> +static bool s390_init_all_iplbs(S390IPLState *ipl)
> +{
> +    int iplb_num = 0;
> +    IplParameterBlock iplb_chain[7];
> +    DeviceState *dev_st = get_boot_device(0);
> +    Object *machine = qdev_get_machine();
> +
> +    /*
> +     * Parse the boot devices.  Generate an IPLB for only the first boot device
> +     * which will later be set with DIAG308.
> +     */
> +    if (!dev_st) {
> +        ipl->qipl.chain_len = 0;
> +        return false;
> +    }
> +
> +    /* If no machine loadparm was defined fill it with spaces */
> +    if (memcmp(S390_CCW_MACHINE(machine)->loadparm, NO_LOADPARM, 8) == 0) {
> +        object_property_set_str(machine, "loadparm", "        ", NULL);
> +    }
> +
> +    iplb_num = 1;
> +    s390_build_iplb(dev_st, &ipl->iplb);
> +
> +    /*  Index any fallback boot devices */
> +    while (get_boot_device(iplb_num)) {
> +        iplb_num++;
> +    }
> +
> +    if (iplb_num > MAX_BOOT_DEVS) {
> +        warn_report("Excess boot devices defined! %d boot devices found, "
> +                    "but only the first %d will be considered.",
> +                    iplb_num, MAX_BOOT_DEVS);
> +
> +        iplb_num = MAX_BOOT_DEVS;
> +    }
> +
> +    ipl->qipl.chain_len = iplb_num - 1;

... and this needs to be changed into:

     ipl->qipl.chain_len = cpu_to_be16(iplb_num - 1);

> +    /*
> +     * Build fallback IPLBs for any boot devices above index 0, up to a
> +     * maximum amount as defined in ipl.h
> +     */
> +    if (iplb_num > 1) {
> +        /* Start at 1 because the IPLB for boot index 0 is not chained */
> +        for (int i = 1; i < iplb_num; i++) {
> +            dev_st = get_boot_device(i);
> +            s390_build_iplb(dev_st, &iplb_chain[i - 1]);
> +        }
> +
> +        ipl->qipl.next_iplb = s390_ipl_map_iplb_chain(iplb_chain);

And this needs to be change into:

     ipl->qipl.next_iplb = cpu_to_be64(s390_ipl_map_iplb_chain(iplb_chain));

I am already in progress of picking up your patches, so if you agree with my 
suggestions, I can fix it on my side, too.

  Thomas


> +    }
> +
> +    return iplb_num;
> +}



  parent reply	other threads:[~2024-10-22 13:14 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-20  1:29 [PATCH v5 00/19] s390x: Add Full Boot Order Support jrossi
2024-10-20  1:29 ` [PATCH v5 01/19] hw/s390x/ipl: Provide more memory to the s390-ccw.img firmware jrossi
2024-10-20  1:29 ` [PATCH v5 02/19] pc-bios/s390-ccw: Use the libc from SLOF and remove sclp prints jrossi
2024-10-22 17:36   ` Thomas Huth
2024-10-22 20:12     ` Jared Rossi
2024-10-23  4:51       ` Thomas Huth
2024-10-23 10:30         ` Jared Rossi
2024-10-20  1:29 ` [PATCH v5 03/19] pc-bios/s390-ccw: Link the netboot code into the main s390-ccw.img binary jrossi
2024-10-20  1:29 ` [PATCH v5 04/19] hw/s390x: Remove the possibility to load the s390-netboot.img binary jrossi
2024-10-20  1:29 ` [PATCH v5 05/19] pc-bios/s390-ccw: Merge netboot.mak into the main Makefile jrossi
2024-10-20  1:29 ` [PATCH v5 06/19] docs/system/s390x/bootdevices: Update the documentation about network booting jrossi
2024-10-20  1:29 ` [PATCH v5 07/19] pc-bios/s390-ccw: Remove panics from ISO IPL path jrossi
2024-10-21  8:41   ` Thomas Huth
2024-10-20  1:29 ` [PATCH v5 08/19] pc-bios/s390-ccw: Remove panics from ECKD " jrossi
2024-10-21  9:12   ` Thomas Huth
2024-10-20  1:29 ` [PATCH v5 09/19] pc-bios/s390-ccw: Remove panics from SCSI " jrossi
2024-10-21  9:26   ` Thomas Huth
2024-10-20  1:29 ` [PATCH v5 10/19] pc-bios/s390-ccw: Remove panics from DASD " jrossi
2024-10-20  1:29 ` [PATCH v5 11/19] pc-bios/s390-ccw: Remove panics from Netboot " jrossi
2024-10-21  9:30   ` Thomas Huth
2024-10-20  1:29 ` [PATCH v5 12/19] pc-bios/s390-ccw: Enable failed IPL to return after error jrossi
2024-10-20  1:29 ` [PATCH v5 13/19] include/hw/s390x: Add include files for common IPL structs jrossi
2024-10-20  1:29 ` [PATCH v5 14/19] s390x: Add individual loadparm assignment to CCW device jrossi
2024-10-21 12:26   ` Thomas Huth
2024-10-31  8:45   ` Thomas Huth
2024-11-05 20:22     ` Jared Rossi
2024-10-20  1:29 ` [PATCH v5 15/19] hw/s390x: Build an IPLB for each boot device jrossi
2024-10-21 12:43   ` Thomas Huth
2024-10-22 13:13   ` Thomas Huth [this message]
2024-10-22 14:25     ` Jared Rossi
2024-10-20  1:29 ` [PATCH v5 16/19] s390x: Rebuild IPLB for SCSI device directly from DIAG308 jrossi
2024-10-20  1:29 ` [PATCH v5 17/19] pc-bios/s390x: Enable multi-device boot loop jrossi
2024-10-22  7:33   ` Thomas Huth
2024-10-20  1:29 ` [PATCH v5 18/19] docs/system: Update documentation for s390x IPL jrossi
2024-10-20  1:29 ` [PATCH v5 19/19] tests/qtest: Add s390x boot order tests to cdrom-test.c jrossi
2024-10-21 14:52   ` Thomas Huth
2024-10-31 15:50 ` [PATCH v5 00/19] s390x: Add Full Boot Order Support Thomas Huth
2024-11-05 16:42   ` Jared Rossi
2024-11-06 11:10     ` Thomas Huth
2024-11-07 20:42       ` Jared Rossi
2024-11-08 14:37         ` Thomas Huth
2024-11-11 12:23           ` 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=9891e2f8-c5b9-4bc6-84a3-dd0b49920cc6@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).