Skip to content

Commit

Permalink
kcov, usb: hide in_serving_softirq checks in __usb_hcd_giveback_urb
Browse files Browse the repository at this point in the history
Done opencode in_serving_softirq() checks in in_serving_softirq() to avoid
cluttering the code, hide them in kcov helpers instead.

Fixes: aee9ddb ("kcov, usb: only collect coverage from __usb_hcd_giveback_urb in softirq")
Signed-off-by: Andrey Konovalov <[email protected]>
Link: https://lore.kernel.org/r/aeb430c5bb90b0ccdf1ec302c70831c1a47b9c45.1609876340.git.andreyknvl@google.com
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
xairy authored and gregkh committed Jan 7, 2021
1 parent 10a0540 commit e89eed0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 3 additions & 5 deletions drivers/usb/core/hcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1649,14 +1649,12 @@ static void __usb_hcd_giveback_urb(struct urb *urb)
urb->status = status;
/*
* This function can be called in task context inside another remote
* coverage collection section, but KCOV doesn't support that kind of
* coverage collection section, but kcov doesn't support that kind of
* recursion yet. Only collect coverage in softirq context for now.
*/
if (in_serving_softirq())
kcov_remote_start_usb((u64)urb->dev->bus->busnum);
kcov_remote_start_usb_softirq((u64)urb->dev->bus->busnum);
urb->complete(urb);
if (in_serving_softirq())
kcov_remote_stop();
kcov_remote_stop_softirq();

usb_anchor_resume_wakeups(anchor);
atomic_dec(&urb->use_count);
Expand Down
21 changes: 21 additions & 0 deletions include/linux/kcov.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ static inline void kcov_remote_start_usb(u64 id)
kcov_remote_start(kcov_remote_handle(KCOV_SUBSYSTEM_USB, id));
}

/*
* The softirq flavor of kcov_remote_*() functions is introduced as a temporary
* work around for kcov's lack of nested remote coverage sections support in
* task context. Adding suport for nested sections is tracked in:
* https://bugzilla.kernel.org/show_bug.cgi?id=210337
*/

static inline void kcov_remote_start_usb_softirq(u64 id)
{
if (in_serving_softirq())
kcov_remote_start_usb(id);
}

static inline void kcov_remote_stop_softirq(void)
{
if (in_serving_softirq())
kcov_remote_stop();
}

#else

static inline void kcov_task_init(struct task_struct *t) {}
Expand All @@ -66,6 +85,8 @@ static inline u64 kcov_common_handle(void)
}
static inline void kcov_remote_start_common(u64 id) {}
static inline void kcov_remote_start_usb(u64 id) {}
static inline void kcov_remote_start_usb_softirq(u64 id) {}
static inline void kcov_remote_stop_softirq(void) {}

#endif /* CONFIG_KCOV */
#endif /* _LINUX_KCOV_H */

0 comments on commit e89eed0

Please sign in to comment.