From nobody Sat Nov 23 21:18:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1729689516; cv=none; d=zohomail.com; s=zohoarc; b=IPkayq7vsktRjth/zG+hD2NAdeyEnGnl2x4kGCwhipPKOIwmMfjfLjZxRbc9Gt9bRtmqN29pJeqwKJZs1N8PSHAcA1n2W4N0CvUlF3GMC7hH74DDNOBsQF5qRhL6hHYYAk13UGDobdMjTHltNU8RIWO/D+w186rhLkdGRo0SWXM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1729689516; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=KBZV9fF5UzB1z18c6ueAP5BGjy15RQl8nQiHpuOeUfs=; b=hEGv03WB0TyXOVwSaNa0NI3OKNjB1VpmT1xBGvm9r5tJho0RODsH7PG+NBtCOBJIVJMf2MOaPdSGiKR/A6YEeCPa2vPrUswl4L84WmREVb8ong38ZPRowlEF3Y0vyEFzL3g9fbJYUil2fCYWB/V15WpO8hM8PvtjrTHQafptVqI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1729689516887934.5669258938718; Wed, 23 Oct 2024 06:18:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3bFX-000716-1K; Wed, 23 Oct 2024 09:18:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3bFP-0006Pc-6I for qemu-devel@nongnu.org; Wed, 23 Oct 2024 09:17:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t3bFN-0002D4-7H for qemu-devel@nongnu.org; Wed, 23 Oct 2024 09:17:58 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-640-ITcsrr_7OzCV8X76YPfV3Q-1; Wed, 23 Oct 2024 09:17:54 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 709D3194510F; Wed, 23 Oct 2024 13:17:52 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.192.43]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D2A7119560AE; Wed, 23 Oct 2024 13:17:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729689475; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KBZV9fF5UzB1z18c6ueAP5BGjy15RQl8nQiHpuOeUfs=; b=TxrbtG5b4BDVvtP9m4kFjm/u7neiZYQxSp10EKaHwzrX/rwCRHGC6E+0l/OszmJVU5/ECz c/OiVrfKO51QlRd1i21xLhD46JgJQEU4/uudr7oiTLsRFGodQC95n/pBL/JEMK2Ap72BY6 vZtlCTAvkhA5QrSOI19n4l0dU5FhkSU= X-MC-Unique: ITcsrr_7OzCV8X76YPfV3Q-1 From: Thomas Huth To: qemu-devel@nongnu.org Cc: Peter Maydell , Jared Rossi Subject: [PULL 15/23] hw/s390x: Build an IPLB for each boot device Date: Wed, 23 Oct 2024 15:17:02 +0200 Message-ID: <20241023131710.906748-16-thuth@redhat.com> In-Reply-To: <20241023131710.906748-1-thuth@redhat.com> References: <20241023131710.906748-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.263, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1729689518334116600 Content-Type: text/plain; charset="utf-8" From: Jared Rossi 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 remaini= ng boot devices is stored in the QIPL global variable for possible later acces= s by the guest during IPL. Signed-off-by: Jared Rossi Reviewed-by: Thomas Huth Message-ID: <20241020012953.1380075-16-jrossi@linux.ibm.com> [thuth: Fix endianness problem when accessing the qipl structure] Signed-off-by: Thomas Huth --- hw/s390x/ipl.h | 1 + include/hw/s390x/ipl/qipl.h | 4 +- hw/s390x/ipl.c | 129 ++++++++++++++++++++++++++++-------- 3 files changed, 105 insertions(+), 29 deletions(-) diff --git a/hw/s390x/ipl.h b/hw/s390x/ipl.h index b670bad551..54eb48fd6e 100644 --- a/hw/s390x/ipl.h +++ b/hw/s390x/ipl.h @@ -20,6 +20,7 @@ #include "qom/object.h" =20 #define DIAG308_FLAGS_LP_VALID 0x80 +#define MAX_BOOT_DEVS 8 /* Max number of devices that may have a bootindex= */ =20 void s390_ipl_convert_loadparm(char *ascii_lp, uint8_t *ebcdic_lp); void s390_ipl_fmt_loadparm(uint8_t *loadparm, char *str, Error **errp); diff --git a/include/hw/s390x/ipl/qipl.h b/include/hw/s390x/ipl/qipl.h index b67d2ae061..1da4f75aa8 100644 --- a/include/hw/s390x/ipl/qipl.h +++ b/include/hw/s390x/ipl/qipl.h @@ -32,7 +32,9 @@ struct QemuIplParameters { uint8_t reserved1[3]; uint64_t reserved2; uint32_t boot_menu_timeout; - uint8_t reserved3[12]; + uint8_t reserved3[2]; + uint16_t chain_len; + uint64_t next_iplb; } QEMU_PACKED; typedef struct QemuIplParameters QemuIplParameters; =20 diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c index 656996b500..b9d741d0b0 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; } =20 +/* 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 =3D { .name =3D "ipl/iplb_extended", .version_id =3D 0, @@ -398,6 +405,17 @@ static CcwDevice *s390_get_ccw_device(DeviceState *dev= _st, int *devtype) return ccw_dev; } =20 +static uint64_t s390_ipl_map_iplb_chain(IplParameterBlock *iplb_chain) +{ + S390IPLState *ipl =3D get_ipl_device(); + uint16_t count =3D be16_to_cpu(ipl->qipl.chain_len); + uint64_t len =3D sizeof(IplParameterBlock) * count; + uint64_t chain_addr =3D find_iplb_chain_addr(ipl->bios_start_addr, cou= nt); + + 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) } } =20 -static bool s390_gen_initial_iplb(S390IPLState *ipl) +static bool s390_build_iplb(DeviceState *dev_st, IplParameterBlock *iplb) { - DeviceState *dev_st; + S390IPLState *ipl =3D get_ipl_device(); CcwDevice *ccw_dev =3D NULL; SCSIDevice *sd; int devtype; uint8_t *lp; =20 - dev_st =3D get_boot_device(0); - if (dev_st) { - ccw_dev =3D s390_get_ccw_device(dev_st, &devtype); - } - /* * Currently allow IPL only from CCW devices. */ + ccw_dev =3D s390_get_ccw_device(dev_st, &devtype); if (ccw_dev) { lp =3D ccw_dev->loadparm; =20 switch (devtype) { case CCW_DEVTYPE_SCSI: sd =3D SCSI_DEVICE(dev_st); - ipl->iplb.len =3D cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN); - ipl->iplb.blk0_len =3D + iplb->len =3D cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN); + iplb->blk0_len =3D cpu_to_be32(S390_IPLB_MIN_QEMU_SCSI_LEN - S390_IPLB_HEADER= _LEN); - ipl->iplb.pbt =3D S390_IPL_TYPE_QEMU_SCSI; - ipl->iplb.scsi.lun =3D cpu_to_be32(sd->lun); - ipl->iplb.scsi.target =3D cpu_to_be16(sd->id); - ipl->iplb.scsi.channel =3D cpu_to_be16(sd->channel); - ipl->iplb.scsi.devno =3D cpu_to_be16(ccw_dev->sch->devno); - ipl->iplb.scsi.ssid =3D ccw_dev->sch->ssid & 3; + iplb->pbt =3D S390_IPL_TYPE_QEMU_SCSI; + iplb->scsi.lun =3D cpu_to_be32(sd->lun); + iplb->scsi.target =3D cpu_to_be16(sd->id); + iplb->scsi.channel =3D cpu_to_be16(sd->channel); + iplb->scsi.devno =3D cpu_to_be16(ccw_dev->sch->devno); + iplb->scsi.ssid =3D ccw_dev->sch->ssid & 3; break; case CCW_DEVTYPE_VFIO: - ipl->iplb.len =3D cpu_to_be32(S390_IPLB_MIN_CCW_LEN); - ipl->iplb.pbt =3D S390_IPL_TYPE_CCW; - ipl->iplb.ccw.devno =3D cpu_to_be16(ccw_dev->sch->devno); - ipl->iplb.ccw.ssid =3D ccw_dev->sch->ssid & 3; + iplb->len =3D cpu_to_be32(S390_IPLB_MIN_CCW_LEN); + iplb->pbt =3D S390_IPL_TYPE_CCW; + iplb->ccw.devno =3D cpu_to_be16(ccw_dev->sch->devno); + iplb->ccw.ssid =3D ccw_dev->sch->ssid & 3; break; case CCW_DEVTYPE_VIRTIO_NET: + /* The S390IPLState netboot is true if ANY IPLB may use netboo= t */ ipl->netboot =3D true; /* Fall through to CCW_DEVTYPE_VIRTIO case */ case CCW_DEVTYPE_VIRTIO: - ipl->iplb.len =3D cpu_to_be32(S390_IPLB_MIN_CCW_LEN); - ipl->iplb.blk0_len =3D + iplb->len =3D cpu_to_be32(S390_IPLB_MIN_CCW_LEN); + iplb->blk0_len =3D cpu_to_be32(S390_IPLB_MIN_CCW_LEN - S390_IPLB_HEADER_LEN); - ipl->iplb.pbt =3D S390_IPL_TYPE_CCW; - ipl->iplb.ccw.devno =3D cpu_to_be16(ccw_dev->sch->devno); - ipl->iplb.ccw.ssid =3D ccw_dev->sch->ssid & 3; + iplb->pbt =3D S390_IPL_TYPE_CCW; + iplb->ccw.devno =3D cpu_to_be16(ccw_dev->sch->devno); + iplb->ccw.ssid =3D ccw_dev->sch->ssid & 3; break; } =20 @@ -484,8 +499,8 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl) lp =3D S390_CCW_MACHINE(qdev_get_machine())->loadparm; } =20 - s390_ipl_convert_loadparm((char *)lp, ipl->iplb.loadparm); - ipl->iplb.flags |=3D DIAG308_FLAGS_LP_VALID; + s390_ipl_convert_loadparm((char *)lp, iplb->loadparm); + iplb->flags |=3D DIAG308_FLAGS_LP_VALID; =20 return true; } @@ -493,6 +508,62 @@ static bool s390_gen_initial_iplb(S390IPLState *ipl) return false; } =20 +static bool s390_init_all_iplbs(S390IPLState *ipl) +{ + int iplb_num =3D 0; + IplParameterBlock iplb_chain[7]; + DeviceState *dev_st =3D get_boot_device(0); + Object *machine =3D qdev_get_machine(); + + /* + * Parse the boot devices. Generate an IPLB for only the first boot d= evice + * which will later be set with DIAG308. + */ + if (!dev_st) { + ipl->qipl.chain_len =3D 0; + return false; + } + + /* If no machine loadparm was defined fill it with spaces */ + if (memcmp(S390_CCW_MACHINE(machine)->loadparm, NO_LOADPARM, 8) =3D=3D= 0) { + object_property_set_str(machine, "loadparm", " ", NULL); + } + + iplb_num =3D 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 =3D MAX_BOOT_DEVS; + } + + ipl->qipl.chain_len =3D 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 =3D 1; i < iplb_num; i++) { + dev_st =3D get_boot_device(i); + s390_build_iplb(dev_st, &iplb_chain[i - 1]); + } + + ipl->qipl.next_iplb =3D cpu_to_be64(s390_ipl_map_iplb_chain(iplb_c= hain)); + } + + return iplb_num; +} + static bool is_virtio_ccw_device_of_type(IplParameterBlock *iplb, int virtio_id) { @@ -620,7 +691,7 @@ void s390_ipl_reset_request(CPUState *cs, enum s390_res= et reset_type) * this is the original boot device's SCSI * so restore IPL parameter info from it */ - ipl->iplb_valid =3D s390_gen_initial_iplb(ipl); + ipl->iplb_valid =3D s390_build_iplb(get_boot_device(0), &ipl->= iplb); } } if (reset_type =3D=3D S390_RESET_MODIFIED_CLEAR || @@ -714,7 +785,9 @@ void s390_ipl_prepare_cpu(S390CPU *cpu) if (!ipl->kernel || ipl->iplb_valid) { cpu->env.psw.addr =3D ipl->bios_start_addr; if (!ipl->iplb_valid) { - ipl->iplb_valid =3D s390_gen_initial_iplb(ipl); + ipl->iplb_valid =3D s390_init_all_iplbs(ipl); + } else { + ipl->qipl.chain_len =3D 0; } } s390_ipl_set_boot_menu(ipl); --=20 2.47.0