Skip to content

Commit

Permalink
kcov: use t->kcov_mode as enabled indicator
Browse files Browse the repository at this point in the history
Currently kcov_remote_start() and kcov_remote_stop() check t->kcov to find
out whether the coverage is already being collected by the current task.
Use t->kcov_mode for that instead.  This doesn't change the overall
behavior in any way, but serves as a preparation for the following softirq
coverage collection support patch.

Signed-off-by: Andrey Konovalov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Reviewed-by: Dmitry Vyukov <[email protected]>
Cc: Alan Stern <[email protected]>
Cc: Alexander Potapenko <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Marco Elver <[email protected]>
Cc: Andrey Konovalov <[email protected]>
Link: http://lkml.kernel.org/r/f70377945d1d8e6e4916cbce871a12303d6186b4.1585233617.git.andreyknvl@google.com
Link: http://lkml.kernel.org/r/ee1a1dec43059da5d7664c85c1addc89c4cd58de.1584655448.git.andreyknvl@google.com
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
xairy authored and torvalds committed Jun 5, 2020
1 parent eeb91f9 commit 5fe7042
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions kernel/kcov.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,26 +746,33 @@ static const struct file_operations kcov_fops = {
* In turns kcov_remote_stop() clears those pointers from task_struct to stop
* collecting coverage and copies all collected coverage into the kcov area.
*/

static inline bool kcov_mode_enabled(unsigned int mode)
{
return (mode & ~KCOV_IN_CTXSW) != KCOV_MODE_DISABLED;
}

void kcov_remote_start(u64 handle)
{
struct task_struct *t = current;
struct kcov_remote *remote;
struct kcov *kcov;
unsigned int mode;
void *area;
struct task_struct *t;
unsigned int size;
enum kcov_mode mode;
int sequence;

if (WARN_ON(!kcov_check_handle(handle, true, true, true)))
return;
if (WARN_ON(!in_task()))
return;
t = current;

/*
* Check that kcov_remote_start is not called twice
* nor called by user tasks (with enabled kcov).
*/
if (WARN_ON(t->kcov))
mode = READ_ONCE(t->kcov_mode);
if (WARN_ON(kcov_mode_enabled(mode)))
return;

kcov_debug("handle = %llx\n", handle);
Expand Down Expand Up @@ -863,13 +870,20 @@ static void kcov_move_area(enum kcov_mode mode, void *dst_area,
void kcov_remote_stop(void)
{
struct task_struct *t = current;
struct kcov *kcov = t->kcov;
void *area = t->kcov_area;
unsigned int size = t->kcov_size;
int sequence = t->kcov_sequence;
struct kcov *kcov;
unsigned int mode;
void *area;
unsigned int size;
int sequence;

if (!kcov)
mode = READ_ONCE(t->kcov_mode);
barrier();
if (!kcov_mode_enabled(mode))
return;
kcov = t->kcov;
area = t->kcov_area;
size = t->kcov_size;
sequence = t->kcov_sequence;

kcov_stop(t);

Expand Down

0 comments on commit 5fe7042

Please sign in to comment.