All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Cornelia Huck <cornelia.huck@de.ibm.com>, qemu-devel@nongnu.org
Cc: borntraeger@de.ibm.com, jfrei@linux.vnet.ibm.com,
	Farhan Ali <alifm@linux.vnet.ibm.com>,
	agraf@suse.de
Subject: Re: [Qemu-devel] [PATCH v2 3/5] s390x/ipl: Load network boot image
Date: Sat, 25 Feb 2017 07:18:29 +0100	[thread overview]
Message-ID: <4fe97bb7-d6f0-7b58-916f-94dc0ae81616@redhat.com> (raw)
In-Reply-To: <20170223122025.10420-4-cornelia.huck@de.ibm.com>

On 23.02.2017 13:20, Cornelia Huck wrote:
> From: Farhan Ali <alifm@linux.vnet.ibm.com>
> 
> Load the network boot image into guest RAM when the boot
> device selected is a network device. Use some of the reserved
> space in IplBlockCcw to store the start address of the netboot
> image.
> 
> A user could also use 'chreipl'(diag 308/5) to change the boot device.
> So every time we update the IPLB, we need to verify if the selected
> boot device is a network device so we can appropriately load the
> network boot image.
> 
> Signed-off-by: Farhan Ali <alifm@linux.vnet.ibm.com>
> Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
> ---
>  hw/s390x/ipl.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  hw/s390x/ipl.h |  4 ++-
>  2 files changed, 92 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c
> index fd656718a7..195cac559f 100644
> --- a/hw/s390x/ipl.c
> +++ b/hw/s390x/ipl.c
> @@ -20,6 +20,7 @@
>  #include "hw/s390x/virtio-ccw.h"
>  #include "hw/s390x/css.h"
>  #include "ipl.h"
> +#include "qemu/error-report.h"
>  
>  #define KERN_IMAGE_START                0x010000UL
>  #define KERN_PARM_AREA                  0x010480UL
> @@ -227,6 +228,12 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl)
>                  TYPE_VIRTIO_CCW_DEVICE);
>          SCSIDevice *sd = (SCSIDevice *) object_dynamic_cast(OBJECT(dev_st),
>                                                              TYPE_SCSI_DEVICE);
> +        VirtIONet *vn = (VirtIONet *) object_dynamic_cast(OBJECT(dev_st),
> +                                                          TYPE_VIRTIO_NET);
> +
> +        if (vn) {
> +            ipl->netboot = true;
> +        }
>          if (virtio_ccw_dev) {
>              CcwDevice *ccw_dev = CCW_DEVICE(virtio_ccw_dev);
>  
> @@ -259,12 +266,86 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl)
>      return false;
>  }
>  
> +static int load_netboot_image(Error **errp)
> +{
> +    S390IPLState *ipl = get_ipl_device();
> +    char *netboot_filename;
> +    MemoryRegion *sysmem =  get_system_memory();
> +    MemoryRegion *mr = NULL;
> +    void *ram_ptr = NULL;
> +    int img_size = -1;
> +
> +    mr = memory_region_find(sysmem, 0, 1).mr;
> +    if (!mr) {
> +        error_setg(errp, "Failed to find memory region at address 0");
> +        return -1;
> +    }
> +
> +    ram_ptr = memory_region_get_ram_ptr(mr);
> +    if (!ram_ptr) {
> +        error_setg(errp, "No RAM found");
> +        goto unref_mr;
> +    }
> +
> +    netboot_filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, ipl->netboot_fw);
> +    if (netboot_filename == NULL) {
> +        error_setg(errp, "Could not find network bootloader");
> +        goto unref_mr;
> +    }
> +
> +    img_size = load_elf_ram(netboot_filename, NULL, NULL, &ipl->start_addr,
> +                            NULL, NULL, 1, EM_S390, 0, 0, NULL, false);
> +
> +    if (img_size < 0) {
> +        img_size = load_image_size(netboot_filename, ram_ptr, ram_size);
> +        ipl->start_addr = KERN_IMAGE_START;
> +    }
> +
> +    if (img_size < 0) {
> +        error_setg(errp, "Failed to load network bootloader");
> +    }
> +
> +    g_free(netboot_filename);
> +
> +unref_mr:
> +    memory_region_unref(mr);
> +    return img_size;
> +}
> +
> +static bool is_virtio_net_device(IplParameterBlock *iplb)
> +{
> +    uint8_t cssid;
> +    uint8_t ssid;
> +    uint16_t devno;
> +    uint16_t schid;
> +    SubchDev *sch = NULL;
> +
> +    if (iplb->pbt != S390_IPL_TYPE_CCW) {
> +        return false;
> +    }
> +
> +    devno = be16_to_cpu(iplb->ccw.devno);
> +    ssid = iplb->ccw.ssid & 3;
> +
> +    for (schid = 0; schid < MAX_SCHID; schid++) {
> +        for (cssid = 0; cssid < MAX_CSSID; cssid++) {
> +            sch = css_find_subch(1, cssid, ssid, schid);
> +
> +            if (sch && sch->devno == devno) {
> +                return sch->id.cu_model == VIRTIO_ID_NET;
> +            }
> +        }
> +    }
> +   return false;

The above line has only 3 instead of 4 spaces. I wonder why checkpatch
does not complain here...?

> +}
> +
>  void s390_ipl_update_diag308(IplParameterBlock *iplb)
>  {
>      S390IPLState *ipl = get_ipl_device();
>  
>      ipl->iplb = *iplb;
>      ipl->iplb_valid = true;
> +    ipl->netboot = is_virtio_net_device(iplb);
>  }
>  
>  IplParameterBlock *s390_ipl_get_iplb(void)
> @@ -288,6 +369,7 @@ void s390_reipl_request(void)
>  void s390_ipl_prepare_cpu(S390CPU *cpu)
>  {
>      S390IPLState *ipl = get_ipl_device();
> +    Error *err = NULL;
>  
>      cpu->env.psw.addr = ipl->start_addr;
>      cpu->env.psw.mask = IPL_PSW_MASK;
> @@ -298,6 +380,13 @@ void s390_ipl_prepare_cpu(S390CPU *cpu)
>              ipl->iplb_valid = s390_gen_initial_iplb(ipl);
>          }
>      }
> +    if (ipl->netboot) {
> +        if (load_netboot_image(&err) < 0) {
> +            error_report_err(err);
> +            vm_stop(RUN_STATE_INTERNAL_ERROR);
> +        }
> +        ipl->iplb.ccw.netboot_start_addr = ipl->start_addr;

Not sure whether it matters, but in case of early errors during
load_netboot_image(), ipl->start_addr could be used uninitialized here.
Maybe you should move the "ipl->start_addr = KERN_IMAGE_START;" there at
the beginning of the function, to make it also the default value for the
other error cases?

> +    }
>  }
>  
>  static void s390_ipl_reset(DeviceState *dev)
> diff --git a/hw/s390x/ipl.h b/hw/s390x/ipl.h
> index 4ad9a7c05e..46930e4c64 100644
> --- a/hw/s390x/ipl.h
> +++ b/hw/s390x/ipl.h
> @@ -16,7 +16,8 @@
>  #include "cpu.h"
>  
>  struct IplBlockCcw {
> -    uint8_t  reserved0[85];
> +    uint64_t netboot_start_addr;
> +    uint8_t  reserved0[77];
>      uint8_t  ssid;
>      uint16_t devno;
>      uint8_t  vm_flags;
> @@ -100,6 +101,7 @@ struct S390IPLState {
>      IplParameterBlock iplb;
>      bool iplb_valid;
>      bool reipl_requested;
> +    bool netboot;
>  
>      /*< public >*/
>      char *kernel;
> 

 Thomas

  reply	other threads:[~2017-02-25  6:18 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-23 12:20 [Qemu-devel] [PATCH v2 0/5] s390x: network boot Cornelia Huck
2017-02-23 12:20 ` [Qemu-devel] [PATCH v2 1/5] elf-loader: Allow late loading of elf Cornelia Huck
2017-02-25  6:05   ` Thomas Huth
2017-02-27 12:12     ` Cornelia Huck
2017-02-27 15:56   ` Cornelia Huck
2017-02-23 12:20 ` [Qemu-devel] [PATCH v2 2/5] s390x/ipl: Extend S390IPLState to support network boot Cornelia Huck
2017-02-25  6:18   ` Thomas Huth
2017-02-23 12:20 ` [Qemu-devel] [PATCH v2 3/5] s390x/ipl: Load network boot image Cornelia Huck
2017-02-25  6:18   ` Thomas Huth [this message]
2017-02-27 11:51     ` Cornelia Huck
2017-02-27 11:59       ` Thomas Huth
2017-02-23 12:20 ` [Qemu-devel] [PATCH v2 4/5] pc-bios/s390-ccw: Use the ccw bios to start the network boot Cornelia Huck
2017-02-23 12:20 ` [Qemu-devel] [PATCH v2 5/5] pc-bios/s390-ccw.img: rebuild image Cornelia Huck

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=4fe97bb7-d6f0-7b58-916f-94dc0ae81616@redhat.com \
    --to=thuth@redhat.com \
    --cc=agraf@suse.de \
    --cc=alifm@linux.vnet.ibm.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=jfrei@linux.vnet.ibm.com \
    --cc=qemu-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.