Use ioreq-server API
v4 cover Use ioreq-server API
This patch series is v4 of what was originally the single patch "Xen: Use the ioreq-server API when available".
v2 of the series moved the code that added the PCI bus listener to patch #1 and the remainder of the changes to patch #2. Patch #2 was then re-worked to constrain the #ifdefing to xen_common.h, as requested by Stefano.
v3 of the series modifies patch #1 to add the listener interface into the core qdev, rather than the PCI bus code. This change only requires trivial modification to patch #2, to only act on realize/ unrealize of PCI devices. Patch #2 was also modified at Stefano's request to remove an extra identity check of memory sections against the ram region.
v4 of the series replaces the use of a vmstate pre_save callback with extra code in the existing runstate change notification callback. It also tidies up some things in xen-hvm.c pointed out by Stefano and adds his ack to patch #2.
PATCH v4 1/2 Add device listener interface
The Xen ioreq-server API, introduced in Xen 4.5, requires that PCI device models explicitly register with Xen for config space accesses. This patch adds a listener interface into qdev-core which can be used by the Xen interface code to monitor for arrival and departure of PCI devices.
--- hw/core/qdev.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ include/hw/qdev-core.h | 10 +++++++++ include/qemu/typedefs.h | 1 + 3 files changed, 65 insertions(+)
hw/core/qdev.c +54 -0
@@ -175,6 +175,56 @@ int qdev_init(DeviceState *dev)return 0 ; } +static QTAILQ_HEAD(qdev_listeners, DeviceListener) qdev_listeners + =QTAILQ_HEAD_INITIALIZER (qdev_listeners); + +enum ListenerDirection { Forward, Reverse }; + +#define QDEV_LISTENER_CALL(_callback, _direction, _args...) \ + do { \ + DeviceListener *_listener; \ + \ + switch (_direction) { \ + case Forward: \ + QTAILQ_FOREACH(_listener, &qdev_listeners, link) { \ + if (_listener->_callback) { \ + _listener->_callback(_listener, ##_args); \ + } \ + } \ + break; \ + case Reverse: \ + QTAILQ_FOREACH_REVERSE(_listener, &qdev_listeners, \ + qdev_listeners, link) { \ + if (_listener->_callback) { \ + _listener->_callback(_listener, ##_args); \ + } \ + } \ + break; \ + default: \ + abort(); \ + } \ + } while (0) + +static int qdev_listener_add (DeviceState *dev,void *opaque) +{ +QDEV_LISTENER_CALL (realize, Forward, dev); + +return 0 ; +} + +void qdev_listener_register (DeviceListener *listener) +{ +QTAILQ_INSERT_TAIL (&qdev_listeners, listener, link); + +qbus_walk_children (sysbus_get_default (),NULL ,NULL , qdev_listener_add, +NULL ,NULL ); +} + +void qdev_listener_unregister (DeviceListener *listener) +{ +QTAILQ_REMOVE (&qdev_listeners, listener, link); +} +static void device_realize (DeviceState *dev,Error **errp) {DeviceClass *dc =DEVICE_GET_CLASS (dev);
@@ -186,12 +236,16 @@ static void device_realize(DeviceState *dev, Error **errp)return ; } } + +QDEV_LISTENER_CALL (realize, Forward, dev); }static void device_unrealize (DeviceState *dev,Error **errp) {DeviceClass *dc =DEVICE_GET_CLASS (dev); +QDEV_LISTENER_CALL (unrealize, Reverse, dev); +if (dc->exit) {int rc = dc->exit (dev);if (rc <0 ) {
include/hw/qdev-core.h +10 -0
@@ -167,6 +167,12 @@ struct DeviceState {int alias_required_for_version; }; +struct DeviceListener { +void (*realize)(DeviceListener *listener,DeviceState *dev); +void (*unrealize)(DeviceListener *listener,DeviceState *dev); +QTAILQ_ENTRY (DeviceListener) link; +}; +#define TYPE_BUS "bus"#define BUS (obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS)#define BUS_CLASS (klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS)
@@ -368,4 +374,8 @@ static inline void qbus_set_hotplug_handler(BusState *bus, DeviceState *handler, QDEV_HOTPLUG_HANDLER_PROPERTY, errp); bus->allow_hotplug = 1; } + +void qdev_listener_register (DeviceListener *listener); +void qdev_listener_unregister (DeviceListener *listener); +#endif
include/qemu/typedefs.h +1 -0
@@ -20,6 +20,7 @@ typedef struct Property Property;typedef struct PropertyInfo PropertyInfo ;typedef struct CompatProperty CompatProperty ;typedef struct DeviceState DeviceState ; +typedef struct DeviceListener DeviceListener ;typedef struct BusState BusState ;typedef struct BusClass BusClass ;
Signature · 1 line
1.7.10.4
PATCH v4 1/2 Add device listener interface
In reply to Paul DurrantThe Xen ioreq-server API, introduced in Xen 4.5, requires that PCI device models explicitly register with Xen for config space accesses. This patch adds a listener interface into qdev-core which can be used by the Xen interface code to monitor for arrival and departure of PCI devices.
--- hw/core/qdev.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ include/hw/qdev-core.h | 10 +++++++++ include/qemu/typedefs.h | 1 + 3 files changed, 65 insertions(+)
hw/core/qdev.c +54 -0
@@ -175,6 +175,56 @@ int qdev_init(DeviceState *dev)return 0 ; } +static QTAILQ_HEAD(qdev_listeners, DeviceListener) qdev_listeners + =QTAILQ_HEAD_INITIALIZER (qdev_listeners); + +enum ListenerDirection { Forward, Reverse }; + +#define QDEV_LISTENER_CALL(_callback, _direction, _args...) \ + do { \ + DeviceListener *_listener; \ + \ + switch (_direction) { \ + case Forward: \ + QTAILQ_FOREACH(_listener, &qdev_listeners, link) { \ + if (_listener->_callback) { \ + _listener->_callback(_listener, ##_args); \ + } \ + } \ + break; \ + case Reverse: \ + QTAILQ_FOREACH_REVERSE(_listener, &qdev_listeners, \ + qdev_listeners, link) { \ + if (_listener->_callback) { \ + _listener->_callback(_listener, ##_args); \ + } \ + } \ + break; \ + default: \ + abort(); \ + } \ + } while (0) + +static int qdev_listener_add (DeviceState *dev,void *opaque) +{ +QDEV_LISTENER_CALL (realize, Forward, dev); + +return 0 ; +} + +void qdev_listener_register (DeviceListener *listener) +{ +QTAILQ_INSERT_TAIL (&qdev_listeners, listener, link); + +qbus_walk_children (sysbus_get_default (),NULL ,NULL , qdev_listener_add, +NULL ,NULL ); +} + +void qdev_listener_unregister (DeviceListener *listener) +{ +QTAILQ_REMOVE (&qdev_listeners, listener, link); +} +static void device_realize (DeviceState *dev,Error **errp) {DeviceClass *dc =DEVICE_GET_CLASS (dev);
@@ -186,12 +236,16 @@ static void device_realize(DeviceState *dev, Error **errp)return ; } } + +QDEV_LISTENER_CALL (realize, Forward, dev); }static void device_unrealize (DeviceState *dev,Error **errp) {DeviceClass *dc =DEVICE_GET_CLASS (dev); +QDEV_LISTENER_CALL (unrealize, Reverse, dev); +if (dc->exit) {int rc = dc->exit (dev);if (rc <0 ) {
include/hw/qdev-core.h +10 -0
@@ -167,6 +167,12 @@ struct DeviceState {int alias_required_for_version; }; +struct DeviceListener { +void (*realize)(DeviceListener *listener,DeviceState *dev); +void (*unrealize)(DeviceListener *listener,DeviceState *dev); +QTAILQ_ENTRY (DeviceListener) link; +}; +#define TYPE_BUS "bus"#define BUS (obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS)#define BUS_CLASS (klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS)
@@ -368,4 +374,8 @@ static inline void qbus_set_hotplug_handler(BusState *bus, DeviceState *handler, QDEV_HOTPLUG_HANDLER_PROPERTY, errp); bus->allow_hotplug = 1; } + +void qdev_listener_register (DeviceListener *listener); +void qdev_listener_unregister (DeviceListener *listener); +#endif
include/qemu/typedefs.h +1 -0
@@ -20,6 +20,7 @@ typedef struct Property Property;typedef struct PropertyInfo PropertyInfo ;typedef struct CompatProperty CompatProperty ;typedef struct DeviceState DeviceState ; +typedef struct DeviceListener DeviceListener ;typedef struct BusState BusState ;typedef struct BusClass BusClass ;
Signature · 1 line
1.7.10.4
PATCH v4 2/2 Xen: Use the ioreq-server API when available
In reply to Paul DurrantThe ioreq-server API added to Xen 4.5 offers better security than the existing Xen/QEMU interface because the shared pages that are used to pass emulation request/results back and forth are removed from the guest's memory space before any requests are serviced. This prevents the guest from mapping these pages (they are in a well known location) and attempting to attack QEMU by synthesizing its own request structures. Hence, this patch modifies configure to detect whether the API is available, and adds the necessary code to use the API if it is.
--- configure | 29 ++++++ include/hw/xen/xen_common.h | 223 +++++++++++++++++++++++++++++++++++++++++++ trace-events | 9 ++ xen-hvm.c | 156 ++++++++++++++++++++++++++---- 4 files changed, 396 insertions(+), 21 deletions(-)
configure +29 -0
@@ -1876,6 +1876,32 @@ int main(void) { xc_gnttab_open(NULL, 0); xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); + xc_hvm_create_ioreq_server(xc, 0, 0, NULL); + return 0; +} +EOF + compile_prog "" "$xen_libs" + then + xen_ctrl_version=450 + xen=yes + + elif + cat > $TMPC <<EOF && +#include <xenctrl.h> +#include <xenstore.h> +#include <stdint.h> +#include <xen/hvm/hvm_info_table.h> +#if !defined(HVM_MAX_VCPUS) +# error HVM_MAX_VCPUS not defined +#endif +int main(void) { + xc_interface *xc; + xs_daemon_open(); + xc = xc_interface_open(0, 0, 0); + xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); + xc_gnttab_open(NULL, 0); + xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); + xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); return 0; } EOF
@@ -4282,6 +4308,9 @@ if test -n "$sparc_cpu"; then echo "Target Sparc Arch $sparc_cpu" fi echo "xen support $xen" +if test "$xen" = "yes" ; then + echo "xen ctrl version $xen_ctrl_version" +fi echo "brlapi support $brlapi" echo "bluez support $bluez" echo "Documentation $docs"
include/hw/xen/xen_common.h +223 -0
234 lines not on this page · raw message
trace-events +9 -0
@@ -895,6 +895,15 @@ pvscsi_tx_rings_num_pages(const char* label, uint32_t num) "Number of %s pages: # xen-hvm.c xen_ram_alloc(unsigned long ram_addr, unsigned long size) "requested: %#lx, size %#lx" xen_client_set_memory(uint64_t start_addr, unsigned long size, bool log_dirty) "%#"PRIx64" size %#lx, log_dirty %i" +xen_ioreq_server_create(uint32_t id) "id: %u" +xen_ioreq_server_destroy(uint32_t id) "id: %u" +xen_ioreq_server_state(uint32_t id, bool enable) "id: %u: enable: %i" +xen_map_mmio_range(uint32_t id, uint64_t start_addr, uint64_t end_addr) "id: %u start: %#"PRIx64" end: %#"PRIx64 +xen_unmap_mmio_range(uint32_t id, uint64_t start_addr, uint64_t end_addr) "id: %u start: %#"PRIx64" end: %#"PRIx64 +xen_map_portio_range(uint32_t id, uint64_t start_addr, uint64_t end_addr) "id: %u start: %#"PRIx64" end: %#"PRIx64 +xen_unmap_portio_range(uint32_t id, uint64_t start_addr, uint64_t end_addr) "id: %u start: %#"PRIx64" end: %#"PRIx64 +xen_map_pcidev(uint32_t id, uint8_t bus, uint8_t dev, uint8_t func) "id: %u bdf: %02x.%02x.%02x" +xen_unmap_pcidev(uint32_t id, uint8_t bus, uint8_t dev, uint8_t func) "id: %u bdf: %02x.%02x.%02x" # xen-mapcache.c xen_map_cache(uint64_t phys_addr) "want %#"PRIx64
xen-hvm.c +135 -21
256 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v4 2/2 Xen: Use the ioreq-server API when available
In reply to Paul DurrantThe ioreq-server API added to Xen 4.5 offers better security than the existing Xen/QEMU interface because the shared pages that are used to pass emulation request/results back and forth are removed from the guest's memory space before any requests are serviced. This prevents the guest from mapping these pages (they are in a well known location) and attempting to attack QEMU by synthesizing its own request structures. Hence, this patch modifies configure to detect whether the API is available, and adds the necessary code to use the API if it is.
--- configure | 29 ++++++ include/hw/xen/xen_common.h | 223 +++++++++++++++++++++++++++++++++++++++++++ trace-events | 9 ++ xen-hvm.c | 156 ++++++++++++++++++++++++++---- 4 files changed, 396 insertions(+), 21 deletions(-)
configure +29 -0
@@ -1876,6 +1876,32 @@ int main(void) { xc_gnttab_open(NULL, 0); xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); + xc_hvm_create_ioreq_server(xc, 0, 0, NULL); + return 0; +} +EOF + compile_prog "" "$xen_libs" + then + xen_ctrl_version=450 + xen=yes + + elif + cat > $TMPC <<EOF && +#include <xenctrl.h> +#include <xenstore.h> +#include <stdint.h> +#include <xen/hvm/hvm_info_table.h> +#if !defined(HVM_MAX_VCPUS) +# error HVM_MAX_VCPUS not defined +#endif +int main(void) { + xc_interface *xc; + xs_daemon_open(); + xc = xc_interface_open(0, 0, 0); + xc_hvm_set_mem_type(0, 0, HVMMEM_ram_ro, 0, 0); + xc_gnttab_open(NULL, 0); + xc_domain_add_to_physmap(0, 0, XENMAPSPACE_gmfn, 0, 0); + xc_hvm_inject_msi(xc, 0, 0xf0000000, 0x00000000); return 0; } EOF
@@ -4282,6 +4308,9 @@ if test -n "$sparc_cpu"; then echo "Target Sparc Arch $sparc_cpu" fi echo "xen support $xen" +if test "$xen" = "yes" ; then + echo "xen ctrl version $xen_ctrl_version" +fi echo "brlapi support $brlapi" echo "bluez support $bluez" echo "Documentation $docs"
include/hw/xen/xen_common.h +223 -0
234 lines not on this page · raw message
trace-events +9 -0
@@ -895,6 +895,15 @@ pvscsi_tx_rings_num_pages(const char* label, uint32_t num) "Number of %s pages: # xen-hvm.c xen_ram_alloc(unsigned long ram_addr, unsigned long size) "requested: %#lx, size %#lx" xen_client_set_memory(uint64_t start_addr, unsigned long size, bool log_dirty) "%#"PRIx64" size %#lx, log_dirty %i" +xen_ioreq_server_create(uint32_t id) "id: %u" +xen_ioreq_server_destroy(uint32_t id) "id: %u" +xen_ioreq_server_state(uint32_t id, bool enable) "id: %u: enable: %i" +xen_map_mmio_range(uint32_t id, uint64_t start_addr, uint64_t end_addr) "id: %u start: %#"PRIx64" end: %#"PRIx64 +xen_unmap_mmio_range(uint32_t id, uint64_t start_addr, uint64_t end_addr) "id: %u start: %#"PRIx64" end: %#"PRIx64 +xen_map_portio_range(uint32_t id, uint64_t start_addr, uint64_t end_addr) "id: %u start: %#"PRIx64" end: %#"PRIx64 +xen_unmap_portio_range(uint32_t id, uint64_t start_addr, uint64_t end_addr) "id: %u start: %#"PRIx64" end: %#"PRIx64 +xen_map_pcidev(uint32_t id, uint8_t bus, uint8_t dev, uint8_t func) "id: %u bdf: %02x.%02x.%02x" +xen_unmap_pcidev(uint32_t id, uint8_t bus, uint8_t dev, uint8_t func) "id: %u bdf: %02x.%02x.%02x" # xen-mapcache.c xen_map_cache(uint64_t phys_addr) "want %#"PRIx64
xen-hvm.c +135 -21
256 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Ping?
Quoted 32 lines
-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Paul Durrant
Sent: 16 October 2014 13:11
To: [email protected]; [email protected]
Subject: [Xen-devel] [PATCH v4 0/2] Use ioreq-server APIThis patch series is v4 of what was originally the single patch "Xen: Use the ioreq-server API when available".
v2 of the series moved the code that added the PCI bus listener to patch #1 and the remainder of the changes to patch #2. Patch #2 was then re-worked to constrain the #ifdefing to
xen_common.h, as requested by Stefano.v3 of the series modifies patch #1 to add the listener interface into the core qdev, rather than the PCI bus code. This change only requires trivial modification to patch #2, to only act on realize/ unrealize of PCI devices. Patch #2 was also modified at Stefano's request to remove an extra identity check of memory sections against the ram region.
v4 of the series replaces the use of a vmstate
pre_savecallback with extra code in the existing runstate change notification callback. It also tidies up some things inxen-hvm.cpointed out by Stefano and adds his ack to patch #2._______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Ping?
Quoted 32 lines
-----Original Message-----
From: [email protected] [mailto:xen-devel- [email protected]] On Behalf Of Paul Durrant
Sent: 16 October 2014 13:11
To: [email protected]; [email protected]
Subject: [Xen-devel] [PATCH v4 0/2] Use ioreq-server APIThis patch series is v4 of what was originally the single patch "Xen: Use the ioreq-server API when available".
v2 of the series moved the code that added the PCI bus listener to patch #1 and the remainder of the changes to patch #2. Patch #2 was then re-worked to constrain the #ifdefing to
xen_common.h, as requested by Stefano.v3 of the series modifies patch #1 to add the listener interface into the core qdev, rather than the PCI bus code. This change only requires trivial modification to patch #2, to only act on realize/ unrealize of PCI devices. Patch #2 was also modified at Stefano's request to remove an extra identity check of memory sections against the ram region.
v4 of the series replaces the use of a vmstate
pre_savecallback with extra code in the existing runstate change notification callback. It also tidies up some things inxen-hvm.cpointed out by Stefano and adds his ack to patch #2._______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel