2015-11-06 14:32:40 +03:00
|
|
|
/*
|
|
|
|
* css bridge implementation
|
|
|
|
*
|
|
|
|
* Copyright 2012,2016 IBM Corp.
|
|
|
|
* Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
|
|
|
|
* Pierre Morel <pmorel@linux.vnet.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or (at
|
|
|
|
* your option) any later version. See the COPYING file in the top-level
|
|
|
|
* directory.
|
|
|
|
*/
|
2019-05-23 17:35:07 +03:00
|
|
|
|
2015-11-06 14:32:40 +03:00
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "qapi/error.h"
|
|
|
|
#include "hw/hotplug.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2015-11-06 14:32:40 +03:00
|
|
|
#include "hw/sysbus.h"
|
|
|
|
#include "qemu/bitops.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2015-11-06 14:32:40 +03:00
|
|
|
#include "hw/s390x/css.h"
|
2016-02-26 08:46:12 +03:00
|
|
|
#include "ccw-device.h"
|
2015-11-06 14:32:40 +03:00
|
|
|
#include "hw/s390x/css-bridge.h"
|
2017-05-17 03:48:05 +03:00
|
|
|
#include "cpu.h"
|
2015-11-06 14:32:40 +03:00
|
|
|
|
2016-02-26 08:46:12 +03:00
|
|
|
/*
|
|
|
|
* Invoke device-specific unplug handler, disable the subchannel
|
|
|
|
* (including sending a channel report to the guest) and remove the
|
|
|
|
* device from the virtual css bus.
|
|
|
|
*/
|
|
|
|
static void ccw_device_unplug(HotplugHandler *hotplug_dev,
|
|
|
|
DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
CcwDevice *ccw_dev = CCW_DEVICE(dev);
|
|
|
|
CCWDeviceClass *k = CCW_DEVICE_GET_CLASS(ccw_dev);
|
|
|
|
SubchDev *sch = ccw_dev->sch;
|
|
|
|
Error *err = NULL;
|
|
|
|
|
|
|
|
if (k->unplug) {
|
|
|
|
k->unplug(hotplug_dev, dev, &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We should arrive here only for device_del, since we don't support
|
|
|
|
* direct hot(un)plug of channels.
|
|
|
|
*/
|
|
|
|
assert(sch != NULL);
|
|
|
|
/* Subchannel is now disabled and no longer valid. */
|
|
|
|
sch->curr_status.pmcw.flags &= ~(PMCW_FLAGS_MASK_ENA |
|
|
|
|
PMCW_FLAGS_MASK_DNV);
|
|
|
|
|
|
|
|
css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, 1, 0);
|
|
|
|
|
qdev: Unrealize must not fail
Devices may have component devices and buses.
Device realization may fail. Realization is recursive: a device's
realize() method realizes its components, and device_set_realized()
realizes its buses (which should in turn realize the devices on that
bus, except bus_set_realized() doesn't implement that, yet).
When realization of a component or bus fails, we need to roll back:
unrealize everything we realized so far. If any of these unrealizes
failed, the device would be left in an inconsistent state. Must not
happen.
device_set_realized() lets it happen: it ignores errors in the roll
back code starting at label child_realize_fail.
Since realization is recursive, unrealization must be recursive, too.
But how could a partly failed unrealize be rolled back? We'd have to
re-realize, which can fail. This design is fundamentally broken.
device_set_realized() does not roll back at all. Instead, it keeps
unrealizing, ignoring further errors.
It can screw up even for a device with no buses: if the lone
dc->unrealize() fails, it still unregisters vmstate, and calls
listeners' unrealize() callback.
bus_set_realized() does not roll back either. Instead, it stops
unrealizing.
Fortunately, no unrealize method can fail, as we'll see below.
To fix the design error, drop parameter @errp from all the unrealize
methods.
Any unrealize method that uses @errp now needs an update. This leads
us to unrealize() methods that can fail. Merely passing it to another
unrealize method cannot cause failure, though. Here are the ones that
do other things with @errp:
* virtio_serial_device_unrealize()
Fails when qbus_set_hotplug_handler() fails, but still does all the
other work. On failure, the device would stay realized with its
resources completely gone. Oops. Can't happen, because
qbus_set_hotplug_handler() can't actually fail here. Pass
&error_abort to qbus_set_hotplug_handler() instead.
* hw/ppc/spapr_drc.c's unrealize()
Fails when object_property_del() fails, but all the other work is
already done. On failure, the device would stay realized with its
vmstate registration gone. Oops. Can't happen, because
object_property_del() can't actually fail here. Pass &error_abort
to object_property_del() instead.
* spapr_phb_unrealize()
Fails and bails out when remove_drcs() fails, but other work is
already done. On failure, the device would stay realized with some
of its resources gone. Oops. remove_drcs() fails only when
chassis_from_bus()'s object_property_get_uint() fails, and it can't
here. Pass &error_abort to remove_drcs() instead.
Therefore, no unrealize method can fail before this patch.
device_set_realized()'s recursive unrealization via bus uses
object_property_set_bool(). Can't drop @errp there, so pass
&error_abort.
We similarly unrealize with object_property_set_bool() elsewhere,
always ignoring errors. Pass &error_abort instead.
Several unrealize methods no longer handle errors from other unrealize
methods: virtio_9p_device_unrealize(),
virtio_input_device_unrealize(), scsi_qdev_unrealize(), ...
Much of the deleted error handling looks wrong anyway.
One unrealize methods no longer ignore such errors:
usb_ehci_pci_exit().
Several realize methods no longer ignore errors when rolling back:
v9fs_device_realize_common(), pci_qdev_unrealize(),
spapr_phb_realize(), usb_qdev_realize(), vfio_ccw_realize(),
virtio_device_realize().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-17-armbru@redhat.com>
2020-05-05 18:29:24 +03:00
|
|
|
object_property_set_bool(OBJECT(dev), false, "realized", &error_abort);
|
2016-02-26 08:46:12 +03:00
|
|
|
}
|
|
|
|
|
2015-11-06 14:32:40 +03:00
|
|
|
static void virtual_css_bus_reset(BusState *qbus)
|
|
|
|
{
|
|
|
|
/* This should actually be modelled via the generic css */
|
|
|
|
css_reset();
|
|
|
|
}
|
|
|
|
|
2016-07-11 13:55:44 +03:00
|
|
|
static char *virtual_css_bus_get_dev_path(DeviceState *dev)
|
|
|
|
{
|
|
|
|
CcwDevice *ccw_dev = CCW_DEVICE(dev);
|
|
|
|
SubchDev *sch = ccw_dev->sch;
|
|
|
|
VirtualCssBridge *bridge =
|
|
|
|
VIRTUAL_CSS_BRIDGE(qdev_get_parent_bus(dev)->parent);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can't provide a dev path for backward compatibility on
|
|
|
|
* older machines, as it is visible in the migration stream.
|
|
|
|
*/
|
|
|
|
return bridge->css_dev_path ?
|
|
|
|
g_strdup_printf("/%02x.%1x.%04x", sch->cssid, sch->ssid, sch->devno) :
|
|
|
|
NULL;
|
|
|
|
}
|
|
|
|
|
2015-11-06 14:32:40 +03:00
|
|
|
static void virtual_css_bus_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
BusClass *k = BUS_CLASS(klass);
|
|
|
|
|
|
|
|
k->reset = virtual_css_bus_reset;
|
2016-07-11 13:55:44 +03:00
|
|
|
k->get_dev_path = virtual_css_bus_get_dev_path;
|
2015-11-06 14:32:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtual_css_bus_info = {
|
|
|
|
.name = TYPE_VIRTUAL_CSS_BUS,
|
|
|
|
.parent = TYPE_BUS,
|
|
|
|
.instance_size = sizeof(VirtualCssBus),
|
|
|
|
.class_init = virtual_css_bus_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
VirtualCssBus *virtual_css_bus_init(void)
|
|
|
|
{
|
|
|
|
VirtualCssBus *cbus;
|
|
|
|
BusState *bus;
|
|
|
|
DeviceState *dev;
|
|
|
|
|
|
|
|
/* Create bridge device */
|
|
|
|
dev = qdev_create(NULL, TYPE_VIRTUAL_CSS_BRIDGE);
|
2017-11-28 16:08:14 +03:00
|
|
|
object_property_add_child(qdev_get_machine(), TYPE_VIRTUAL_CSS_BRIDGE,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
OBJECT(dev));
|
2015-11-06 14:32:40 +03:00
|
|
|
qdev_init_nofail(dev);
|
|
|
|
|
|
|
|
/* Create bus on bridge device */
|
|
|
|
bus = qbus_create(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
|
|
|
|
cbus = VIRTUAL_CSS_BUS(bus);
|
|
|
|
|
|
|
|
/* Enable hotplugging */
|
2019-02-12 21:24:59 +03:00
|
|
|
qbus_set_hotplug_handler(bus, OBJECT(dev), &error_abort);
|
2015-11-06 14:32:40 +03:00
|
|
|
|
2016-11-24 13:10:39 +03:00
|
|
|
css_register_io_adapters(CSS_IO_ADAPTER_VIRTIO, true, false,
|
2017-03-07 06:07:44 +03:00
|
|
|
0, &error_abort);
|
2016-11-24 13:10:39 +03:00
|
|
|
|
2015-11-06 14:32:40 +03:00
|
|
|
return cbus;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***************** Virtual-css Bus Bridge Device ********************/
|
|
|
|
|
2016-07-11 13:55:44 +03:00
|
|
|
static Property virtual_css_bridge_properties[] = {
|
|
|
|
DEFINE_PROP_BOOL("css_dev_path", VirtualCssBridge, css_dev_path,
|
|
|
|
true),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2017-12-06 17:44:37 +03:00
|
|
|
static bool prop_get_true(Object *obj, Error **errp)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-06 14:32:40 +03:00
|
|
|
static void virtual_css_bridge_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
|
2016-02-26 08:46:12 +03:00
|
|
|
hc->unplug = ccw_device_unplug;
|
2015-11-06 14:32:40 +03:00
|
|
|
set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, virtual_css_bridge_properties);
|
2017-12-06 17:44:37 +03:00
|
|
|
object_class_property_add_bool(klass, "cssid-unrestricted",
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
prop_get_true, NULL);
|
2017-12-06 17:44:37 +03:00
|
|
|
object_class_property_set_description(klass, "cssid-unrestricted",
|
|
|
|
"A css device can use any cssid, regardless whether virtual"
|
2020-05-05 18:29:15 +03:00
|
|
|
" or not (read only, always true)");
|
2015-11-06 14:32:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo virtual_css_bridge_info = {
|
|
|
|
.name = TYPE_VIRTUAL_CSS_BRIDGE,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
2016-07-11 13:55:44 +03:00
|
|
|
.instance_size = sizeof(VirtualCssBridge),
|
2015-11-06 14:32:40 +03:00
|
|
|
.class_init = virtual_css_bridge_class_init,
|
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ TYPE_HOTPLUG_HANDLER },
|
|
|
|
{ }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void virtual_css_register(void)
|
|
|
|
{
|
|
|
|
type_register_static(&virtual_css_bridge_info);
|
|
|
|
type_register_static(&virtual_css_bus_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(virtual_css_register)
|