From nobody Mon Feb 9 11:28:17 2026 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63C0534F485 for ; Fri, 19 Dec 2025 15:47:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766159250; cv=none; b=L3iF4RIrPwn1SGLC2mAYzgTKHeupqhIw+4+6STjuiAdicQHIyWjZ2x6qDoa4QSLu31zalG59PN51VI0Unn2QGFl5HiS0D6TI2RSFyD96lCvPe2ehta5+JbOTAmwuuV5kMhvPbS0cuPyxDnL/3GLekm2YOHqVai1pRDYKdpt7cnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766159250; c=relaxed/simple; bh=Xhk0xsW0tGqUud5kt1c33VabY4PrqeJpXHkHXkMftFw=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qDscnKnx0+cVkC9w+s/dSgWMBEUtYhRKHsnS/tWb1ULAUxK03EKskpQ/V/fRwsxeBKmKZz6PKz9DBJZRZuW65EvIyQpmba/zosYCIehTYQiEbFdNjqwHFx6C4ioXwuAwbXEtYOrkibceLDrYIdTUgXwggiEww5oZ6ZDoZxAtx1k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--elver.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Pl1r8SKj; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--elver.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Pl1r8SKj" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-430fc83f58dso1056063f8f.2 for ; Fri, 19 Dec 2025 07:47:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1766159247; x=1766764047; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=OO33/jJhJQVIdzyn/h7cV8sb9potmD4v/pwOWqkGaBs=; b=Pl1r8SKjxaw5QQmAttAJDQz7fH++bHf2iAWCOto/JuUcpq4Uo1PmlFDkV3LTgrrHoZ bDUX6mnr6eMlL/PsSx580C1p4lJFeCnX6PKALNVhD79is7yby0qwLmZG9MoquigGEk12 KLykN6pojkZ+vEJquapjwy+zWsqLpGoVb5Gy+iYnep+g5usnqfnI82b5v7o7hQLZQhXJ kgPX2XKfVrHpQAwySCg6UEE9PrPI9k+Ip8Um1SzonUyh6ctmgyAewWOgrlR61D6VLbQI 2AvopbyCrcdFmR8pRzFe/4fyqCTIziurlR80eWXVvdrE2QvtpGuf7ydnzgw3TZYwFdrA Hkww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766159247; x=1766764047; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OO33/jJhJQVIdzyn/h7cV8sb9potmD4v/pwOWqkGaBs=; b=PTRLRGIzok/ztVr7XstWmRImiHMnwVQmtMHFUB7iF0KTx6DdQQAtjwRLx8Zutv+op6 ybyWyb+FtchebKv7QirnO/u87AuctqmxU5B4Sp97ITUJd5cr43/he7ugMbm7FmuK/x6E sxoDJ+qLuMV0XAFh8ToJ/31zTlyWx6SWkxjgNpponhjn79hfBAuan+SHPw3o2ojqdkgc c7OHizCLAv+jmXYu8hOMo51lI09rV3ASZErVJIJXcAayqMhJU2Efe1F0oErBnXNfEXJ7 gwN2ZB194S6ZpRBritNZze0gTIXVeOT0vSA8O/UxvOKQTjk6GNiQOLrVk72Zo7URkfQn 9IYw== X-Forwarded-Encrypted: i=1; AJvYcCVURya2pLjYjS1vIrPRBpfWl4ND/+G+HXflI9dulylwMrwq0Y5f4MKgyExJnIqYnQ0ZRU27MgFQmhh8nEg=@vger.kernel.org X-Gm-Message-State: AOJu0YxpFG/1Kw2dJD4sohlLxBCCWh4ULfcfC1OkSRgbqJxf8B6+02tz Lz0KwEaTuxj/TX2fidDDJ9989M6kU28Xe8A/8WH6mRugOnHD1jXGCd/Sn18MhiK8l400ujmD+fb ryA== X-Google-Smtp-Source: AGHT+IFerDd1vd4X97dkJpWHrvPSjwQcqOjMG8Z0RXSvdbWhPjy9O9psZiuBXvn9GzAtKPBtfUrWDqrhqg== X-Received: from wrbbs1.prod.google.com ([2002:a05:6000:701:b0:42b:2aa2:e459]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:2303:b0:429:b9bc:e81a with SMTP id ffacd0b85a97d-4324e458883mr2916935f8f.0.1766159245502; Fri, 19 Dec 2025 07:47:25 -0800 (PST) Date: Fri, 19 Dec 2025 16:40:19 +0100 In-Reply-To: <20251219154418.3592607-1-elver@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251219154418.3592607-1-elver@google.com> X-Mailer: git-send-email 2.52.0.322.g1dd061c0dc-goog Message-ID: <20251219154418.3592607-31-elver@google.com> Subject: [PATCH v5 30/36] kcsan: Enable context analysis From: Marco Elver To: elver@google.com, Peter Zijlstra , Boqun Feng , Ingo Molnar , Will Deacon Cc: "David S. Miller" , Luc Van Oostenryck , Chris Li , "Paul E. McKenney" , Alexander Potapenko , Arnd Bergmann , Bart Van Assche , Christoph Hellwig , Dmitry Vyukov , Eric Dumazet , Frederic Weisbecker , Greg Kroah-Hartman , Herbert Xu , Ian Rogers , Jann Horn , Joel Fernandes , Johannes Berg , Jonathan Corbet , Josh Triplett , Justin Stitt , Kees Cook , Kentaro Takeda , Lukas Bulwahn , Mark Rutland , Mathieu Desnoyers , Miguel Ojeda , Nathan Chancellor , Neeraj Upadhyay , Nick Desaulniers , Steven Rostedt , Tetsuo Handa , Thomas Gleixner , Thomas Graf , Uladzislau Rezki , Waiman Long , kasan-dev@googlegroups.com, linux-crypto@vger.kernel.org, linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-security-module@vger.kernel.org, linux-sparse@vger.kernel.org, linux-wireless@vger.kernel.org, llvm@lists.linux.dev, rcu@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Enable context analysis for the KCSAN subsystem. Signed-off-by: Marco Elver --- v4: * Rename capability -> context analysis. v3: * New patch. --- kernel/kcsan/Makefile | 2 ++ kernel/kcsan/report.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/kernel/kcsan/Makefile b/kernel/kcsan/Makefile index a45f3dfc8d14..824f30c93252 100644 --- a/kernel/kcsan/Makefile +++ b/kernel/kcsan/Makefile @@ -1,4 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 +CONTEXT_ANALYSIS :=3D y + KCSAN_SANITIZE :=3D n KCOV_INSTRUMENT :=3D n UBSAN_SANITIZE :=3D n diff --git a/kernel/kcsan/report.c b/kernel/kcsan/report.c index e95ce7d7a76e..11a48b78f8d1 100644 --- a/kernel/kcsan/report.c +++ b/kernel/kcsan/report.c @@ -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 =3D &report_times[0]; unsigned long invalid_before; @@ -366,6 +367,7 @@ static int sym_strcmp(void *addr1, void *addr2) =20 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 nu= m_entries, unsigned long } =20 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 =3D 0; unsigned long stack_entries[NUM_STACK_ENTRIES] =3D { 0 }; @@ -496,6 +500,7 @@ static void print_report(enum kcsan_value_change value_= change, } =20 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, stru= ct other_info *other_info) =20 /* * 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); =20 @@ -603,6 +607,7 @@ static void prepare_report_producer(unsigned long *flag= s, static bool prepare_report_consumer(unsigned long *flags, const struct access_info *ai, struct other_info *other_info) + __cond_acquires(true, &report_lock) { =20 raw_spin_lock_irqsave(&report_lock, *flags); --=20 2.52.0.322.g1dd061c0dc-goog