From nobody Mon Feb 9 01:16:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488281929182104.38623000684242; Tue, 28 Feb 2017 03:38:49 -0800 (PST) Received: from localhost ([::1]:60425 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cig7C-0004hA-2t for importer@patchew.org; Tue, 28 Feb 2017 06:38:46 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52957) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cig0k-0007wG-VT for qemu-devel@nongnu.org; Tue, 28 Feb 2017 06:32:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cig0h-0002aO-Rz for qemu-devel@nongnu.org; Tue, 28 Feb 2017 06:32:06 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:45400 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cig0h-0002Zv-Ln for qemu-devel@nongnu.org; Tue, 28 Feb 2017 06:32:03 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1SBNmfh048062 for ; Tue, 28 Feb 2017 06:32:03 -0500 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0b-001b2d01.pphosted.com with ESMTP id 28vp24098c-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 28 Feb 2017 06:32:02 -0500 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 28 Feb 2017 11:32:01 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 28 Feb 2017 11:31:58 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 8DB3A17D8056; Tue, 28 Feb 2017 11:35:11 +0000 (GMT) Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1SBVwPB2228542; Tue, 28 Feb 2017 11:31:58 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 954035203F; Tue, 28 Feb 2017 10:30:33 +0000 (GMT) Received: from gondolin.boeblingen.de.ibm.com (unknown [9.152.224.55]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id 61E505204B; Tue, 28 Feb 2017 10:30:33 +0000 (GMT) From: Cornelia Huck To: peter.maydell@linaro.org Date: Tue, 28 Feb 2017 12:31:51 +0100 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170228113153.23867-1-cornelia.huck@de.ibm.com> References: <20170228113153.23867-1-cornelia.huck@de.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17022811-0008-0000-0000-000003F15CE5 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17022811-0009-0000-0000-00001C9DB9DD Message-Id: <20170228113153.23867-4-cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-28_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702280107 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL for-2.9 3/5] s390x/ipl: Load network boot image X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Farhan Ali , agraf@suse.de, qemu-devel@nongnu.org, borntraeger@de.ibm.com, jfrei@linux.vnet.ibm.com, Cornelia Huck Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Farhan Ali 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 Signed-off-by: Cornelia Huck --- 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..7978c7d52a 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" =20 #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 =3D (SCSIDevice *) object_dynamic_cast(OBJECT(dev_s= t), TYPE_SCSI_DEVI= CE); + VirtIONet *vn =3D (VirtIONet *) object_dynamic_cast(OBJECT(dev_st), + TYPE_VIRTIO_NET); + + if (vn) { + ipl->netboot =3D true; + } if (virtio_ccw_dev) { CcwDevice *ccw_dev =3D CCW_DEVICE(virtio_ccw_dev); =20 @@ -259,12 +266,86 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl) return false; } =20 +static int load_netboot_image(Error **errp) +{ + S390IPLState *ipl =3D get_ipl_device(); + char *netboot_filename; + MemoryRegion *sysmem =3D get_system_memory(); + MemoryRegion *mr =3D NULL; + void *ram_ptr =3D NULL; + int img_size =3D -1; + + mr =3D memory_region_find(sysmem, 0, 1).mr; + if (!mr) { + error_setg(errp, "Failed to find memory region at address 0"); + return -1; + } + + ram_ptr =3D memory_region_get_ram_ptr(mr); + if (!ram_ptr) { + error_setg(errp, "No RAM found"); + goto unref_mr; + } + + netboot_filename =3D qemu_find_file(QEMU_FILE_TYPE_BIOS, ipl->netboot_= fw); + if (netboot_filename =3D=3D NULL) { + error_setg(errp, "Could not find network bootloader"); + goto unref_mr; + } + + img_size =3D load_elf_ram(netboot_filename, NULL, NULL, &ipl->start_ad= dr, + NULL, NULL, 1, EM_S390, 0, 0, NULL, false); + + if (img_size < 0) { + img_size =3D load_image_size(netboot_filename, ram_ptr, ram_size); + ipl->start_addr =3D 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 =3D NULL; + + if (iplb->pbt !=3D S390_IPL_TYPE_CCW) { + return false; + } + + devno =3D be16_to_cpu(iplb->ccw.devno); + ssid =3D iplb->ccw.ssid & 3; + + for (schid =3D 0; schid < MAX_SCHID; schid++) { + for (cssid =3D 0; cssid < MAX_CSSID; cssid++) { + sch =3D css_find_subch(1, cssid, ssid, schid); + + if (sch && sch->devno =3D=3D devno) { + return sch->id.cu_model =3D=3D VIRTIO_ID_NET; + } + } + } + return false; +} + void s390_ipl_update_diag308(IplParameterBlock *iplb) { S390IPLState *ipl =3D get_ipl_device(); =20 ipl->iplb =3D *iplb; ipl->iplb_valid =3D true; + ipl->netboot =3D is_virtio_net_device(iplb); } =20 IplParameterBlock *s390_ipl_get_iplb(void) @@ -288,6 +369,7 @@ void s390_reipl_request(void) void s390_ipl_prepare_cpu(S390CPU *cpu) { S390IPLState *ipl =3D get_ipl_device(); + Error *err =3D NULL; =20 cpu->env.psw.addr =3D ipl->start_addr; cpu->env.psw.mask =3D IPL_PSW_MASK; @@ -298,6 +380,13 @@ void s390_ipl_prepare_cpu(S390CPU *cpu) ipl->iplb_valid =3D 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 =3D ipl->start_addr; + } } =20 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" =20 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; =20 /*< public >*/ char *kernel; --=20 2.11.0