mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-16 04:27:36 +07:00
0ed557aa81
During a context switch, we first switch_mm() to the next task's mm, then switch_to() that new task. This means that vmalloc'd regions which had previously been faulted in can transiently disappear in the context of the prev task. Functions instrumented by KCOV may try to access a vmalloc'd kcov_area during this window, and as the fault handling code is instrumented, this results in a recursive fault. We must avoid accessing any kcov_area during this window. We can do so with a new flag in kcov_mode, set prior to switching the mm, and cleared once the new task is live. Since task_struct::kcov_mode isn't always a specific enum kcov_mode value, this is made an unsigned int. The manipulation is hidden behind kcov_{prepare,finish}_switch() helpers, which are empty for !CONFIG_KCOV kernels. The code uses macros because I can't use static inline functions without a circular include dependency between <linux/sched.h> and <linux/kcov.h>, since the definition of task_struct uses things defined in <linux/kcov.h> Link: http://lkml.kernel.org/r/20180504135535.53744-4-mark.rutland@arm.com Signed-off-by: Mark Rutland <mark.rutland@arm.com> Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
49 lines
1.1 KiB
C
49 lines
1.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_KCOV_H
|
|
#define _LINUX_KCOV_H
|
|
|
|
#include <uapi/linux/kcov.h>
|
|
|
|
struct task_struct;
|
|
|
|
#ifdef CONFIG_KCOV
|
|
|
|
enum kcov_mode {
|
|
/* Coverage collection is not enabled yet. */
|
|
KCOV_MODE_DISABLED = 0,
|
|
/* KCOV was initialized, but tracing mode hasn't been chosen yet. */
|
|
KCOV_MODE_INIT = 1,
|
|
/*
|
|
* Tracing coverage collection mode.
|
|
* Covered PCs are collected in a per-task buffer.
|
|
*/
|
|
KCOV_MODE_TRACE_PC = 2,
|
|
/* Collecting comparison operands mode. */
|
|
KCOV_MODE_TRACE_CMP = 3,
|
|
};
|
|
|
|
#define KCOV_IN_CTXSW (1 << 30)
|
|
|
|
void kcov_task_init(struct task_struct *t);
|
|
void kcov_task_exit(struct task_struct *t);
|
|
|
|
#define kcov_prepare_switch(t) \
|
|
do { \
|
|
(t)->kcov_mode |= KCOV_IN_CTXSW; \
|
|
} while (0)
|
|
|
|
#define kcov_finish_switch(t) \
|
|
do { \
|
|
(t)->kcov_mode &= ~KCOV_IN_CTXSW; \
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
static inline void kcov_task_init(struct task_struct *t) {}
|
|
static inline void kcov_task_exit(struct task_struct *t) {}
|
|
static inline void kcov_prepare_switch(struct task_struct *t) {}
|
|
static inline void kcov_finish_switch(struct task_struct *t) {}
|
|
|
|
#endif /* CONFIG_KCOV */
|
|
#endif /* _LINUX_KCOV_H */
|