From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f201.google.com (mail-lj1-f201.google.com [209.85.208.201]) (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 CD3F02FC01B for ; Thu, 20 Nov 2025 15:41:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763653270; cv=none; b=pdDIbGeoa5b2+zNnBRu7OixmxjSCKXVfRUgCl++VJ+c9mG5noRxKkVNAoAXLT0iS4lu7lh4syd7HNueeqyhzz+74Nu3HXVay5l1GIH/37PQfqS08idJOMmS1RFefQZf7Qc2DTN3v1Vb72wgNJj4+Cg5DG/cOxb0QiHW5Ahsp7Oc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763653270; c=relaxed/simple; bh=EwfXd6yRg4bFKtUUrXe0W+ENNOKQmqy6Ot7CBhxbXoQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=u30SOIVCYehpfz4mo1uHxpaLQ6RqR8Sj6Wn+f7gIvBWmCuNDTA8rcGA7N8OAxhJe3bCWjwRb6iG59ZSazvx7DbU1OmRl/I9EoCrczUyPyme7WGsyrGSvDPC2jee2hNIfuThcPn0Fo11gXc3SLaRf+BiU8jSEA0yJF40j7N+3nS0= 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=n2yO5/6d; arc=none smtp.client-ip=209.85.208.201 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="n2yO5/6d" Received: by mail-lj1-f201.google.com with SMTP id 38308e7fff4ca-37a46c5d929so6538851fa.0 for ; Thu, 20 Nov 2025 07:41:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763653263; x=1764258063; 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=sW5aRQBUT1YS/p7X2M8vu94/jdaGEDQWZc189ONsN2k=; b=n2yO5/6dPHQHZhOXi66xAJnAVC61gJ/vpGlWnEDQnEgedgraieqhK8ONnYWlgKEAmS dKi3OCvH0tUhvJ+qeQtrsqX5DP/mQtba8ocIvqZGgY9r5PdvzfBJc036ys4Ie3ZolYjK 0nrZNMobzPam5Fd9yT7UJwqnGris4gUPJzLSgcGOofSN0NHRKCZqZj2x3UzPZc+PTfxY vDLzemxLwiUH8utIPEn25ejnQdFzLBeF4CFttCRKhfCTwL2Ew9yYzu6eAj7eQE6eOYhE uuaewF3iF3vinTX0AagyNEJx6/eBAU+E3W0rNor96jQgBobX880fnq4vDUfFtfpYQI/l fqQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763653263; x=1764258063; 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=sW5aRQBUT1YS/p7X2M8vu94/jdaGEDQWZc189ONsN2k=; b=WEbDaGRLzIhrjjrp7Ym9fgDKal+iyNU6mf7QLMYR/yNHTUNH1PEpOf/3SY28WhZ+Oy 9MjRvsytoXMPPnLf0a2yPve2iZTdrqrkfNtUj+Yurnf+RYELkJBIXPne4zBaFpm3hY6q Y7rl5teIhIMYCmQ8ipuYD0tuC45C55418w1NQrOaJ2+fs8O5MqU1QIcWIrInAIbxxg9u BkyUTZjvkhcs3MSGw+qfHEB/wC7JGs/yh9PtmoI7xj2W8Jv+EefEh4p4N+AOxlyDkUd5 F8EtCgnFSN9oyQtSsA4cdPnyQF9P59l094IN+/jhOcTNgZI2Q8qeUFGhOzG1Q1BwapYx armg== X-Forwarded-Encrypted: i=1; AJvYcCV40dPkTxjI8hhkpuBCWttdvwmJCz8UoNPXnjuaqEC6OWK8S8c8NAV9CmCywNixNjX3kmMa3bvGrYKqu3I=@vger.kernel.org X-Gm-Message-State: AOJu0YwSOhN8w684ChOtkG4YCCsvbLZ0QOswtWHJILQRQDNPoGEFGl3Q x/XZyp1jVukJkn5+ZtW/NflkWgi0bndqK4g43QXPvgo1vlW2yYzFTPa6kk2YvkCgJLX7q7K4f5Z 6Yg== X-Google-Smtp-Source: AGHT+IER1f7gc9WQ7LnpbrPIA/y0BLZGbO4bUsdn+Ne1pOxE592x9Yu2PvTpMRh0Noc8+8JrQHGkxnvByA== X-Received: from wrsz10.prod.google.com ([2002:a5d:4c8a:0:b0:42b:3a01:7808]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:adf:f290:0:b0:42b:3e0a:64b7 with SMTP id ffacd0b85a97d-42cb9a560c2mr2413997f8f.53.1763651508025; Thu, 20 Nov 2025 07:11:48 -0800 (PST) Date: Thu, 20 Nov 2025 16:09:32 +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-8-elver@google.com> Subject: [PATCH v4 07/35] lockdep: Annotate lockdep assertions for 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" Clang's context analysis can be made aware of functions that assert that locks are held. Presence of these annotations causes the analysis to assume the context guard is held after calls to the annotated function, and avoid false positives with complex control-flow; for example, where not all control-flow paths in a function require a held lock, and therefore marking the function with __must_hold(..) is inappropriate. Signed-off-by: Marco Elver --- v4: * Rename capability -> context analysis. v3: * __assert -> __assume rename --- include/linux/lockdep.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 67964dc4db95..2c99a6823161 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -282,16 +282,16 @@ extern void lock_unpin_lock(struct lockdep_map *lock, struct pin_cookie); do { WARN_ON_ONCE(debug_locks && !(cond)); } while (0) #define lockdep_assert_held(l) \ - lockdep_assert(lockdep_is_held(l) != LOCK_STATE_NOT_HELD) + do { lockdep_assert(lockdep_is_held(l) != LOCK_STATE_NOT_HELD); __assume_ctx_guard(l); } while (0) #define lockdep_assert_not_held(l) \ lockdep_assert(lockdep_is_held(l) != LOCK_STATE_HELD) #define lockdep_assert_held_write(l) \ - lockdep_assert(lockdep_is_held_type(l, 0)) + do { lockdep_assert(lockdep_is_held_type(l, 0)); __assume_ctx_guard(l); } while (0) #define lockdep_assert_held_read(l) \ - lockdep_assert(lockdep_is_held_type(l, 1)) + do { lockdep_assert(lockdep_is_held_type(l, 1)); __assume_shared_ctx_guard(l); } while (0) #define lockdep_assert_held_once(l) \ lockdep_assert_once(lockdep_is_held(l) != LOCK_STATE_NOT_HELD) @@ -389,10 +389,10 @@ extern int lockdep_is_held(const void *); #define lockdep_assert(c) do { } while (0) #define lockdep_assert_once(c) do { } while (0) -#define lockdep_assert_held(l) do { (void)(l); } while (0) +#define lockdep_assert_held(l) __assume_ctx_guard(l) #define lockdep_assert_not_held(l) do { (void)(l); } while (0) -#define lockdep_assert_held_write(l) do { (void)(l); } while (0) -#define lockdep_assert_held_read(l) do { (void)(l); } while (0) +#define lockdep_assert_held_write(l) __assume_ctx_guard(l) +#define lockdep_assert_held_read(l) __assume_shared_ctx_guard(l) #define lockdep_assert_held_once(l) do { (void)(l); } while (0) #define lockdep_assert_none_held_once() do { } while (0) -- 2.52.0.rc1.455.g30608eb744-goog