Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d26817a9 authored by Andrey Konovalov's avatar Andrey Konovalov Committed by Alistair Delva
Browse files

UPSTREAM: vhost, kcov: collect coverage from vhost_worker

(Upstream commit 8f6a7f96dc29cefe16ab60f06f9c3a43510b96fd.)

Add kcov_remote_start()/kcov_remote_stop() annotations to the
vhost_worker() function, which is responsible for processing vhost
works.

Since vhost_worker() threads are spawned per vhost device instance the
common kcov handle is used for kcov_remote_start()/stop() annotations
(see Documentation/dev-tools/kcov.rst for details).  As the result kcov
can now be used to collect coverage from vhost worker threads.

Link: http://lkml.kernel.org/r/e49d5d154e5da6c9ada521d2b7ce10a49ce9f98b.1572366574.git.andreyknvl@google.com


Signed-off-by: default avatarAndrey Konovalov <andreyknvl@google.com>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: Alexander Potapenko <glider@google.com>
Cc: Anders Roxell <anders.roxell@linaro.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: David Windsor <dwindsor@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Elena Reshetova <elena.reshetova@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Marco Elver <elver@google.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarAndrey Konovalov <andreyknvl@google.com>
Bug: 147413187
Change-Id: Ie99a67ede00a839a28472877e5c3263db69d1c58
parent ca852080
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -30,6 +30,7 @@
#include <linux/sched/signal.h>
#include <linux/sched/signal.h>
#include <linux/interval_tree_generic.h>
#include <linux/interval_tree_generic.h>
#include <linux/nospec.h>
#include <linux/nospec.h>
#include <linux/kcov.h>


#include "vhost.h"
#include "vhost.h"


@@ -357,7 +358,9 @@ static int vhost_worker(void *data)
		llist_for_each_entry_safe(work, work_next, node, node) {
		llist_for_each_entry_safe(work, work_next, node, node) {
			clear_bit(VHOST_WORK_QUEUED, &work->flags);
			clear_bit(VHOST_WORK_QUEUED, &work->flags);
			__set_current_state(TASK_RUNNING);
			__set_current_state(TASK_RUNNING);
			kcov_remote_start_common(dev->kcov_handle);
			work->fn(work);
			work->fn(work);
			kcov_remote_stop();
			if (need_resched())
			if (need_resched())
				schedule();
				schedule();
		}
		}
@@ -546,6 +549,7 @@ long vhost_dev_set_owner(struct vhost_dev *dev)


	/* No owner, become one */
	/* No owner, become one */
	dev->mm = get_task_mm(current);
	dev->mm = get_task_mm(current);
	dev->kcov_handle = kcov_common_handle();
	worker = kthread_create(vhost_worker, dev, "vhost-%d", current->pid);
	worker = kthread_create(vhost_worker, dev, "vhost-%d", current->pid);
	if (IS_ERR(worker)) {
	if (IS_ERR(worker)) {
		err = PTR_ERR(worker);
		err = PTR_ERR(worker);
@@ -571,6 +575,7 @@ long vhost_dev_set_owner(struct vhost_dev *dev)
	if (dev->mm)
	if (dev->mm)
		mmput(dev->mm);
		mmput(dev->mm);
	dev->mm = NULL;
	dev->mm = NULL;
	dev->kcov_handle = 0;
err_mm:
err_mm:
	return err;
	return err;
}
}
@@ -682,6 +687,7 @@ void vhost_dev_cleanup(struct vhost_dev *dev)
	if (dev->worker) {
	if (dev->worker) {
		kthread_stop(dev->worker);
		kthread_stop(dev->worker);
		dev->worker = NULL;
		dev->worker = NULL;
		dev->kcov_handle = 0;
	}
	}
	if (dev->mm)
	if (dev->mm)
		mmput(dev->mm);
		mmput(dev->mm);
+1 −0
Original line number Original line Diff line number Diff line
@@ -173,6 +173,7 @@ struct vhost_dev {
	int iov_limit;
	int iov_limit;
	int weight;
	int weight;
	int byte_weight;
	int byte_weight;
	u64 kcov_handle;
};
};


bool vhost_exceeds_weight(struct vhost_virtqueue *vq, int pkts, int total_len);
bool vhost_exceeds_weight(struct vhost_virtqueue *vq, int pkts, int total_len);