usbmon with explicit hooks
Hi, guys:
I thought the David's argument over and decided that it makes usbmon simpler if hooks are made explicit. Most importantly, URBs are not tracked anymore at all. This magically fixes ISO and interrupt URBs. The struct urb does not have anything added anymore, there's no need to jiggle with urb->complete.
However, I still need to change how we help root hubs at ARM. This time I do not touch pipe and use the old check when it's valid. This should address everyone's concerns. If I hear no new howls of outrage, I'm going to submit this to Greg.
Cheers,
-- Pete
drivers/usb/core/hcd.c +56 -10
@@ -86,6 +86,7 @@/* host controllers we manage */ LIST_HEAD (usb_bus_list); +EXPORT_SYMBOL_GPL (usb_bus_list);/* used when allocating bus numbers */ #define USB_MAXBUS 64
@@ -96,6 +97,7 @@ static struct usb_busmap busmap;/* used when updating list of hcds */ DECLARE_MUTEX (usb_bus_list_lock);/* exported only for usbfs */ +EXPORT_SYMBOL_GPL (usb_bus_list_lock);/* used when updating hcd data */ static DEFINE_SPINLOCK (hcd_data_lock);
@@ -103,6 +105,10 @@ static DEFINE_SPINLOCK(hcd_data_lock);/* wait queue for synchronous unlinks */ DECLARE_WAIT_QUEUE_HEAD (usb_kill_urb_queue); +#if defined(CONFIG_USB_MON ) || defined(CONFIG_USB_MON_MODULE ) +struct usb_mon_operations *mon_ops; +#endif /* CONFIG_USB_MON */ +/*-------------------------------------------------------------------------*/ /*
@@ -746,6 +752,7 @@ int usb_register_bus(struct usb_bus *busup (&usb_bus_list_lock);usbfs_add_bus (bus); +usbmon_notify_bus_add (bus);dev_info (bus->controller,"new USB bus registered, assigned bus number %d\n" , bus->busnum);return 0 ;
@@ -773,6 +780,7 @@ void usb_deregister_bus (struct usb_buslist_del (&bus->bus_list);up (&usb_bus_list_lock); +usbmon_notify_bus_remove (bus);usbfs_remove_bus (bus);clear_bit (bus->busnum, busmap.busmap);
@@ -1058,9 +1066,7 @@ static int hcd_submit_urb (struct urb *u* as simple as possible. */ -// NOTE: a generic device/urb monitoring hook would go here. -// hcd_monitor_hook(MONITOR_URB_SUBMIT, urb) -// It would catch submission paths for all urbs. +usbmon_urb_submit (&hcd->self, urb);/* * Atomically queue the urb, first to our records, then to the HCD.
@@ -1087,6 +1093,7 @@ static int hcd_submit_urb (struct urb *uspin_unlock_irqrestore (&hcd_data_lock, flags);if (status) {INIT_LIST_HEAD (&urb->urb_list); +usbmon_urb_submit_error (&hcd->self, urb, status);return status; }
@@ -1103,8 +1110,6 @@ static int hcd_submit_urb (struct urb *u* valid and usb_buffer_{sync,unmap}() not be needed, since * they could clobber root hub response data. */ - urb->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP - |URB_NO_SETUP_DMA_MAP ); status =rh_urb_enqueue (hcd, urb); goto done; }
@@ -1139,6 +1144,7 @@ done:if (urb->reject)wake_up (&usb_kill_urb_queue);usb_put_urb (urb); +usbmon_urb_submit_error (&hcd->self, urb, status); }return status; }
@@ -1461,14 +1467,13 @@ static struct usb_operations usb_hcd_ope*/ void usb_hcd_giveback_urb (struct usb_hcd *hcd,struct urb *urb,struct pt_regs *regs) { -urb_unlink (urb); +int at_root_hub; -// NOTE: a generic device/urb monitoring hook would go here. -// hcd_monitor_hook(MONITOR_URB_FINISH, urb, dev) -// It would catch exit/unlink paths for all urbs. + at_root_hub = (urb->dev == hcd->self.root_hub); +urb_unlink (urb);/* lower level hcd code should use *_dma exclusively */ -if (hcd->self.controller->dma_mask) { +if (hcd->self.controller->dma_mask && !at_root_hub) {if (usb_pipecontrol (urb->pipe) && !(urb->transfer_flags &URB_NO_SETUP_DMA_MAP )) dma_unmap_single (hcd->self.controller, urb->setup_dma,
@@ -1484,6 +1489,7 @@ void usb_hcd_giveback_urb (struct usb_hc : DMA_TO_DEVICE); } +usbmon_urb_complete (&hcd->self, urb);/* pass ownership to the completion handler */ urb->complete (urb, regs);atomic_dec (&urb->use_count);
@@ -1591,3 +1597,43 @@ void usb_put_hcd (struct usb_hcd *hcd)usb_bus_put (&hcd->self); }EXPORT_SYMBOL (usb_put_hcd); + +/*-------------------------------------------------------------------------*/ + +#if defined(CONFIG_USB_MON ) || defined(CONFIG_USB_MON_MODULE ) + +struct usb_mon_operations *mon_ops; + +/* +* The registration is unlocked. +* We do it this way because we do not want to lock in hot paths. +* +* Notice that the code is minimally error-proof. Because usbmon needs +* symbols from usbcore, usbcore gets referenced and cannot be unloaded first. +*/ + +int usb_mon_register (struct usb_mon_operations *ops) +{ + +if (mon_ops) +return -EBUSY ; + + mon_ops = ops; +mb (); +return 0 ; +} +EXPORT_SYMBOL_GPL (usb_mon_register); + +void usb_mon_deregister (void ) +{ + +if (mon_ops ==NULL ) { +printk (KERN_ERR "USB: monitor was not registered\n" ); +return ; + } + mon_ops =NULL ; +mb (); +} +EXPORT_SYMBOL_GPL (usb_mon_deregister); + +#endif /* CONFIG_USB_MON */
drivers/usb/core/hcd.h +57 -0
63 lines not on this page · raw message
drivers/usb/Kconfig +2 -0
@@ -56,6 +56,8 @@ source "drivers/usb/media/Kconfig" source "drivers/usb/net/Kconfig" +source "drivers/usb/mon/Kconfig" + comment "USB port drivers" depends on USB
drivers/usb/Makefile +2 -0
@@ -6,6 +6,8 @@ obj-$(CONFIG_USB) += core/ +obj-$(CONFIG_USB_MON) += mon/ + obj-$(CONFIG_USB_EHCI_HCD) += host/ obj-$(CONFIG_USB_OHCI_HCD) += host/ obj-$(CONFIG_USB_UHCI_HCD) += host/
drivers/usb/mon/Kconfig +22 -0
@@ -0,0 +1,22 @@ +# +# USB Monitor configuration +# + +# In normal life, it makes little sense to have usbmon as a module, and in fact +# it is harmful, because there is no way to autoload the module. +# The 'm' option is allowed for hackers who debug the usbmon itself, +# and for those who have usbcore as a module. +config USB_MON + tristate "USB Monitor" + depends on USB + default y + help + If you say Y here, a component which captures the USB traffic + between peripheral-specific drivers and HC drivers will be built. + The USB_MON is similar in spirit and may be compatible with Dave + Harding's USBMon. + + This is somewhat experimental at this time, but it should be safe, + as long as you aren't building this as a module and then removing it. + + If unsure, say Y. Do not say M.
drivers/usb/mon/Makefile +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for USB Core files and filesystem +# + +usbmon-objs := mon_main.o mon_stat.o mon_text.o + +obj-$(CONFIG_USB_MON) += usbmon.o
drivers/usb/mon/mon_main.c +377 -0
377 lines not on this page · raw message
drivers/usb/mon/mon_stat.c +74 -0
74 lines not on this page · raw message
drivers/usb/mon/mon_text.c +395 -0
395 lines not on this page · raw message
drivers/usb/mon/usb_mon.h +51 -0
51 lines not on this page · raw message
include/linux/usb.h +4 -0
@@ -285,6 +285,10 @@ struct usb_bus {struct class_device class_dev;/* class device for this bus */ void (*release)(struct usb_bus *bus);/* function to destroy this bus's memory */ +#if defined(CONFIG_USB_MON ) || defined(CONFIG_USB_MON_MODULE ) +struct mon_bus *mon_bus;/* non-null when associated */ +int monitored;/* non-zero when monitored */ +#endif };#define to_usb_bus (d) container_of(d, struct usb_bus, class_dev)