From nobody Sat Nov 23 20:22:34 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=1731951522; cv=none; d=zohomail.com; s=zohoarc; b=Qwnff4VhCrzwREMXFjwO1b0pAwFRqHMWZQhP2OAKXQ17LZ0B4wIk+YzTWh1Tj+5hXcOMkuUqb7B4R1h6CafmnW+rSfsSfcJsSvdigMI8sIUmcKrN8aq83FFs/CN2G96U96vb1tcm4t+LdKq+5zg/vE3FwzaAC4FTwoYbfXImKWg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1731951522; 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=YnECL1oMu75MemisnEJ7sBQ9uK/sxW5ymL9eBjvWFcY=; b=M+BXrvhZkAJFSguvaAZyleH+Hkkzt6SFCbESSeNxwwkvAeF5R68ieV2yJcitHyY2okLplqoMqsllgJHjHjvW+8XJuh6Fr9LUFrjSF5KzjYhQIujP89l6Uttd9vXeyO/IEh/d/6HNHGMHicbg+rfWCC2Uy7KfoPdACKp/YbMv1/8= 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 1731951522563351.89343143637086; Mon, 18 Nov 2024 09:38:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tD5gv-0000bl-8e; Mon, 18 Nov 2024 12:37:37 -0500 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 1tD5ga-0008Hi-7k for qemu-devel@nongnu.org; Mon, 18 Nov 2024 12:37:17 -0500 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 1tD5gY-0004qJ-GC for qemu-devel@nongnu.org; Mon, 18 Nov 2024 12:37:15 -0500 Received: from mx-prod-mc-04.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-224-n7hq9Kt8O2ehM0YBFKUutQ-1; Mon, 18 Nov 2024 12:37:00 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8C94B197904C; Mon, 18 Nov 2024 17:36:58 +0000 (UTC) Received: from thuth-p1g4.redhat.com (unknown [10.39.194.53]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2CB67195DF81; Mon, 18 Nov 2024 17:36:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731951433; 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=YnECL1oMu75MemisnEJ7sBQ9uK/sxW5ymL9eBjvWFcY=; b=hqTUTs4zkM6X8Pjrg7zwbNMAoq1Rz5YHvYhVLwGoaAfwwdFJDySOK7RItZb5zI12ffzwTj InTHTKzrL5Pd666OWgdzOS5xfhYM93VZsXHaamJFz345GCFnNWIG9n0KKw6HR0Mu0pqO1H cQPXJNqEgX05WoiPnnDhV2aF/ggqjN0= X-MC-Unique: n7hq9Kt8O2ehM0YBFKUutQ-1 X-Mimecast-MFC-AGG-ID: n7hq9Kt8O2ehM0YBFKUutQ From: Thomas Huth To: qemu-devel@nongnu.org Cc: Peter Maydell , Eric Farman Subject: [PULL 07/12] hw: Add "loadparm" property to scsi disk devices for booting on s390x Date: Mon, 18 Nov 2024 18:36:29 +0100 Message-ID: <20241118173634.473532-8-thuth@redhat.com> In-Reply-To: <20241118173634.473532-1-thuth@redhat.com> References: <20241118173634.473532-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 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: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.142, 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: 1731951524999116600 Content-Type: text/plain; charset="utf-8" While adding the new flexible boot order feature on s390x recently, we missed to add the "loadparm" property to the scsi-hd and scsi-cd devices. This property is required on s390x to pass the information to the boot loader about which kernel should be started or whether the boot menu should be shown. But even more serious: The missing property is now causing trouble with the corresponding libvirt patches that assume that the "loadparm" property is either settable for all bootable devices (when the "boot order" feature is implemented in QEMU), or none (meaning the behaviour of older QEMUs that only allowed one "loadparm" at the machine level). To fix this broken situation, let's implement the "loadparm" property in for the SCSI devices, too. Message-ID: <20241115141202.1877294-1-thuth@redhat.com> Acked-by: Eric Farman Signed-off-by: Thomas Huth --- include/hw/qdev-properties-system.h | 3 ++ hw/core/qdev-properties-system.c | 26 +++++++++++++++++ hw/s390x/ipl.c | 19 ++++--------- hw/scsi/scsi-disk.c | 43 +++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 13 deletions(-) diff --git a/include/hw/qdev-properties-system.h b/include/hw/qdev-properti= es-system.h index cdcc63056e..7ec37f6316 100644 --- a/include/hw/qdev-properties-system.h +++ b/include/hw/qdev-properties-system.h @@ -3,6 +3,9 @@ =20 #include "hw/qdev-properties.h" =20 +bool qdev_prop_sanitize_s390x_loadparm(uint8_t *loadparm, const char *str, + Error **errp); + extern const PropertyInfo qdev_prop_chr; extern const PropertyInfo qdev_prop_macaddr; extern const PropertyInfo qdev_prop_reserved_region; diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-sys= tem.c index 35deef05f3..a61c5ee6dd 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -58,6 +58,32 @@ static bool check_prop_still_unset(Object *obj, const ch= ar *name, return false; } =20 +bool qdev_prop_sanitize_s390x_loadparm(uint8_t *loadparm, const char *str, + Error **errp) +{ + int i, len; + + len =3D strlen(str); + if (len > 8) { + error_setg(errp, "'loadparm' can only contain up to 8 characters"); + return false; + } + + for (i =3D 0; i < len; i++) { + uint8_t c =3D qemu_toupper(str[i]); /* mimic HMC */ + + if (qemu_isalnum(c) || c =3D=3D '.' || c =3D=3D ' ') { + loadparm[i] =3D c; + } else { + error_setg(errp, + "invalid character in 'loadparm': '%c' (ASCII 0x%02= x)", + c, c); + return false; + } + } + + return true; +} =20 /* --- drive --- */ =20 diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c index dc02b0fdda..30734661ad 100644 --- a/hw/s390x/ipl.c +++ b/hw/s390x/ipl.c @@ -418,21 +418,9 @@ static uint64_t s390_ipl_map_iplb_chain(IplParameterBl= ock *iplb_chain) =20 void s390_ipl_fmt_loadparm(uint8_t *loadparm, char *str, Error **errp) { - int i; - /* Initialize the loadparm with spaces */ memset(loadparm, ' ', LOADPARM_LEN); - for (i =3D 0; i < LOADPARM_LEN && str[i]; i++) { - uint8_t c =3D qemu_toupper(str[i]); /* mimic HMC */ - - if (qemu_isalnum(c) || c =3D=3D '.' || c =3D=3D ' ') { - loadparm[i] =3D c; - } else { - error_setg(errp, "LOADPARM: invalid character '%c' (ASCII 0x%0= 2x)", - c, c); - return; - } - } + qdev_prop_sanitize_s390x_loadparm(loadparm, str, errp); } =20 void s390_ipl_convert_loadparm(char *ascii_lp, uint8_t *ebcdic_lp) @@ -452,6 +440,7 @@ static bool s390_build_iplb(DeviceState *dev_st, IplPar= ameterBlock *iplb) SCSIDevice *sd; int devtype; uint8_t *lp; + g_autofree void *scsi_lp =3D NULL; =20 /* * Currently allow IPL only from CCW devices. @@ -463,6 +452,10 @@ static bool s390_build_iplb(DeviceState *dev_st, IplPa= rameterBlock *iplb) switch (devtype) { case CCW_DEVTYPE_SCSI: sd =3D SCSI_DEVICE(dev_st); + scsi_lp =3D object_property_get_str(OBJECT(sd), "loadparm", NU= LL); + if (scsi_lp && strlen(scsi_lp) > 0) { + lp =3D scsi_lp; + } 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); diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index cb222da7a5..8e553487d5 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -32,6 +32,7 @@ #include "migration/vmstate.h" #include "hw/scsi/emulation.h" #include "scsi/constants.h" +#include "sysemu/arch_init.h" #include "sysemu/block-backend.h" #include "sysemu/blockdev.h" #include "hw/block/block.h" @@ -111,6 +112,7 @@ struct SCSIDiskState { char *vendor; char *product; char *device_id; + char *loadparm; /* only for s390x */ bool tray_open; bool tray_locked; /* @@ -3135,6 +3137,43 @@ BlockAIOCB *scsi_dma_writev(int64_t offset, QEMUIOVe= ctor *iov, return blk_aio_pwritev(s->qdev.conf.blk, offset, iov, 0, cb, cb_opaque= ); } =20 +static char *scsi_property_get_loadparm(Object *obj, Error **errp) +{ + return g_strdup(SCSI_DISK_BASE(obj)->loadparm); +} + +static void scsi_property_set_loadparm(Object *obj, const char *value, + Error **errp) +{ + void *lp_str; + + if (object_property_get_int(obj, "bootindex", NULL) < 0) { + error_setg(errp, "'loadparm' is only valid for boot devices"); + return; + } + + lp_str =3D g_malloc0(strlen(value)); + if (!qdev_prop_sanitize_s390x_loadparm(lp_str, value, errp)) { + g_free(lp_str); + return; + } + SCSI_DISK_BASE(obj)->loadparm =3D lp_str; +} + +static void scsi_property_add_specifics(DeviceClass *dc) +{ + ObjectClass *oc =3D OBJECT_CLASS(dc); + + /* The loadparm property is only supported on s390x */ + if (arch_type & QEMU_ARCH_S390X) { + object_class_property_add_str(oc, "loadparm", + scsi_property_get_loadparm, + scsi_property_set_loadparm); + object_class_property_set_description(oc, "loadparm", + "load parameter (s390x only)= "); + } +} + static void scsi_disk_base_class_initfn(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); @@ -3218,6 +3257,8 @@ static void scsi_hd_class_initfn(ObjectClass *klass, = void *data) dc->desc =3D "virtual SCSI disk"; device_class_set_props(dc, scsi_hd_properties); dc->vmsd =3D &vmstate_scsi_disk_state; + + scsi_property_add_specifics(dc); } =20 static const TypeInfo scsi_hd_info =3D { @@ -3258,6 +3299,8 @@ static void scsi_cd_class_initfn(ObjectClass *klass, = void *data) dc->desc =3D "virtual SCSI CD-ROM"; device_class_set_props(dc, scsi_cd_properties); dc->vmsd =3D &vmstate_scsi_disk_state; + + scsi_property_add_specifics(dc); } =20 static const TypeInfo scsi_cd_info =3D { --=20 2.47.0