From patchwork Tue Jun 14 12:13:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cornelia Huck X-Patchwork-Id: 9175763 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 041C86075D for ; Tue, 14 Jun 2016 12:29:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E726722473 for ; Tue, 14 Jun 2016 12:29:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DBA3527E78; Tue, 14 Jun 2016 12:29:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 13B6822473 for ; Tue, 14 Jun 2016 12:29:23 +0000 (UTC) Received: from localhost ([::1]:34866 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCnT8-0005zc-4w for patchwork-qemu-devel@patchwork.kernel.org; Tue, 14 Jun 2016 08:29:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34270) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCnEU-0008VI-91 for qemu-devel@nongnu.org; Tue, 14 Jun 2016 08:14:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCnEM-0002TI-H8 for qemu-devel@nongnu.org; Tue, 14 Jun 2016 08:14:13 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:30018) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCnEM-0002T8-98 for qemu-devel@nongnu.org; Tue, 14 Jun 2016 08:14:06 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u5ECDpvr131684 for ; Tue, 14 Jun 2016 08:14:05 -0400 Received: from e06smtp08.uk.ibm.com (e06smtp08.uk.ibm.com [195.75.94.104]) by mx0a-001b2d01.pphosted.com with ESMTP id 23jfmncpde-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 14 Jun 2016 08:14:05 -0400 Received: from localhost by e06smtp08.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 14 Jun 2016 13:14:02 +0100 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp08.uk.ibm.com (192.168.101.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 14 Jun 2016 13:14:00 +0100 X-IBM-Helo: d06dlp01.portsmouth.uk.ibm.com X-IBM-MailFrom: cornelia.huck@de.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id D5CAA17D8067 for ; Tue, 14 Jun 2016 13:15:12 +0100 (BST) Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [9.149.37.248]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u5ECDxMt2818454 for ; Tue, 14 Jun 2016 12:13:59 GMT Received: from d06av07.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u5ECDxFr005737 for ; Tue, 14 Jun 2016 08:13:59 -0400 Received: from gondolin.boeblingen.de.ibm.com (dyn-9-152-224-202.boeblingen.de.ibm.com [9.152.224.202]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u5ECDvp6005597 (version=TLSv1/SSLv3 cipher=AES256-SHA256 bits=256 verify=NO); Tue, 14 Jun 2016 08:13:58 -0400 From: Cornelia Huck To: peter.maydell@linaro.org Date: Tue, 14 Jun 2016 14:13:52 +0200 X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160614121355.9320-1-cornelia.huck@de.ibm.com> References: <20160614121355.9320-1-cornelia.huck@de.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16061412-0032-0000-0000-000001D8134F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16061412-0033-0000-0000-00001B4C9AE2 Message-Id: <20160614121355.9320-5-cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-06-14_05:, , 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-1604210000 definitions=main-1606140137 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL 4/7] s390x/css: introduce property type for device ids 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: Cornelia Huck , borntraeger@de.ibm.com, jfrei@linux.vnet.ibm.com, agraf@suse.de, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Let's introduce a CssDevId to handle device ids of the xx.x.xxxx type used for channel devices. This has some benefits: - We can use them in virtio-ccw and split the validity checks for a channel device id in general from the constraint checking within the virtio-ccw scope. - We can reuse the device id type for future non-virtio channel devices. While we're at it, improve the validity checks and disallow e.g. trailing characters. Suggested-by: Dong Jia Shi Acked-by: David Hildenbrand Reviewed-by: Dong Jia Shi Signed-off-by: Cornelia Huck --- hw/s390x/css.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw.c | 79 ++++++++++++++++++++---------------------------- hw/s390x/virtio-ccw.h | 2 +- include/hw/s390x/css.h | 17 +++++++++++ 4 files changed, 131 insertions(+), 48 deletions(-) diff --git a/hw/s390x/css.c b/hw/s390x/css.c index aceb1c0..7666881 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -11,6 +11,7 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/visitor.h" #include #include "qemu/bitops.h" #include "exec/address-spaces.h" @@ -1681,3 +1682,83 @@ void css_reset(void) channel_subsys.max_cssid = 0; channel_subsys.max_ssid = 0; } + +static void get_css_devid(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + DeviceState *dev = DEVICE(obj); + Property *prop = opaque; + CssDevId *dev_id = qdev_get_prop_ptr(dev, prop); + char buffer[] = "xx.x.xxxx"; + char *p = buffer; + int r; + + if (dev_id->valid) { + + r = snprintf(buffer, sizeof(buffer), "%02x.%1x.%04x", dev_id->cssid, + dev_id->ssid, dev_id->devid); + assert(r == sizeof(buffer) - 1); + + /* drop leading zero */ + if (dev_id->cssid <= 0xf) { + p++; + } + } else { + snprintf(buffer, sizeof(buffer), ""); + } + + visit_type_str(v, name, &p, errp); +} + +/* + * parse .. and assert valid range for cssid/ssid + */ +static void set_css_devid(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + DeviceState *dev = DEVICE(obj); + Property *prop = opaque; + CssDevId *dev_id = qdev_get_prop_ptr(dev, prop); + Error *local_err = NULL; + char *str; + int num, n1, n2; + unsigned int cssid, ssid, devid; + + if (dev->realized) { + qdev_prop_set_after_realize(dev, name, errp); + return; + } + + visit_type_str(v, name, &str, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + num = sscanf(str, "%2x.%1x%n.%4x%n", &cssid, &ssid, &n1, &devid, &n2); + if (num != 3 || (n2 - n1) != 5 || strlen(str) != n2) { + error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); + goto out; + } + if ((cssid > MAX_CSSID) || (ssid > MAX_SSID)) { + error_setg(errp, "Invalid cssid or ssid: cssid %x, ssid %x", + cssid, ssid); + goto out; + } + + dev_id->cssid = cssid; + dev_id->ssid = ssid; + dev_id->devid = devid; + dev_id->valid = true; + +out: + g_free(str); +} + +PropertyInfo css_devid_propinfo = { + .name = "str", + .description = "Identifier of an I/O device in the channel " + "subsystem, example: fe.1.23ab", + .get = get_css_devid, + .set = set_css_devid, +}; diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index 2b68e5e..e62a3a3 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -737,14 +737,9 @@ static void virtio_sch_disable_cb(SubchDev *sch) static void virtio_ccw_device_realize(VirtioCcwDevice *dev, Error **errp) { - unsigned int cssid = 0; - unsigned int ssid = 0; unsigned int schid; - unsigned int devno; - bool have_devno = false; bool found = false; SubchDev *sch; - int num; Error *err = NULL; VirtIOCCWDeviceClass *k = VIRTIO_CCW_DEVICE_GET_CLASS(dev); @@ -763,54 +758,44 @@ static void virtio_ccw_device_realize(VirtioCcwDevice *dev, Error **errp) * Use a device number if provided. Otherwise, fall back to subchannel * number. */ - if (dev->bus_id) { - num = sscanf(dev->bus_id, "%x.%x.%04x", &cssid, &ssid, &devno); - if (num == 3) { - if ((cssid > MAX_CSSID) || (ssid > MAX_SSID)) { - error_setg(errp, "Invalid cssid or ssid: cssid %x, ssid %x", - cssid, ssid); - goto out_err; - } - /* Enforce use of virtual cssid. */ - if (cssid != VIRTUAL_CSSID) { - error_setg(errp, "cssid %x not valid for virtio devices", - cssid); - goto out_err; - } - if (css_devno_used(cssid, ssid, devno)) { + if (dev->bus_id.valid) { + /* Enforce use of virtual cssid. */ + if (dev->bus_id.cssid != VIRTUAL_CSSID) { + error_setg(errp, "cssid %x not valid for virtio devices", + dev->bus_id.cssid); + goto out_err; + } + if (css_devno_used(dev->bus_id.cssid, dev->bus_id.ssid, + dev->bus_id.devid)) { error_setg(errp, "Device %x.%x.%04x already exists", - cssid, ssid, devno); + dev->bus_id.cssid, dev->bus_id.ssid, + dev->bus_id.devid); goto out_err; - } - sch->cssid = cssid; - sch->ssid = ssid; - sch->devno = devno; - have_devno = true; - } else { - error_setg(errp, "Malformed devno parameter '%s'", dev->bus_id); - goto out_err; } - } + sch->cssid = dev->bus_id.cssid; + sch->ssid = dev->bus_id.ssid; + sch->devno = dev->bus_id.devid; - /* Find the next free id. */ - if (have_devno) { + /* Find the next free id. */ for (schid = 0; schid <= MAX_SCHID; schid++) { - if (!css_find_subch(1, cssid, ssid, schid)) { + if (!css_find_subch(1, sch->cssid, sch->ssid, schid)) { sch->schid = schid; - css_subch_assign(cssid, ssid, schid, devno, sch); + css_subch_assign(sch->cssid, sch->ssid, sch->schid, + sch->devno, sch); found = true; break; } } if (!found) { error_setg(errp, "No free subchannel found for %x.%x.%04x", - cssid, ssid, devno); + sch->cssid, sch->ssid, sch->devno); goto out_err; } - trace_virtio_ccw_new_device(cssid, ssid, schid, devno, - "user-configured"); + trace_virtio_ccw_new_device(sch->cssid, sch->ssid, sch->schid, + sch->devno, "user-configured"); } else { - cssid = VIRTUAL_CSSID; + unsigned int cssid = VIRTUAL_CSSID, ssid, devno; + for (ssid = 0; ssid <= MAX_SSID; ssid++) { for (schid = 0; schid <= MAX_SCHID; schid++) { if (!css_find_subch(1, cssid, ssid, schid)) { @@ -868,7 +853,7 @@ static void virtio_ccw_device_realize(VirtioCcwDevice *dev, Error **errp) } if (err) { error_propagate(errp, err); - css_subch_assign(cssid, ssid, schid, devno, NULL); + css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL); goto out_err; } @@ -1516,7 +1501,7 @@ static void virtio_ccw_device_unplugged(DeviceState *d) /**************** Virtio-ccw Bus Device Descriptions *******************/ static Property virtio_ccw_net_properties[] = { - DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id), + DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, bus_id), DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, @@ -1545,7 +1530,7 @@ static const TypeInfo virtio_ccw_net = { }; static Property virtio_ccw_blk_properties[] = { - DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id), + DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, bus_id), DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, @@ -1574,7 +1559,7 @@ static const TypeInfo virtio_ccw_blk = { }; static Property virtio_ccw_serial_properties[] = { - DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id), + DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, bus_id), DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, @@ -1603,7 +1588,7 @@ static const TypeInfo virtio_ccw_serial = { }; static Property virtio_ccw_balloon_properties[] = { - DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id), + DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, bus_id), DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, @@ -1632,7 +1617,7 @@ static const TypeInfo virtio_ccw_balloon = { }; static Property virtio_ccw_scsi_properties[] = { - DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id), + DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, bus_id), DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, @@ -1662,7 +1647,7 @@ static const TypeInfo virtio_ccw_scsi = { #ifdef CONFIG_VHOST_SCSI static Property vhost_ccw_scsi_properties[] = { - DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id), + DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, bus_id), DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, VIRTIO_CCW_MAX_REV), DEFINE_PROP_END_OF_LIST(), @@ -1700,7 +1685,7 @@ static void virtio_ccw_rng_instance_init(Object *obj) } static Property virtio_ccw_rng_properties[] = { - DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id), + DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, bus_id), DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, @@ -1856,7 +1841,7 @@ static const TypeInfo virtio_ccw_bus_info = { #ifdef CONFIG_VIRTFS static Property virtio_ccw_9p_properties[] = { - DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id), + DEFINE_PROP_CSS_DEV_ID("devno", VirtioCcwDevice, bus_id), DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, diff --git a/hw/s390x/virtio-ccw.h b/hw/s390x/virtio-ccw.h index 86b9edb..0bfb5d9 100644 --- a/hw/s390x/virtio-ccw.h +++ b/hw/s390x/virtio-ccw.h @@ -80,7 +80,7 @@ typedef struct VirtIOCCWDeviceClass { struct VirtioCcwDevice { DeviceState parent_obj; SubchDev *sch; - char *bus_id; + CssDevId bus_id; int revision; uint32_t max_rev; VirtioBusState bus; diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h index 98b2e2c..38f4d77 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -151,5 +151,22 @@ int css_do_rsch(SubchDev *sch); int css_do_rchp(uint8_t cssid, uint8_t chpid); bool css_present(uint8_t cssid); #endif +/* + * Identify a device within the channel subsystem. + * Note that this can be used to identify either the subchannel or + * the attached I/O device, as there's always one I/O device per + * subchannel. + */ +typedef struct CssDevId { + uint8_t cssid; + uint8_t ssid; + uint16_t devid; + bool valid; +} CssDevId; + +extern PropertyInfo css_devid_propinfo; + +#define DEFINE_PROP_CSS_DEV_ID(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, css_devid_propinfo, CssDevId) #endif