diff mbox series

[v3,2/3] usb, kcov: collect coverage from hub_event

Message ID de4fe1c219db2d002d905dc1736e2a3bfa1db997.1572366574.git.andreyknvl@google.com
State Awaiting Upstream
Delegated to: David Miller
Headers show
Series kcov: collect coverage from usb and vhost | expand

Commit Message

Andrey Konovalov Oct. 29, 2019, 4:32 p.m. UTC
This patch adds kcov_remote_start()/kcov_remote_stop() annotations to the
hub_event() function, which is responsible for processing events on USB
buses, in particular events that happen during USB device enumeration.
Since hub_event() is run in a global background kernel thread (see
Documentation/dev-tools/kcov.rst for details), each USB bus gets a unique
global handle from the USB subsystem kcov handle range. As the result kcov
can now be used to collect coverage from events that happen on a
particular USB bus.

Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 drivers/usb/core/hub.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Greg Kroah-Hartman Nov. 7, 2019, 10:19 a.m. UTC | #1
On Tue, Oct 29, 2019 at 05:32:28PM +0100, Andrey Konovalov wrote:
> This patch adds kcov_remote_start()/kcov_remote_stop() annotations to the
> hub_event() function, which is responsible for processing events on USB
> buses, in particular events that happen during USB device enumeration.
> Since hub_event() is run in a global background kernel thread (see
> Documentation/dev-tools/kcov.rst for details), each USB bus gets a unique
> global handle from the USB subsystem kcov handle range. As the result kcov
> can now be used to collect coverage from events that happen on a
> particular USB bus.
> 
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
> ---
>  drivers/usb/core/hub.c | 5 +++++
>  1 file changed, 5 insertions(+)

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
diff mbox series

Patch

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 236313f41f4a..823dd675f6db 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -29,6 +29,7 @@ 
 #include <linux/random.h>
 #include <linux/pm_qos.h>
 #include <linux/kobject.h>
+#include <linux/kcov.h>
 
 #include <linux/uaccess.h>
 #include <asm/byteorder.h>
@@ -5374,6 +5375,8 @@  static void hub_event(struct work_struct *work)
 	hub_dev = hub->intfdev;
 	intf = to_usb_interface(hub_dev);
 
+	kcov_remote_start_usb((u64)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... */
@@ -5480,6 +5483,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[] = {