Skip to content

Commit

Permalink
kcov: collect coverage from remote threads
Browse files Browse the repository at this point in the history
  • Loading branch information
xairy committed Jun 11, 2018
1 parent 29dcea8 commit 7244f9e
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 26 deletions.
4 changes: 4 additions & 0 deletions drivers/usb/core/hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -5197,6 +5197,8 @@ static void hub_event(struct work_struct *work)
hub_dev = hub->intfdev;
intf = to_usb_interface(hub_dev);

kcov_remote_start(kcov_remote_handle_usb(hdev->bus->busnum));

dev_dbg(hub_dev, "state %d ports %d chg %04x evt %04x\n",
hdev->state, hdev->maxchild,
/* NOTE: expects max 15 ports... */
Expand Down Expand Up @@ -5303,6 +5305,8 @@ static void hub_event(struct work_struct *work)
/* Balance the stuff in kick_hub_wq() and allow autosuspend */
usb_autopm_put_interface(intf);
kref_put(&hub->kref, hub_release);

kcov_remote_stop();
}

static const struct usb_device_id hub_id_table[] = {
Expand Down
8 changes: 8 additions & 0 deletions include/linux/kcov.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ struct task_struct;

#ifdef CONFIG_KCOV

#define KCOV_PER_THREAD_AREA_SIZE (PAGE_SIZE << 4)

enum kcov_mode {
/* Coverage collection is not enabled yet. */
KCOV_MODE_DISABLED = 0,
Expand All @@ -25,10 +27,16 @@ enum kcov_mode {
void kcov_task_init(struct task_struct *t);
void kcov_task_exit(struct task_struct *t);

void kcov_remote_start(u64 handle);
void kcov_remote_stop(void);

#else

static inline void kcov_task_init(struct task_struct *t) {}
static inline void kcov_task_exit(struct task_struct *t) {}

static inline void kcov_remote_start(u64 handle) {}
static inline void kcov_remote_stop(void) {}

#endif /* CONFIG_KCOV */
#endif /* _LINUX_KCOV_H */
10 changes: 10 additions & 0 deletions include/uapi/linux/kcov.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#define KCOV_INIT_TRACE _IOR('c', 1, unsigned long)
#define KCOV_ENABLE _IO('c', 100)
#define KCOV_DISABLE _IO('c', 101)
#define KCOV_REMOTE_ENABLE _IOW('c', 102, unsigned long)
#define KCOV_REMOTE_TRACK _IOW('c', 103, u64)
#define KCOV_REMOTE_DISABLE _IO('c', 104)

enum {
/*
Expand All @@ -32,4 +35,11 @@ enum {
#define KCOV_CMP_SIZE(n) ((n) << 1)
#define KCOV_CMP_MASK KCOV_CMP_SIZE(3)

#define KCOV_REMOTE_HANDLE_USB 0x4242424200000000ul

static inline u64 kcov_remote_handle_usb(int bus)
{
return KCOV_REMOTE_HANDLE_USB + (u64)bus;
}

#endif /* _LINUX_KCOV_IOCTLS_H */
Loading

0 comments on commit 7244f9e

Please sign in to comment.