From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.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 9E3BF362127 for ; Thu, 20 Nov 2025 15:13:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763651636; cv=none; b=IF2AwqMgvIhCi3x0Z5hxqR874wdDqEwOqS7C+Q3dsKNbAUsbyq7pHcV8newoNLSMU4xKb1HIoxfWgbJx9ll+7fIr8U1ve6ntf+LfqlijnHaRtOyKkglOKh8VE3TqGTG1vEWpGvx8teIojVasIiWtQ/7FX4AEDX+J0IEmvu91z/s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763651636; c=relaxed/simple; bh=3Y89mJHosRaENaLb5tk2xkCy/Hd7qH1R9BEoKf0fV0w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DNSpx0FmClr0BtrF5CeBdNurkADxuyI8dWVSMF0weuioHVSGADZ6FwLpAugqOm/gEAKV4HgH32NAWc/PMlgiik1OusQ9njE2BxjXNayEuvmwR0zmHQ+1wn1I2REOPMfXgzheCscXO4VQMkLoOoqgpADX1X71FouSbTmT8tiWl0g= 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=TvAPmE33; arc=none smtp.client-ip=209.85.218.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="TvAPmE33" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-b735eea0bddso90149366b.2 for ; Thu, 20 Nov 2025 07:13:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763651608; x=1764256408; 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=kN628sGqwThlti0A3ZPE5fg7KLj/Ov6I/vXTKugeedg=; b=TvAPmE33jm22PVBm0hD8dEQlO4JMJXndCs/Q4k0zmCtQqGcjEc9PdQ7e+sEFlhmejG iaTZ7d7sFgGbWDwsNFCE35vdj9rPdKP30GFS+OHa3ASmsya7nbDGvR1Y//qSOy9+d4Qs Etk+3JmiZszDDwl8P1j/nCw0FBXCmw29GSXc9mQsetQjFDc3/V36e1/kQ4Ih5TgpqY34 UmWMR51LuUWvnHxvt8cRbBbSGchrnp6sv2tlqo3hfte8ZKSRn0ANDoSiEv0PZSvc7X0k i+F1WdcqigX0rX9VY2ZRmAPSWEOj19sNLzVcWExiJRDoTYQMjt0UH83C6EZrQ9Op6IQg 5S5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763651608; x=1764256408; 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=kN628sGqwThlti0A3ZPE5fg7KLj/Ov6I/vXTKugeedg=; b=jW3K3tDjb5fb6GXkQv/TvJKE/atIG9AwsCbKaD3oNYTIAOvP8miKGVmbRoQBJKtmR4 +oJDKM8JjU8VOpB0lczNXwDO0CQAq/w+Oe+frwI2kzwPK2ppGHc40qR0ltIGidVT20cc MH2b5oxa5l/1sGFVr/SOr4Taa28nSXT0tgIpD3TudfQBBcNBmXSGyx/B+Vy7ty7JgKSO lHEP5kVF8q8pmE9NfueQHxnduqBZ6fRjiJbrSFJbJdeAxu+wf+0ZdOEV7dtn9xjTqU4S AjzsiNjDZqF41SFemuUfWjAJHvMeEWC7bAG5L/pWXr00ngyUM2VYAsFSKHgOAcYFlsoW XKqg== X-Forwarded-Encrypted: i=1; AJvYcCUPbqKdcE6po3+wiFP1Rw7sYPTRXmyIsBkbC1VgGszdaWvonTWL9OjYZ31XXv7t0e9ohiu7IhPFNH5Y6G8=@vger.kernel.org X-Gm-Message-State: AOJu0YyyrVFmWkgCEzm6GRY0qqHo0WdKvdnTWt7RD1cGGmEMW1JEsxr9 MKxAD3+6krRWovgwfYrSlxp0p05dzlSO74uCGQF9KrSth99K/OHL5Mj+n7Oj/nR1QO2x7AZMZZr scQ== X-Google-Smtp-Source: AGHT+IGPQ40L++aTOvA8JIRy1kdoYShFPO1YhmYJSO3OkON5NZw8EMACaSNJB6l90jTWpiXg4l2yJf3kSw== X-Received: from ejcwe11.prod.google.com ([2002:a17:907:d64b:b0:b72:63c8:2878]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a17:906:6a0d:b0:b76:23b0:7d6f with SMTP id a640c23a62f3a-b76554a515bmr362722666b.56.1763651608428; Thu, 20 Nov 2025 07:13:28 -0800 (PST) Date: Thu, 20 Nov 2025 16:09:50 +0100 In-Reply-To: <20251120151033.3840508-7-elver@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251120145835.3833031-2-elver@google.com> <20251120151033.3840508-7-elver@google.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog Message-ID: <20251120151033.3840508-26-elver@google.com> Subject: [PATCH v4 25/35] compiler: Let data_race() imply disabled 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-Type: text/plain; charset="UTF-8" Many patterns that involve data-racy accesses often deliberately ignore normal synchronization rules to avoid taking a lock. If we have a lock-guarded variable on which we do a lock-less data-racy access, rather than having to write context_unsafe(data_race(..)), simply make the data_race(..) macro imply context-unsafety. The data_race() macro already denotes the intent that something subtly unsafe is about to happen, so it should be clear enough as-is. Signed-off-by: Marco Elver --- v4: * Rename capability -> context analysis. v2: * New patch. --- include/linux/compiler.h | 2 ++ lib/test_context-analysis.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 5b45ea7dff3e..8ad1d4fd14e3 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -186,7 +186,9 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, #define data_race(expr) \ ({ \ __kcsan_disable_current(); \ + disable_context_analysis(); \ __auto_type __v = (expr); \ + enable_context_analysis(); \ __kcsan_enable_current(); \ __v; \ }) diff --git a/lib/test_context-analysis.c b/lib/test_context-analysis.c index 522769c9586d..4612025a1065 100644 --- a/lib/test_context-analysis.c +++ b/lib/test_context-analysis.c @@ -92,6 +92,8 @@ static void __used test_raw_spinlock_trylock_extra(struct test_raw_spinlock_data { unsigned long flags; + data_race(d->counter++); /* no warning */ + if (raw_spin_trylock_irq(&d->lock)) { d->counter++; raw_spin_unlock_irq(&d->lock); -- 2.52.0.rc1.455.g30608eb744-goog