From nobody Sun Feb 8 23:24:37 2026 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.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 E0D3334FF54 for ; Fri, 19 Dec 2025 15:47:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766159253; cv=none; b=n4wxM6kkvNfsh1ZcRU1mF1zJTDJAgjJ6Xlp9tyaPjSiSYol3KOqHSUIubP8n6acmw943idOJNWAIH6mGiD8//IXIpTZgZ0uOC67KqZnZL81tUWu3Fg7hkQIF/FlKGf91sknE+n5HE5/cTlowcnqxZNU2sogzZfXrrjIWpflv8Wo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766159253; c=relaxed/simple; bh=42FYH4YydcI8JRQNr8EFVNHBN8JBHnU8gH/4zTSZoQU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=upM2fuXYBrN06BYKe+tukfIswISSnXoYJmhhUdy1AVHF55SZqCQuOqbt9d/o6CeGA4nELPmcCYN+YVdyYxb6JJNE2wusudut5+3bpjFrp260Gi58gFiCJ9u6lHgvi0dX5iNbi5TlufTCvH6RtMp94yfITJv7IKHMiZt/qtu2hHk= 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=wcfeUZ6W; arc=none smtp.client-ip=209.85.208.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="wcfeUZ6W" Received: by mail-ed1-f74.google.com with SMTP id 4fb4d7f45d1cf-64b9ccc9661so764703a12.1 for ; Fri, 19 Dec 2025 07:47:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1766159249; x=1766764049; 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=4XK3qzntTZnJieCCKu4A/HzWNSoArWneMhDpC7gb9Kg=; b=wcfeUZ6W6BSHNwFdMJmk44FzON3r2Nkg8OnOk6qCERTgO970VqHIl6H7k937ecJLn8 4ACPHMcISQpWhqumcXSOUjAJzPm+gB1BrFBt9QFRTGHP4y5OSUcnXSac3EydAyHiah0N ckC0AtrQ53TQ8nARLISMuCJBsAF0aO7dPasmVv8kT977LUwxndZ37ZabTx8VYedAwwBs 0B2DoySkn9AteiUqCu7HhnfIsBrXn5gkuLQVZrivnh2P0EEAplVF0uhDyfuCw6UrEahB C3WZY3L5bIcj+KmwzVLjAUJliQoIp1maAwEupmGUk9/aoXwrSP/NyOfAueJqg5oM6GN8 6arw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766159249; x=1766764049; 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=4XK3qzntTZnJieCCKu4A/HzWNSoArWneMhDpC7gb9Kg=; b=odmdv0z5hHBxUTGNnneGVy0b3hl7OVcvMWVURKMuVJO8ztBrsnxnnKvntkvqIArtxk 6IolNGMEsLOgpqg8yfUTsnSkyHYgKH529uEazigqEV25LXfanlFUQd/rv2tSI36Gv+bQ quW0PY6F6M1uV2H8NtX+RjqaF4FryOq5ZaKtGuNT0tc04f0BXGSm7RZv7Z+UfSd55azk G9Kt3WnGHfMQoLqaUZXI9XPBP0g40biTzA+Xic3XPWfXjnwZRGWmiNAJwAGw/gW67PA4 JKCth1pgderd2S2sOXdjhhojRqKbO1D3T6GZEIHPDbRp/nbCkGfYOVM9JwwH/yJOL+q7 o1Sw== X-Forwarded-Encrypted: i=1; AJvYcCXL+In+FjbDC8+O0HflcUiDvFl5HIr2SczW5b/FL5Mc3JvVG9QVdaEpkKGRJ4vCpQZtMumMG4vkqndxKFA=@vger.kernel.org X-Gm-Message-State: AOJu0YxsabV/NPtfasnDbuFa0Y005+gp1e0ODs4HCz0g8wbKxn5HNZxD Fl81PnbtcH33yhbLmAZjX3+cLnxzKy/60qBT3t7Ipi2FTVVIbyXkcSGdNWzXjVKe95EusIHhuue J3Q== X-Google-Smtp-Source: AGHT+IHX5UXwk2F+9TvQVKLp2kAzUS4yz1dfz5S20YIyCpvaeeaogsyAn1dyrJKuFHxwFv13c6Ax3+QEyg== X-Received: from edpr3.prod.google.com ([2002:aa7:c143:0:b0:64b:9f62:a079]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:d62:b0:64b:993f:ce06 with SMTP id 4fb4d7f45d1cf-64b993fd097mr1762424a12.32.1766159249192; Fri, 19 Dec 2025 07:47:29 -0800 (PST) Date: Fri, 19 Dec 2025 16:40:20 +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-32-elver@google.com> Subject: [PATCH v5 31/36] stackdepot: 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 stackdepot. Signed-off-by: Marco Elver --- v4: * Rename capability -> context analysis. v2: * Remove disable/enable_context_analysis() around headers. --- lib/Makefile | 1 + lib/stackdepot.c | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 89defefbf6c0..e755eee4e76f 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -250,6 +250,7 @@ obj-$(CONFIG_POLYNOMIAL) +=3D polynomial.o # Prevent the compiler from calling builtins like memcmp() or bcmp() from = this # file. CFLAGS_stackdepot.o +=3D -fno-builtin +CONTEXT_ANALYSIS_stackdepot.o :=3D y obj-$(CONFIG_STACKDEPOT) +=3D stackdepot.o KASAN_SANITIZE_stackdepot.o :=3D n # In particular, instrumenting stackdepot.c with KMSAN will result in infi= nite diff --git a/lib/stackdepot.c b/lib/stackdepot.c index de0b0025af2b..166f50ad8391 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -61,18 +61,18 @@ static unsigned int stack_bucket_number_order; /* Hash mask for indexing the table. */ static unsigned int stack_hash_mask; =20 +/* The lock must be held when performing pool or freelist modifications. */ +static DEFINE_RAW_SPINLOCK(pool_lock); /* Array of memory regions that store stack records. */ -static void **stack_pools; +static void **stack_pools __pt_guarded_by(&pool_lock); /* Newly allocated pool that is not yet added to stack_pools. */ static void *new_pool; /* Number of pools in stack_pools. */ static int pools_num; /* Offset to the unused space in the currently used pool. */ -static size_t pool_offset =3D DEPOT_POOL_SIZE; +static size_t pool_offset __guarded_by(&pool_lock) =3D DEPOT_POOL_SIZE; /* Freelist of stack records within stack_pools. */ -static LIST_HEAD(free_stacks); -/* The lock must be held when performing pool or freelist modifications. */ -static DEFINE_RAW_SPINLOCK(pool_lock); +static __guarded_by(&pool_lock) LIST_HEAD(free_stacks); =20 /* Statistics counters for debugfs. */ enum depot_counter_id { @@ -291,6 +291,7 @@ EXPORT_SYMBOL_GPL(stack_depot_init); * Initializes new stack pool, and updates the list of pools. */ static bool depot_init_pool(void **prealloc) + __must_hold(&pool_lock) { lockdep_assert_held(&pool_lock); =20 @@ -338,6 +339,7 @@ static bool depot_init_pool(void **prealloc) =20 /* Keeps the preallocated memory to be used for a new stack depot pool. */ static void depot_keep_new_pool(void **prealloc) + __must_hold(&pool_lock) { lockdep_assert_held(&pool_lock); =20 @@ -357,6 +359,7 @@ static void depot_keep_new_pool(void **prealloc) * the current pre-allocation. */ static struct stack_record *depot_pop_free_pool(void **prealloc, size_t si= ze) + __must_hold(&pool_lock) { struct stack_record *stack; void *current_pool; @@ -391,6 +394,7 @@ static struct stack_record *depot_pop_free_pool(void **= prealloc, size_t size) =20 /* Try to find next free usable entry from the freelist. */ static struct stack_record *depot_pop_free(void) + __must_hold(&pool_lock) { struct stack_record *stack; =20 @@ -428,6 +432,7 @@ static inline size_t depot_stack_record_size(struct sta= ck_record *s, unsigned in /* Allocates a new stack in a stack depot pool. */ static struct stack_record * depot_alloc_stack(unsigned long *entries, unsigned int nr_entries, u32 has= h, depot_flags_t flags, void **prealloc) + __must_hold(&pool_lock) { struct stack_record *stack =3D NULL; size_t record_size; @@ -486,6 +491,7 @@ depot_alloc_stack(unsigned long *entries, unsigned int = nr_entries, u32 hash, dep } =20 static struct stack_record *depot_fetch_stack(depot_stack_handle_t handle) + __must_not_hold(&pool_lock) { const int pools_num_cached =3D READ_ONCE(pools_num); union handle_parts parts =3D { .handle =3D handle }; @@ -502,7 +508,8 @@ static struct stack_record *depot_fetch_stack(depot_sta= ck_handle_t handle) return NULL; } =20 - pool =3D stack_pools[pool_index]; + /* @pool_index either valid, or user passed in corrupted value. */ + pool =3D context_unsafe(stack_pools[pool_index]); if (WARN_ON(!pool)) return NULL; =20 @@ -515,6 +522,7 @@ static struct stack_record *depot_fetch_stack(depot_sta= ck_handle_t handle) =20 /* Links stack into the freelist. */ static void depot_free_stack(struct stack_record *stack) + __must_not_hold(&pool_lock) { unsigned long flags; =20 --=20 2.52.0.322.g1dd061c0dc-goog