Commit 5b1c674d authored by Pete Zaitcev's avatar Pete Zaitcev Committed by Greg Kroah-Hartman

[PATCH] USB: update usbmon, fix glued lines

This update contains one bug fix: some lines can come out truncated,
because of the safety cutoff. This happened because I forgot to update
the size when status packets began to be printed.

The rest is:
 - Comments updates
 - Allow snooping with pkmap on x86_64, which is cache-coherent
 - Enlarge event buffers (certainly we can have a couple of pages)
 - Add event counter

First touch upon usbmon for 2.6.18.
Signed-off-by: default avatarPete Zaitcev <zaitcev@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 4bc203d9
...@@ -13,7 +13,10 @@ ...@@ -13,7 +13,10 @@
#include <linux/usb.h> /* Only needed for declarations in usb_mon.h */ #include <linux/usb.h> /* Only needed for declarations in usb_mon.h */
#include "usb_mon.h" #include "usb_mon.h"
#ifdef __i386__ /* CONFIG_ARCH_I386 does not exit */ /*
* PC-compatibles, are, fortunately, sufficiently cache-coherent for this.
*/
#if defined(__i386__) || defined(__x86_64__) /* CONFIG_ARCH_I386 doesn't exit */
#define MON_HAS_UNMAP 1 #define MON_HAS_UNMAP 1
#define phys_to_page(phys) pfn_to_page((phys) >> PAGE_SHIFT) #define phys_to_page(phys) pfn_to_page((phys) >> PAGE_SHIFT)
......
...@@ -97,6 +97,7 @@ static void mon_submit(struct usb_bus *ubus, struct urb *urb) ...@@ -97,6 +97,7 @@ static void mon_submit(struct usb_bus *ubus, struct urb *urb)
if (mbus->nreaders == 0) if (mbus->nreaders == 0)
goto out_locked; goto out_locked;
mbus->cnt_events++;
list_for_each (pos, &mbus->r_list) { list_for_each (pos, &mbus->r_list) {
r = list_entry(pos, struct mon_reader, r_link); r = list_entry(pos, struct mon_reader, r_link);
r->rnf_submit(r->r_data, urb); r->rnf_submit(r->r_data, urb);
...@@ -152,6 +153,7 @@ static void mon_complete(struct usb_bus *ubus, struct urb *urb) ...@@ -152,6 +153,7 @@ static void mon_complete(struct usb_bus *ubus, struct urb *urb)
} }
spin_lock_irqsave(&mbus->lock, flags); spin_lock_irqsave(&mbus->lock, flags);
mbus->cnt_events++;
list_for_each (pos, &mbus->r_list) { list_for_each (pos, &mbus->r_list) {
r = list_entry(pos, struct mon_reader, r_link); r = list_entry(pos, struct mon_reader, r_link);
r->rnf_complete(r->r_data, urb); r->rnf_complete(r->r_data, urb);
...@@ -163,7 +165,6 @@ static void mon_complete(struct usb_bus *ubus, struct urb *urb) ...@@ -163,7 +165,6 @@ static void mon_complete(struct usb_bus *ubus, struct urb *urb)
/* /*
* Stop monitoring. * Stop monitoring.
* Obviously this must be well locked, so no need to play with mb's.
*/ */
static void mon_stop(struct mon_bus *mbus) static void mon_stop(struct mon_bus *mbus)
{ {
......
...@@ -31,8 +31,8 @@ static int mon_stat_open(struct inode *inode, struct file *file) ...@@ -31,8 +31,8 @@ static int mon_stat_open(struct inode *inode, struct file *file)
mbus = inode->u.generic_ip; mbus = inode->u.generic_ip;
sp->slen = snprintf(sp->str, STAT_BUF_SIZE, sp->slen = snprintf(sp->str, STAT_BUF_SIZE,
"nreaders %d text_lost %u\n", "nreaders %d events %u text_lost %u\n",
mbus->nreaders, mbus->cnt_text_lost); mbus->nreaders, mbus->cnt_events, mbus->cnt_text_lost);
file->private_data = sp; file->private_data = sp;
return 0; return 0;
......
...@@ -26,10 +26,13 @@ ...@@ -26,10 +26,13 @@
/* /*
* This limit exists to prevent OOMs when the user process stops reading. * This limit exists to prevent OOMs when the user process stops reading.
* If usbmon were available to unprivileged processes, it might be open
* to a local DoS. But we have to keep to root in order to prevent
* password sniffing from HID devices.
*/ */
#define EVENT_MAX 25 #define EVENT_MAX (2*PAGE_SIZE / sizeof(struct mon_event_text))
#define PRINTF_DFL 130 #define PRINTF_DFL 160
struct mon_event_text { struct mon_event_text {
struct list_head e_link; struct list_head e_link;
...@@ -111,7 +114,7 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb, ...@@ -111,7 +114,7 @@ static inline char mon_text_get_data(struct mon_event_text *ep, struct urb *urb,
* number of corner cases, but it seems that the following is * number of corner cases, but it seems that the following is
* more or less safe. * more or less safe.
* *
* We do not even try to look transfer_buffer, because it can * We do not even try to look at transfer_buffer, because it can
* contain non-NULL garbage in case the upper level promised to * contain non-NULL garbage in case the upper level promised to
* set DMA for the HCD. * set DMA for the HCD.
*/ */
......
...@@ -27,6 +27,7 @@ struct mon_bus { ...@@ -27,6 +27,7 @@ struct mon_bus {
struct kref ref; /* Under mon_lock */ struct kref ref; /* Under mon_lock */
/* Stats */ /* Stats */
unsigned int cnt_events;
unsigned int cnt_text_lost; unsigned int cnt_text_lost;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment