From patchwork Tue Aug 29 17:11:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13369234 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A548FC6FA8F for ; Tue, 29 Aug 2023 17:11:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 676408E0032; Tue, 29 Aug 2023 13:11:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6241B8E002F; Tue, 29 Aug 2023 13:11:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C5B48E0032; Tue, 29 Aug 2023 13:11:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 35F338E002F for ; Tue, 29 Aug 2023 13:11:42 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 06A5B80247 for ; Tue, 29 Aug 2023 17:11:42 +0000 (UTC) X-FDA: 81177784044.08.6CBD8E4 Received: from out-249.mta1.migadu.com (out-249.mta1.migadu.com [95.215.58.249]) by imf25.hostedemail.com (Postfix) with ESMTP id 5DD0CA001E for ; Tue, 29 Aug 2023 17:11:39 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=LIEnc9qf; spf=pass (imf25.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.249 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693329099; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iO6rOKx0E5Y80aTOb2gdl835Yi8CPfP2ICeqYsm38a8=; b=YFsDq7onN0nbXyWn8GLsY7e/Xdpml/n2dZ2maT6dkeVthHo49VGi4WS7TGP2hKVZBn38ro 1M8IP2VIfdNPgc5u5qzJ4f1nimM6ykTdbrD4V4sKd98Q5eQPcDqtIf3wjRgkVG2Hwywz9y uSl1pNbn+aXC52isTVAmeJgRgKzpauE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693329099; a=rsa-sha256; cv=none; b=k0GA9WnzNM9QXdmn9zc5xsYrvRZA7n7urgtSQG+YDuzesbTSg9D/Rhlo2lvJDUU0m2V5ON h/ONbwUUi5tw3o5ZH03fSXhMzEWvesRgIWN82RnjZsqaIivM8isn3Dyyr29RDj2RA68rES 4srNl3KbQAr7JSK/iNeUkYyfNpSKykk= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=LIEnc9qf; spf=pass (imf25.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.249 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev 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 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 5DD0CA001E X-Rspam-User: X-Stat-Signature: 3auhtgpf189nuza69gwx3tsz3b1y6z7a X-Rspamd-Server: rspam03 X-HE-Tag: 1693329099-572030 X-HE-Meta: U2FsdGVkX19nl9+otGqTnH6tQgUR79L5TzI6u6X5XeJrgo+pPpW0UHzvfMy3MGRLhpXFEHgZ9WUKHkMNGInG8rNjWITbezrRUYTDc56OoNgMjzw6TDa0eMNw7wkK7OFVRsEu59LaQUjgs2r2fdxSMmB6ZpQQFZdy7mAi3z5Q88PARMp0Tkl1L9HO55ENmJZYh/h1mVaF8CSQqygMxtmUgonRWQhbxMp+r0/avO2pRWFWedXnknn12iWAK28kO8GG5jwCJPLm9HW4QSs78P5nCKocz9T6M+4YLwuZoCiYgNQqAxnhzMcPbgKwAcZfOmqHh0DfoZaVmNw5NobifIDzeS80eR2zgg7akLXV27sCLsqO0Owc+/NMzG8bqNoKHtRCLSOQrhTxgx4MouJaNgiPx/SHME29oeaeQagGqED72P7zsQUsUN47fuSMedKLSkSQoJWox6AJ30op9lrN2eF2lPw5zphvojjZobMtnIewyFC9tpiM1k3d7WxDkEzTcJqBSZnvvzmklA29XY/QOHrukybisiqPjYnt26RcPJq7QZatMSz2THH8UVvSDSLnpUC7ZZcc3+9z3AsTD/ZturmyqOmiqWQh3atXqNmHHnokF+PYreQOCTv5Oa3BVz1uYSURh7Q+W9qMqzxQ/QFay8bs67WexJPsiBrjLLemg2gNpynYyVapLfaHPfH1/aTuK67XvAp+4PXuRTBStTiUC13mkUjSIWFY7Fve038fEpuU5125GiEpeZPc/VuW6YP4Mq/d0CcrbIhC4lhIZGKGKBgQ0xVCi2QP0G4DQ3bWBZ8NbaI08Map9KceJUKkODaPqVs/gd5FdPLoak7W0zJFP3A0KQDzRQlvRJbcgiwhiL941bir957iZ9ktqIrv3Pag2g4IQprSSC0GlaeB7vYRVZ2h2E5V0PjaWskVN1AtduwMXMchgz/ciefBvJsyiY7g9yrC6YKgIMpq4LFsljymm/t r5NbZDzh InmqNwgEXs4X50PuuFBuoZ/3YA4gxkZLc14rZ63JxMhkvvbxTim1Qoe82vpr9rHMSfS+tFar1nOwkICF19eJT/pSFa3LrynQlg6Liz4g2rW5UIWKFnduLWMJdTqVtjEpBDXK+ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 = 0; memcpy(stack->entries, entries, flex_array_size(stack, entries, size)); pool_offset += 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, u32 hash, void **prealloc) return stack; } +static struct stack_record *depot_fetch_stack(depot_stack_handle_t handle) +{ + union handle_parts parts = { .handle = handle }; + /* + * READ_ONCE pairs with potential concurrent write in + * depot_alloc_stack. + */ + int pool_index_cached = READ_ONCE(pool_index); + void *pool; + size_t offset = 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 = stack_pools[parts.pool_index]; + if (!pool) + return NULL; + + stack = 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 = { .handle = handle }; - /* - * READ_ONCE pairs with potential concurrent write in - * depot_alloc_stack. - */ - int pool_index_cached = READ_ONCE(pool_index); - void *pool; - size_t offset = parts.offset << DEPOT_STACK_ALIGN; struct stack_record *stack; *entries = NULL; @@ -476,15 +495,7 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, if (!handle || stack_depot_disabled) return 0; - 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 = stack_pools[parts.pool_index]; - if (!pool) - return 0; - stack = pool + offset; + stack = depot_fetch_stack(handle); *entries = stack->entries; return stack->size;