Commit 0eaa911f authored by Marco Elver's avatar Marco Elver Committed by Peter Zijlstra
Browse files

kcsan: Enable context analysis



Enable context analysis for the KCSAN subsystem.

Signed-off-by: default avatarMarco Elver <elver@google.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://patch.msgid.link/20251219154418.3592607-31-elver@google.com
parent 6556fde2
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0
CONTEXT_ANALYSIS := y

KCSAN_SANITIZE := n
KCOV_INSTRUMENT := n
UBSAN_SANITIZE := n
+8 −3
Original line number Diff line number Diff line
@@ -116,6 +116,7 @@ static DEFINE_RAW_SPINLOCK(report_lock);
 * been reported since (now - KCSAN_REPORT_ONCE_IN_MS).
 */
static bool rate_limit_report(unsigned long frame1, unsigned long frame2)
	__must_hold(&report_lock)
{
	struct report_time *use_entry = &report_times[0];
	unsigned long invalid_before;
@@ -366,6 +367,7 @@ static int sym_strcmp(void *addr1, void *addr2)

static void
print_stack_trace(unsigned long stack_entries[], int num_entries, unsigned long reordered_to)
	__must_hold(&report_lock)
{
	stack_trace_print(stack_entries, num_entries, 0);
	if (reordered_to)
@@ -373,6 +375,7 @@ print_stack_trace(unsigned long stack_entries[], int num_entries, unsigned long
}

static void print_verbose_info(struct task_struct *task)
	__must_hold(&report_lock)
{
	if (!task)
		return;
@@ -389,6 +392,7 @@ static void print_report(enum kcsan_value_change value_change,
			 const struct access_info *ai,
			 struct other_info *other_info,
			 u64 old, u64 new, u64 mask)
	__must_hold(&report_lock)
{
	unsigned long reordered_to = 0;
	unsigned long stack_entries[NUM_STACK_ENTRIES] = { 0 };
@@ -496,6 +500,7 @@ static void print_report(enum kcsan_value_change value_change,
}

static void release_report(unsigned long *flags, struct other_info *other_info)
	__releases(&report_lock)
{
	/*
	 * Use size to denote valid/invalid, since KCSAN entirely ignores
@@ -507,13 +512,11 @@ static void release_report(unsigned long *flags, struct other_info *other_info)

/*
 * Sets @other_info->task and awaits consumption of @other_info.
 *
 * Precondition: report_lock is held.
 * Postcondition: report_lock is held.
 */
static void set_other_info_task_blocking(unsigned long *flags,
					 const struct access_info *ai,
					 struct other_info *other_info)
	__must_hold(&report_lock)
{
	/*
	 * We may be instrumenting a code-path where current->state is already
@@ -572,6 +575,7 @@ static void set_other_info_task_blocking(unsigned long *flags,
static void prepare_report_producer(unsigned long *flags,
				    const struct access_info *ai,
				    struct other_info *other_info)
	__must_not_hold(&report_lock)
{
	raw_spin_lock_irqsave(&report_lock, *flags);

@@ -603,6 +607,7 @@ static void prepare_report_producer(unsigned long *flags,
static bool prepare_report_consumer(unsigned long *flags,
				    const struct access_info *ai,
				    struct other_info *other_info)
	__cond_acquires(true, &report_lock)
{

	raw_spin_lock_irqsave(&report_lock, *flags);