usb: add xen pvUSB backend
Hi,
Here comes the usb patch queue, finally bringing the xen pvUSB backend. Also a small ohci fix.
please pull,
Gerd
The following changes since commit e081c24d30c1e7b29eb4450aa16d6a0da5782797:
Merge remote-tracking branch 'remotes/ehabkost/tags/machine-pull-request' into staging (2016-05-23 10:30:41 +0100)
are available in the git repository at:
git://git.kraxel.org/qemu tags/pull-usb-20160523-1
for you to fetch changes up to d400fc018b326104d26d730e5cc8c36c1f662c34:
usb/ohci: Fix crash with when specifying too many num-ports (2016-05-23 14:59:40 +0200)
----------------------------------------------------------------
usb: add xen pvUSB backend, add num-ports check to ohci.
----------------------------------------------------------------
Juergen Gross (3):
xen: introduce dummy system device
xen: write information about supported backends
xen: add pvUSB backend
Thomas Huth (1):
usb/ohci: Fix crash with when specifying too many num-ports
hw/usb/Makefile.objs | 4 + hw/usb/hcd-ohci.c | 6 + hw/usb/xen-usb.c | 1080 ++++++++++++++++++++++++++++++++++++++++++ hw/xen/xen_backend.c | 63 +++ hw/xen/xen_devconfig.c | 52 +- hw/xenpv/xen_machine_pv.c | 43 ++ include/hw/xen/xen_backend.h | 6 + include/hw/xen/xen_common.h | 2 + 8 files changed, 1206 insertions(+), 50 deletions(-) create mode 100644 hw/usb/xen-usb.c
[Qemu-devel] [PULL 1/4] xen: introduce dummy system device
From: Juergen Gross <[email protected]>
Introduce a new dummy system device serving as parent for virtual buses. This will enable new pv backends to introduce virtual buses which are removable again opposed to system buses which are meant to stay once added.
Message-id: [email protected]
--- hw/xenpv/xen_machine_pv.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/hw/xen/xen_backend.h | 1 + 2 files changed, 41 insertions(+)
hw/xenpv/xen_machine_pv.c +40 -0
@@ -25,10 +25,15 @@#include "qemu/osdep.h" #include "hw/hw.h" #include "hw/boards.h" +#include "hw/sysbus.h" #include "hw/xen/xen_backend.h" #include "xen_domainbuild.h" #include "sysemu/block-backend.h" +#define TYPE_XENSYSDEV "xensysdev" + +DeviceState *xen_sysdev; +static void xen_init_pv (MachineState *machine) {DriveInfo *dinfo;
@@ -67,6 +72,9 @@ static void xen_init_pv(MachineState *machine)break ; } + xen_sysdev =qdev_create (NULL ,TYPE_XENSYSDEV ); +qdev_init_nofail (xen_sysdev); +xen_be_register ("console" , &xen_console_ops);xen_be_register ("vkbd" , &xen_kbdmouse_ops);xen_be_register ("vfb" , &xen_framebuffer_ops);
@@ -101,6 +109,38 @@ static void xen_init_pv(MachineState *machine)xen_init_display (xen_domid); } +static int xen_sysdev_init (SysBusDevice *dev) +{ +return 0 ; +} + +static Property xen_sysdev_properties[] = { + {/* end of property list */ }, +}; + +static void xen_sysdev_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +SysBusDeviceClass *k =SYS_BUS_DEVICE_CLASS (klass); + + k->init = xen_sysdev_init; + dc->props = xen_sysdev_properties; +} + +static const TypeInfo xensysdev_info = { + .name =TYPE_XENSYSDEV , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (SysBusDevice), + .class_init = xen_sysdev_class_init, +}; + +static void xenpv_register_types (void ) +{ +type_register_static (&xensysdev_info); +} + +type_init (xenpv_register_types); +static void xenpv_machine_init (MachineClass *mc) { mc->desc ="Xen Para-virtualized PC" ;
include/hw/xen/xen_backend.h +1 -0
@@ -60,6 +60,7 @@ extern xc_interface *xen_xc;extern xenforeignmemory_handle *xen_fmem;extern struct xs_handle *xenstore;extern const char *xen_protocol; +extern DeviceState *xen_sysdev;/* xenstore helper functions */ int xenstore_write_str (const char *base,const char *node,const char *val);
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
[Qemu-devel] [PULL 2/4] xen: write information about supported backends
In reply to Gerd HoffmannFrom: Juergen Gross <[email protected]>
Add a Xenstore directory for each supported pv backend. This will allow Xen tools to decide which backend type to use in case there are multiple possibilities.
The information is added under /local/domain/<backend-domid>/device-model/<domid>/backends before the "running" state is written to Xenstore. Using a directory for each backend enables us to add parameters for specific backends in the future.
This interface is documented in the Xen source repository in the file docs/misc/qemu-backends.txt
In order to reuse the Xenstore directory creation already present in hw/xen/xen_devconfig.c move the related functions to hw/xen/xen_backend.c where they fit better.
Message-id: [email protected]
--- hw/xen/xen_backend.c | 63 ++++++++++++++++++++++++++++++++++++++++++++ hw/xen/xen_devconfig.c | 52 ++---------------------------------- include/hw/xen/xen_backend.h | 2 ++ 3 files changed, 67 insertions(+), 50 deletions(-)
hw/xen/xen_backend.c +63 -0
@@ -42,11 +42,36 @@ struct xs_handle *xenstore = NULL;const char *xen_protocol;/* private */ +struct xs_dirs { +char *xs_dir; +QTAILQ_ENTRY (xs_dirs) list; +}; +static QTAILQ_HEAD(xs_dirs_head, xs_dirs) xs_cleanup = +QTAILQ_HEAD_INITIALIZER (xs_cleanup); + static QTAILQ_HEAD(XenDeviceHead, XenDevice) xendevs = QTAILQ_HEAD_INITIALIZER(xendevs);static int debug =0 ;/* ------------------------------------------------------------- */ +static void xenstore_cleanup_dir (char *dir) +{ +struct xs_dirs *d; + + d =g_malloc (sizeof (*d)); + d->xs_dir = dir; +QTAILQ_INSERT_TAIL (&xs_cleanup, d, list); +} + +void xen_config_cleanup (void ) +{ +struct xs_dirs *d; + + QTAILQ_FOREACH(d, &xs_cleanup, list) { +xs_rm (xenstore,0 , d->xs_dir); + } +} +int xenstore_write_str (const char *base,const char *node,const char *val) {char abspath[XEN_BUFSIZE ];
@@ -75,6 +100,30 @@ char *xenstore_read_str(const char *base, const char *node)return ret; } +int xenstore_mkdir (char *path,int p) +{ +struct xs_permissions perms[2 ] = { + { + .id =0 ,/* set owner: dom0 */ + }, { + .id = xen_domid, + .perms = p, + } + }; + +if (!xs_mkdir (xenstore,0 , path)) { +xen_be_printf (NULL ,0 ,"xs_mkdir %s: failed\n" , path); +return -1 ; + } +xenstore_cleanup_dir (g_strdup (path)); + +if (!xs_set_permissions (xenstore,0 , path, perms,2 )) { +xen_be_printf (NULL ,0 ,"xs_set_permissions %s: failed\n" , path); +return -1 ; + } +return 0 ; +} +int xenstore_write_int (const char *base,const char *node,int ival) {char val[12 ];
@@ -726,6 +775,20 @@ err:int xen_be_register (const char *type,struct XenDevOps *ops) { +char path[50 ]; +int rc; + +if (ops->backend_register) { + rc = ops->backend_register (); +if (rc) { +return rc; + } + } + +snprintf (path,sizeof (path),"device-model/%u/backends/%s" , xen_domid, + type); +xenstore_mkdir (path,XS_PERM_NONE ); +return xenstore_scan (type, xen_domid, ops); }
hw/xen/xen_devconfig.c +2 -50
64 lines not on this page · raw message
include/hw/xen/xen_backend.h +2 -0
@@ -28,6 +28,7 @@ struct XenDevOps {int (*free)(struct XenDevice *xendev);void (*backend_changed)(struct XenDevice *xendev,const char *node);void (*frontend_changed)(struct XenDevice *xendev,const char *node); +int (*backend_register)(void ); };struct XenDevice {
@@ -63,6 +64,7 @@ extern const char *xen_protocol;extern DeviceState *xen_sysdev;/* xenstore helper functions */ +int xenstore_mkdir (char *path,int p);int xenstore_write_str (const char *base,const char *node,const char *val);int xenstore_write_int (const char *base,const char *node,int ival);int xenstore_write_int64 (const char *base,const char *node,int64_t ival);
Signature · 7 lines
1.8.3.1 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
[Qemu-devel] [PULL 3/4] xen: add pvUSB backend
In reply to Gerd HoffmannFrom: Juergen Gross <[email protected]>
Add a backend for para-virtualized USB devices for xen domains.
The backend is using host-libusb to forward USB requests from a domain via libusb to the real device(s) passed through.
Message-id: [email protected]
--- hw/usb/Makefile.objs | 4 + hw/usb/xen-usb.c | 1080 ++++++++++++++++++++++++++++++++++++++++++ hw/xenpv/xen_machine_pv.c | 3 + include/hw/xen/xen_backend.h | 3 + include/hw/xen/xen_common.h | 2 + 5 files changed, 1092 insertions(+) create mode 100644 hw/usb/xen-usb.c
hw/usb/Makefile.objs +4 -0
@@ -38,3 +38,7 @@ common-obj-$(CONFIG_USB_REDIR) += redirect.o quirks.o # usb pass-through common-obj-y += $(patsubst %,host-%.o,$(HOST_USB)) + +ifeq ($(CONFIG_USB_LIBUSB),y) +common-obj-$(CONFIG_XEN_BACKEND) += xen-usb.o +endif
hw/usb/xen-usb.c new file +1080 -0
1,080 lines not on this page · raw message
hw/xenpv/xen_machine_pv.c +3 -0
@@ -80,6 +80,9 @@ static void xen_init_pv(MachineState *machine)xen_be_register ("vfb" , &xen_framebuffer_ops);xen_be_register ("qdisk" , &xen_blkdev_ops);xen_be_register ("qnic" , &xen_netdev_ops); +#ifdef CONFIG_USB_LIBUSB +xen_be_register ("qusb" , &xen_usb_ops); +#endif /* configure framebuffer */ if (xenfb_enabled) {
include/hw/xen/xen_backend.h +3 -0
@@ -101,6 +101,9 @@ extern struct XenDevOps xen_kbdmouse_ops; /* xen_framebuffer.c */extern struct XenDevOps xen_framebuffer_ops;/* xen_framebuffer.c */ extern struct XenDevOps xen_blkdev_ops;/* xen_disk.c */ extern struct XenDevOps xen_netdev_ops;/* xen_nic.c */ +#ifdef CONFIG_USB_LIBUSB +extern struct XenDevOps xen_usb_ops;/* xen-usb.c */ +#endif void xen_init_display (int domid);
include/hw/xen/xen_common.h +2 -0
@@ -49,6 +49,8 @@ typedef xc_gnttab xengnttab_handle;#define xengnttab_unmap (h, a, n) xc_gnttab_munmap(h, a, n)#define xengnttab_map_grant_refs (h, c, d, r, p) \ xc_gnttab_map_grant_refs(h, c, d, r, p) +#define xengnttab_map_domain_grant_refs (h, c, d, r, p) \ + xc_gnttab_map_domain_grant_refs(h, c, d, r, p)#define xenforeignmemory_open (l, f) xen_xc
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [Xen-devel] [PULL 3/4] xen: add pvUSB backend
Review
Quoted 4 lines · Gerd Hoffmann
+++ b/hw/usb/Makefile.objs
(quoted diff) +3
-0+common-obj-$(CONFIG_XEN_BACKEND) += xen-usb.o +++ b/hw/usb/xen-usb.c + usb_bus_new(&usbif->bus, sizeof(usbif->bus), &xen_usb_bus_ops, xen_sysdev);
xen_sysdev is in an i386-only file, as a result qemu fails to link.
Olaf
Re: [Qemu-devel] [Xen-devel] [PULL 3/4] xen: add pvUSB backend
Quoted 8 lines · Olaf Hering
Review
Quoted 4 lines · Gerd Hoffmann
+++ b/hw/usb/Makefile.objs
(quoted diff) +3
-0+common-obj-$(CONFIG_XEN_BACKEND) += xen-usb.o +++ b/hw/usb/xen-usb.c + usb_bus_new(&usbif->bus, sizeof(usbif->bus), &xen_usb_bus_ops, xen_sysdev);
xen_sysdevis in an i386-only file, as a result qemu fails to link.
Ping. Juergen? Xen folks? Can anyone have a look please?
I think the fix would be s/xen_sysdev/xendev/, but I can't test that myself.
cheers,
Gerd
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [Qemu-devel] [Xen-devel] [PULL 3/4] xen: add pvUSB backend
Quoted 11 lines · Gerd Hoffmann
Quoted 8 lines · Olaf Hering
Review
Quoted 4 lines · Gerd Hoffmann
+++ b/hw/usb/Makefile.objs
(quoted diff) +3
-0+common-obj-$(CONFIG_XEN_BACKEND) += xen-usb.o +++ b/hw/usb/xen-usb.c + usb_bus_new(&usbif->bus, sizeof(usbif->bus), &xen_usb_bus_ops, xen_sysdev);
xen_sysdevis in an i386-only file, as a result qemu fails to link.Ping. Juergen? Xen folks? Can anyone have a look please?
Sorry, just was 3 weeks offline due to moving across Germany (900 km).
Quoted 2 lines
I think the fix would be s/xen_sysdev/xendev/, but I can't test that myself.
I think the proper solution is to move the xen_sysdev definition and initialization from hw/xenpv/xen_machine_pv.c to hw/xen/xen_backend.c
I'll send a patch.
Juergen
[Qemu-devel] [PULL 4/4] usb/ohci: Fix crash with when specifying too many num-ports
In reply to Gerd HoffmannFrom: Thomas Huth <[email protected]>
QEMU currently crashes when an OHCI controller is instantiated with too many ports, e.g. "-device pci-ohci,num-ports=100,masterbus=1". Thus add a proper check in usb_ohci_init() to make sure that we do not use more than OHCI_MAX_PORTS = 15 ports here.
Ticket: https://bugs.launchpad.net/qemu/+bug/1581308
Message-id: [email protected]
--- hw/usb/hcd-ohci.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/usb/hcd-ohci.c +6 -0
@@ -1848,6 +1848,12 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState *dev, ohci->as = as; +if (num_ports >OHCI_MAX_PORTS ) { +error_setg (errp,"OHCI num-ports=%d is too big (limit is %d ports)" , + num_ports,OHCI_MAX_PORTS ); +return ; + } +if (usb_frame_time ==0 ) {#ifdef OHCI_TIME_WARP usb_frame_time =NANOSECONDS_PER_SECOND ;
Signature · 1 line
1.8.3.1
Peter Maydell
AppliedQuoted 24 lines · Gerd Hoffmann
Hi,
Here comes the usb patch queue, finally bringing the xen pvUSB backend. Also a small ohci fix.
please pull,
GerdThe following changes since commit
e081c24d30c1e7b29eb4450aa16d6a0da5782797:Merge remote-tracking branch 'remotes/ehabkost/tags/machine-pull-request' into staging (2016-05-23 10:30:41 +0100)
are available in the git repository at:
git://git.kraxel.org/qemutags/pull-usb-20160523-1for you to fetch changes up to
d400fc018b326104d26d730e5cc8c36c1f662c34:usb/ohci: Fix crash with when specifying too many num-ports (2016-05-23 14:59:40 +0200)
----------------------------------------------------------------
usb: add xen pvUSB backend, add num-ports check to ohci.
Quoted 8 lines
----------------------------------------------------------------
Juergen Gross (3):
xen: introduce dummy system device
xen: write information about supported backends
xen: add pvUSB backendThomas Huth (1):
usb/ohci: Fix crash with when specifying too many num-ports
Applied, thanks.
-- PMM