From nobody Sun Dec 14 06:38:17 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F9D8C83F1F for ; Tue, 29 Aug 2023 17:12:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237674AbjH2RMP (ORCPT ); Tue, 29 Aug 2023 13:12:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237655AbjH2RLo (ORCPT ); Tue, 29 Aug 2023 13:11:44 -0400 Received: from out-246.mta1.migadu.com (out-246.mta1.migadu.com [IPv6:2001:41d0:203:375::f6]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8469CCD6 for ; Tue, 29 Aug 2023 10:11:40 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1693329097; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iO6rOKx0E5Y80aTOb2gdl835Yi8CPfP2ICeqYsm38a8=; b=LIEnc9qf0bdzjRuVfvd2JdO2h3KjGuPt1jpYgEgLcKhd+uMTNri0079VJZ7BuNqzfKhWpH nChiTXEn/GCsQoyhhHm4/OnyjGw6tvxpMZ/P/+tL4MFSJeV+Aw2nZXmyYGKoQ8vfzv/ONv 7MlOomIeIzvZ5a8LNRxAPzvNoJy8ViI= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 04/15] stackdepot: add depot_fetch_stack helper Date: Tue, 29 Aug 2023 19:11:14 +0200 Message-Id: <757ff72866010146fafda3049cb3749611cd7dd3.1693328501.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Andrey Konovalov Add a helper depot_fetch_stack function that fetches the pointer to a stack record. With this change, all static depot_* functions now operate on stack pools and the exported stack_depot_* functions operate on the hash table. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 482eac40791e..2128108f2acb 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -304,6 +304,7 @@ depot_alloc_stack(unsigned long *entries, int size, u32= hash, void **prealloc) stack->handle.extra =3D 0; memcpy(stack->entries, entries, flex_array_size(stack, entries, size)); pool_offset +=3D required_size; + /* * Let KMSAN know the stored stack record is initialized. This shall * prevent false positive reports if instrumented code accesses it. @@ -313,6 +314,32 @@ depot_alloc_stack(unsigned long *entries, int size, u3= 2 hash, void **prealloc) return stack; } =20 +static struct stack_record *depot_fetch_stack(depot_stack_handle_t handle) +{ + union handle_parts parts =3D { .handle =3D handle }; + /* + * READ_ONCE pairs with potential concurrent write in + * depot_alloc_stack. + */ + int pool_index_cached =3D READ_ONCE(pool_index); + void *pool; + size_t offset =3D parts.offset << DEPOT_STACK_ALIGN; + struct stack_record *stack; + + if (parts.pool_index > pool_index_cached) { + WARN(1, "pool index %d out of bounds (%d) for stack id %08x\n", + parts.pool_index, pool_index_cached, handle); + return NULL; + } + + pool =3D stack_pools[parts.pool_index]; + if (!pool) + return NULL; + + stack =3D pool + offset; + return stack; +} + /* Calculates the hash for a stack. */ static inline u32 hash_stack(unsigned long *entries, unsigned int size) { @@ -456,14 +483,6 @@ EXPORT_SYMBOL_GPL(stack_depot_save); unsigned int stack_depot_fetch(depot_stack_handle_t handle, unsigned long **entries) { - union handle_parts parts =3D { .handle =3D handle }; - /* - * READ_ONCE pairs with potential concurrent write in - * depot_alloc_stack. - */ - int pool_index_cached =3D READ_ONCE(pool_index); - void *pool; - size_t offset =3D parts.offset << DEPOT_STACK_ALIGN; struct stack_record *stack; =20 *entries =3D NULL; @@ -476,15 +495,7 @@ unsigned int stack_depot_fetch(depot_stack_handle_t ha= ndle, if (!handle || stack_depot_disabled) return 0; =20 - if (parts.pool_index > pool_index_cached) { - WARN(1, "pool index %d out of bounds (%d) for stack id %08x\n", - parts.pool_index, pool_index_cached, handle); - return 0; - } - pool =3D stack_pools[parts.pool_index]; - if (!pool) - return 0; - stack =3D pool + offset; + stack =3D depot_fetch_stack(handle); =20 *entries =3D stack->entries; return stack->size; --=20 2.25.1