From nobody Thu Oct 2 10:55:18 2025 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 55FE930DD33 for ; Thu, 18 Sep 2025 14:05:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758204350; cv=none; b=R/CQ1tCgQ6P/whB2UNvLQy0Ue0WL8qwHASz1YsQkLw2gpwfWTj9xVqtDOQpCET5+LtrHRFLeRbtRT++wZnf0qPWyEXeeV6kfW7tGKc1E6M29dv2L9OV9ngrGYCwLsugCQzbIrvnPGuwjeN5OrndsXPDAttFu3lEK9HbK1gVR1cQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758204350; c=relaxed/simple; bh=GUCT3hVcQ4xcGERZZKRbfZAspfWfY7UoHqQT+IPHxCk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=R418AskOIiFXzMYf8RMxPkz+KOKIr7R1og09O9b+OeLUtUwKawuO0KxTCvwO4szrXKQwehBOVde56ndgBePTtG6QUCafsx6Msn0Tgnf7fih84pJPjW1/O2+Djxh5bZceiF1dtA8CnB7lMVBjjjpIn9iADpiBUrNEJbGC1HDbJLI= 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=kJ4qRZvA; arc=none smtp.client-ip=209.85.128.73 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="kJ4qRZvA" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-45b986a7b8aso5463985e9.0 for ; Thu, 18 Sep 2025 07:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1758204346; x=1758809146; 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=Y8a5df3Pjl9f6q04E+YVKjYiENmaUJ17VWF4NqYxrig=; b=kJ4qRZvAK20Ir6c19b7vpwwjgqpbl4AI8logzpssiKulQkG/7hU45YF9sjzqJKyFP/ 7JSpxY/fdB2Chd1pJbP5r0QPG4PgqiRA8w9MmRYNe6s0r5Eto36yZY4JMGmBXuwmjs3k TYkn7D1aC7+euyuJ9IbOywL8B3WLRso5J4asxKE5zs8oRgjsdoflpIzOaNg9Occ/SmGe scu9f+xExKujLW5m5V5TlyBHJF7DSt25PRd9yMB17ETFrSbjVeFn8s6Ck3vFWNw0ddVr nYAImgqyA+v8BJ0xIzXpMQi9l4geEydyt/OV4oWvuR0hTlGWlzNpB3qYukxiiHWSZSvl FJsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758204346; x=1758809146; 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=Y8a5df3Pjl9f6q04E+YVKjYiENmaUJ17VWF4NqYxrig=; b=r7cPMxsV1kfPgJ4zR6+STj0PLV3z9WvJKdwAmgoahjMZpAm+muuMRHUgyUmqaz7yzM QDNuX3G87gztNWHU3yywZhU96AxUfb19dLF9z5GAqEmGyVTYZBBbH+TfKuM///yDmRBc wcuZntN4hhZLqRrspOmjwblpDPD17kQL0D96XRE6RE1tOo0386op19hmnkbW3ta6B15R meloANbyZ1FD21dL/1kUh+pmbRn8KuqOXG/qqByqgMeEdmsQFagn+3q4/Jk5ydn4Rjwg eZqv84lP3VVn4zvKzWa5vw65s5jj1fD5jLhXhqAUdqgWwHcfWX1d0+05yo5GF7I6TdrV dzEw== X-Forwarded-Encrypted: i=1; AJvYcCWKZBY7Fr6XfALSQXJHuxFQ85MMOtxdFomtrPANLc9hBZkd7nrL7EaCSVdqTU+l3jFvr6KNBWowZaM4bJk=@vger.kernel.org X-Gm-Message-State: AOJu0YwlxnjyAAPUJb6b75TIluyvnghJcAP/966QVToFTtAm/vh3O69g 2hIlFAOAVw1ouuSAcZzjhpA2cfhJalqPtVjyqQLtCQ4k3+wi9Sv0X/2TyCdUD9gUFy17uiexJp3 9hA== X-Google-Smtp-Source: AGHT+IFEiq4FEWWIzjiYKjnsdpYfxFd6yNadJ6YvqxXYjoCzs/skSdmVV05LRZuP59mbBWsmDTBBrQoRCA== X-Received: from wmbdv20.prod.google.com ([2002:a05:600c:6214:b0:458:bdde:5c9b]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:314e:b0:45d:f7e4:8969 with SMTP id 5b1f17b1804b1-46202bf788fmr56586255e9.4.1758204345502; Thu, 18 Sep 2025 07:05:45 -0700 (PDT) Date: Thu, 18 Sep 2025 15:59:18 +0200 In-Reply-To: <20250918140451.1289454-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: <20250918140451.1289454-1-elver@google.com> X-Mailer: git-send-email 2.51.0.384.g4c02a37b29-goog Message-ID: <20250918140451.1289454-8-elver@google.com> Subject: [PATCH v3 07/35] lockdep: Annotate lockdep assertions for capability analysis From: Marco Elver To: elver@google.com, Peter Zijlstra , Boqun Feng , Ingo Molnar , Will Deacon Cc: "David S. Miller" , Luc Van Oostenryck , "Paul E. McKenney" , Alexander Potapenko , Arnd Bergmann , Bart Van Assche , Bill Wendling , Christoph Hellwig , Dmitry Vyukov , Eric Dumazet , Frederic Weisbecker , Greg Kroah-Hartman , Herbert Xu , Ian Rogers , Jann Horn , Joel Fernandes , 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, llvm@lists.linux.dev, rcu@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Clang's capability analysis can be made aware of functions that assert that capabilities/locks are held. Presence of these annotations causes the analysis to assume the capability 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 --- 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..11b3d22555ff 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) =20 #define lockdep_assert_held(l) \ - lockdep_assert(lockdep_is_held(l) !=3D LOCK_STATE_NOT_HELD) + do { lockdep_assert(lockdep_is_held(l) !=3D LOCK_STATE_NOT_HELD); __assum= e_cap(l); } while (0) =20 #define lockdep_assert_not_held(l) \ lockdep_assert(lockdep_is_held(l) !=3D LOCK_STATE_HELD) =20 #define lockdep_assert_held_write(l) \ - lockdep_assert(lockdep_is_held_type(l, 0)) + do { lockdep_assert(lockdep_is_held_type(l, 0)); __assume_cap(l); } while= (0) =20 #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_cap(l); = } while (0) =20 #define lockdep_assert_held_once(l) \ lockdep_assert_once(lockdep_is_held(l) !=3D 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) =20 -#define lockdep_assert_held(l) do { (void)(l); } while (0) +#define lockdep_assert_held(l) __assume_cap(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_cap(l) +#define lockdep_assert_held_read(l) __assume_shared_cap(l) #define lockdep_assert_held_once(l) do { (void)(l); } while (0) #define lockdep_assert_none_held_once() do { } while (0) =20 --=20 2.51.0.384.g4c02a37b29-goog