2019-01-08 17:48:47 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Citrix Systems Inc.
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HW_XEN_BUS_H
|
|
|
|
#define HW_XEN_BUS_H
|
|
|
|
|
2019-01-08 17:48:49 +03:00
|
|
|
#include "hw/xen/xen_common.h"
|
2019-01-08 17:48:47 +03:00
|
|
|
#include "hw/sysbus.h"
|
2019-01-08 17:48:50 +03:00
|
|
|
#include "qemu/notify.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2019-01-08 17:48:50 +03:00
|
|
|
|
|
|
|
typedef void (*XenWatchHandler)(void *opaque);
|
|
|
|
|
2019-09-13 11:21:56 +03:00
|
|
|
typedef struct XenWatchList XenWatchList;
|
2019-01-08 17:48:50 +03:00
|
|
|
typedef struct XenWatch XenWatch;
|
2019-04-08 18:16:15 +03:00
|
|
|
typedef struct XenEventChannel XenEventChannel;
|
2019-01-08 17:48:47 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct XenDevice {
|
2019-01-08 17:48:47 +03:00
|
|
|
DeviceState qdev;
|
2019-01-08 17:48:49 +03:00
|
|
|
domid_t frontend_id;
|
|
|
|
char *name;
|
2019-09-13 11:21:57 +03:00
|
|
|
struct xs_handle *xsh;
|
|
|
|
XenWatchList *watch_list;
|
2019-01-08 17:48:49 +03:00
|
|
|
char *backend_path, *frontend_path;
|
|
|
|
enum xenbus_state backend_state, frontend_state;
|
|
|
|
Notifier exit;
|
2019-01-08 17:48:59 +03:00
|
|
|
XenWatch *backend_state_watch, *frontend_state_watch;
|
|
|
|
bool backend_online;
|
|
|
|
XenWatch *backend_online_watch;
|
2019-01-08 17:48:51 +03:00
|
|
|
xengnttab_handle *xgth;
|
|
|
|
bool feature_grant_copy;
|
2019-09-13 11:21:58 +03:00
|
|
|
bool inactive;
|
2019-04-08 18:16:15 +03:00
|
|
|
QLIST_HEAD(, XenEventChannel) event_channels;
|
2019-09-13 11:21:58 +03:00
|
|
|
QLIST_ENTRY(XenDevice) list;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
|
|
|
typedef struct XenDevice XenDevice;
|
2019-01-08 17:48:47 +03:00
|
|
|
|
2019-01-08 17:48:49 +03:00
|
|
|
typedef char *(*XenDeviceGetName)(XenDevice *xendev, Error **errp);
|
2019-01-08 17:48:47 +03:00
|
|
|
typedef void (*XenDeviceRealize)(XenDevice *xendev, Error **errp);
|
2019-01-08 17:48:50 +03:00
|
|
|
typedef void (*XenDeviceFrontendChanged)(XenDevice *xendev,
|
|
|
|
enum xenbus_state frontend_state,
|
|
|
|
Error **errp);
|
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
|
|
|
typedef void (*XenDeviceUnrealize)(XenDevice *xendev);
|
2019-01-08 17:48:47 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct XenDeviceClass {
|
2019-01-08 17:48:47 +03:00
|
|
|
/*< private >*/
|
|
|
|
DeviceClass parent_class;
|
|
|
|
/*< public >*/
|
2019-01-08 17:48:49 +03:00
|
|
|
const char *backend;
|
|
|
|
const char *device;
|
|
|
|
XenDeviceGetName get_name;
|
2019-01-08 17:48:47 +03:00
|
|
|
XenDeviceRealize realize;
|
2019-01-08 17:48:50 +03:00
|
|
|
XenDeviceFrontendChanged frontend_changed;
|
2019-01-08 17:48:47 +03:00
|
|
|
XenDeviceUnrealize unrealize;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2019-01-08 17:48:47 +03:00
|
|
|
|
|
|
|
#define TYPE_XEN_DEVICE "xen-device"
|
2020-09-16 21:25:18 +03:00
|
|
|
OBJECT_DECLARE_TYPE(XenDevice, XenDeviceClass, XEN_DEVICE)
|
2019-01-08 17:48:47 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct XenBus {
|
2019-01-08 17:48:47 +03:00
|
|
|
BusState qbus;
|
2019-01-08 17:48:49 +03:00
|
|
|
domid_t backend_id;
|
|
|
|
struct xs_handle *xsh;
|
2019-09-13 11:21:56 +03:00
|
|
|
XenWatchList *watch_list;
|
2020-10-01 11:15:00 +03:00
|
|
|
unsigned int backend_types;
|
|
|
|
XenWatch **backend_watch;
|
2019-09-13 11:21:58 +03:00
|
|
|
QLIST_HEAD(, XenDevice) inactive_devices;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2019-01-08 17:48:47 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct XenBusClass {
|
2019-01-08 17:48:47 +03:00
|
|
|
/*< private >*/
|
|
|
|
BusClass parent_class;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2019-01-08 17:48:47 +03:00
|
|
|
|
|
|
|
#define TYPE_XEN_BUS "xen-bus"
|
2020-09-01 00:07:37 +03:00
|
|
|
OBJECT_DECLARE_TYPE(XenBus, XenBusClass,
|
qom: Remove module_obj_name parameter from OBJECT_DECLARE* macros
One of the goals of having less boilerplate on QOM declarations
is to avoid human error. Requiring an extra argument that is
never used is an opportunity for mistakes.
Remove the unused argument from OBJECT_DECLARE_TYPE and
OBJECT_DECLARE_SIMPLE_TYPE.
Coccinelle patch used to convert all users of the macros:
@@
declarer name OBJECT_DECLARE_TYPE;
identifier InstanceType, ClassType, lowercase, UPPERCASE;
@@
OBJECT_DECLARE_TYPE(InstanceType, ClassType,
- lowercase,
UPPERCASE);
@@
declarer name OBJECT_DECLARE_SIMPLE_TYPE;
identifier InstanceType, lowercase, UPPERCASE;
@@
OBJECT_DECLARE_SIMPLE_TYPE(InstanceType,
- lowercase,
UPPERCASE);
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Acked-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Paul Durrant <paul@xen.org>
Acked-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20200916182519.415636-4-ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2020-09-16 21:25:17 +03:00
|
|
|
XEN_BUS)
|
2019-01-08 17:48:47 +03:00
|
|
|
|
|
|
|
void xen_bus_init(void);
|
|
|
|
|
2019-01-08 17:48:50 +03:00
|
|
|
void xen_device_backend_set_state(XenDevice *xendev,
|
|
|
|
enum xenbus_state state);
|
|
|
|
enum xenbus_state xen_device_backend_get_state(XenDevice *xendev);
|
|
|
|
|
2019-01-08 17:48:59 +03:00
|
|
|
void xen_device_backend_printf(XenDevice *xendev, const char *key,
|
|
|
|
const char *fmt, ...)
|
|
|
|
GCC_FMT_ATTR(3, 4);
|
|
|
|
void xen_device_frontend_printf(XenDevice *xendev, const char *key,
|
|
|
|
const char *fmt, ...)
|
|
|
|
GCC_FMT_ATTR(3, 4);
|
|
|
|
|
|
|
|
int xen_device_frontend_scanf(XenDevice *xendev, const char *key,
|
|
|
|
const char *fmt, ...);
|
|
|
|
|
2019-01-08 17:48:51 +03:00
|
|
|
void xen_device_set_max_grant_refs(XenDevice *xendev, unsigned int nr_refs,
|
|
|
|
Error **errp);
|
|
|
|
void *xen_device_map_grant_refs(XenDevice *xendev, uint32_t *refs,
|
|
|
|
unsigned int nr_refs, int prot,
|
|
|
|
Error **errp);
|
|
|
|
void xen_device_unmap_grant_refs(XenDevice *xendev, void *map,
|
|
|
|
unsigned int nr_refs, Error **errp);
|
|
|
|
|
|
|
|
typedef struct XenDeviceGrantCopySegment {
|
|
|
|
union {
|
|
|
|
void *virt;
|
|
|
|
struct {
|
|
|
|
uint32_t ref;
|
|
|
|
off_t offset;
|
|
|
|
} foreign;
|
|
|
|
} source, dest;
|
|
|
|
size_t len;
|
|
|
|
} XenDeviceGrantCopySegment;
|
|
|
|
|
|
|
|
void xen_device_copy_grant_refs(XenDevice *xendev, bool to_domain,
|
|
|
|
XenDeviceGrantCopySegment segs[],
|
|
|
|
unsigned int nr_segs, Error **errp);
|
|
|
|
|
2019-04-08 18:16:17 +03:00
|
|
|
typedef bool (*XenEventHandler)(void *opaque);
|
2019-01-08 17:48:52 +03:00
|
|
|
|
|
|
|
XenEventChannel *xen_device_bind_event_channel(XenDevice *xendev,
|
|
|
|
unsigned int port,
|
|
|
|
XenEventHandler handler,
|
|
|
|
void *opaque, Error **errp);
|
2019-12-16 17:34:51 +03:00
|
|
|
void xen_device_set_event_channel_context(XenDevice *xendev,
|
|
|
|
XenEventChannel *channel,
|
|
|
|
AioContext *ctx,
|
|
|
|
Error **errp);
|
2019-01-08 17:48:52 +03:00
|
|
|
void xen_device_notify_event_channel(XenDevice *xendev,
|
|
|
|
XenEventChannel *channel,
|
|
|
|
Error **errp);
|
|
|
|
void xen_device_unbind_event_channel(XenDevice *xendev,
|
|
|
|
XenEventChannel *channel,
|
|
|
|
Error **errp);
|
|
|
|
|
2019-01-08 17:48:47 +03:00
|
|
|
#endif /* HW_XEN_BUS_H */
|