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 D1C35364E9F 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=1763651635; cv=none; b=PTu079zU55fsJ+u/kObyUDukiwb0YB73/1XW8EFbTqJC89C+3Pp9Y5lPE8RCKJkP01T9HYV/bMAs1iSpRg0Hk3R2FSOuT4fcdc+uj740VdYKO+dcENtL8DM3Xa1fSGHZKDc5q1KHQ9+c4ztnB3T3QlNNYfJpEIPKKOICnoRVMus= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763651635; c=relaxed/simple; bh=3Y89mJHosRaENaLb5tk2xkCy/Hd7qH1R9BEoKf0fV0w=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=b2lHPrG6ddDfvKyqiN9kyH0NsSiLnBXgCmE+CBtrDFptJlxnUAU71q9k2IPcK8PL5t5pxmcXjIY8+2rvoTuNDLZqVuZ/gK7oErtcdFBW+HoFNgsXis3OJjur1yh5RJydxkVzB/CVJZ+76za1/GqIxm0ZOmssLaWmGnkbo9d08MQ= 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=ekSHrE5z; 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="ekSHrE5z" Received: by mail-ej1-f74.google.com with SMTP id a640c23a62f3a-b736eca894fso79415666b.1 for ; Thu, 20 Nov 2025 07:13:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763651609; x=1764256409; 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=ekSHrE5zybqJTGQ6PputajlArki3ecYjV6YbSd28O7uoxhpgNG71RAqFQStJYMZikS jgHJ1a3WUcu8xi6qNBis5i9CC5W8KJwF4TFLQqYNQy/VO1arXQoE1Rwq6Z1XU2aNn9J5 Tx8IH9fEqiV9nPZPERqKks6fzr2ysC5FjxS7ugt+7ikp9RiK20XzPodS7N8Q2ZqQsCT+ OzAluTJmnfngm0ZQN1+76+zPg/cvrxLuFwFk8ubI7m28RrFPdaL5dU1N1KEBA28UiFMn ITO1qqNUxTJl7VTHWL+Nt81FmuMMFVGU4EdPVZ8VMLn5xQs6l7mAr9JpTwtPsguVFQ0A faxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763651609; x=1764256409; 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=oezxFMl0JLCWve3STNtJPGXEerNVfntSrTD7DFJcHMjGmN8IEuEwJR5w0gaaBbVVXg zBRMSyARo8QwPp7/AusN9simc6F9Lrnp9l5JgQ5KKcPxQ0q8h429RApggWZiLOXNYqE+ SwRhwfONGO7m8rggK5DzMJArkzJ+WCti9+/gMg6XVj43EW/LS/bXEVew1SkW7XyALUjg mIHd08bmVeWMxQ7v84KwejyiYKDepdFaR89Z2STe5dZTkiNyS33fKeAjEh8p/lM/R1RY B1ryr4mDdWgenNhb37agt/4cKG5W38L8AXoSbGeWc0GeqZ3SW4V6hmgskgHPTiAeycij +aAA== X-Forwarded-Encrypted: i=1; AJvYcCURwAy9vxjaoLeL9H5ykzivXPdczonKM0xIuWNZzVan9deTG9VfY7yhgLkRje3Ouk8OmApJVUikbLbm0GQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxwoG+BXwhP/ZWNLD3km8fBqjUq3SM81mC5luEHGmfzN7awSf76 1dlrEbt86Ou6mqqBRTP2pfPya67M+yfVYffawx7pbnBYezDmr862z6PbkQN+dqWkGGIeaO1zKSY gZw== 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-crypto@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