Skip to content

Commit 5fe7042

Browse files
xairytorvalds
authored andcommitted
kcov: use t->kcov_mode as enabled indicator
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]>
1 parent eeb91f9 commit 5fe7042

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

kernel/kcov.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -746,26 +746,33 @@ static const struct file_operations kcov_fops = {
746746
* In turns kcov_remote_stop() clears those pointers from task_struct to stop
747747
* collecting coverage and copies all collected coverage into the kcov area.
748748
*/
749+
750+
static inline bool kcov_mode_enabled(unsigned int mode)
751+
{
752+
return (mode & ~KCOV_IN_CTXSW) != KCOV_MODE_DISABLED;
753+
}
754+
749755
void kcov_remote_start(u64 handle)
750756
{
757+
struct task_struct *t = current;
751758
struct kcov_remote *remote;
752759
struct kcov *kcov;
760+
unsigned int mode;
753761
void *area;
754-
struct task_struct *t;
755762
unsigned int size;
756-
enum kcov_mode mode;
757763
int sequence;
758764

759765
if (WARN_ON(!kcov_check_handle(handle, true, true, true)))
760766
return;
761767
if (WARN_ON(!in_task()))
762768
return;
763-
t = current;
769+
764770
/*
765771
* Check that kcov_remote_start is not called twice
766772
* nor called by user tasks (with enabled kcov).
767773
*/
768-
if (WARN_ON(t->kcov))
774+
mode = READ_ONCE(t->kcov_mode);
775+
if (WARN_ON(kcov_mode_enabled(mode)))
769776
return;
770777

771778
kcov_debug("handle = %llx\n", handle);
@@ -863,13 +870,20 @@ static void kcov_move_area(enum kcov_mode mode, void *dst_area,
863870
void kcov_remote_stop(void)
864871
{
865872
struct task_struct *t = current;
866-
struct kcov *kcov = t->kcov;
867-
void *area = t->kcov_area;
868-
unsigned int size = t->kcov_size;
869-
int sequence = t->kcov_sequence;
873+
struct kcov *kcov;
874+
unsigned int mode;
875+
void *area;
876+
unsigned int size;
877+
int sequence;
870878

871-
if (!kcov)
879+
mode = READ_ONCE(t->kcov_mode);
880+
barrier();
881+
if (!kcov_mode_enabled(mode))
872882
return;
883+
kcov = t->kcov;
884+
area = t->kcov_area;
885+
size = t->kcov_size;
886+
sequence = t->kcov_sequence;
873887

874888
kcov_stop(t);
875889

0 commit comments

Comments
 (0)