From patchwork Fri Feb 10 21:15:49 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: 13136451 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 8A0AFC636D7 for ; Fri, 10 Feb 2023 21:16:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 045FB6B0182; Fri, 10 Feb 2023 16:16:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F10096B0184; Fri, 10 Feb 2023 16:16:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CE9ED6B0185; Fri, 10 Feb 2023 16:16:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id AF7F66B0182 for ; Fri, 10 Feb 2023 16:16:14 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 82311120A88 for ; Fri, 10 Feb 2023 21:16:14 +0000 (UTC) X-FDA: 80452640268.06.513CA08 Received: from out-159.mta0.migadu.com (out-159.mta0.migadu.com [91.218.175.159]) by imf06.hostedemail.com (Postfix) with ESMTP id 2A711180016 for ; Fri, 10 Feb 2023 21:16:11 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=w90TbDJL; spf=pass (imf06.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.159 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=1676063772; 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=0D/1F5CMwtFSAEjWxVZCsgWbjza4wyrBe5NUV/UGD6o=; b=cpb+MDijVW2zaBJg5UTHwjOrhwCekpw6ng+L8XrerJWsdbKNDPuecHD1J6VDnK4fI4SlYr xVyynXEKC2BZjP5RPOTkt56MABm6JRM0trw33xkl7pJU0GIoi+EAyRt8/f1kjuCcnnTTY3 6ggZpqWHr3tkLkLsOJ1s8A5XAXBsN7o= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=w90TbDJL; spf=pass (imf06.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.159 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063772; a=rsa-sha256; cv=none; b=oFczqv+Q//XCmlDooUTWKfYIgyWIG/wki9s2xA+FlkJ5AzaHlgyQkZ51h3/i6EiSnhSmL4 CHyrx6GkGphzTvf+3qsj+pzU04KA2ASmyKsd31bAoQPPnBAnOV14uYAFD7cV2qxA4EoKlh M01CstNlV4T/CY1oY/nm6T7/4bRyGNY= 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=1676063770; 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=0D/1F5CMwtFSAEjWxVZCsgWbjza4wyrBe5NUV/UGD6o=; b=w90TbDJLt0ZRNUv+tRWkGomx6sQyICbCgQEPnt1JsbFWaZ282XQPMKF2f5cQ82Clmg9BHX VjULQagAwhIZtpi71wVBMmUW3JtSrn+nHsDsIUsCwGlqfxbhgbiOBeDK3wsHLvGUBE4Vua zfSWstzrAqbr2dd+iwkYJ0V3Cw/OIZw= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 01/18] lib/stackdepot: put functions in logical order Date: Fri, 10 Feb 2023 22:15:49 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2A711180016 X-Rspam-User: X-Stat-Signature: ayqop6pjf4qnxqe1qxnopewzwesnez5b X-HE-Tag: 1676063771-497948 X-HE-Meta: U2FsdGVkX18mpp9qRxXM9abiIWM5tbjvRk2eHVWyXSvvAtnLR9U7eW9AXy6Ab8bmMswNb2hS3JMYV1ieu9m4o0eX58j0OqsJTgjR90NMaA3rILDpOc02ktoDwoztz75dh5SpSDL8fQOejhQCY1a6fpVZBgCLYQ9PefJIMMw3jxdsd1Aa6CLmyGBEHzGWy14pIdeF6iHhGc92+6KKWuewBSZTwtMb5UlB1x32RNiVzgC2YmQMunDnU/kZXp2ITP1HptPEuPOPYmGl/rF+4EQMSYCEhAgkJVUni8Ckci19+Fc8185s/2LvHIbW5rFDdLeEL+H/cnGwsS24gSBjC4SfvkiAs7RJ/xNjJEXzEhfjNESomRkuVFfQXtBALNx432f9rSxbV0oEoK2H8JWQ52RJI8YT5pcaDFQZmmNgfo9BKbv6c6+RRIvR9h2aSx7QM7cBwieWLe4TiBTnFU0yC5JFL964v8s82k9tSyi4eoC1lrBaS4iR5Q/Z2fdZeWOVxeB6qaEGK3SnjnBPSJl81hUwUiRu47B6usPPq6lEVQUBSc8IK0OTlq2KmH6KXcSP5bzJP4Wb7rTKhb62nO15yu8ySQbO8kst3OTzRKB+W+PwdMBJIxLqpyFMHFpiqqiIWhSAuwR0DpR6caYfwbFnNuPnsppN/RkOqNgaPAnx35EzAG8IH4L+UEHJNneoYkSEzIYXLA7ZENjDA6ZnuNoJkCqANV5YX62l6V0nWsEMGrqUs+3D5KMJ/F0xKVy8VkMAkZsb9GlJb0kQWwLjw6TVh0InQtgLzC8eYuAVuq5+0cbJG6qlSF2PqwtcwFRzzVgp2MT64J7sf+xqHP141EVIR6DqyqnK6oWxn5scC0j7DsjAHFCuJBpz5XvGcFR21aWs1pPrgtZvDb5GutPoxuxscAOp40nakZtsAD1X+iCBNJBT6zgGdFwHxvJccFRK6w++Rw4LkgutKsbehOlRj4AJuFh 49FpxN9n K9BjBES8GEG9W4Nu9VXCNp1xU+I8zHthSMZTWDf1fp+hBddS7sA5DRculfw9kpwflKn+cG7L6wi7FSecRJMLjCwGB+R37SIXkb19qc4922sSlNi8= 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 Put stack depot functions' declarations and definitions in a more logical order: 1. Functions that save stack traces into stack depot. 2. Functions that fetch and print stack traces. 3. stack_depot_get_extra_bits that operates on stack depot handles and does not interact with the stack depot storage. No functional changes. Reviewed-by: Alexander Potapenko Signed-off-by: Andrey Konovalov --- include/linux/stackdepot.h | 15 +- lib/stackdepot.c | 314 ++++++++++++++++++------------------- 2 files changed, 165 insertions(+), 164 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index 9ca7798d7a31..1296a6eeaec0 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -14,17 +14,13 @@ #include typedef u32 depot_stack_handle_t; + /* * Number of bits in the handle that stack depot doesn't use. Users may store * information in them. */ #define STACK_DEPOT_EXTRA_BITS 5 -depot_stack_handle_t __stack_depot_save(unsigned long *entries, - unsigned int nr_entries, - unsigned int extra_bits, - gfp_t gfp_flags, bool can_alloc); - /* * Every user of stack depot has to call stack_depot_init() during its own init * when it's decided that it will be calling stack_depot_save() later. This is @@ -59,17 +55,22 @@ static inline void stack_depot_want_early_init(void) { } static inline int stack_depot_early_init(void) { return 0; } #endif +depot_stack_handle_t __stack_depot_save(unsigned long *entries, + unsigned int nr_entries, + unsigned int extra_bits, + gfp_t gfp_flags, bool can_alloc); + depot_stack_handle_t stack_depot_save(unsigned long *entries, unsigned int nr_entries, gfp_t gfp_flags); unsigned int stack_depot_fetch(depot_stack_handle_t handle, unsigned long **entries); -unsigned int stack_depot_get_extra_bits(depot_stack_handle_t handle); +void stack_depot_print(depot_stack_handle_t stack); int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size, int spaces); -void stack_depot_print(depot_stack_handle_t stack); +unsigned int stack_depot_get_extra_bits(depot_stack_handle_t handle); #endif diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 79e894cf8406..4bfaf3bce619 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -79,84 +79,6 @@ static int next_slab_inited; static size_t depot_offset; static DEFINE_RAW_SPINLOCK(depot_lock); -unsigned int stack_depot_get_extra_bits(depot_stack_handle_t handle) -{ - union handle_parts parts = { .handle = handle }; - - return parts.extra; -} -EXPORT_SYMBOL(stack_depot_get_extra_bits); - -static bool init_stack_slab(void **prealloc) -{ - if (!*prealloc) - return false; - /* - * This smp_load_acquire() pairs with smp_store_release() to - * |next_slab_inited| below and in depot_alloc_stack(). - */ - if (smp_load_acquire(&next_slab_inited)) - return true; - if (stack_slabs[depot_index] == NULL) { - stack_slabs[depot_index] = *prealloc; - *prealloc = NULL; - } else { - /* If this is the last depot slab, do not touch the next one. */ - if (depot_index + 1 < STACK_ALLOC_MAX_SLABS) { - stack_slabs[depot_index + 1] = *prealloc; - *prealloc = NULL; - } - /* - * This smp_store_release pairs with smp_load_acquire() from - * |next_slab_inited| above and in stack_depot_save(). - */ - smp_store_release(&next_slab_inited, 1); - } - return true; -} - -/* Allocation of a new stack in raw storage */ -static struct stack_record * -depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) -{ - struct stack_record *stack; - size_t required_size = struct_size(stack, entries, size); - - required_size = ALIGN(required_size, 1 << STACK_ALLOC_ALIGN); - - if (unlikely(depot_offset + required_size > STACK_ALLOC_SIZE)) { - if (unlikely(depot_index + 1 >= STACK_ALLOC_MAX_SLABS)) { - WARN_ONCE(1, "Stack depot reached limit capacity"); - return NULL; - } - depot_index++; - depot_offset = 0; - /* - * smp_store_release() here pairs with smp_load_acquire() from - * |next_slab_inited| in stack_depot_save() and - * init_stack_slab(). - */ - if (depot_index + 1 < STACK_ALLOC_MAX_SLABS) - smp_store_release(&next_slab_inited, 0); - } - init_stack_slab(prealloc); - if (stack_slabs[depot_index] == NULL) - return NULL; - - stack = stack_slabs[depot_index] + depot_offset; - - stack->hash = hash; - stack->size = size; - stack->handle.slabindex = depot_index; - stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN; - stack->handle.valid = 1; - stack->handle.extra = 0; - memcpy(stack->entries, entries, flex_array_size(stack, entries, size)); - depot_offset += required_size; - - return stack; -} - /* one hash table bucket entry per 16kB of memory */ #define STACK_HASH_SCALE 14 /* limited between 4k and 1M buckets */ @@ -270,6 +192,76 @@ int stack_depot_init(void) } EXPORT_SYMBOL_GPL(stack_depot_init); +static bool init_stack_slab(void **prealloc) +{ + if (!*prealloc) + return false; + /* + * This smp_load_acquire() pairs with smp_store_release() to + * |next_slab_inited| below and in depot_alloc_stack(). + */ + if (smp_load_acquire(&next_slab_inited)) + return true; + if (stack_slabs[depot_index] == NULL) { + stack_slabs[depot_index] = *prealloc; + *prealloc = NULL; + } else { + /* If this is the last depot slab, do not touch the next one. */ + if (depot_index + 1 < STACK_ALLOC_MAX_SLABS) { + stack_slabs[depot_index + 1] = *prealloc; + *prealloc = NULL; + } + /* + * This smp_store_release pairs with smp_load_acquire() from + * |next_slab_inited| above and in stack_depot_save(). + */ + smp_store_release(&next_slab_inited, 1); + } + return true; +} + +/* Allocation of a new stack in raw storage */ +static struct stack_record * +depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) +{ + struct stack_record *stack; + size_t required_size = struct_size(stack, entries, size); + + required_size = ALIGN(required_size, 1 << STACK_ALLOC_ALIGN); + + if (unlikely(depot_offset + required_size > STACK_ALLOC_SIZE)) { + if (unlikely(depot_index + 1 >= STACK_ALLOC_MAX_SLABS)) { + WARN_ONCE(1, "Stack depot reached limit capacity"); + return NULL; + } + depot_index++; + depot_offset = 0; + /* + * smp_store_release() here pairs with smp_load_acquire() from + * |next_slab_inited| in stack_depot_save() and + * init_stack_slab(). + */ + if (depot_index + 1 < STACK_ALLOC_MAX_SLABS) + smp_store_release(&next_slab_inited, 0); + } + init_stack_slab(prealloc); + if (stack_slabs[depot_index] == NULL) + return NULL; + + stack = stack_slabs[depot_index] + depot_offset; + + stack->hash = hash; + stack->size = size; + stack->handle.slabindex = depot_index; + stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN; + stack->handle.valid = 1; + stack->handle.extra = 0; + memcpy(stack->entries, entries, flex_array_size(stack, entries, size)); + depot_offset += required_size; + + return stack; +} + /* Calculate hash for a stack */ static inline u32 hash_stack(unsigned long *entries, unsigned int size) { @@ -309,85 +301,6 @@ static inline struct stack_record *find_stack(struct stack_record *bucket, return NULL; } -/** - * stack_depot_snprint - print stack entries from a depot into a buffer - * - * @handle: Stack depot handle which was returned from - * stack_depot_save(). - * @buf: Pointer to the print buffer - * - * @size: Size of the print buffer - * - * @spaces: Number of leading spaces to print - * - * Return: Number of bytes printed. - */ -int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size, - int spaces) -{ - unsigned long *entries; - unsigned int nr_entries; - - nr_entries = stack_depot_fetch(handle, &entries); - return nr_entries ? stack_trace_snprint(buf, size, entries, nr_entries, - spaces) : 0; -} -EXPORT_SYMBOL_GPL(stack_depot_snprint); - -/** - * stack_depot_print - print stack entries from a depot - * - * @stack: Stack depot handle which was returned from - * stack_depot_save(). - * - */ -void stack_depot_print(depot_stack_handle_t stack) -{ - unsigned long *entries; - unsigned int nr_entries; - - nr_entries = stack_depot_fetch(stack, &entries); - if (nr_entries > 0) - stack_trace_print(entries, nr_entries, 0); -} -EXPORT_SYMBOL_GPL(stack_depot_print); - -/** - * stack_depot_fetch - Fetch stack entries from a depot - * - * @handle: Stack depot handle which was returned from - * stack_depot_save(). - * @entries: Pointer to store the entries address - * - * Return: The number of trace entries for this depot. - */ -unsigned int stack_depot_fetch(depot_stack_handle_t handle, - unsigned long **entries) -{ - union handle_parts parts = { .handle = handle }; - void *slab; - size_t offset = parts.offset << STACK_ALLOC_ALIGN; - struct stack_record *stack; - - *entries = NULL; - if (!handle) - return 0; - - if (parts.slabindex > depot_index) { - WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n", - parts.slabindex, depot_index, handle); - return 0; - } - slab = stack_slabs[parts.slabindex]; - if (!slab) - return 0; - stack = slab + offset; - - *entries = stack->entries; - return stack->size; -} -EXPORT_SYMBOL_GPL(stack_depot_fetch); - /** * __stack_depot_save - Save a stack trace from an array * @@ -533,3 +446,90 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, return __stack_depot_save(entries, nr_entries, 0, alloc_flags, true); } EXPORT_SYMBOL_GPL(stack_depot_save); + +/** + * stack_depot_fetch - Fetch stack entries from a depot + * + * @handle: Stack depot handle which was returned from + * stack_depot_save(). + * @entries: Pointer to store the entries address + * + * Return: The number of trace entries for this depot. + */ +unsigned int stack_depot_fetch(depot_stack_handle_t handle, + unsigned long **entries) +{ + union handle_parts parts = { .handle = handle }; + void *slab; + size_t offset = parts.offset << STACK_ALLOC_ALIGN; + struct stack_record *stack; + + *entries = NULL; + if (!handle) + return 0; + + if (parts.slabindex > depot_index) { + WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n", + parts.slabindex, depot_index, handle); + return 0; + } + slab = stack_slabs[parts.slabindex]; + if (!slab) + return 0; + stack = slab + offset; + + *entries = stack->entries; + return stack->size; +} +EXPORT_SYMBOL_GPL(stack_depot_fetch); + +/** + * stack_depot_print - print stack entries from a depot + * + * @stack: Stack depot handle which was returned from + * stack_depot_save(). + * + */ +void stack_depot_print(depot_stack_handle_t stack) +{ + unsigned long *entries; + unsigned int nr_entries; + + nr_entries = stack_depot_fetch(stack, &entries); + if (nr_entries > 0) + stack_trace_print(entries, nr_entries, 0); +} +EXPORT_SYMBOL_GPL(stack_depot_print); + +/** + * stack_depot_snprint - print stack entries from a depot into a buffer + * + * @handle: Stack depot handle which was returned from + * stack_depot_save(). + * @buf: Pointer to the print buffer + * + * @size: Size of the print buffer + * + * @spaces: Number of leading spaces to print + * + * Return: Number of bytes printed. + */ +int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size, + int spaces) +{ + unsigned long *entries; + unsigned int nr_entries; + + nr_entries = stack_depot_fetch(handle, &entries); + return nr_entries ? stack_trace_snprint(buf, size, entries, nr_entries, + spaces) : 0; +} +EXPORT_SYMBOL_GPL(stack_depot_snprint); + +unsigned int stack_depot_get_extra_bits(depot_stack_handle_t handle) +{ + union handle_parts parts = { .handle = handle }; + + return parts.extra; +} +EXPORT_SYMBOL(stack_depot_get_extra_bits); From patchwork Fri Feb 10 21:15:50 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: 13136449 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 4533CC636D4 for ; Fri, 10 Feb 2023 21:16:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A9A66B017F; Fri, 10 Feb 2023 16:16:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8594F6B0180; Fri, 10 Feb 2023 16:16:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6FAFE6B0182; Fri, 10 Feb 2023 16:16:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 625DE6B017F for ; Fri, 10 Feb 2023 16:16:14 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3527341274 for ; Fri, 10 Feb 2023 21:16:14 +0000 (UTC) X-FDA: 80452640268.10.142D005 Received: from out-100.mta0.migadu.com (out-100.mta0.migadu.com [91.218.175.100]) by imf19.hostedemail.com (Postfix) with ESMTP id 7AE2F1A0017 for ; Fri, 10 Feb 2023 21:16:12 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Lpp+lB8h; spf=pass (imf19.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.100 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=1676063772; 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=z1gm2uHZDO3x8BSiOJ0jeaJz4iOmzsaE5lyAkDJqHg0=; b=W4FkomKUScRQgeFClf6JrrqQBnezJ7TMuJXYCpk86xaN60iDXJAQSdjJNqFvb71FTU8/74 O0Dio9wGouqKxab6yG5bOYSHkzs84o2xVov9Uhfite8fwIWa/4JumihILbbO0S3+GVUurY 0VWfy4le+qo3VJSW6EU0AE8qi97ZKBc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Lpp+lB8h; spf=pass (imf19.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.100 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063772; a=rsa-sha256; cv=none; b=QOTkXlHY3B0vDOv7LlCf0OxLR6n3HE1uMD1dMLAFXf4Bw0RiUu4c8fqlyOEm4SSTI1rvTV wehZw8nnXAf0bZyNI0uJK6G/VZrg6qXQvURM1+PuTHDfAU4UA89BC49SxuqPH5iBHHCWbP EWnYuZ+NV2sUqba5FcJBpjmu3uk+gcg= 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=1676063770; 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=z1gm2uHZDO3x8BSiOJ0jeaJz4iOmzsaE5lyAkDJqHg0=; b=Lpp+lB8htFhm3jM77dYrWl3dcQNjGvQPekyllxMw/5S9HTXcy8zozqt61j4IoOjzYexjNX /RA+b/g0ZhTr1fEhl1rwKYR5Zx1bPii9TPaSk7EW/Ugs3bN1GKdaZhurVbCpfZUbM7A36L V0utwNuGGe4199Y176cZaBlvcdKvq/Y= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 02/18] lib/stackdepot: use pr_fmt to define message format Date: Fri, 10 Feb 2023 22:15:50 +0100 Message-Id: <3d09db0171a0e92ff3eb0ee74de74558bc9b56c4.1676063693.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: r78swpjr9kyqutsgskbdc1gu6cnkceox X-Rspam-User: X-Rspamd-Queue-Id: 7AE2F1A0017 X-Rspamd-Server: rspam06 X-HE-Tag: 1676063772-613914 X-HE-Meta: U2FsdGVkX1/T2XNhJTsnOkjAdnuQ44hy+Yml1aEUNIFcuPXWak4mDmIgDtv16TR9rlFa1As5LKsojSADCNSTgGL5/jyH/j8VmZ81SLCKo9i4gYtSnwmwHOl2hz74IVFIg09dxvGcURXjlv5NYCSLF16/HSMmiHFgesF1O4vHQEQFS0BatU4xdsIRegIlQeLbQTP6SIFFbZhf/+kgsKtRWPvhesykCMyLVk32KuZUmZiuIoH+YDygkCHGEA+WW18fzNMyH4f5vUi4SInGXegjksIhdBSz1ZaE/thdnYxawIY5bKOIS8Cp5K54L57RhBlAURiNWuQIXVDim/GsDDTRqWg0wuYjpTZ0SY3yiFCvJa7dtMBgvt1JgPJV6zZWt7icK0x6G/lPWOGvClzyWKoN9byq2D08hT+HBKoYyp+b8RI4uBvzPznQSBZCQ1jRgCnUAaeWhT7GHLoQHFePA/C3WK2V8uT/E9vb5WzsZQNUh/WjGMT0Rct4CW/1NiaxqL/nKmPGfNklKtcxVD4Vh3AgFiprGJ/pzTnlaqTeNtJj9f7Tce/pSZ2GSYOuzDlrkkp5nVUmO5ukwyqzQrVJph2P74AodCWQgPBvV5b2RsZVs9CCTEyQllII9MB6wO0BGiQierAKF+vDfzj3WX+fRB11BG0aHF/dG3WoVlXU5pKRLcpEYqGxATM7LW4Tor0mERANLPorFTv36lH9ei+prUIg623qn8ewL+cixIJViVdtXv3IKVYWY3H4gif07mXtdQmWRQbGBjq/pL4+ijH+yDJvlkgzRjpzQT5g0njvW6aIiwjADzFkkaMJvB6JdgV5zBWu7h2fdj/uQfE1jFrscji9D0tsUBo7nwCubvVz/RhNy1dn9pqlD3buLD4uMtIKqofVAvD/9UdLuASqRz1mJQPVtnAS4Xi0PBwvGhkgQYwGodMP5O30e0TfMBXwHKo6FKjapY/tsSFP0BIrzmBMiXM vu2VQHkD 97bwXRLOoLirU83C/A3eAQe6QIxOQxoewUB/ab65DR8ThUAcCaxYRF8BpGdM/nm4wLduboEtJHfbKR9FsCJs4nNA08KlLrGVB7j2JhIeX4kG5JURTKWnkK6kRAarNPYjvNy13faI7LXb97iaAONAL2WWylw== 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 Use pr_fmt to define the format for printing stack depot messages instead of duplicating the "Stack Depot" prefix in each message. Reviewed-by: Alexander Potapenko Signed-off-by: Andrey Konovalov --- lib/stackdepot.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 4bfaf3bce619..83787e46a3ab 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -19,6 +19,8 @@ * Based on code by Dmitry Chernenkov. */ +#define pr_fmt(fmt) "stackdepot: " fmt + #include #include #include @@ -98,7 +100,7 @@ static int __init is_stack_depot_disabled(char *str) ret = kstrtobool(str, &stack_depot_disable); if (!ret && stack_depot_disable) { - pr_info("Stack Depot is disabled\n"); + pr_info("disabled\n"); stack_table = NULL; } return 0; @@ -142,7 +144,7 @@ int __init stack_depot_early_init(void) 1UL << STACK_HASH_ORDER_MAX); if (!stack_table) { - pr_err("Stack Depot hash table allocation failed, disabling\n"); + pr_err("hash table allocation failed, disabling\n"); stack_depot_disable = true; return -ENOMEM; } @@ -177,11 +179,11 @@ int stack_depot_init(void) if (entries > 1UL << STACK_HASH_ORDER_MAX) entries = 1UL << STACK_HASH_ORDER_MAX; - pr_info("Stack Depot allocating hash table of %lu entries with kvcalloc\n", + pr_info("allocating hash table of %lu entries with kvcalloc\n", entries); stack_table = kvcalloc(entries, sizeof(struct stack_record *), GFP_KERNEL); if (!stack_table) { - pr_err("Stack Depot hash table allocation failed, disabling\n"); + pr_err("hash table allocation failed, disabling\n"); stack_depot_disable = true; ret = -ENOMEM; } From patchwork Fri Feb 10 21:15:51 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: 13136453 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 DFB7CC64ED6 for ; Fri, 10 Feb 2023 21:16:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 801676B0184; Fri, 10 Feb 2023 16:16:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 74F386B018A; Fri, 10 Feb 2023 16:16:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 489B86B0186; Fri, 10 Feb 2023 16:16:15 -0500 (EST) 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 2ED606B0187 for ; Fri, 10 Feb 2023 16:16:15 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E9675A05D5 for ; Fri, 10 Feb 2023 21:16:14 +0000 (UTC) X-FDA: 80452640268.06.5B3C2F3 Received: from out-61.mta0.migadu.com (out-61.mta0.migadu.com [91.218.175.61]) by imf20.hostedemail.com (Postfix) with ESMTP id 03B621C0012 for ; Fri, 10 Feb 2023 21:16:12 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=dh6wp1Eq; spf=pass (imf20.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.61 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=1676063773; 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=TynB0J5qbcRBuS5BSP3vU74TPjYQ5881BbX5zggeusA=; b=jRT4cyxoULzmKPl/wl0sDLlfbT/fSuosws6IuReHRVew9NKJ7pXEF8SEvSWeuJcKC25UTL aE1lxMbXFD5vL7NHx0kJwaCuR221X9wa+cb4hrSNlUFkLSH0NMiI/yALqtuFy2QsASWfoV itipQBYHE5am6HwKR8ugjw3z3sKHLi4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=dh6wp1Eq; spf=pass (imf20.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.61 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063773; a=rsa-sha256; cv=none; b=3x/hrWYgNPpMvEjOWab7Wbh6MIHpS40vWXGte7h4E2rtUHbz4daBvi/9H4qYtpIV6oZ6b/ YSyLqjcXmjZMNNP59qiU3aDeOQ0rYYXLysmFpw1OPZDY5bsU/sNMYBOxyuVHgOr9MX1F2Q tJAyVGF5C6ECI9bPGDpfIZjFIN9D2KE= 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=1676063771; 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=TynB0J5qbcRBuS5BSP3vU74TPjYQ5881BbX5zggeusA=; b=dh6wp1EqOTMKyjulToF3PGpHL07c95IW5NbSt/MzdKc79pr+pw97EP00jur8k4z+yetFel /ecpknQs8C1JGX0prFLgAXXqAocf8DfCIiG3PqKscoYf56mpFm8re5II/1XciBU1k1yYS3 mlxzDJaMkZ+1kzsCR5YUOSnRgiuRFcg= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 03/18] lib/stackdepot, mm: rename stack_depot_want_early_init Date: Fri, 10 Feb 2023 22:15:51 +0100 Message-Id: <359f31bf67429a06e630b4395816a967214ef753.1676063693.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 6u36ry7ynsnk9939bxpyd4zajgbspwmu X-Rspamd-Queue-Id: 03B621C0012 X-HE-Tag: 1676063772-897998 X-HE-Meta: U2FsdGVkX1/Z9E0c47x12s7FNNl736saIqd4WlAOgYkm2Q4TwIBh6v+CATGRe/n1Wv5weYe39E7f/q5R1zeE9ph4PHH45ynB6zs4uoQ4XunEYisx+YJr30hJdh4C06S8/rc1zQueuR6PvWV90oUMXn8Cfyy4Eppytsx+3KaCjq+hd5Z3EVuzfJLNIDtRzHwQsD5SdiaZGy47KVwlm31fdeSECeO1fiszZy5lexM7dffvQ7FXV8nnvJLDMmw5Z+2kf0nnHylrXrWyEPnVEeWAFfuj4X6fWWA4bvj/DEqAQ/UJK9pZxzMk/qWkpqauAVT2Eu6EP6VDH0vhsbbWc9B6HqFqTBf3eN4ODHsEuqFrsx0nQcXfxQ6wuR9hvEemK1BEQ4TkRAoNgdCeabgaKpKTKmcCsyejQt28QRQIeohVg6iDvy6DW2MTPtjBT6OEJZRpE75zzexzNGexcstTsaxpHh/L4buLkgFdK6Fb2zwOAtwBwGROYbMw13OXyy++OptUPqBhgUY34T8oO4xtYQsvgsmvyD9yN6AgwxtZcxl3jQC6fhXYSBNxsfUjF43ssKYYSzLPc9w4Ms174L7oQwkg8uaDTY4L9YQmHxeaMB7iSzB7sSZ8WaKtmdiF0N3uh7wpsbGFSEGnMC2C3YF4T9L8C41cGx92qI3MXOv2BXpyt+Dtgpgf8ZAB9eZUtUbvhfKcCGQoxnP/aCGpaYBbebg9j01x3gW1t+ffR+AW+mNsgINyr1l0I+BWF0P/DFi/NyNgIjsvbvIxWcncccX7sxV7ZqYjuTRhoR0ixMIoAH56fPrsP9CkFXlKLzZzUxvTGhH5icHbDOvfPBqjBgB/LJk4lUxh9IXt4klo3+lCUum1flkeD3X7pQ/63EfHpHWL8SjTdkdn73Y/h6r23kO10xM63/YkWe2aZyHwwbQ4B59h4s0HsEKUCaE8GQ9GozFAV+VGD7kGZ2MEPGPzLNFL2Sx N1avE9B4 dn0UdqInLNCkSDs1K+RV3v4eJc12AsyxtwDNnzXLuxL4WSCgH3VhKVWMbuPosBZPL5GGrLxhensrmXT/pCQUjHzgvT7JArgSqhhMz7HAOHDDkQ1vPmm90HAuwiWH01wkm4nGJD/tKWpD/ZPu5dv7CJ13ZAQ== 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 Rename stack_depot_want_early_init to stack_depot_request_early_init. The old name is confusing, as it hints at returning some kind of intention of stack depot. The new name reflects that this function requests an action from stack depot instead. No functional changes. Reviewed-by: Alexander Potapenko Acked-by: Vlastimil Babka Signed-off-by: Andrey Konovalov --- include/linux/stackdepot.h | 14 +++++++------- lib/stackdepot.c | 10 +++++----- mm/page_owner.c | 2 +- mm/slub.c | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index 1296a6eeaec0..c4e3abc16b16 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -31,26 +31,26 @@ typedef u32 depot_stack_handle_t; * enabled as part of mm_init(), for subsystems where it's known at compile time * that stack depot will be used. * - * Another alternative is to call stack_depot_want_early_init(), when the + * Another alternative is to call stack_depot_request_early_init(), when the * decision to use stack depot is taken e.g. when evaluating kernel boot * parameters, which precedes the enablement point in mm_init(). * - * stack_depot_init() and stack_depot_want_early_init() can be called regardless - * of CONFIG_STACKDEPOT and are no-op when disabled. The actual save/fetch/print - * functions should only be called from code that makes sure CONFIG_STACKDEPOT - * is enabled. + * stack_depot_init() and stack_depot_request_early_init() can be called + * regardless of CONFIG_STACKDEPOT and are no-op when disabled. The actual + * save/fetch/print functions should only be called from code that makes sure + * CONFIG_STACKDEPOT is enabled. */ #ifdef CONFIG_STACKDEPOT int stack_depot_init(void); -void __init stack_depot_want_early_init(void); +void __init stack_depot_request_early_init(void); /* This is supposed to be called only from mm_init() */ int __init stack_depot_early_init(void); #else static inline int stack_depot_init(void) { return 0; } -static inline void stack_depot_want_early_init(void) { } +static inline void stack_depot_request_early_init(void) { } static inline int stack_depot_early_init(void) { return 0; } #endif diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 83787e46a3ab..136706efe339 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -71,7 +71,7 @@ struct stack_record { unsigned long entries[]; /* Variable-sized array of entries. */ }; -static bool __stack_depot_want_early_init __initdata = IS_ENABLED(CONFIG_STACKDEPOT_ALWAYS_INIT); +static bool __stack_depot_early_init_requested __initdata = IS_ENABLED(CONFIG_STACKDEPOT_ALWAYS_INIT); static bool __stack_depot_early_init_passed __initdata; static void *stack_slabs[STACK_ALLOC_MAX_SLABS]; @@ -107,12 +107,12 @@ static int __init is_stack_depot_disabled(char *str) } early_param("stack_depot_disable", is_stack_depot_disabled); -void __init stack_depot_want_early_init(void) +void __init stack_depot_request_early_init(void) { - /* Too late to request early init now */ + /* Too late to request early init now. */ WARN_ON(__stack_depot_early_init_passed); - __stack_depot_want_early_init = true; + __stack_depot_early_init_requested = true; } int __init stack_depot_early_init(void) @@ -128,7 +128,7 @@ int __init stack_depot_early_init(void) if (kasan_enabled() && !stack_hash_order) stack_hash_order = STACK_HASH_ORDER_MAX; - if (!__stack_depot_want_early_init || stack_depot_disable) + if (!__stack_depot_early_init_requested || stack_depot_disable) return 0; if (stack_hash_order) diff --git a/mm/page_owner.c b/mm/page_owner.c index 2d27f532df4c..90a4a087e6c7 100644 --- a/mm/page_owner.c +++ b/mm/page_owner.c @@ -48,7 +48,7 @@ static int __init early_page_owner_param(char *buf) int ret = kstrtobool(buf, &page_owner_enabled); if (page_owner_enabled) - stack_depot_want_early_init(); + stack_depot_request_early_init(); return ret; } diff --git a/mm/slub.c b/mm/slub.c index 13459c69095a..f2c6c356bc36 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1592,7 +1592,7 @@ static int __init setup_slub_debug(char *str) } else { slab_list_specified = true; if (flags & SLAB_STORE_USER) - stack_depot_want_early_init(); + stack_depot_request_early_init(); } } @@ -1611,7 +1611,7 @@ static int __init setup_slub_debug(char *str) out: slub_debug = global_flags; if (slub_debug & SLAB_STORE_USER) - stack_depot_want_early_init(); + stack_depot_request_early_init(); if (slub_debug != 0 || slub_debug_string) static_branch_enable(&slub_debug_enabled); else From patchwork Fri Feb 10 21:15:52 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: 13136452 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 7CE7FC05027 for ; Fri, 10 Feb 2023 21:16:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57D386B0187; Fri, 10 Feb 2023 16:16:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 54D616B0184; Fri, 10 Feb 2023 16:16:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3ECB26B0188; Fri, 10 Feb 2023 16:16:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2B6B06B0186 for ; Fri, 10 Feb 2023 16:16:15 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 06C341C6B6C for ; Fri, 10 Feb 2023 21:16:15 +0000 (UTC) X-FDA: 80452640310.06.79743E9 Received: from out-14.mta0.migadu.com (out-14.mta0.migadu.com [91.218.175.14]) by imf20.hostedemail.com (Postfix) with ESMTP id 352FA1C0004 for ; Fri, 10 Feb 2023 21:16:12 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=SbrBALja; spf=pass (imf20.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.14 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=1676063773; 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=1W2C2HZe7YWsaOly5qIInZGLXczRmh4K22qjFQ2kImw=; b=xggxK0LuTOAXZlk2HcFhNA9qlay3BP5AJrw80aB6SiG72TukPqv6XIZ53WSk9Ttr6kz1BK YZHjku9fs55Oc+Ub/b6dKeir4aD2d7fxikuEEUi4MJIVND3WrtCt37H7Rs8nj5XDtLRgPb hTYrIjTPlGqaU0JFnqtCs57rEeGj1VE= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=SbrBALja; spf=pass (imf20.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.14 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063773; a=rsa-sha256; cv=none; b=XjOwzVaqHLbAOXkSg3zMp62KZVOO2usZyHRVuQ84ey26XLjTuMvA26+m1kssgmzbIz89QO 6LI+j8d6TFlHjxuLJGtlpp7mTFFYY8pRa97BjCeQjjofZuZf0jmOYTQerjIdCMs7psh7rH b9tWPIG7gSEMnE5WwN4aqytPBb5Vbzw= 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=1676063771; 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=1W2C2HZe7YWsaOly5qIInZGLXczRmh4K22qjFQ2kImw=; b=SbrBALja+Ooglua5ZF4CpZXeCqhnn3ktsGqlo80JYGScIgCd0Ef8Sogpvh9B6KEJ1l9nbn bTrUyYzIfNYfjbYKAuyfsSFN/0AdP6+6xd5cjSKKeHV5VDBTK/njzgsYccEE+MB4tqIlLk Obf2ZoUmkwsQQEiMXFd5LJ0j55MgSt0= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 04/18] lib/stackdepot: rename stack_depot_disable Date: Fri, 10 Feb 2023 22:15:52 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 352FA1C0004 X-Stat-Signature: sojtj3adujibsord5mpxsejddyrui3q1 X-HE-Tag: 1676063772-539145 X-HE-Meta: U2FsdGVkX19zUVLGerWjVisqj6Bltiky+rVII8zJA6+QM8S/7bV5I22+5xytg1H7zyzVRT4y7J434x+wCsw2xRWa1iLCgSVfu79Q/yEN8gVutN+I8SMl0qpNDdt7TsKVl5RnUPN1WwqzMPDPsNQZCR3DHWvI9ppK1brUACEmosaFkis5JeUHVuyFdu3rgrAO+J8i1cch534SnfvK1ihSJZjUomvtQEuxKtalxjdvXp8KRZwZ+EOc2oAfRzKzK+29lWlsHTloqkalrzm3mKJICgCsNkAC3eIQ6zy5KXrfEZDfOM9xM5C0ewQ1FM1l8efa8NPD+zEM1mtSK1BWKj6P1P15vvRn604ql3E4GUuT3NOp4KIEkG3IwXFmclDvIMGhUKM9IOpwrIZXSZXRCN7o3X47jE4YHkJW8rIr9u9NhqM7585AzvhOkKTpKqVnvdySZmACmVEVYwKzD76NsZxPX0ot5ty8a5X5UBIxdzy6Ainkl+x1a72DZy2S4ThJbL8j2RuK7V++SwXI5rX04oURUGavWR+BaxIWb6SdhuPY5EDHm8UL8JAZ4czpPLHUurnA1NaQrhteEm/0WqckFnSoLyg1lOnW53J9pIqc5iTeJ/7IybB8AymS/C4oYSw2kXnUoBiP3dEnX0C0ETnxFwwtuT6UT7xIt3gx/b+Ud130me8AshjJM7XXKnwNHL59PLT9V8FQacRUtDE8Typ4J4YDYW/vegU+kibg2Muc0if+EJY2EODrrkvE2rul47BArOfGeagMJlRNjCbMCq4mlN749fFTgNKCxv8SiT//Fcag8I9tbQjQR5VLOQGKocmCyyuN1Yc9oyugz+QbxppcWekChwklZAbwTzeYGYld3VEaNRrNrgpHrU5vF6dC8cjc0q89qE3CEzp9DgFnwkY5UP0AsWIzjuDECYMBGYMXq2+hCGd2RTVNMHxLS7wwVuKryXP9yYe6F0KblGS2k6Muq3s lYpFFUO4 h4D/1EkG0ZTL8IFGapS0PDr6HBzfx0uL2f4wdJ5pl3i2F/Ca4ebJfqIJKmPgclZfJ8ojCVJldLR0dROhO4MLMkMZ0yFYmwUs6YyIDhRq6eNhtDrSGGzPWOIwURQbNH34Kt645zM7wxawiO0UWutX4qjy3fg== 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 Rename stack_depot_disable to stack_depot_disabled to make its name look similar to the names of other stack depot flags. Also put stack_depot_disabled's definition together with the other flags. Also rename is_stack_depot_disabled to disable_stack_depot: this name looks more conventional for a function that processes a boot parameter. No functional changes. Reviewed-by: Alexander Potapenko Signed-off-by: Andrey Konovalov --- lib/stackdepot.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 136706efe339..202e07c4f02d 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -71,6 +71,7 @@ struct stack_record { unsigned long entries[]; /* Variable-sized array of entries. */ }; +static bool stack_depot_disabled; static bool __stack_depot_early_init_requested __initdata = IS_ENABLED(CONFIG_STACKDEPOT_ALWAYS_INIT); static bool __stack_depot_early_init_passed __initdata; @@ -91,21 +92,20 @@ static DEFINE_RAW_SPINLOCK(depot_lock); static unsigned int stack_hash_order; static unsigned int stack_hash_mask; -static bool stack_depot_disable; static struct stack_record **stack_table; -static int __init is_stack_depot_disabled(char *str) +static int __init disable_stack_depot(char *str) { int ret; - ret = kstrtobool(str, &stack_depot_disable); - if (!ret && stack_depot_disable) { + ret = kstrtobool(str, &stack_depot_disabled); + if (!ret && stack_depot_disabled) { pr_info("disabled\n"); stack_table = NULL; } return 0; } -early_param("stack_depot_disable", is_stack_depot_disabled); +early_param("stack_depot_disable", disable_stack_depot); void __init stack_depot_request_early_init(void) { @@ -128,7 +128,7 @@ int __init stack_depot_early_init(void) if (kasan_enabled() && !stack_hash_order) stack_hash_order = STACK_HASH_ORDER_MAX; - if (!__stack_depot_early_init_requested || stack_depot_disable) + if (!__stack_depot_early_init_requested || stack_depot_disabled) return 0; if (stack_hash_order) @@ -145,7 +145,7 @@ int __init stack_depot_early_init(void) if (!stack_table) { pr_err("hash table allocation failed, disabling\n"); - stack_depot_disable = true; + stack_depot_disabled = true; return -ENOMEM; } @@ -158,7 +158,7 @@ int stack_depot_init(void) int ret = 0; mutex_lock(&stack_depot_init_mutex); - if (!stack_depot_disable && !stack_table) { + if (!stack_depot_disabled && !stack_table) { unsigned long entries; int scale = STACK_HASH_SCALE; @@ -184,7 +184,7 @@ int stack_depot_init(void) stack_table = kvcalloc(entries, sizeof(struct stack_record *), GFP_KERNEL); if (!stack_table) { pr_err("hash table allocation failed, disabling\n"); - stack_depot_disable = true; + stack_depot_disabled = true; ret = -ENOMEM; } stack_hash_mask = entries - 1; @@ -353,7 +353,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, */ nr_entries = filter_irq_stacks(entries, nr_entries); - if (unlikely(nr_entries == 0) || stack_depot_disable) + if (unlikely(nr_entries == 0) || stack_depot_disabled) goto fast_exit; hash = hash_stack(entries, nr_entries); From patchwork Fri Feb 10 21:15:53 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: 13136454 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 2701BC636D4 for ; Fri, 10 Feb 2023 21:16:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21C126B0188; Fri, 10 Feb 2023 16:16:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A3256B018A; Fri, 10 Feb 2023 16:16:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 01C616B018B; Fri, 10 Feb 2023 16:16:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E1BE26B0188 for ; Fri, 10 Feb 2023 16:16:15 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A9DAC121218 for ; Fri, 10 Feb 2023 21:16:15 +0000 (UTC) X-FDA: 80452640310.27.76A236B Received: from out-35.mta0.migadu.com (out-35.mta0.migadu.com [91.218.175.35]) by imf17.hostedemail.com (Postfix) with ESMTP id D88EB40011 for ; Fri, 10 Feb 2023 21:16:13 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=NMUMtEuq; spf=pass (imf17.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.35 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=1676063774; 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=b3Y1ZbtnHRjNaHONV9sUdyWjn+clMFk+2c4Skh5NOGM=; b=I7tCIOsKJwmq/x/ovFHwn79uVITyJsDex4vCSTJVplZ7pybg2TDNXHEkRwGH0pZAJM1S0y 4R5p4oWlge0nDlhCeLO3MqiRBhL0nsyu303FX7iPfqP3JOyEqdqKq1W5Zx6dJIEgbntHlG Dt7MirBBTjIaWDY8SDikrjvBRVLvrd4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=NMUMtEuq; spf=pass (imf17.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.35 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063774; a=rsa-sha256; cv=none; b=Mr8NbLwskJadUdf0Hr/v/V3PnWsCJDuepoCImNav8+09kMkwEpd2zZpPmRlx4cpfHd/jz9 2MUm6vyoNl7UDhbxeKPVruoITIfkRJ07ANqsOIidC9/g23uBdqtesgKN88JkBLF/cn0o4G SUBrL+NgUWq+enfxBiePYxRsJSrU0b0= 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=1676063772; 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=b3Y1ZbtnHRjNaHONV9sUdyWjn+clMFk+2c4Skh5NOGM=; b=NMUMtEuqwG0vlR2vqyaN6nCSOlFMRLLh2rBnX4ez3xSLDuXFeviXMGAoN1X/Gw8TaR2kMk vtoOxPtdDghv1NP+wPb2bGmxgUWe7yTaTqOfl3aWDVxPWgAJOi9o7DnwQMwnwQ9VH1Oy9s +feNTY56vXN778kgFVfIUPPpUMerwac= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 05/18] lib/stackdepot: annotate init and early init functions Date: Fri, 10 Feb 2023 22:15:53 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D88EB40011 X-Stat-Signature: dcgbymnropekrpedq1h6tqqi8ezrtgxr X-Rspam-User: X-HE-Tag: 1676063773-997221 X-HE-Meta: U2FsdGVkX18Xf71INR+qpDOwB97kKEtFTnWPyT0yBFOz7nzCRBtmWjkq4/rEsKI11p3qxWkIPUrEn+dbwZOEgMhn1JyVPmwwcChJ/q2daDVkwDMSQcAayiwF4tQa4DPD9Z6Ad+UrSINeIB/06KD7i0MOm8miaesndTRKRN1xiSaIqcRgGp2OPBgnNNwqHp+jpwyJAbPTzozxpEQ0h6rzgELwwKdksyV5XtG0IDlRFGEowyLQk6qatPO3qNHh+yTmUp4iZC+bWs/ADCABkL2xUZeTl6oXi3VhWcdh9Ltk4cV1MGnfkHNkraESyWNQjZpMu+qk54bxVUS7dz1WujKfCOJeVUDJ6mUB77BMDaPttcJpJLaGy3kTe3DKLgWG67Ctnss850D4oSunmWTim3zXYvbpD0vZX52swZXxDc5Opke92xUwmvN07VkvpGS61v0Du5GhPomprLmrOZD0xPBjUwTeXbQ3EDdXp1kEnkmxjvVP5q8rQD6uZR0zzY+Fd1UfTjaFAlmirEqFxgIMJPq6D2SauJNk5R4MSOoShuENmHPQNn0so9XzXwCmUqNShUyM9RjDQ7em71YmgixlWwCvyWl0nu/GOEOcc4Ja6Q1ZZDjGgG4Aud6wwH4vf5JgVTQd3xP/PrZ2Zlkp2bZnAEf30BCgrGboHLw7o4x3GPop6WcJYDnEK//zv+UoY7GxfmuCX1QbLvzkdRUr6Flvd00EVfsVq2NRTG3d7RLKYvlFVkJFi+BzLEoc9HaOv2OKSW87SaooZywmflK6XrrzRTDdgUIMaSK60lr3OkNeQ9Rok6K2j4nlxyhb9ul9FkxlnVg6tAHBKMJqKRWbsz7FpDFe7lg+taoBo38JFmtoFFuv3gpCQVj7yg6veGlB3htDdvq8yliJWnA4WDLSw0JH3VvtsudokCHrU7N1fSQ/k9EZXMCpoIObJ8/y8ABhgCUHCZmQJx7zzWwCYNyHAwUtfJs q7qibGSu UW0SsEspY6FFy8HdeHNCSTclzl+scG+AsfMQCFcgpF020Bo3w+avb4I0ZXME3D7S8QaQjf4jI/iSqsnWrHZob//NTVPJJtKqs/g9A 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 comments to stack_depot_early_init and stack_depot_init to explain certain parts of their implementation. Also add a pr_info message to stack_depot_early_init similar to the one in stack_depot_init. Also move the scale variable in stack_depot_init to the scope where it is being used. Reviewed-by: Alexander Potapenko Signed-off-by: Andrey Konovalov --- lib/stackdepot.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 202e07c4f02d..9fab711e4826 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -115,24 +115,34 @@ void __init stack_depot_request_early_init(void) __stack_depot_early_init_requested = true; } +/* Allocates a hash table via memblock. Can only be used during early boot. */ int __init stack_depot_early_init(void) { unsigned long entries = 0; - /* This is supposed to be called only once, from mm_init() */ + /* This function must be called only once, from mm_init(). */ if (WARN_ON(__stack_depot_early_init_passed)) return 0; - __stack_depot_early_init_passed = true; + /* + * If KASAN is enabled, use the maximum order: KASAN is frequently used + * in fuzzing scenarios, which leads to a large number of different + * stack traces being stored in stack depot. + */ if (kasan_enabled() && !stack_hash_order) stack_hash_order = STACK_HASH_ORDER_MAX; if (!__stack_depot_early_init_requested || stack_depot_disabled) return 0; + /* + * If stack_hash_order is not set, leave entries as 0 to rely on the + * automatic calculations performed by alloc_large_system_hash. + */ if (stack_hash_order) - entries = 1UL << stack_hash_order; + entries = 1UL << stack_hash_order; + pr_info("allocating hash table via alloc_large_system_hash\n"); stack_table = alloc_large_system_hash("stackdepot", sizeof(struct stack_record *), entries, @@ -142,7 +152,6 @@ int __init stack_depot_early_init(void) &stack_hash_mask, 1UL << STACK_HASH_ORDER_MIN, 1UL << STACK_HASH_ORDER_MAX); - if (!stack_table) { pr_err("hash table allocation failed, disabling\n"); stack_depot_disabled = true; @@ -152,6 +161,7 @@ int __init stack_depot_early_init(void) return 0; } +/* Allocates a hash table via kvcalloc. Can be used after boot. */ int stack_depot_init(void) { static DEFINE_MUTEX(stack_depot_init_mutex); @@ -160,11 +170,16 @@ int stack_depot_init(void) mutex_lock(&stack_depot_init_mutex); if (!stack_depot_disabled && !stack_table) { unsigned long entries; - int scale = STACK_HASH_SCALE; + /* + * Similarly to stack_depot_early_init, use stack_hash_order + * if assigned, and rely on automatic scaling otherwise. + */ if (stack_hash_order) { entries = 1UL << stack_hash_order; } else { + int scale = STACK_HASH_SCALE; + entries = nr_free_buffer_pages(); entries = roundup_pow_of_two(entries); @@ -179,7 +194,7 @@ int stack_depot_init(void) if (entries > 1UL << STACK_HASH_ORDER_MAX) entries = 1UL << STACK_HASH_ORDER_MAX; - pr_info("allocating hash table of %lu entries with kvcalloc\n", + pr_info("allocating hash table of %lu entries via kvcalloc\n", entries); stack_table = kvcalloc(entries, sizeof(struct stack_record *), GFP_KERNEL); if (!stack_table) { From patchwork Fri Feb 10 21:15:54 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: 13136455 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 7C152C05027 for ; Fri, 10 Feb 2023 21:17:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A3646B018A; Fri, 10 Feb 2023 16:17:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 153426B018C; Fri, 10 Feb 2023 16:17:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0432C6B018D; Fri, 10 Feb 2023 16:17:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E83526B018A for ; Fri, 10 Feb 2023 16:17:17 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BE233AB880 for ; Fri, 10 Feb 2023 21:17:17 +0000 (UTC) X-FDA: 80452642914.23.30E54D3 Received: from out-147.mta1.migadu.com (out-147.mta1.migadu.com [95.215.58.147]) by imf04.hostedemail.com (Postfix) with ESMTP id 0AA7B40003 for ; Fri, 10 Feb 2023 21:17:15 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=oyhVeDaz; spf=pass (imf04.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.147 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063836; a=rsa-sha256; cv=none; b=I6uIhrg9JeUn/+rutcKviN1CDQd53Zjd72YN4sLaJN1V6caAFYfos8SjVcNjNXvEm3Q0WW daWRA8IYs5nNPZGg+027D5hJB7zzzefX5nyTdV0a72LDkLq+dijOnDZRIPMMh6Z8u92egf GuL9dN+YieRhSB/If3kmvAIHNmc96KM= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=oyhVeDaz; spf=pass (imf04.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.147 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=1676063836; 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=f9A90r0/KX/Fhu2j5j2j+xtwq4a98UiE0RWErOhidkA=; b=DkhZeSMbR2Ob2+QSVO/QsKUHOGJDyvkJSLf6uKQtRsXJhW0BASx8D5hNBKcjCRj5BlwWg+ l3D9vehzIfd2NUbKkJWb8AK19D5uo5NdFOXxw6naRWW2CXDADbGKUZSjZNmsn6el5JhUQN yYCTLzb6tko3dgsEYclvzS6wH0O0VOc= 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=1676063833; 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=f9A90r0/KX/Fhu2j5j2j+xtwq4a98UiE0RWErOhidkA=; b=oyhVeDazZBut0ST4TNl1RQwS/DL0yrlLv1E7JYFnymtKhHMiB0u4WihfIpRSbWuByfnfY8 ZL4ITqwDVRl0DLjQnKz5Wxc8IJHpjd/MW8dfSTAoazs2uZDQVgNmsTC1x8YcK2CMWQLY8D suYeEvzU/sxSRp/4iLW7FSTp/J4Bl7s= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 06/18] lib/stackdepot: lower the indentation in stack_depot_init Date: Fri, 10 Feb 2023 22:15:54 +0100 Message-Id: <8e382f1f0c352e4b2ad47326fec7782af961fe8e.1676063693.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Queue-Id: 0AA7B40003 X-Rspamd-Server: rspam01 X-Stat-Signature: ggu1oncpy31b6iw6c94jjx1tmaozwimn X-HE-Tag: 1676063835-586352 X-HE-Meta: U2FsdGVkX1/MA9eJwvxa04ik2f8mPPbxC/iKLt2vRiJ33sq+3n/Cm3MSKo5nLjtg2xmavxA7Z9sm9sHp8bkmsm5Ji073Pgku/ZowPEWrw/OG1kOFE2RQ2VAf8a7Imipv8IM/Y5TD7IfsXVSL3MGJ/HpPstK0tYxkwIrZgQd53xXaSRwc4uH9DiPDWFQBCvuxXq+b8u4jm353KxwK1EHEP8wS4fUFnAivBGhfQbGcWvlTV9Ktw01tnh0uR0YtmWcvKdb5yM7wQOok6YTkbqRMfeJZWst86+dc6ezFBiVNQPg2hGw180Fc9XyCbsOSBZYLWwvm+CvPZgrxbcW/J/06r7qttZXASlY+6vFhdHkjEMl6hNCSz+b5DG4FBkHp4fDu3Dv+XOnnjLa+OY27nZC4AmzpAB5SVEojVv2Ius1ApI4NoA3AhPMiuoZ87/Eo48EcpPxF9MbqKW/tcLgn9DuVGG1qsp790bKfiEjvLdD3Vh2bROA8SLxox3raQXTBLML3dk8BVTqJiKdM3dlyKY6oMfAAxSjRBQOjtyK2saqjfqg3iZi3R3ajUG0+YbfQWg1cpaPN1m99cVHUsutKekmFjy+rIaZD5k0qpxwUdHaLWbxpks5ny/7p/p5Znh7xEbMvX2OPXuoz5QsDLlAJgRpJsAhiVt4vy9v35phkT4G0NrEJH7L+BGcuFHgh4NKOS8I7VDvZotpulLrjLdRPbfAzCNNoA+h+Fcfx3QRN3NTEX98dKoUq3v6auQI4f7nJz+huqfz1AY4LqWywQ7xByq3OT54br3MmSS/0RwvkzhHhRM4mzNmgNLDaJypRmHmHZ+nNqGjVTZqAROb+5lP4gthSBn1ToZwFBH452V8WYqHLzXn557s5VfvsUUSAyRAOz03ESfPN9E8nRK1hUgl4n1UFLY7KJlMxr8EsXkpMaroRfjFfG554v14DMsYT0kpxeBHUnf5+yr3IhAVwmAxhiK+ fcWR7TXd Yfmh3mt8y/H0JCFenD2J9RrJq82xuAmi3wTAE+8WCz5rcMUqDWS4AwpLEnrSe2lqJgdAqB33RZo1A1BNCzOzRElOvLTWVY6YLwvet7FT2eCUoZNt0ynPKB+NQLwUikQsAOpSOqW9iD+wt2pbJmzrPifMBZw== 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 stack_depot_init does most things inside an if check. Move them out and use a goto statement instead. No functional changes. Reviewed-by: Alexander Potapenko Signed-off-by: Andrey Konovalov --- lib/stackdepot.c | 70 +++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 9fab711e4826..3c713f70b0a3 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -165,46 +165,50 @@ int __init stack_depot_early_init(void) int stack_depot_init(void) { static DEFINE_MUTEX(stack_depot_init_mutex); + unsigned long entries; int ret = 0; mutex_lock(&stack_depot_init_mutex); - if (!stack_depot_disabled && !stack_table) { - unsigned long entries; - /* - * Similarly to stack_depot_early_init, use stack_hash_order - * if assigned, and rely on automatic scaling otherwise. - */ - if (stack_hash_order) { - entries = 1UL << stack_hash_order; - } else { - int scale = STACK_HASH_SCALE; - - entries = nr_free_buffer_pages(); - entries = roundup_pow_of_two(entries); - - if (scale > PAGE_SHIFT) - entries >>= (scale - PAGE_SHIFT); - else - entries <<= (PAGE_SHIFT - scale); - } + if (stack_depot_disabled || stack_table) + goto out_unlock; - if (entries < 1UL << STACK_HASH_ORDER_MIN) - entries = 1UL << STACK_HASH_ORDER_MIN; - if (entries > 1UL << STACK_HASH_ORDER_MAX) - entries = 1UL << STACK_HASH_ORDER_MAX; - - pr_info("allocating hash table of %lu entries via kvcalloc\n", - entries); - stack_table = kvcalloc(entries, sizeof(struct stack_record *), GFP_KERNEL); - if (!stack_table) { - pr_err("hash table allocation failed, disabling\n"); - stack_depot_disabled = true; - ret = -ENOMEM; - } - stack_hash_mask = entries - 1; + /* + * Similarly to stack_depot_early_init, use stack_hash_order + * if assigned, and rely on automatic scaling otherwise. + */ + if (stack_hash_order) { + entries = 1UL << stack_hash_order; + } else { + int scale = STACK_HASH_SCALE; + + entries = nr_free_buffer_pages(); + entries = roundup_pow_of_two(entries); + + if (scale > PAGE_SHIFT) + entries >>= (scale - PAGE_SHIFT); + else + entries <<= (PAGE_SHIFT - scale); } + + if (entries < 1UL << STACK_HASH_ORDER_MIN) + entries = 1UL << STACK_HASH_ORDER_MIN; + if (entries > 1UL << STACK_HASH_ORDER_MAX) + entries = 1UL << STACK_HASH_ORDER_MAX; + + pr_info("allocating hash table of %lu entries via kvcalloc\n", entries); + stack_table = kvcalloc(entries, sizeof(struct stack_record *), GFP_KERNEL); + if (!stack_table) { + pr_err("hash table allocation failed, disabling\n"); + stack_depot_disabled = true; + ret = -ENOMEM; + goto out_unlock; + } + stack_hash_mask = entries - 1; + +out_unlock: mutex_unlock(&stack_depot_init_mutex); + return ret; } EXPORT_SYMBOL_GPL(stack_depot_init); From patchwork Fri Feb 10 21:15:55 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: 13136458 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 D5FDAC6379F for ; Fri, 10 Feb 2023 21:17:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5EBAC6B0190; Fri, 10 Feb 2023 16:17:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 574476B0191; Fri, 10 Feb 2023 16:17:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 32FFA6B0193; Fri, 10 Feb 2023 16:17:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0F3856B0191 for ; Fri, 10 Feb 2023 16:17:19 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DFC1EA1180 for ; Fri, 10 Feb 2023 21:17:18 +0000 (UTC) X-FDA: 80452642956.13.74E10A6 Received: from out-198.mta1.migadu.com (out-198.mta1.migadu.com [95.215.58.198]) by imf02.hostedemail.com (Postfix) with ESMTP id 2C17D8001E for ; Fri, 10 Feb 2023 21:17:15 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="gCrR/J+B"; spf=pass (imf02.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.198 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063836; a=rsa-sha256; cv=none; b=3DC2kcmE2ers4E88MXkD9qH/VzSLEUOreaArXH8xXfpW7Km5mr7sL6IyFie6B22GJkz0cj feg2NaC43MhbjHiY5/f01AvMgQl0GXr6adGetxQCfHR0gF2U9rRIc0So4BWL2T2TuHtrnS szZ55EaS66CDFlqq7/4P7t9NHEPuTms= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="gCrR/J+B"; spf=pass (imf02.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.198 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=1676063836; 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=IMmtEbwX6SEFFs7KeDaMCDunDTh7JDSXGutwuFTHEE4=; b=bvmMwMoAyKwTwek6JtdKArCE0Iwp8UyAI6FWviKiprTwLEZ80u0pL/0MxeRKmOqTJfJVHa 9BINno1JjOC6iwOZflXKyCKVrZ/YKJmKSf9M95Dvhbf4WnMQyzrONnrNtgx46fQCv5OGfm bJQIim2hynrcM4DCBoFsimBkkJ7gBa4= 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=1676063834; 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=IMmtEbwX6SEFFs7KeDaMCDunDTh7JDSXGutwuFTHEE4=; b=gCrR/J+BL8uRipK+1P9oz0iyvJaqaAsbV6wrhymIwhr711MIK77R5Rm//kctV9oSok7pb7 peWTsywOV6H6eTgzHOJLcPPKMIOiPJt9TZzJeiLrcDJVV6iCUitSNz8en5c/vesUMIL5LW gej1rXj6zjHhtOWEii8sTUmmez6Agco= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 07/18] lib/stackdepot: reorder and annotate global variables Date: Fri, 10 Feb 2023 22:15:55 +0100 Message-Id: <5606a6c70659065a25bee59cd10e57fc60bb4110.1676063693.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Queue-Id: 2C17D8001E X-Rspamd-Server: rspam01 X-Stat-Signature: mrwkgyqzf9asetkxxehnctmm54qc9df5 X-HE-Tag: 1676063835-558619 X-HE-Meta: U2FsdGVkX19hhr3JGC/ZHMIPGqOK4Sxg0ptAi2y1VvCAsneO54W7+pzvsjJnrOdKp9eS8nQmwAybQYNhBVzvz9WQBrqnIzx3Akxj/YZtBIPQyXcRcW1lc0vRz/7k05FrlVuWGYjLUJwDGR6GM8vhaRi4ypTTlFyhs0xMz0wzuzzmc5N0bdFkhsqhqbusDRdCJpx30xxsp/KHEDy9Tfftygv+UQ1gAfQjXg5ovLPvM7jdrm9LyK5AuzM24AhMuQIgF/MK8QJrmRs8DD9Xc/rTXERtEVOcytLNdRNY4ZrToB91CO5u5d0kJGe5tRZSQXoObMQFG1WcSHV5XDpLS1UIKok8lS5eAN6cL1GbWf49CzzeCjJUfD6wkjpxK819SIxl/FpIh814NRPzY3B0Tqz4b7/cKDomCe10fmo3BvEvIKkNFFmLu5eGjYja3ebBu53xAJUw9+H6a09epSfEozXMIxBNEsA8AoG1rq82Z2K8iyzZFzDZm9Q7hR6xFPoMNm+H7Vkgt79Hvo1Sb09h/IrpXRM/6YJN/JvjMHPeVQiSZfPoMm6B51T7QFY4DFwBip3EyJbJ9dlCaGPHf/Uw60TeO9PbXYsBwuRb5avKYC4PE1LY0KOg9Z1XaAGfRyWw+FDnVZPLCwgc0yDluoNFqr5j8mgPCUPe7cQNxgI/jeiv9yWeVc1BLmlSQROEIcxe7PPEmrWGm/8BYZFGaF2yu/j2TIhzs0g/ep1B4qjqkAD/odlgx6zYWtxnXXJNVFbDLoein7jsD5DhqZVoPQd4MEQpAx9NPkLm0TqbC5dHfnbC6qiI0WYyMrUwbDReSnWbP6797OJfD8OC/w5q7eUTGjp0aMeRV0kiIh+Z++Wu6swihE9+miHUsJr9B20KeUEWyyeWGNlsudByDMPaUwnj0MBFPdckZdoQxwWnJZ2T6vDJy9thGPt6g4c0LMbwMZolN0by96fIqdOWMDYN3c0d6AD Pq+Hmpre GumQU3htt8OjBXVJGqRLXkSOhcKBpkqkCucnc7BhFcaAhWdZGakAL6Et6GO2CEK1N2WgdhGV1OvgoLLz77f9bm335IVkAvooAUmPpJUyAvhYw9aw= 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 Group stack depot global variables by their purpose: 1. Hash table-related variables, 2. Slab-related variables, and add comments. Also clean up comments for hash table-related constants. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 3c713f70b0a3..de1afe3fb24d 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -75,24 +75,31 @@ static bool stack_depot_disabled; static bool __stack_depot_early_init_requested __initdata = IS_ENABLED(CONFIG_STACKDEPOT_ALWAYS_INIT); static bool __stack_depot_early_init_passed __initdata; -static void *stack_slabs[STACK_ALLOC_MAX_SLABS]; - -static int depot_index; -static int next_slab_inited; -static size_t depot_offset; -static DEFINE_RAW_SPINLOCK(depot_lock); - -/* one hash table bucket entry per 16kB of memory */ +/* Use one hash table bucket per 16 KB of memory. */ #define STACK_HASH_SCALE 14 -/* limited between 4k and 1M buckets */ +/* Limit the number of buckets between 4K and 1M. */ #define STACK_HASH_ORDER_MIN 12 #define STACK_HASH_ORDER_MAX 20 +/* Initial seed for jhash2. */ #define STACK_HASH_SEED 0x9747b28c +/* Hash table of pointers to stored stack traces. */ +static struct stack_record **stack_table; +/* Fixed order of the number of table buckets. Used when KASAN is enabled. */ static unsigned int stack_hash_order; +/* Hash mask for indexing the table. */ static unsigned int stack_hash_mask; -static struct stack_record **stack_table; +/* Array of memory regions that store stack traces. */ +static void *stack_slabs[STACK_ALLOC_MAX_SLABS]; +/* Currently used slab in stack_slabs. */ +static int depot_index; +/* Offset to the unused space in the currently used slab. */ +static size_t depot_offset; +/* Lock that protects the variables above. */ +static DEFINE_RAW_SPINLOCK(depot_lock); +/* Whether the next slab is initialized. */ +static int next_slab_inited; static int __init disable_stack_depot(char *str) { From patchwork Fri Feb 10 21:15:56 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: 13136456 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 259ACC636D4 for ; Fri, 10 Feb 2023 21:17:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA58D6B018C; Fri, 10 Feb 2023 16:17:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 969966B018E; Fri, 10 Feb 2023 16:17:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8323F6B018F; Fri, 10 Feb 2023 16:17:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 734286B018C for ; Fri, 10 Feb 2023 16:17:18 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3E9474125F for ; Fri, 10 Feb 2023 21:17:18 +0000 (UTC) X-FDA: 80452642956.15.515A509 Received: from out-223.mta1.migadu.com (out-223.mta1.migadu.com [95.215.58.223]) by imf22.hostedemail.com (Postfix) with ESMTP id 4A52DC0012 for ; Fri, 10 Feb 2023 21:17:15 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=c+1AHXrK; spf=pass (imf22.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.223 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=1676063836; 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=GEKMsp8Q42qNZP01Wy8jBcM+2lagQkM9mc2pThcVWag=; b=J2GKq+85mhHVsqS9SQ90lveMPuQ4c/LkKt/rW8YAjehcUZusm/LNJGxHuqsABympRedvdI 9I6we8xEaf8rloFbjMeYbHP2YJ7TOPN38NjAPYToK1clKYAvJ2yuiARj2+9IZSceyeAgEo IaZsqbEuqTwFMJ7K2XUReM9cIgDTC6Y= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=c+1AHXrK; spf=pass (imf22.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.223 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063836; a=rsa-sha256; cv=none; b=kZQeFbyqiQGdIwaAlycxPUIgWKpe1d1Riv21bV5PWtVzxlqdH27Ut/GGkuO514JvG1xtzX 8EozSUwVS34vIXbZz7vmjqlTTqQ7nfMj4MTiGXItkc1Ex6lcwSSOzgcADR8y7gwzeE4yKs aeOCW7Fdow5ZmrSwlzmb0/49GdpEwI0= 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=1676063834; 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=GEKMsp8Q42qNZP01Wy8jBcM+2lagQkM9mc2pThcVWag=; b=c+1AHXrKHUEP1+bsNrE9ZwOjSb/qQQiGk2OxmWYCZ8OMAfHwDap2ap2QjPrAyQKgJaVNpk t5NCczUJqVa0kDs1WFAq8iet967tqgR9YBckizmQ28+6qrCOK9T0sdvJgs3Uvs6IURwelC 6z3t4aQyjMsr+yK+IdYsE2bJpkl5puw= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 08/18] lib/stackdepot: rename hash table constants and variables Date: Fri, 10 Feb 2023 22:15:56 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: 33fhufm5w63jgoies1mcuaf7th9zuisc X-Rspam-User: X-Rspamd-Queue-Id: 4A52DC0012 X-Rspamd-Server: rspam06 X-HE-Tag: 1676063835-597769 X-HE-Meta: U2FsdGVkX1+dAFhYK7YNF4ahvYxLuhquQoX5poMS3k00crGuS4yYRL1wMYvoWIagPBLDlV2jR/BJVDzGiF8wB0dxZB8LRjRnT3zKYiYHGJmFd7zSSSR2H0z5ocytwfHl4kc98EaGHOBb1JcZKI/QFvnze5q9Fi60xSodcY3dyaQ+KRPy/ufsS845ylWIYmG5y0x1ziskXXS+N60y2ilddAMQA96qW8cHC7MR6J7ov28ntARJJ8iVY4/DaaQb5KO7zCrAHoRjR8obS1SA1COfBfsLHO+NDP5Cms9w/40fVUEWwr3ux4YUvvDUDssJML/hRXalS5/zOJHZsF8cPkCdXx+3gUV7Kl/jjNwzIiyg08qny6+PqYdxJ/L1W4Xu2iZZc0aKzQY/x/IaqrSHl7izFzjN8OK+Kvl4Su0ZH8gkHi1hZ5VWyWX8Reg6rwlIbdMEhg3QSkJR+pZ9/1zebp58K+9FAzqsL8u8dMOvsoOSY8PRn6ZrdwM/DhWpaniVmMWfTCH8lJiZkkN+FigRYV+L+4Ojn7INtR8wGzyF8fFVQ0OFSBqzHwabendFHKJ8y0Tn2xyXzGXA64u/z84z7XN9QD8fYEfS0HPEDFAkXtZEjTJWkFl8TMCMbfsMH1vjJ0WcGzIApu5wHCkzr3K2F1WlapeldSjtbqpmAVPWyHHTusAPbvqj9N6u9/AI5f7ZFKI/NOA+F27UvexcjgdgqfZemP2cZXUSj9ngq/Ay3CtEd4BnA6LV5Cf1bnsDJx/49/GRDmRwP8B3HvT5fvNR3yz+HWJuvU3fMiW7ZfkpP+Rc+0fcYQ4Jz2MDDsVIAJUb8REBwe60VODh7X0KmPQujQDMagLDVLbngc/0B2jQovBMMidR1XOgTt2KOauuSo6xV0ypE/D8NX1zWp0SfiE4rmwxJalZXB4Zy4a4k8gywLQ63mxJZCf7HNxt0fFai85qrTtqykHhVdWLsVAOmKY8kSd fvUs7O5v 7BKyWLfUAnAJFeKEHwLSQo6DCQEY0JTv5KgktA+VCZNCq6+K7DPtU+JasKkgENLpC7vDYAaZtFa/g/gv8BpJsQHnC32X6S1Vlnksu 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 Give more meaningful names to hash table-related constants and variables: 1. Rename STACK_HASH_SCALE to STACK_HASH_TABLE_SCALE to point out that it is related to scaling the hash table. 2. Rename STACK_HASH_ORDER_MIN/MAX to STACK_BUCKET_NUMBER_ORDER_MIN/MAX to point out that it is related to the number of hash table buckets. 3. Rename stack_hash_order to stack_bucket_number_order for the same reason as #2. No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- Changes v1->v2: - Rename STACK_HASH_SCALE to STACK_HASH_TABLE_SCALE. --- lib/stackdepot.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index de1afe3fb24d..d1ab53197353 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -76,17 +76,17 @@ static bool __stack_depot_early_init_requested __initdata = IS_ENABLED(CONFIG_ST static bool __stack_depot_early_init_passed __initdata; /* Use one hash table bucket per 16 KB of memory. */ -#define STACK_HASH_SCALE 14 +#define STACK_HASH_TABLE_SCALE 14 /* Limit the number of buckets between 4K and 1M. */ -#define STACK_HASH_ORDER_MIN 12 -#define STACK_HASH_ORDER_MAX 20 +#define STACK_BUCKET_NUMBER_ORDER_MIN 12 +#define STACK_BUCKET_NUMBER_ORDER_MAX 20 /* Initial seed for jhash2. */ #define STACK_HASH_SEED 0x9747b28c /* Hash table of pointers to stored stack traces. */ static struct stack_record **stack_table; /* Fixed order of the number of table buckets. Used when KASAN is enabled. */ -static unsigned int stack_hash_order; +static unsigned int stack_bucket_number_order; /* Hash mask for indexing the table. */ static unsigned int stack_hash_mask; @@ -137,28 +137,28 @@ int __init stack_depot_early_init(void) * in fuzzing scenarios, which leads to a large number of different * stack traces being stored in stack depot. */ - if (kasan_enabled() && !stack_hash_order) - stack_hash_order = STACK_HASH_ORDER_MAX; + if (kasan_enabled() && !stack_bucket_number_order) + stack_bucket_number_order = STACK_BUCKET_NUMBER_ORDER_MAX; if (!__stack_depot_early_init_requested || stack_depot_disabled) return 0; /* - * If stack_hash_order is not set, leave entries as 0 to rely on the - * automatic calculations performed by alloc_large_system_hash. + * If stack_bucket_number_order is not set, leave entries as 0 to rely + * on the automatic calculations performed by alloc_large_system_hash. */ - if (stack_hash_order) - entries = 1UL << stack_hash_order; + if (stack_bucket_number_order) + entries = 1UL << stack_bucket_number_order; pr_info("allocating hash table via alloc_large_system_hash\n"); stack_table = alloc_large_system_hash("stackdepot", sizeof(struct stack_record *), entries, - STACK_HASH_SCALE, + STACK_HASH_TABLE_SCALE, HASH_EARLY | HASH_ZERO, NULL, &stack_hash_mask, - 1UL << STACK_HASH_ORDER_MIN, - 1UL << STACK_HASH_ORDER_MAX); + 1UL << STACK_BUCKET_NUMBER_ORDER_MIN, + 1UL << STACK_BUCKET_NUMBER_ORDER_MAX); if (!stack_table) { pr_err("hash table allocation failed, disabling\n"); stack_depot_disabled = true; @@ -181,13 +181,13 @@ int stack_depot_init(void) goto out_unlock; /* - * Similarly to stack_depot_early_init, use stack_hash_order + * Similarly to stack_depot_early_init, use stack_bucket_number_order * if assigned, and rely on automatic scaling otherwise. */ - if (stack_hash_order) { - entries = 1UL << stack_hash_order; + if (stack_bucket_number_order) { + entries = 1UL << stack_bucket_number_order; } else { - int scale = STACK_HASH_SCALE; + int scale = STACK_HASH_TABLE_SCALE; entries = nr_free_buffer_pages(); entries = roundup_pow_of_two(entries); @@ -198,10 +198,10 @@ int stack_depot_init(void) entries <<= (PAGE_SHIFT - scale); } - if (entries < 1UL << STACK_HASH_ORDER_MIN) - entries = 1UL << STACK_HASH_ORDER_MIN; - if (entries > 1UL << STACK_HASH_ORDER_MAX) - entries = 1UL << STACK_HASH_ORDER_MAX; + if (entries < 1UL << STACK_BUCKET_NUMBER_ORDER_MIN) + entries = 1UL << STACK_BUCKET_NUMBER_ORDER_MIN; + if (entries > 1UL << STACK_BUCKET_NUMBER_ORDER_MAX) + entries = 1UL << STACK_BUCKET_NUMBER_ORDER_MAX; pr_info("allocating hash table of %lu entries via kvcalloc\n", entries); stack_table = kvcalloc(entries, sizeof(struct stack_record *), GFP_KERNEL); From patchwork Fri Feb 10 21:15:57 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: 13136457 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 9F605C636D7 for ; Fri, 10 Feb 2023 21:17:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 095F86B018F; Fri, 10 Feb 2023 16:17:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F36926B0190; Fri, 10 Feb 2023 16:17:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB1E96B0191; Fri, 10 Feb 2023 16:17:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B8B886B018F for ; Fri, 10 Feb 2023 16:17:18 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7F0C980592 for ; Fri, 10 Feb 2023 21:17:18 +0000 (UTC) X-FDA: 80452642956.18.BDA82AB Received: from out-234.mta1.migadu.com (out-234.mta1.migadu.com [95.215.58.234]) by imf21.hostedemail.com (Postfix) with ESMTP id C66A21C0004 for ; Fri, 10 Feb 2023 21:17:16 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=dPUdX3td; spf=pass (imf21.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.234 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=1676063837; 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=k1dYguidu/ftb/l9KscZ+n0HL8ER05ZmODhupOX0dXU=; b=cNNSw/2FQlj+8Rt2kkaf9wW9Cu0kyjVPmICgqLqnUhkBokDqNTcSpQ4YENGD3tRltZP04N KxFhO+A9ObNEGq5mZ9+AgB2kEa0D84WS4x5PAOerELXJ0XjCbqmc2y7ZGr1RtLX+bVfJ0Y BNV0GMI4GGyuiuIDyrX3dUiQ3ikiV5g= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=dPUdX3td; spf=pass (imf21.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.234 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063837; a=rsa-sha256; cv=none; b=NyC42xOMZ0NjhZVIL5pkWglnK97CTA9LmhmZfqfBXsjby7u1fx0MQgszxY2V/f4mWDx/lt CVIppVdfAHxnA1Cc+wH/qhC7ViHyPMzGyL/VKuvKSeFENdW4YRqas9cI9i4YXG7ZuflDqt OAy88Jy2HlyjGEqMnsXnRgKe+Qih6ew= 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=1676063835; 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=k1dYguidu/ftb/l9KscZ+n0HL8ER05ZmODhupOX0dXU=; b=dPUdX3td2hwjMJwaydwAO7P6cUwMqS7s04CWXZgZq4rTtFDVS2WfxxJlWzHAOeK9hg6Lnp mCqInVHJA2e4igp9gnVXcPY1rn3bEgd5mZ2Atb1ioMZCMAInTnVEmakuMT0E/nYF/mUMJS xuCob2cUSwIvHkTDy32/Oyfxzxb+b/M= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 09/18] lib/stackdepot: rename slab to pool Date: Fri, 10 Feb 2023 22:15:57 +0100 Message-Id: <923c507edb350c3b6ef85860f36be489dfc0ad21.1676063693.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: C66A21C0004 X-Stat-Signature: 3jtfkw5a4r6pwxapqyp6unc67y1ahn6t X-HE-Tag: 1676063836-670218 X-HE-Meta: U2FsdGVkX1+5WCprh8F6XOlHXoiEvDAeFfnBQ11RRaHA2cOvZk9n/k49zpOR3ylx27hYH0tJcu/ZGyfAg51rUCbyGrIgusjrPz/OlcpL4inWHKejq2DEiYnPJvAhoGV4m/q+EfYjo0tWpqIJmNnAVGfqJpz+nd0duq//bBy4tk2e9q/WxdREuiVENTTuTtNiR/cTJxR2Ca51tVsYOo/gs8aZajW478QLgnT0ipgOutop8eYGT62XnypwE4AZmb0BxeIFhkYae20SU9jKZRGwPO545z8Lx/DxQqqSzpCJ7ch2bdvQMyRSmg7ILxidcQ0Sz8UyCnKlkNijEeDejRmgqL0/PxxuRQcK2OLONUykF1cYO+pwFUoNkLo7FLuyzzfF26MqH+raChHUC9iZFpG32l9k91mMqgWxM6hG/fFBm2w7Y3O29VGWkuZN6xG1uN6Vj8cM+j1il+OafmPWxsgzoNntLvQY4gC6Tcz1G7CtwDML1ezL331vGkVjfHjA/MHZDy/uwBJPkx1TInNwCalCY3yByH+kGXEvrMpKn7XDqIv3jrqKhmd8NRrNdtuRBt7ims9k7LwN4SCculZFzcYXsdFfWJ8EpjQs9h8IGXqsoQZoUrP3g0wfeyczIDSlg924SGEF4I3KR6fWNEcdeFiEYmcoGLXjmuiXqKV4msel+wEntYwvIQIlOaFj2siEybXBP1+Jrhe/vR7D53bcN5OXHEv1uusm02UeszCcZJIOo/CsJ0ENujMR7qi3crk9rb7WVCgdbovrAsuFMFfmJO+imh0/nmgEmyZLHwUTEXE77GjLmsyd6sLo5zrtbk/FWpgCsofB3pKI47Px2hYIao36Mtyqy8FmXg8HTKWUyMtri7yM6Ti6hM/H6NzE+V9Nb8LR4KuuxSR3Gu5R/JfG3M5SoL5YDhchC73mfDueOFF7aeZLm0tWq09xBWkyfXpX4E/qONhaWx+yKB8TpphCL+8 Y7bLBZ33 7EgbXi6AcwQLUCnVm9WryTTV4U+AOIGg45N/dFxBcXQR2FxWIjpgUuU0Dh1f6Rg2YNvyDOw7FfdE6ijHX49GhR88Fh9say5zWqnvs 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 Use "pool" instead of "slab" for naming memory regions stack depot uses to store stack traces. Using "slab" is confusing, as stack depot pools have nothing to do with the slab allocator. Also give better names to pool-related global variables: change "depot_" prefix to "pool_" to point out that these variables are related to stack depot pools. Also rename the slabindex (poolindex) field in handle_parts to pool_index to align its name with the pool_index global variable. No functional changes. Signed-off-by: Andrey Konovalov Acked-by: Vlastimil Babka Reviewed-by: Alexander Potapenko --- Changes v1->v2: - Use "pool" instead of "slab" for memory regions that store stack traces. --- lib/stackdepot.c | 106 +++++++++++++++++++++++------------------------ 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index d1ab53197353..522e36cf449f 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -39,7 +39,7 @@ #define DEPOT_STACK_BITS (sizeof(depot_stack_handle_t) * 8) #define STACK_ALLOC_NULL_PROTECTION_BITS 1 -#define STACK_ALLOC_ORDER 2 /* 'Slab' size order for stack depot, 4 pages */ +#define STACK_ALLOC_ORDER 2 /* Pool size order for stack depot, 4 pages */ #define STACK_ALLOC_SIZE (1LL << (PAGE_SHIFT + STACK_ALLOC_ORDER)) #define STACK_ALLOC_ALIGN 4 #define STACK_ALLOC_OFFSET_BITS (STACK_ALLOC_ORDER + PAGE_SHIFT - \ @@ -47,16 +47,16 @@ #define STACK_ALLOC_INDEX_BITS (DEPOT_STACK_BITS - \ STACK_ALLOC_NULL_PROTECTION_BITS - \ STACK_ALLOC_OFFSET_BITS - STACK_DEPOT_EXTRA_BITS) -#define STACK_ALLOC_SLABS_CAP 8192 -#define STACK_ALLOC_MAX_SLABS \ - (((1LL << (STACK_ALLOC_INDEX_BITS)) < STACK_ALLOC_SLABS_CAP) ? \ - (1LL << (STACK_ALLOC_INDEX_BITS)) : STACK_ALLOC_SLABS_CAP) +#define STACK_ALLOC_POOLS_CAP 8192 +#define STACK_ALLOC_MAX_POOLS \ + (((1LL << (STACK_ALLOC_INDEX_BITS)) < STACK_ALLOC_POOLS_CAP) ? \ + (1LL << (STACK_ALLOC_INDEX_BITS)) : STACK_ALLOC_POOLS_CAP) /* The compact structure to store the reference to stacks. */ union handle_parts { depot_stack_handle_t handle; struct { - u32 slabindex : STACK_ALLOC_INDEX_BITS; + u32 pool_index : STACK_ALLOC_INDEX_BITS; u32 offset : STACK_ALLOC_OFFSET_BITS; u32 valid : STACK_ALLOC_NULL_PROTECTION_BITS; u32 extra : STACK_DEPOT_EXTRA_BITS; @@ -91,15 +91,15 @@ static unsigned int stack_bucket_number_order; static unsigned int stack_hash_mask; /* Array of memory regions that store stack traces. */ -static void *stack_slabs[STACK_ALLOC_MAX_SLABS]; -/* Currently used slab in stack_slabs. */ -static int depot_index; -/* Offset to the unused space in the currently used slab. */ -static size_t depot_offset; +static void *stack_pools[STACK_ALLOC_MAX_POOLS]; +/* Currently used pool in stack_pools. */ +static int pool_index; +/* Offset to the unused space in the currently used pool. */ +static size_t pool_offset; /* Lock that protects the variables above. */ -static DEFINE_RAW_SPINLOCK(depot_lock); -/* Whether the next slab is initialized. */ -static int next_slab_inited; +static DEFINE_RAW_SPINLOCK(pool_lock); +/* Whether the next pool is initialized. */ +static int next_pool_inited; static int __init disable_stack_depot(char *str) { @@ -220,30 +220,30 @@ int stack_depot_init(void) } EXPORT_SYMBOL_GPL(stack_depot_init); -static bool init_stack_slab(void **prealloc) +static bool init_stack_pool(void **prealloc) { if (!*prealloc) return false; /* * This smp_load_acquire() pairs with smp_store_release() to - * |next_slab_inited| below and in depot_alloc_stack(). + * |next_pool_inited| below and in depot_alloc_stack(). */ - if (smp_load_acquire(&next_slab_inited)) + if (smp_load_acquire(&next_pool_inited)) return true; - if (stack_slabs[depot_index] == NULL) { - stack_slabs[depot_index] = *prealloc; + if (stack_pools[pool_index] == NULL) { + stack_pools[pool_index] = *prealloc; *prealloc = NULL; } else { - /* If this is the last depot slab, do not touch the next one. */ - if (depot_index + 1 < STACK_ALLOC_MAX_SLABS) { - stack_slabs[depot_index + 1] = *prealloc; + /* If this is the last depot pool, do not touch the next one. */ + if (pool_index + 1 < STACK_ALLOC_MAX_POOLS) { + stack_pools[pool_index + 1] = *prealloc; *prealloc = NULL; } /* * This smp_store_release pairs with smp_load_acquire() from - * |next_slab_inited| above and in stack_depot_save(). + * |next_pool_inited| above and in stack_depot_save(). */ - smp_store_release(&next_slab_inited, 1); + smp_store_release(&next_pool_inited, 1); } return true; } @@ -257,35 +257,35 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) required_size = ALIGN(required_size, 1 << STACK_ALLOC_ALIGN); - if (unlikely(depot_offset + required_size > STACK_ALLOC_SIZE)) { - if (unlikely(depot_index + 1 >= STACK_ALLOC_MAX_SLABS)) { + if (unlikely(pool_offset + required_size > STACK_ALLOC_SIZE)) { + if (unlikely(pool_index + 1 >= STACK_ALLOC_MAX_POOLS)) { WARN_ONCE(1, "Stack depot reached limit capacity"); return NULL; } - depot_index++; - depot_offset = 0; + pool_index++; + pool_offset = 0; /* * smp_store_release() here pairs with smp_load_acquire() from - * |next_slab_inited| in stack_depot_save() and - * init_stack_slab(). + * |next_pool_inited| in stack_depot_save() and + * init_stack_pool(). */ - if (depot_index + 1 < STACK_ALLOC_MAX_SLABS) - smp_store_release(&next_slab_inited, 0); + if (pool_index + 1 < STACK_ALLOC_MAX_POOLS) + smp_store_release(&next_pool_inited, 0); } - init_stack_slab(prealloc); - if (stack_slabs[depot_index] == NULL) + init_stack_pool(prealloc); + if (stack_pools[pool_index] == NULL) return NULL; - stack = stack_slabs[depot_index] + depot_offset; + stack = stack_pools[pool_index] + pool_offset; stack->hash = hash; stack->size = size; - stack->handle.slabindex = depot_index; - stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN; + stack->handle.pool_index = pool_index; + stack->handle.offset = pool_offset >> STACK_ALLOC_ALIGN; stack->handle.valid = 1; stack->handle.extra = 0; memcpy(stack->entries, entries, flex_array_size(stack, entries, size)); - depot_offset += required_size; + pool_offset += required_size; return stack; } @@ -336,10 +336,10 @@ static inline struct stack_record *find_stack(struct stack_record *bucket, * @nr_entries: Size of the storage array * @extra_bits: Flags to store in unused bits of depot_stack_handle_t * @alloc_flags: Allocation gfp flags - * @can_alloc: Allocate stack slabs (increased chance of failure if false) + * @can_alloc: Allocate stack pools (increased chance of failure if false) * * Saves a stack trace from @entries array of size @nr_entries. If @can_alloc is - * %true, is allowed to replenish the stack slab pool in case no space is left + * %true, is allowed to replenish the stack pool in case no space is left * (allocates using GFP flags of @alloc_flags). If @can_alloc is %false, avoids * any allocations and will fail if no space is left to store the stack trace. * @@ -396,14 +396,14 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, goto exit; /* - * Check if the current or the next stack slab need to be initialized. + * Check if the current or the next stack pool need to be initialized. * If so, allocate the memory - we won't be able to do that under the * lock. * * The smp_load_acquire() here pairs with smp_store_release() to - * |next_slab_inited| in depot_alloc_stack() and init_stack_slab(). + * |next_pool_inited| in depot_alloc_stack() and init_stack_pool(). */ - if (unlikely(can_alloc && !smp_load_acquire(&next_slab_inited))) { + if (unlikely(can_alloc && !smp_load_acquire(&next_pool_inited))) { /* * Zero out zone modifiers, as we don't have specific zone * requirements. Keep the flags related to allocation in atomic @@ -417,7 +417,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, prealloc = page_address(page); } - raw_spin_lock_irqsave(&depot_lock, flags); + raw_spin_lock_irqsave(&pool_lock, flags); found = find_stack(*bucket, entries, nr_entries, hash); if (!found) { @@ -437,10 +437,10 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, * We didn't need to store this stack trace, but let's keep * the preallocated memory for the future. */ - WARN_ON(!init_stack_slab(&prealloc)); + WARN_ON(!init_stack_pool(&prealloc)); } - raw_spin_unlock_irqrestore(&depot_lock, flags); + raw_spin_unlock_irqrestore(&pool_lock, flags); exit: if (prealloc) { /* Nobody used this memory, ok to free it. */ @@ -488,7 +488,7 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, unsigned long **entries) { union handle_parts parts = { .handle = handle }; - void *slab; + void *pool; size_t offset = parts.offset << STACK_ALLOC_ALIGN; struct stack_record *stack; @@ -496,15 +496,15 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, if (!handle) return 0; - if (parts.slabindex > depot_index) { - WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n", - parts.slabindex, depot_index, handle); + if (parts.pool_index > pool_index) { + WARN(1, "pool index %d out of bounds (%d) for stack id %08x\n", + parts.pool_index, pool_index, handle); return 0; } - slab = stack_slabs[parts.slabindex]; - if (!slab) + pool = stack_pools[parts.pool_index]; + if (!pool) return 0; - stack = slab + offset; + stack = pool + offset; *entries = stack->entries; return stack->size; From patchwork Fri Feb 10 21:15:58 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: 13136459 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 4686BC05027 for ; Fri, 10 Feb 2023 21:17:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD04F6B0191; Fri, 10 Feb 2023 16:17:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A07876B0192; Fri, 10 Feb 2023 16:17:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 886966B0195; Fri, 10 Feb 2023 16:17:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 68E156B0192 for ; Fri, 10 Feb 2023 16:17:19 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 3EE57A1180 for ; Fri, 10 Feb 2023 21:17:19 +0000 (UTC) X-FDA: 80452642998.11.4B2A71D Received: from out-133.mta1.migadu.com (out-133.mta1.migadu.com [95.215.58.133]) by imf18.hostedemail.com (Postfix) with ESMTP id 6C2681C001E for ; Fri, 10 Feb 2023 21:17:17 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=SagK2gsx; spf=pass (imf18.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.133 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=1676063837; 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=C1pklH2NkOlTJAHbPzx+nHrEQIp6yNaNdAfbP7NW3o0=; b=bCmhIIf+GUqMqCUVr4HCz4BrJy1W0837OVK87uJ4mMFhhTAf2R46Ci0uND+XT0KCP2VujQ Fh5QtgOBkY75Hu4E1/9eOHma0fX/WLhEi8v5pgdGP9ru+6VSkYE4Rzl0QR17joNAfbSvDS a44dFI6CQ+l5aK9i4CyBTY+XX8mjStU= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=SagK2gsx; spf=pass (imf18.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.133 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063837; a=rsa-sha256; cv=none; b=j3b9xm8M6dmLDn5HOvrEaWsRBSHor74YB0W7bt6NliGhAXfHxeBNx/CyvsdH+5X1xUamy5 JKMoIbmGdZ9SSyBCiPyiCica+74A2lcQY+FHCoRY245bGDFxSomVl7Wn0HpJwpSBXL7rjC E28zCVkhFHdFHa8apP+9ggogUsM82ok= 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=1676063835; 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=C1pklH2NkOlTJAHbPzx+nHrEQIp6yNaNdAfbP7NW3o0=; b=SagK2gsxbvOWT+w/hLC0FRbCHZrjxp0Pp51OaIqyRyPod85oFY766GqOrA1hJ+WtbIF3KL ho8d9GYzLVk4QS8kf0Lycn2hGllcaSZv3uOfOeg6Rkd8Z8EnmKpdYFjGKBM7wv3n36S190 cer+cVsokuJpsF4ZbuEL4RB+LJH9/WQ= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 10/18] lib/stackdepot: rename handle and pool constants Date: Fri, 10 Feb 2023 22:15:58 +0100 Message-Id: <84fcceb0acc261a356a0ad4bdfab9ff04bea2445.1676063693.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: mofrzmw7mrx4o5kkmgbejfj9apgfe4o7 X-Rspamd-Queue-Id: 6C2681C001E X-HE-Tag: 1676063837-496097 X-HE-Meta: U2FsdGVkX1/VYXPjJ7kXeqcDXDO6Yy8BZP99ZyWdf+RJF3SWaccuoBGnZCJKwkxavF5F9+iD8x/WYIauM6ZZ7tsbF4ZBUV8nV/a/jLNpJAGAqHCg5shHoZrJxmXqlTLCsxE94nBXJgMmsCGqbbYrErvajqPtLlncNIld08yCeOxH5YT+Vtm1P2hsNDrtGh0IvrorIyAeCyICHW4IR5mvqtVyY8MDBsd6t0OXo3wfDGTc5LJuyFFOq7u2kKh1+8+xof4AG5enmua8aDOT1RdiT1/yY5AcF25i7UV+gGHQqRUVI0s7nxN/3R6wyblsPCyIRRnfRnL1jxsViVyADW/00Yki5b8OsB0CF4vZM5gO2M+jyshN0t919gG12Dl4awLcqbHg+v9Ht8t3OMu1cbsfTAE5HMHJdlb2B+suSKNF4LoU6sDkoGZoctI73MYup20SviNymozoKePO0D24XiYvrBj1/JE8pj/gYGaWFz6Jo0F02yCcOuvDB2jOJpAIGcb+qr7nibIfAyFrU3C+7qExIHn23qQnhcC+vnZBNL8wshd+8/Hx6ijezZcd+Dwq9lHiadfCABhUL1DeyaUnJYBZTzQN9oC4mGSM/A6SQd+t7dDRHj4nmGZU5Ioh4jXrJrn0UoHAvzZWAtToa+HH3uSASrf4+WMJFBBomBfEIPYw0vjFSbI+w+oHpSXB6Pz9o0hB4X7NIhx+h9ahLSrkiGofzLUF/NspNxfefXhA2gjb81/9UcYOuJXgKO0SJNmhfxlByPBuyR38nhDqe2FO6+RocGqlHX9UQKywRpKKUMAn072OxxjHDkCazA/bbOoQfmjkF0g3FzfNqeeP3V4sidyhpJBcNm1d+qfaIN+m+bLWvveq9TAGqPyiQq/TlDF58+iZmVEi5XjWfRM0f6Zgys7kPXHQCFgI6ZDv/PaMbqeWXm2RLrB+qshVV1Xe3brNij4DoC9UItQFtdk/rRjWd2t hMFoBBlo MuIIeNlJXMtnv7Ui9uUYE9ZPD62Cg6u6ElMSTq4NdTdxHh/A15nBYTBUQtTuPHPfJa2H1X6UQKAqxskPfODnKY3QyomZUblzYBztr 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 Change the "STACK_ALLOC_" prefix to "DEPOT_" for the constants that define the number of bits in stack depot handles and the maximum number of pools. The old prefix is unclear and makes wonder about how these constants are related to stack allocations. The new prefix is also shorter. Also simplify the comment for DEPOT_POOL_ORDER. No functional changes. Reviewed-by: Alexander Potapenko Signed-off-by: Andrey Konovalov --- lib/stackdepot.c | 56 +++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 522e36cf449f..97bba462ee13 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -36,30 +36,28 @@ #include #include -#define DEPOT_STACK_BITS (sizeof(depot_stack_handle_t) * 8) - -#define STACK_ALLOC_NULL_PROTECTION_BITS 1 -#define STACK_ALLOC_ORDER 2 /* Pool size order for stack depot, 4 pages */ -#define STACK_ALLOC_SIZE (1LL << (PAGE_SHIFT + STACK_ALLOC_ORDER)) -#define STACK_ALLOC_ALIGN 4 -#define STACK_ALLOC_OFFSET_BITS (STACK_ALLOC_ORDER + PAGE_SHIFT - \ - STACK_ALLOC_ALIGN) -#define STACK_ALLOC_INDEX_BITS (DEPOT_STACK_BITS - \ - STACK_ALLOC_NULL_PROTECTION_BITS - \ - STACK_ALLOC_OFFSET_BITS - STACK_DEPOT_EXTRA_BITS) -#define STACK_ALLOC_POOLS_CAP 8192 -#define STACK_ALLOC_MAX_POOLS \ - (((1LL << (STACK_ALLOC_INDEX_BITS)) < STACK_ALLOC_POOLS_CAP) ? \ - (1LL << (STACK_ALLOC_INDEX_BITS)) : STACK_ALLOC_POOLS_CAP) +#define DEPOT_HANDLE_BITS (sizeof(depot_stack_handle_t) * 8) + +#define DEPOT_VALID_BITS 1 +#define DEPOT_POOL_ORDER 2 /* Pool size order, 4 pages */ +#define DEPOT_POOL_SIZE (1LL << (PAGE_SHIFT + DEPOT_POOL_ORDER)) +#define DEPOT_STACK_ALIGN 4 +#define DEPOT_OFFSET_BITS (DEPOT_POOL_ORDER + PAGE_SHIFT - DEPOT_STACK_ALIGN) +#define DEPOT_POOL_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_VALID_BITS - \ + DEPOT_OFFSET_BITS - STACK_DEPOT_EXTRA_BITS) +#define DEPOT_POOLS_CAP 8192 +#define DEPOT_MAX_POOLS \ + (((1LL << (DEPOT_POOL_INDEX_BITS)) < DEPOT_POOLS_CAP) ? \ + (1LL << (DEPOT_POOL_INDEX_BITS)) : DEPOT_POOLS_CAP) /* The compact structure to store the reference to stacks. */ union handle_parts { depot_stack_handle_t handle; struct { - u32 pool_index : STACK_ALLOC_INDEX_BITS; - u32 offset : STACK_ALLOC_OFFSET_BITS; - u32 valid : STACK_ALLOC_NULL_PROTECTION_BITS; - u32 extra : STACK_DEPOT_EXTRA_BITS; + u32 pool_index : DEPOT_POOL_INDEX_BITS; + u32 offset : DEPOT_OFFSET_BITS; + u32 valid : DEPOT_VALID_BITS; + u32 extra : STACK_DEPOT_EXTRA_BITS; }; }; @@ -91,7 +89,7 @@ static unsigned int stack_bucket_number_order; static unsigned int stack_hash_mask; /* Array of memory regions that store stack traces. */ -static void *stack_pools[STACK_ALLOC_MAX_POOLS]; +static void *stack_pools[DEPOT_MAX_POOLS]; /* Currently used pool in stack_pools. */ static int pool_index; /* Offset to the unused space in the currently used pool. */ @@ -235,7 +233,7 @@ static bool init_stack_pool(void **prealloc) *prealloc = NULL; } else { /* If this is the last depot pool, do not touch the next one. */ - if (pool_index + 1 < STACK_ALLOC_MAX_POOLS) { + if (pool_index + 1 < DEPOT_MAX_POOLS) { stack_pools[pool_index + 1] = *prealloc; *prealloc = NULL; } @@ -255,10 +253,10 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) struct stack_record *stack; size_t required_size = struct_size(stack, entries, size); - required_size = ALIGN(required_size, 1 << STACK_ALLOC_ALIGN); + required_size = ALIGN(required_size, 1 << DEPOT_STACK_ALIGN); - if (unlikely(pool_offset + required_size > STACK_ALLOC_SIZE)) { - if (unlikely(pool_index + 1 >= STACK_ALLOC_MAX_POOLS)) { + if (unlikely(pool_offset + required_size > DEPOT_POOL_SIZE)) { + if (unlikely(pool_index + 1 >= DEPOT_MAX_POOLS)) { WARN_ONCE(1, "Stack depot reached limit capacity"); return NULL; } @@ -269,7 +267,7 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) * |next_pool_inited| in stack_depot_save() and * init_stack_pool(). */ - if (pool_index + 1 < STACK_ALLOC_MAX_POOLS) + if (pool_index + 1 < DEPOT_MAX_POOLS) smp_store_release(&next_pool_inited, 0); } init_stack_pool(prealloc); @@ -281,7 +279,7 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) stack->hash = hash; stack->size = size; stack->handle.pool_index = pool_index; - stack->handle.offset = pool_offset >> STACK_ALLOC_ALIGN; + stack->handle.offset = pool_offset >> DEPOT_STACK_ALIGN; stack->handle.valid = 1; stack->handle.extra = 0; memcpy(stack->entries, entries, flex_array_size(stack, entries, size)); @@ -412,7 +410,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, alloc_flags &= ~GFP_ZONEMASK; alloc_flags &= (GFP_ATOMIC | GFP_KERNEL); alloc_flags |= __GFP_NOWARN; - page = alloc_pages(alloc_flags, STACK_ALLOC_ORDER); + page = alloc_pages(alloc_flags, DEPOT_POOL_ORDER); if (page) prealloc = page_address(page); } @@ -444,7 +442,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, exit: if (prealloc) { /* Nobody used this memory, ok to free it. */ - free_pages((unsigned long)prealloc, STACK_ALLOC_ORDER); + free_pages((unsigned long)prealloc, DEPOT_POOL_ORDER); } if (found) retval.handle = found->handle.handle; @@ -489,7 +487,7 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, { union handle_parts parts = { .handle = handle }; void *pool; - size_t offset = parts.offset << STACK_ALLOC_ALIGN; + size_t offset = parts.offset << DEPOT_STACK_ALIGN; struct stack_record *stack; *entries = NULL; From patchwork Fri Feb 10 21:15:59 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: 13136460 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 93551C636D7 for ; Fri, 10 Feb 2023 21:17:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 37B7B6B0192; Fri, 10 Feb 2023 16:17:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B6606B0195; Fri, 10 Feb 2023 16:17:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1565B6B0197; Fri, 10 Feb 2023 16:17:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E47E16B0192 for ; Fri, 10 Feb 2023 16:17:20 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8D9811C3987 for ; Fri, 10 Feb 2023 21:17:20 +0000 (UTC) X-FDA: 80452643040.30.949A3FC Received: from out-65.mta1.migadu.com (out-65.mta1.migadu.com [95.215.58.65]) by imf11.hostedemail.com (Postfix) with ESMTP id DA3B44000F for ; Fri, 10 Feb 2023 21:17:17 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=KLl8qvzo; spf=pass (imf11.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.65 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=1676063838; 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=vdN0qpq7PVidlsBHChLWKkpFVAJ9uzHha5rImS4k+3M=; b=lQgEcriLyqG4M1AknlK2EtVpazfBmKByPbmAqGOZD/NNWLipqfXfEbqc7+YmTBK71CVd2I mPHL4lNcclKx1hn82G136i25AMoVfyJqJTn8bNoOV9iK/PU1mqrAWyY1dOm3lGiOFj/sNR m84TOLnQ1B9pED6+0MZl8aJibRX7p9U= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=KLl8qvzo; spf=pass (imf11.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.65 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063838; a=rsa-sha256; cv=none; b=lrqKECzTuQFovDNTYmBCLCatGQvxRshM1+5Z5U+oVI8pX8qUHYxlbiJGyWTPBM6fUmbxCf MHYO1sRskuLMF8pvqI3XwoPS1Zn21de52CypL4Sx8Gt2Ec/0b9zb0V1cCFofrk/bOXi+97 UT8uKG/WL63Jj8Wxh9VqNOMAvF5lJHQ= 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=1676063836; 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=vdN0qpq7PVidlsBHChLWKkpFVAJ9uzHha5rImS4k+3M=; b=KLl8qvzoKbycCxdT4nCBIk0Y5JSFEiRTzE8rQ7hPWQgJyI6aNYe9J4JiYp9VP8KyQscvcE TnBdBtXz72gahKjUZfNLixZQ+HBoFx1lollCt6vbrb/4uXRxWFRj+bxxz26jLclDITfqn0 lOVvAXmBPC4TV8M5PBP+IoohhLxIuWs= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 11/18] lib/stackdepot: rename init_stack_pool Date: Fri, 10 Feb 2023 22:15:59 +0100 Message-Id: <23106a3e291d8df0aba33c0e2fe86dc596286479.1676063693.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: DA3B44000F X-Stat-Signature: cpncnzwswhehdzqyradyaqho8j4dbus7 X-Rspam-User: X-HE-Tag: 1676063837-761243 X-HE-Meta: U2FsdGVkX18ONv4U09VQO75erdmZp8b8LpRhB1S4EQv+yMZcWYBYuxMXJYPBh7W37rqaarhQfIVWGmbs25+dhq7Pi2LbPanFk09IoqQRYunZWH+YpLzTiCU/65b40Ih2abPRCm8ZO1OHHKP0GkbElr5MigWzaqc74CpqsTRLq4wFcPndXgMbwR4WjsBto/2Yg/VvOXF1h1jv2re60G4g1x/sO2CIE7AflsL0f4JD2YCdUM+ohFrxFZemr3VQ76UDuQAhoj7TMxRMXKay0oEuEZLwoTWRa1WZPLSAIgSlYw2vzSIOAUlfebfIVQMoVHCg5OiUiTG0G6a0XvDBndE33ypOEnDwxfHCPTcWkSVGlJo0xwL2F7GEPJmXMnE/C4A3V15GmuaI9FxesarDwgs93VkBbrwt+8FZ+bikrWfYVdSQmHOJsmhzudymncVdUOfs76o2f3Uc7g3TREIJRq7leT7TXOkxI+inVQw2jcpS0mAppK6W+ZY2dGR1+XuB/d1ohzku9dhhEkvJMn6UdfAEG5LDECbWGBpTtG/+yUyj5Zdiizi+dHEfOEXLGAow0OntykobtB98bpxes1zoppSBMykj300W7BZpI5uvC19+mWdXQBqskgffBuUZcFZoNl7DazoyN2xxKPa7u+wzC8eCum4/xmQOX8aQLna7On+5oxM2O24LwAGdNBTWgMMwP3EHjCMtP+asN2XXWHgUIlsWIbFiYf2vp78ROc/SZYUiGKbWoSBydGQQwRjUXjEKqN6NG1qrVL4K080DWHipxtnxjgX/ux+ppKYp23dtFmeuxkK64NkRg8aaFsv3ua7TIt3yUi5IwqsvrXOwgj3/2OVy8jVSH6xZPgttkaU8PUPQWcTUfuyEu6wzAr3dn5ZeXvTqkcaGf8PC0Lm6t7SaHZTZ/OJbJ8fZ3XBPVpLXatM/INvGDFN5/xOcM/7z0lI66Os+tG4okWe5X0F7mJHq09/ sj5kTiea YS7OdyniagcfrAHVUWcleTZd35aNOYzOMtQ0kxeuctnnvT5qbvJJhiPSgZTNSYytlwV1sqj2ny6GUWbcO49d6lc90AVRWlEE1RBhVGHLbBRyKkM0P3nacGU9FVxG7NfsykvbDExyJdGYW8Hj5J+/psSKLvQ== 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 Rename init_stack_pool to depot_init_pool to align the name with depot_alloc_stack. No functional changes. Reviewed-by: Alexander Potapenko Signed-off-by: Andrey Konovalov --- lib/stackdepot.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 97bba462ee13..7f5f08bb6c3a 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -218,7 +218,7 @@ int stack_depot_init(void) } EXPORT_SYMBOL_GPL(stack_depot_init); -static bool init_stack_pool(void **prealloc) +static bool depot_init_pool(void **prealloc) { if (!*prealloc) return false; @@ -265,12 +265,12 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) /* * smp_store_release() here pairs with smp_load_acquire() from * |next_pool_inited| in stack_depot_save() and - * init_stack_pool(). + * depot_init_pool(). */ if (pool_index + 1 < DEPOT_MAX_POOLS) smp_store_release(&next_pool_inited, 0); } - init_stack_pool(prealloc); + depot_init_pool(prealloc); if (stack_pools[pool_index] == NULL) return NULL; @@ -399,7 +399,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, * lock. * * The smp_load_acquire() here pairs with smp_store_release() to - * |next_pool_inited| in depot_alloc_stack() and init_stack_pool(). + * |next_pool_inited| in depot_alloc_stack() and depot_init_pool(). */ if (unlikely(can_alloc && !smp_load_acquire(&next_pool_inited))) { /* @@ -435,7 +435,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, * We didn't need to store this stack trace, but let's keep * the preallocated memory for the future. */ - WARN_ON(!init_stack_pool(&prealloc)); + WARN_ON(!depot_init_pool(&prealloc)); } raw_spin_unlock_irqrestore(&pool_lock, flags); From patchwork Fri Feb 10 21:16:00 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: 13136461 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 81CE0C05027 for ; Fri, 10 Feb 2023 21:18:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C9CD6B0195; Fri, 10 Feb 2023 16:18:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 184296B0198; Fri, 10 Feb 2023 16:18:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 068A26B0199; Fri, 10 Feb 2023 16:18:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id EAC1D6B0195 for ; Fri, 10 Feb 2023 16:18:20 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C0BB9A0601 for ; Fri, 10 Feb 2023 21:18:20 +0000 (UTC) X-FDA: 80452645560.23.DFEA27E Received: from out-40.mta1.migadu.com (out-40.mta1.migadu.com [95.215.58.40]) by imf28.hostedemail.com (Postfix) with ESMTP id D13DBC0016 for ; Fri, 10 Feb 2023 21:18:18 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=b9EI77+L; spf=pass (imf28.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.40 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=1676063899; 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=QNTpFR8imhU+1RyFIUQnZTnn23HrW1qgGxbRYaqWOq4=; b=u3EK6mjGDr9Q4r5K/KzGgYWEMmckiBXMXzPG+V1uz6Z9lZdDsbq4zrQKvy/gpIl5vxp26F DKOUbo5877OqGUTRMNcqtVKCx4tf6F+xOfMa/4Do8O8N7ZzNASeSNFd18/Dh1drvJG5JLq 1VKlLj+lgP8ix87Xwo07LGfNiPNw5m0= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=b9EI77+L; spf=pass (imf28.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.40 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063899; a=rsa-sha256; cv=none; b=tdkID6RRAawJ3nWJVGk9IrkIzs+jjnisUoa1pY1DlejuLmvOz73zH7OY7E4mXbOUeBaG40 dxsfVEbkN22Lbx1h2mHEVHWMlfh00syRfTKVA28f4dmC8UEEZnrszrKhD7sbDV66qrGf8H zJQEx/lS9Xr+pfER9A+0tsvcrfL6NbY= 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=1676063897; 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=QNTpFR8imhU+1RyFIUQnZTnn23HrW1qgGxbRYaqWOq4=; b=b9EI77+Lu2ejg1Id6cPrNsMBDYr8WIpJ2zMEg4RXlgJI+QYF6OL/oaxKk1OH2WIRdUewQW zBxE8rT/+Ts7luOzOazTc5KLDee/mIDM5G27VvuS9X7RoT9lIJeLwV8TTioXm6vGFwrCjU VRzh0cOmh0kJxe7ubs0kkTWdypYXNt4= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 12/18] lib/stacktrace: drop impossible WARN_ON for depot_init_pool Date: Fri, 10 Feb 2023 22:16:00 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: cxptuusigy4bwq4kyqof6181nxsyhhp5 X-Rspam-User: X-Rspamd-Queue-Id: D13DBC0016 X-Rspamd-Server: rspam06 X-HE-Tag: 1676063898-616571 X-HE-Meta: U2FsdGVkX19mEJ9QN1+slWkNdyofrQjgyhw8VFfvW2Lg6+jz0sVTcQdWXYMBNe8LTNhc+mpqPVBwqkMZeZSbTa40/1Q40XXgaAZ/2kA9vmzAOPExwxNZ9n3Xe2+v3M91qh/Ght+um7SdoE0AdIf/hU1Jr+7lMmAdhQ+pAooz/hi25Zut3HYRrxFB2/eJl18n5wFSu1PeEOpFw/xHVpPmBMbeXpG7PQthXVBAh3/XAyVlAd9Y4h2ZBsflA4e4XULdtlFi7Q192L7iwZlTexUgpabttJM4QDMdqoUu9s+AHCrKc+aYlBCXNszRplwef9+rBnH4QyzNFkop+5Z2NaAtziip8Df12Av9q1MaQqWXbIZXoUUjZN/VjN94rVxUN5loePQGaboCIU11L9/iLubmmNYTAXzWzIDpeCQNuGxXxHmjAsqfVCQeGfJO2mqygD2CHZMmTmyBAehLhede+xXhD1+qFMEIgJDvuNwsmR90ItRlVCUEJrbHi7RvpN9Wnh9RXawMFK8Rf83hVqQNQBR9pro/t0eLRMEuNLAdeArFc2PtwmJ7jL69/y+tRATlVWpsLsoPETu7dXIBVaZDgx7zY17c3cvQSbpOw2YOYk894DGgP8s9HIQ3rjO/3TCdvO1XK6YQRUaCYn4Nb1jyXujt2E9U5HaOiHtpCRIqc6pVZIF3yimTZk8xQmiutFwxtH9Id3RudseE5RGm438lhNA9ttwMZRNhUiYOaSSdxgcv1Sgwnxj6J7RSzvVMCkdwUxDL+MD2olpU5pt4n1T4RQA59t+xClqJOZ0hAkHZcxSL2KF+uMOqIChs+FenvB88JwOy+KwRlyvhsxolM93oqFFirWbM5jp5c2FvyurMC2wTsxui+S4Wx++qt3UloFK/9QRmtlCExEguaNAs20spPG1Dt/u2ZxB5rR2VVfZ2PkFyRyxo6FcsYCLKb5fMHeqaoh3RNljBVcK3FttoK63j8xt QISnp6MV M7y4dGcmz6pda7uefs0/5/t6GB6Lk0g6EVZkTFfA7e9XsCvG6bI5R3VHxXK1PIlzIcTOolmMwrK+Y+UCnwgkUFZpXjEk+aYVamDHY0+rriELKd+6Y3OSVXKQGBzaqbcwRWVtgJ8p4NWR+GJ39aym2f1Xcbw== 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 depot_init_pool has two call sites: 1. In depot_alloc_stack with a potentially NULL prealloc. 2. In __stack_depot_save with a non-NULL prealloc. At the same time depot_init_pool can only return false when prealloc is NULL. As the second call site makes sure that prealloc is not NULL, the WARN_ON there can never trigger. Thus, drop the WARN_ON and also move the prealloc check from depot_init_pool to its first call site. Also change the return type of depot_init_pool to void as it now always returns true. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 7f5f08bb6c3a..d4d988276b91 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -218,16 +218,14 @@ int stack_depot_init(void) } EXPORT_SYMBOL_GPL(stack_depot_init); -static bool depot_init_pool(void **prealloc) +static void depot_init_pool(void **prealloc) { - if (!*prealloc) - return false; /* * This smp_load_acquire() pairs with smp_store_release() to * |next_pool_inited| below and in depot_alloc_stack(). */ if (smp_load_acquire(&next_pool_inited)) - return true; + return; if (stack_pools[pool_index] == NULL) { stack_pools[pool_index] = *prealloc; *prealloc = NULL; @@ -243,7 +241,6 @@ static bool depot_init_pool(void **prealloc) */ smp_store_release(&next_pool_inited, 1); } - return true; } /* Allocation of a new stack in raw storage */ @@ -270,7 +267,8 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) if (pool_index + 1 < DEPOT_MAX_POOLS) smp_store_release(&next_pool_inited, 0); } - depot_init_pool(prealloc); + if (*prealloc) + depot_init_pool(prealloc); if (stack_pools[pool_index] == NULL) return NULL; @@ -435,7 +433,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, * We didn't need to store this stack trace, but let's keep * the preallocated memory for the future. */ - WARN_ON(!depot_init_pool(&prealloc)); + depot_init_pool(&prealloc); } raw_spin_unlock_irqrestore(&pool_lock, flags); From patchwork Fri Feb 10 21:16:01 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: 13136462 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 72825C636D4 for ; Fri, 10 Feb 2023 21:18:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB33B6B0198; Fri, 10 Feb 2023 16:18:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CC4216B019A; Fri, 10 Feb 2023 16:18:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AEF7C6B019B; Fri, 10 Feb 2023 16:18:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 917756B0198 for ; Fri, 10 Feb 2023 16:18:21 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 68515C0327 for ; Fri, 10 Feb 2023 21:18:21 +0000 (UTC) X-FDA: 80452645602.19.19EC8C1 Received: from out-52.mta1.migadu.com (out-52.mta1.migadu.com [95.215.58.52]) by imf10.hostedemail.com (Postfix) with ESMTP id 862C6C0007 for ; Fri, 10 Feb 2023 21:18:19 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="sVBTl7/5"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.52 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676063899; 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=pGvDrOxyRt5kOFDmqXD5ITBuCpaHJonxkPgV6Sd4X2o=; b=RHsgclwFPESLAWodD9vmQIj4nWizlQ8SPAu7mowkfCIjBxQQuz9y8zqQhQOODj2QyAs/EV UeAyXGOouX42XBrTOkivgK+5EdgAJxl4OOtrtOHjNY2XsYB9ciqecsQEp+bLH4cAo6OFJ1 QE1ROBake8hlt3796B1++E3Wozde0qA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="sVBTl7/5"; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf10.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.52 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063899; a=rsa-sha256; cv=none; b=L9R2vMkbEBX2RNvXjH54+Gh6L/DTZFnz7BQ5NnLWxkJ2UKWbcR/REIo5DEdPVi8QVy33HB fYsVEqWZ51ZXnDpUDwvX0toh3aDm8n6lZJvmj0I6WQpbV4QRF1sUc2HUEmpgdsQNKgORlI dFPvuU9Bu+ap+o/9Fk1JK2Vb2xHLJAE= 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=1676063898; 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=pGvDrOxyRt5kOFDmqXD5ITBuCpaHJonxkPgV6Sd4X2o=; b=sVBTl7/5HAlYJsoNTAYJS7jHmyG0mwufQdpCh0QT0n6Tk9BlAh4+4jHAXFjNeAehSp09ID IEpp2QiI5YzquQvB0+kSXtzyz/47zqk8vIOAWAnjB9JeZRWKZTC7iXXkh/2GlVESua2t5Y R7dMt2pIa9/i109Fj4DEUmTYzXbV/98= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 13/18] lib/stackdepot: annotate depot_init_pool and depot_alloc_stack Date: Fri, 10 Feb 2023 22:16:01 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 862C6C0007 X-Stat-Signature: urbpscws5nh9u8nrnrc68rcykwhh46wn X-HE-Tag: 1676063899-158855 X-HE-Meta: U2FsdGVkX1+OZMp6qviEUqqykFQ0HsTJuUsa/uASnJHCCKI0FkWgKjdZwncqmftGEpHT6G5TITJxRHlT7o3i9fknpkCVTz7XC70rGJg/hVSPcwWlcq32+O6ehrQ4VAIAeySSCXH5bucoHcY+5HVX96f9gKfYM1Bv28Snl1e7sfUCGB9OWPxovreu2WnjUEekKBQDao1T/OAawmCuHYj7M4DZY2MhbFMP9Wz98qkivTAeXT0O9AJa9xzCFjBP7vc8oVHWgeFbx9cpDO2HtHWhI928wB+0RIA77PqCsZWrY71yImIYPN24Qxp+o7a88UxNZlx5lwTD0iTlf9b73Ay9N/9OhfM+6ZZvdBWLzlxrAZYnIkYvCGkRKcxGJiD2VjwKDBl3h4/+3Agkmsd7nYDV4Vx6I7/9fYi1wH//HM1AplA8o10CMirNYl+qxDOZiQa9X0Pf8Xxq0WLa4DyNYp8WalWkCu7S9NiR5GMKIhJQI8cei3KEHGnEdL3fxA4jlIgM2WLeVh9EtPLtdEMJ3AgV/UHzQiNHVlLrqKCJaLJzepD+XzsjN7z885suiH9FMuKFLS/pUvpBGdtr5z3X7fCyfMZui6D6uXSAqEJ1Pjc/9sM1VelMf9rq0cRStJNuqxA6oxrgcpO5HAZDnObrrZoQL6cEyqwOO6pyBCRtUgqfqEx5bE+EFEprB8LKGW7/mp02pUcYVcAJc6N1c08OavL23zEqBFLs4Al8S/XNW/Jj1GKt6zmETTNre94uj8qOQD4G4ZEqfBT4iHvbUkBteHE9BOZ8rzKc5yRxCX+xpWaOzaUqifF537PjBwotlzureJNYng88P5ytd6AKvthnt2on/UOwkkq/T6ubbb/wkRBIfAVtTzr6D5R90IDGXg6/4VNU5Nyt7EL2fGFl73gRLqhrLeuafNx4RLRYaBZoAl63mbi20HD7zbn+HF/vjv5rN3BgT4xDDHCnTurf+gnQs6u RU3aZHtq e/X1JFSuO0xblK+pf2zaI4z1YlACpJJ6JRcF4/TUYF0nDnV0Ieakc7v3sNV9AQ4C8pS4QCQm6K4mzcr8GUHiRVpsW1e3qsv0NA/5Afplljiw26W5BIJR+F9lVqr/bb8ghRawxuWQTZu1zxa2ZPoKYSXhfjw== 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 Clean up the exisiting comments and add new ones to depot_init_pool and depot_alloc_stack. As a part of the clean-up, remove mentions of which variable is accessed by smp_store_release and smp_load_acquire: it is clear as is from the code. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index d4d988276b91..c4bc198c3d93 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -218,32 +218,39 @@ int stack_depot_init(void) } EXPORT_SYMBOL_GPL(stack_depot_init); +/* Uses preallocated memory to initialize a new stack depot pool. */ static void depot_init_pool(void **prealloc) { /* - * This smp_load_acquire() pairs with smp_store_release() to - * |next_pool_inited| below and in depot_alloc_stack(). + * smp_load_acquire() here pairs with smp_store_release() below and + * in depot_alloc_stack(). */ if (smp_load_acquire(&next_pool_inited)) return; + + /* Check if the current pool is not yet allocated. */ if (stack_pools[pool_index] == NULL) { + /* Use the preallocated memory for the current pool. */ stack_pools[pool_index] = *prealloc; *prealloc = NULL; } else { - /* If this is the last depot pool, do not touch the next one. */ + /* + * Otherwise, use the preallocated memory for the next pool + * as long as we do not exceed the maximum number of pools. + */ if (pool_index + 1 < DEPOT_MAX_POOLS) { stack_pools[pool_index + 1] = *prealloc; *prealloc = NULL; } /* - * This smp_store_release pairs with smp_load_acquire() from - * |next_pool_inited| above and in stack_depot_save(). + * This smp_store_release pairs with smp_load_acquire() above + * and in stack_depot_save(). */ smp_store_release(&next_pool_inited, 1); } } -/* Allocation of a new stack in raw storage */ +/* Allocates a new stack in a stack depot pool. */ static struct stack_record * depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) { @@ -252,28 +259,35 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) required_size = ALIGN(required_size, 1 << DEPOT_STACK_ALIGN); + /* Check if there is not enough space in the current pool. */ if (unlikely(pool_offset + required_size > DEPOT_POOL_SIZE)) { + /* Bail out if we reached the pool limit. */ if (unlikely(pool_index + 1 >= DEPOT_MAX_POOLS)) { WARN_ONCE(1, "Stack depot reached limit capacity"); return NULL; } + + /* Move on to the next pool. */ pool_index++; pool_offset = 0; /* - * smp_store_release() here pairs with smp_load_acquire() from - * |next_pool_inited| in stack_depot_save() and - * depot_init_pool(). + * smp_store_release() here pairs with smp_load_acquire() in + * stack_depot_save() and depot_init_pool(). */ if (pool_index + 1 < DEPOT_MAX_POOLS) smp_store_release(&next_pool_inited, 0); } + + /* Assign the preallocated memory to a pool if required. */ if (*prealloc) depot_init_pool(prealloc); + + /* Check if we have a pool to save the stack trace. */ if (stack_pools[pool_index] == NULL) return NULL; + /* Save the stack trace. */ stack = stack_pools[pool_index] + pool_offset; - stack->hash = hash; stack->size = size; stack->handle.pool_index = pool_index; From patchwork Fri Feb 10 21:16:02 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: 13136463 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 8D047C636D7 for ; Fri, 10 Feb 2023 21:18:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 575DD6B019A; Fri, 10 Feb 2023 16:18:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D5D76B019C; Fri, 10 Feb 2023 16:18:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D9AC6B019D; Fri, 10 Feb 2023 16:18:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1E7C36B019A for ; Fri, 10 Feb 2023 16:18:22 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D7BA8C03E0 for ; Fri, 10 Feb 2023 21:18:21 +0000 (UTC) X-FDA: 80452645602.14.F54A234 Received: from out-13.mta1.migadu.com (out-13.mta1.migadu.com [95.215.58.13]) by imf06.hostedemail.com (Postfix) with ESMTP id 0C8FC18001B for ; Fri, 10 Feb 2023 21:18:19 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=B+1V8biN; spf=pass (imf06.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.13 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=1676063900; 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=AbtsRD1ly4MmHuz3K8pgOTgQ9ciqaNAhgw745M5z3qM=; b=k6e2dNdAC1DoRYfVo9VuIFY5wJ4xUuLwmn+g8yInoulVFlocCzLtx3/J95HMS/Gn/cZ/NX UFyseC0hafHhzpaqzibI1v6zIPMlBIdXxgcWBklC6AopMtG2xHVImnY4RkPr3JyWLO4OlP cK2x3fjZbw+lnLt+iIFtXOzEP7w8xXQ= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=B+1V8biN; spf=pass (imf06.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.13 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063900; a=rsa-sha256; cv=none; b=mM03SdvAjMNKi4dAG7XeVX+q10KcsYrgsb9UxdTJqAXLliaz/5Q/vKZnumuR+VtiiugcBQ wth39++8oJcYw1GQwlOWVtRC81Tl1caAqQp80yi9rvQMDQdEFsMS7OcdcTCxYCnSbklcNH o3jVlJCoxRbOLQ6Ihc3PbKYE/1VEi4c= 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=1676063898; 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=AbtsRD1ly4MmHuz3K8pgOTgQ9ciqaNAhgw745M5z3qM=; b=B+1V8biNfQMjX3nsdY1+m73D5TjVw+j0Vl7kRfCdc1w7xSYfbVEyBvrta2xNYa6Fed0hwK 4gpQsZv/7kDWYCx2cQrmYjS6QJKG+FhPekhF/wXcEw25xcCoYQRoQenFhU+NvRpIKzhCdw RIpjR+KRI2zLVti6o9s0FEnI3s7YTh0= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 14/18] lib/stackdepot: rename next_pool_inited to next_pool_required Date: Fri, 10 Feb 2023 22:16:02 +0100 Message-Id: <484fd2695dff7a9bdc437a32f8a6ee228535aa02.1676063693.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: mbhzew9zpih8s9frp5gc15df15whaakc X-Rspam-User: X-Rspamd-Queue-Id: 0C8FC18001B X-Rspamd-Server: rspam06 X-HE-Tag: 1676063899-416896 X-HE-Meta: U2FsdGVkX19KcCNACjZcCT0yEHES1yZrIl5h0cLZSNOm+Re7aruEm0LWwJ+ZH5eYAA7g2yaEtpUgyfAXmr3R96EEsmHcrY8axE5+uHn7ru5QXt0SyqsBhHTharg/snYQLT0A5t1rwrl4Wj7Vq8fipTkwDF3bhgSotiuXZP02nl/ccxNY3pQ2CR07JoBz0y11ZwrlVp2n+M82VvSdeYkBOvJZNuZlGnJvrqy+vwz8phitUG6HRJujbh+OK5vYvxQLdnu1pr3K1YJ57YRxX7NRQfo0xtre8emi3+hYKqTFpoa97GmKP4d4kevBd5b9V6uXZ/9e5uWYBRA/n1mvWIr0fBc6jtSmxA24GU9W/V44OR0rjcjvpj8vaqm7ZNw0WqM8A9quqJJtigSvYbsrIGzKhxs1i3rWfC/2K1D2TX5BYq/RRXfK6zWHmW+wAWuTM6+lgaa2X6qSRy9aacX2hLmP7MF0MK4bDlH04YOHuXzIVOIEQ42TRqouqbAU3atpRkIPQJnLmpxlSMg3cBWuuYwbexB18/bj4j3XpB2apaFIQllMirJJ227om68y4c2dkiYriPN+EyYlnC0b+8n08qkskncIliSem6Gdptbp90q+gs5ZzLgMq4jTtoB4MbSj+6uLzeA0EhkMrKmhoDWLptTBRLfDnTuB59fVkf1HJMyEs47QyjRIPF1gZYVvXniKEzvEbvQS75nrL76mobc/jZZgrZcDCjKQzBsZNVwfLemBVcXK9CcXiAcHolePsCXh8bubMpx3s3V6Tlhe8nLE9KK6JfTWkxTQ+mWtS2ZxqTcmB7E5WaiHxq+xU+/Rtfe4td4h0wHU2rwQNJOqQktyNY8v9/J/QXA5EZt06NWbt5iCd7VHEajYUjnv0KWQFK/kI4oLe7cAwa7r06kQZ7XP+bJjdErxg0WNeYM0hoC62LQu5SaonG21mdCOwOx3KRzfSNdsc83LNFf8EQPzBTegCQV 5mxP+FNI CQf8lUyyZeyH00RhbnhjnMQbpX6T83oWbDjJKjSmZzlPrke/d5+SDIyn+NL4ll2iZ8cpZqg5zFRfGuZfPD45LTAQMtiqckAwruFIyotecn4c7w9i0JDL4MJ0PMjHko4wZNBMQXpETyvc3KzVkQS73jMJi1A== 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 Stack depot uses next_pool_inited to mark that either the next pool is initialized or the limit on the number of pools is reached. However, the flag name only reflects the former part of its purpose, which is confusing. Rename next_pool_inited to next_pool_required and invert its value. Also annotate usages of next_pool_required with comments. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index c4bc198c3d93..4df162a84bfe 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -96,8 +96,14 @@ static int pool_index; static size_t pool_offset; /* Lock that protects the variables above. */ static DEFINE_RAW_SPINLOCK(pool_lock); -/* Whether the next pool is initialized. */ -static int next_pool_inited; +/* + * Stack depot tries to keep an extra pool allocated even before it runs out + * of space in the currently used pool. + * This flag marks that this next extra pool needs to be allocated and + * initialized. It has the value 0 when either the next pool is not yet + * initialized or the limit on the number of pools is reached. + */ +static int next_pool_required = 1; static int __init disable_stack_depot(char *str) { @@ -222,10 +228,12 @@ EXPORT_SYMBOL_GPL(stack_depot_init); static void depot_init_pool(void **prealloc) { /* + * If the next pool is already initialized or the maximum number of + * pools is reached, do not use the preallocated memory. * smp_load_acquire() here pairs with smp_store_release() below and * in depot_alloc_stack(). */ - if (smp_load_acquire(&next_pool_inited)) + if (!smp_load_acquire(&next_pool_required)) return; /* Check if the current pool is not yet allocated. */ @@ -243,10 +251,13 @@ static void depot_init_pool(void **prealloc) *prealloc = NULL; } /* + * At this point, either the next pool is initialized or the + * maximum number of pools is reached. In either case, take + * note that initializing another pool is not required. * This smp_store_release pairs with smp_load_acquire() above * and in stack_depot_save(). */ - smp_store_release(&next_pool_inited, 1); + smp_store_release(&next_pool_required, 0); } } @@ -271,11 +282,13 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) pool_index++; pool_offset = 0; /* + * If the maximum number of pools is not reached, take note + * that the next pool needs to initialized. * smp_store_release() here pairs with smp_load_acquire() in * stack_depot_save() and depot_init_pool(). */ if (pool_index + 1 < DEPOT_MAX_POOLS) - smp_store_release(&next_pool_inited, 0); + smp_store_release(&next_pool_required, 1); } /* Assign the preallocated memory to a pool if required. */ @@ -406,14 +419,13 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, goto exit; /* - * Check if the current or the next stack pool need to be initialized. - * If so, allocate the memory - we won't be able to do that under the - * lock. + * Check if another stack pool needs to be initialized. If so, allocate + * the memory now - we won't be able to do that under the lock. * * The smp_load_acquire() here pairs with smp_store_release() to * |next_pool_inited| in depot_alloc_stack() and depot_init_pool(). */ - if (unlikely(can_alloc && !smp_load_acquire(&next_pool_inited))) { + if (unlikely(can_alloc && smp_load_acquire(&next_pool_required))) { /* * Zero out zone modifiers, as we don't have specific zone * requirements. Keep the flags related to allocation in atomic From patchwork Fri Feb 10 21:16:03 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: 13136464 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 B6911C05027 for ; Fri, 10 Feb 2023 21:18:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B66C56B019C; Fri, 10 Feb 2023 16:18:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B18E66B019E; Fri, 10 Feb 2023 16:18:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DF636B019F; Fri, 10 Feb 2023 16:18:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8A6A96B019E for ; Fri, 10 Feb 2023 16:18:22 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6BFDB1C68B1 for ; Fri, 10 Feb 2023 21:18:22 +0000 (UTC) X-FDA: 80452645644.08.BB233CD Received: from out-184.mta1.migadu.com (out-184.mta1.migadu.com [95.215.58.184]) by imf02.hostedemail.com (Postfix) with ESMTP id 9A76380011 for ; Fri, 10 Feb 2023 21:18:20 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mZ77UXQw; spf=pass (imf02.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.184 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063900; a=rsa-sha256; cv=none; b=Cq8b7XtZYwrmms5NebTt4NoXIsxSEYY5S9MhlYdXmHCfEd/UVxzyvNlKdBESammqofSMKo 1Ew2YTPO2UCGWYe+7jpDmdON/5b/2W+Ol677cUtRnp9CjE8Ja7dKDg2q90nHmIrHReMCKd aR32FbpJicBUAGK+Qdpqj/+DDux3Idg= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=mZ77UXQw; spf=pass (imf02.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.184 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=1676063900; 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=UVeF/wdyK+2zAJh1QGD4/79VjlNXyPEki9KG1Xr/HS8=; b=dMh14ktPxTHNZK/ShbAbq0Oa0hyTth5Qwp8fy2dZchy0vfWHjjQQTH2P6u517Io9CSwk7C XmS0kfR5+7PsWJKENWNIsJaJOIEB4OOr/hQxsl8sgVcqAdn5p4dHcr3B7JPp9PZg4WHJRR 8pV6oV0EkGH7fdwzJ5o+i+U85Ie3fFU= 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=1676063899; 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=UVeF/wdyK+2zAJh1QGD4/79VjlNXyPEki9KG1Xr/HS8=; b=mZ77UXQw8ph3QwwxXcMEUBuXupMLlxGBtFsT/tvE3yPr1CWb80YBs30hTsFcDo2cxvMjfU fh5338Sdmtuz7SNFr7A8idY55ISDszradFlit9kl2SJREmvICU9yKZEh/SEEnh1I4YWVCb jOA+wNYeS/EARv0AleT+tvRG6/ySbBA= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 15/18] lib/stacktrace, kasan, kmsan: rework extra_bits interface Date: Fri, 10 Feb 2023 22:16:03 +0100 Message-Id: <317123b5c05e2f82854fc55d8b285e0869d3cb77.1676063693.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Queue-Id: 9A76380011 X-Rspamd-Server: rspam01 X-Stat-Signature: nphr1rhzb8ckycg374koq63e5u1iqdxt X-HE-Tag: 1676063900-69501 X-HE-Meta: U2FsdGVkX18nQ3YSBMoVcPfxlcMAZH7aeV/e+nIVMqwd5REXtyEg1Jt6Pq673T2aOBzFkb1d/SX/TVWnxPQFLIkVx/EXgAe0l5VVD1Q/cfV34yugd5jeBFp9WOcVugkHNXv0rqCHlm2Nq3XstXMalxBSFhiwJfVnENyJjbuqdi1r2ri4bAr+RhvS02OhDh9pjyNRpHZ44HV6XQt6Dug1lezY7os36eXXRoFz6CVPqZcbjoopawZlhXVivfA4mtr/qdJbiJ9e4GU+aYflxljRX6Oxizjm/jVACkarFiH9Z9ZHQXucDdaKdhfZsjMRYRYYnYGDM+W2/3yOmu1Zf0pim7UwDIwkLSUXbdjDq905H6eaBDIo+HS9iVhqg+VidhrrAiYJ3Bv/Qy99nCtEgSnKQDKzQsfn6nU3uIMy3T8PPDPmGhEpeQG7b/1Zg4trrKmvCWDk+ymX0AnKRdrYpbkPkJqXkbJeCZMtwyp0pXWcHDUoCNsWeAdGaRgJuZWpulYQc7xKPJT3KCjrGGLMhLIXRjDFjHNF6JWYYEyoS6gBEmLZE0ZzTJFoKflmrpnfAeaPWsRo30u0ctmmFuIJGAPgN50Oa1CprNcLDnHcQ3iYv2UgyY7pJ/JRv3MAIrxRCGD1eanAnf3uuwIKwKtPDq4CoPyNu+Fgwigdx0riEw+kv8GQI8+1k7MypZH3/8GkigZ0iZJuBH5RE6Hk3qLWOcLmnXJsGb+MKkOii2vqq7NVRD71zsbheSV1zgPV+FazVRd/kda0r4z0cmNxQ3JNiYelQhnROB+MNKfyeG/4QtYwHOAMUBaD14GApp4/o+/wGTLuQ1D7NcnQIjJLC2csrlxG6CRS8rkaJEtgJzmK/MFWiQdkym2YlhFn95sX7RW6EK0T0LDguwqrnm8kaec7+aWv2UVVpJ7534+eIBMkyt2artxQiE2Z66d4b2gBW5w2SnbVYz+MPRCNTjRrsUyiXjp btcCjhOk +1h7rA0y9ZNZZ15XVpoIFTF0RIQB8IrcBUX25SPNI2ySVaMK65l8sLF5+Ui4p2xPWa5gcpf50aLbxgEicRWAgN/Bgcr3HpaNys86Qg9J9DBwfDNrU8g4SZyFR0RVq1x2cDIpo1xzJ/X5FrVK7pESIid4HdA== 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 The current implementation of the extra_bits interface is confusing: passing extra_bits to __stack_depot_save makes it seem that the extra bits are somehow stored in stack depot. In reality, they are only embedded into a stack depot handle and are not used within stack depot. Drop the extra_bits argument from __stack_depot_save and instead provide a new stack_depot_set_extra_bits function (similar to the exsiting stack_depot_get_extra_bits) that saves extra bits into a stack depot handle. Update the callers of __stack_depot_save to use the new interace. This change also fixes a minor issue in the old code: __stack_depot_save does not return NULL if saving stack trace fails and extra_bits is used. Signed-off-by: Andrey Konovalov Changes v1->v2: - Mark stack_depot_set_extra_bits as __must_check. - Only assign extra bits in stack_depot_set_extra_bits for non-empty handles. Reviewed-by: Alexander Potapenko --- include/linux/stackdepot.h | 4 +++- lib/stackdepot.c | 42 ++++++++++++++++++++++++++++++-------- mm/kasan/common.c | 2 +- mm/kmsan/core.c | 10 ++++++--- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index c4e3abc16b16..267f4b2634ee 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -57,7 +57,6 @@ static inline int stack_depot_early_init(void) { return 0; } depot_stack_handle_t __stack_depot_save(unsigned long *entries, unsigned int nr_entries, - unsigned int extra_bits, gfp_t gfp_flags, bool can_alloc); depot_stack_handle_t stack_depot_save(unsigned long *entries, @@ -71,6 +70,9 @@ void stack_depot_print(depot_stack_handle_t stack); int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size, int spaces); +depot_stack_handle_t __must_check stack_depot_set_extra_bits( + depot_stack_handle_t handle, unsigned int extra_bits); + unsigned int stack_depot_get_extra_bits(depot_stack_handle_t handle); #endif diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 4df162a84bfe..8c6e4e9cb535 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -357,7 +357,6 @@ static inline struct stack_record *find_stack(struct stack_record *bucket, * * @entries: Pointer to storage array * @nr_entries: Size of the storage array - * @extra_bits: Flags to store in unused bits of depot_stack_handle_t * @alloc_flags: Allocation gfp flags * @can_alloc: Allocate stack pools (increased chance of failure if false) * @@ -369,10 +368,6 @@ static inline struct stack_record *find_stack(struct stack_record *bucket, * If the stack trace in @entries is from an interrupt, only the portion up to * interrupt entry is saved. * - * Additional opaque flags can be passed in @extra_bits, stored in the unused - * bits of the stack handle, and retrieved using stack_depot_get_extra_bits() - * without calling stack_depot_fetch(). - * * Context: Any context, but setting @can_alloc to %false is required if * alloc_pages() cannot be used from the current context. Currently * this is the case from contexts where neither %GFP_ATOMIC nor @@ -382,7 +377,6 @@ static inline struct stack_record *find_stack(struct stack_record *bucket, */ depot_stack_handle_t __stack_depot_save(unsigned long *entries, unsigned int nr_entries, - unsigned int extra_bits, gfp_t alloc_flags, bool can_alloc) { struct stack_record *found = NULL, **bucket; @@ -471,8 +465,6 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, if (found) retval.handle = found->handle.handle; fast_exit: - retval.extra = extra_bits; - return retval.handle; } EXPORT_SYMBOL_GPL(__stack_depot_save); @@ -493,7 +485,7 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, unsigned int nr_entries, gfp_t alloc_flags) { - return __stack_depot_save(entries, nr_entries, 0, alloc_flags, true); + return __stack_depot_save(entries, nr_entries, alloc_flags, true); } EXPORT_SYMBOL_GPL(stack_depot_save); @@ -576,6 +568,38 @@ int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size, } EXPORT_SYMBOL_GPL(stack_depot_snprint); +/** + * stack_depot_set_extra_bits - Set extra bits in a stack depot handle + * + * @handle: Stack depot handle returned from stack_depot_save() + * @extra_bits: Value to set the extra bits + * + * Return: Stack depot handle with extra bits set + * + * Stack depot handles have a few unused bits, which can be used for storing + * user-specific information. These bits are transparent to the stack depot. + */ +depot_stack_handle_t __must_check stack_depot_set_extra_bits( + depot_stack_handle_t handle, unsigned int extra_bits) +{ + union handle_parts parts = { .handle = handle }; + + /* Don't set extra bits on empty handles. */ + if (!handle) + return 0; + + parts.extra = extra_bits; + return parts.handle; +} +EXPORT_SYMBOL(stack_depot_set_extra_bits); + +/** + * stack_depot_get_extra_bits - Retrieve extra bits from a stack depot handle + * + * @handle: Stack depot handle with extra bits saved + * + * Return: Extra bits retrieved from the stack depot handle + */ unsigned int stack_depot_get_extra_bits(depot_stack_handle_t handle) { union handle_parts parts = { .handle = handle }; diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 833bf2cfd2a3..50f4338b477f 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -43,7 +43,7 @@ depot_stack_handle_t kasan_save_stack(gfp_t flags, bool can_alloc) unsigned int nr_entries; nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0); - return __stack_depot_save(entries, nr_entries, 0, flags, can_alloc); + return __stack_depot_save(entries, nr_entries, flags, can_alloc); } void kasan_set_track(struct kasan_track *track, gfp_t flags) diff --git a/mm/kmsan/core.c b/mm/kmsan/core.c index 112dce135c7f..f710257d6867 100644 --- a/mm/kmsan/core.c +++ b/mm/kmsan/core.c @@ -69,13 +69,15 @@ depot_stack_handle_t kmsan_save_stack_with_flags(gfp_t flags, { unsigned long entries[KMSAN_STACK_DEPTH]; unsigned int nr_entries; + depot_stack_handle_t handle; nr_entries = stack_trace_save(entries, KMSAN_STACK_DEPTH, 0); /* Don't sleep (see might_sleep_if() in __alloc_pages_nodemask()). */ flags &= ~__GFP_DIRECT_RECLAIM; - return __stack_depot_save(entries, nr_entries, extra, flags, true); + handle = __stack_depot_save(entries, nr_entries, flags, true); + return stack_depot_set_extra_bits(handle, extra); } /* Copy the metadata following the memmove() behavior. */ @@ -215,6 +217,7 @@ depot_stack_handle_t kmsan_internal_chain_origin(depot_stack_handle_t id) u32 extra_bits; int depth; bool uaf; + depot_stack_handle_t handle; if (!id) return id; @@ -250,8 +253,9 @@ depot_stack_handle_t kmsan_internal_chain_origin(depot_stack_handle_t id) * positives when __stack_depot_save() passes it to instrumented code. */ kmsan_internal_unpoison_memory(entries, sizeof(entries), false); - return __stack_depot_save(entries, ARRAY_SIZE(entries), extra_bits, - GFP_ATOMIC, true); + handle = __stack_depot_save(entries, ARRAY_SIZE(entries), GFP_ATOMIC, + true); + return stack_depot_set_extra_bits(handle, extra_bits); } void kmsan_internal_set_shadow_origin(void *addr, size_t size, int b, From patchwork Fri Feb 10 21:16:04 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: 13136465 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 482B6C6379F for ; Fri, 10 Feb 2023 21:18:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 527096B019E; Fri, 10 Feb 2023 16:18:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 488146B01A0; Fri, 10 Feb 2023 16:18:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 303D06B01A1; Fri, 10 Feb 2023 16:18:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1EADC6B019E for ; Fri, 10 Feb 2023 16:18:23 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id F20FD807E3 for ; Fri, 10 Feb 2023 21:18:22 +0000 (UTC) X-FDA: 80452645644.07.B4D80BA Received: from out-33.mta1.migadu.com (out-33.mta1.migadu.com [95.215.58.33]) by imf06.hostedemail.com (Postfix) with ESMTP id 2286B180009 for ; Fri, 10 Feb 2023 21:18:20 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=t7vDpQcZ; spf=pass (imf06.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.33 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=1676063901; 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=Qnr9u9smPMPXsKAXlYWG4fUkkGTB3Zxw4vbQvgaYcVg=; b=4/ABSra0oaVMfwgUmnNpOCz2sljyHvf8+LDTCmf4DtEk0vDylN068tLjREN7M3lrje4Gia +ua9NGR8FvIiy1uZU+2vUzfgvutCIJ2N+WP39MUAwkN3u9q+6n21UNtU2QA/ndNR82t8yp 6/UgQEJrUkC270AXf2lRwgGaDxUi+SE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=t7vDpQcZ; spf=pass (imf06.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.33 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063901; a=rsa-sha256; cv=none; b=bblhBegu4BizfBDUnWHNGXWu/EIvNoKTVF8jIIuk9rSxo0PprkztLqDbCfnz4B5QTTm0da QQ8FLLNr7eXNoTF6RtR1pV2YxIJK6GtykK2bA7H36avSxTCN4V6SiNP4JpRIZ6llnCBuxK 0oQbKHVG4zEjADm5bvQCE8LQ3DpW8CE= 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=1676063899; 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=Qnr9u9smPMPXsKAXlYWG4fUkkGTB3Zxw4vbQvgaYcVg=; b=t7vDpQcZUJdsleERJ1PgO38Pvi8xFhTNn74zLonJYcITtx61e02XeD2vPBg9c//+BpeG1V s7T+qicncVYyTp2KtBAyctdyaGSJ7zdRMIgR7n9TfK44wSuf3yHrV92DaF9e4tXpgOOkwx I+Gi5V7tNQW76e1Nfyz/DJq/+nVFLGI= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 16/18] lib/stackdepot: annotate racy pool_index accesses Date: Fri, 10 Feb 2023 22:16:04 +0100 Message-Id: <359ac9c13cd0869c56740fb2029f505e41593830.1676063693.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: e4huhf54figtuma9sz8sg5goe78t6zpi X-Rspam-User: X-Rspamd-Queue-Id: 2286B180009 X-Rspamd-Server: rspam06 X-HE-Tag: 1676063900-36848 X-HE-Meta: U2FsdGVkX1+ybCgC1YgIyA9D4nIIy4CcQza960XAwT0Hp8iG22eiX6gVcdvL+nwJ0zBVB9cDKgR5VXuDFk2nZUSDo1Kv7Buo2m9WD17PzgiG491FfjC4uLnd8hRz9/a5W0iTyWyO90Bkv3YS3+wCh0VrGEIN7pTCuLmOeYqHjiKWuobH3fQ5YAEzl7KjrHVcgqPJ+WM1SZPeVqasq4n9AK+RVlpbhRmws17TAfXRJ1TMXNaVhb+Z6EiewkWTuMZwOBlStm49bjjEwG8gZHET0QANqUo3Ek0POfpyzV+txkuEqyXEWJD5C1863ZhpAgxQPRM802YZ1Dt5NchQDMq9vZExXPodfT7eEY/jFfQjzcJkPTku+qCeTGrYDoSoC9L1Dj8TPFlDfU5YGl9vf4EB9n9O19lPpUnHabPLrD2vqrPO7CbAqtdMINtk8GZq3t7x2JedvhLX/jDbAhhncFc0oS46rnX8e88h0ZJgRC8LJMqgVo5305JnJzcRMdb1nObbVwbmggIiJZJMKWHutJZfQ/Z/MpGnJIwQvRBY8IlhPy/9Z/2Ag64s4rJudJewI6sp7nBbb5V7axK2Lcd0h/YBZzSRRz3oyCSTUZt4n+hqLNRXQIJltg+T8qWOwHGZyCwcLWYdExCuqI53pSuK4HAFZTCcuNwoeKFfrRMqH/7AodbJSMof8yJcYUpALk6u648a8R4LFJQTtkFsgMP479Nu1Hnanb9Aq88pKsvr2I/nInvT2XJsAR5R9atV0ofHgRyI9Z3FHOnV6J7q00KivRche4uz1nHkdHe15AM0f0PoYLAeS6FEPHT8oip98i7bA5q/3ER76zfzPD29mhBr689oF+8RproBzGqImZVVww0xu5LD8GxFg3QEKyA2MyBgGqGFr5hzV6B41C/1kiNHYWZfUrsUDu+gUew8prYpv7a81aCPTJoJgUvLaOIlmKUkA6UDJGYm4D2xALqB8b6xdr+ veqjGOGS mbLX7Z1RV9tebUWkZOIh2JfrwiDpAKSGJPYjtGZMFyXzsm0V+InVpB5xr9VpazjzRmNqSrLr7I2Lmko4WdoWI7+4yy8S4HosmW7pJP0+Aj0vNpYzX7cSmtqyJrNggyuPWYLwv0VTsVoyp0czZknb1GZwWpQ== 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 Accesses to pool_index are protected by pool_lock everywhere except in a sanity check in stack_depot_fetch. The read access there can race with the write access in depot_alloc_stack. Use WRITE/READ_ONCE() to annotate the racy accesses. As the sanity check is only used to print a warning in case of a violation of the stack depot interface usage, it does not make a lot of sense to use proper synchronization. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- Changes v1->v2: - Improve comments as suggested by Marco. --- lib/stackdepot.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 8c6e4e9cb535..684c2168bed9 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -278,8 +278,12 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) return NULL; } - /* Move on to the next pool. */ - pool_index++; + /* + * Move on to the next pool. + * WRITE_ONCE pairs with potential concurrent read in + * stack_depot_fetch(). + */ + WRITE_ONCE(pool_index, pool_index + 1); pool_offset = 0; /* * If the maximum number of pools is not reached, take note @@ -502,6 +506,11 @@ 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; @@ -510,7 +519,7 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, if (!handle) return 0; - if (parts.pool_index > pool_index) { + 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, handle); return 0; From patchwork Fri Feb 10 21:16:05 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: 13136466 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 8CB95C05027 for ; Fri, 10 Feb 2023 21:18:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 243936B01A0; Fri, 10 Feb 2023 16:18:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 12E4A280003; Fri, 10 Feb 2023 16:18:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC1046B01A3; Fri, 10 Feb 2023 16:18:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C72366B01A0 for ; Fri, 10 Feb 2023 16:18:23 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AA3CF1601F6 for ; Fri, 10 Feb 2023 21:18:23 +0000 (UTC) X-FDA: 80452645686.29.70FDA2E Received: from out-92.mta1.migadu.com (out-92.mta1.migadu.com [95.215.58.92]) by imf05.hostedemail.com (Postfix) with ESMTP id AD70F100010 for ; Fri, 10 Feb 2023 21:18:21 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=AlHLyZgb; spf=pass (imf05.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.92 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=1676063902; 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=XFkfD8nWcU19ZRb+TgOQz2ixkVAPXCSEhGc+z57a3G8=; b=2sUFSOfefxmbZnsuBsvdteq9dKBK2G3yP6ouS9fOa+DvSai5jdcb84VDNLE3jMpVlD0ztd oPwhDtycwaqrtXZROr6hvdjqB1mf2KwWJCq+VveWzqPooiiMixRC+agC5V4I6AgpfhWzWs a1O9MEk/qEgMy82NKfkIxvnO8ZDGJ+E= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=AlHLyZgb; spf=pass (imf05.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.92 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063902; a=rsa-sha256; cv=none; b=2JV5N5lr0rIXNHpmzt5AI0MOjw4hl6HsTuZRMYDVOEema8QKlvwPKqjtnUFwmVY3KXicz0 aeK38yWYqo3mLqTgzbCZHmKGY1xkE57EFRxUh0EjTuGzq2KWKJRtSyNYNIj2F0zEwdJ5bl H4RjI4X0NyKOhIWhHoAtCQdlXc5wbeo= 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=1676063900; 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=XFkfD8nWcU19ZRb+TgOQz2ixkVAPXCSEhGc+z57a3G8=; b=AlHLyZgbWtYwcMxzCM7UstqxwRBchMfdGQfs0+otkspc5NnQ6yu1iVkNqKOV5pm0CTJx0q sCq8QxxCwK7UE46eaiNlFlHBEUEl0BCx2UCiV+GEzhMTJy/qTWUNvJBDFpl+Hd148m2NyR u/65wMn0XXpeafUdVkYfQ2Y3vn0ewzQ= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 17/18] lib/stackdepot: various comments clean-ups Date: Fri, 10 Feb 2023 22:16:05 +0100 Message-Id: <5836231b7954355e2311fc9b5870f697ea8e1f7d.1676063693.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: mcjwajg99apdoch9pxbq4zqz9xg7ctw1 X-Rspam-User: X-Rspamd-Queue-Id: AD70F100010 X-Rspamd-Server: rspam06 X-HE-Tag: 1676063901-288831 X-HE-Meta: U2FsdGVkX19AhyNuj9DLMiTbOXlFOMLpUm4ZAVrwcWwbpqiB8aCKoyxl7NMMMzec52iTXYiLrFqktCpeBjR9XpGp29QICEv2GIHllR8TD+lHgXZb3+wRvUuIJ5MTBZD8xXY/MP4iiBDlyDR01Dp+x9HtJlFt/3Wk2RmhTCXh5z7LJMObHlED4u2Wh+2S03eHdd3Y3UhkCuN2OKOz8NfqAkS1xlaJzxrHWTytVIZuBImSbBwTfV/ZPsfSWXsm0LKTnlxgs6CWPiyVtCA4s/vJ1sSa/mGVlaC6jQtsmHDM+ZMBgmULvUU7MYxhYw09UKUh4qLEKfCZCvlVhZJiCwHOPxA/iulL/YanxJH4oWc+coA/6SDQ9KMCFlh/AgFl7hbk1Ci5eCHLUhvwF+Y0bNp7FWKRv1voGuHeOsAo8DLxCH8s11x91/wZNK0txaAmQXfMNVaj5TwpkMtZ4RZLHGdhj0fnQM5ZmrRf/1H7tR9DvhGvl3NGZdvmFJSC33djC90wah1n4LOlTdb0uRlNq01N+0Ztf7AJ0p4thmjsHVU38LIetMuccejPm/MSVfem1zHmf/PUy3hvy7UJjLuHPr7w5Awkw3CPWevKTyCWh9XYIspQ5H1pPHOuDLboyARVb+vtEz7/c7gbI9wYkuA8Oa8IQq3sRs3Yu+2XVkgBu+W6IZdG0JN58cguCeTkkKI57aCmjQG+4HbcqnbEk+u2YHHctc7uj6hLRovHAdWSTbraglcyc7qFAB9ES5xsKZYTz3s3ncUTPhJtBdGEawqocvhm7fFcVi80a8XDmHGYpJfztWg1Z+QJBZwAJ9GYqvRVY4dLTNk+Ho032VJe1RviZXXB+lGnLezpTRHX28r/m0RrFLJTUZ7afyD7Tt35CljmcUyk5jkyBLj3fX9C0/5d3BD/bqyUxfxMd3U6u3K5Pfccs8Ut+Ao70pSPcm46CEdKpcd4d8CHIbZ+zEJDJ6qq7D2 fKLIdv6x BTc33trBfaXQGFvGplsAft6082Sinhqr4jXFBFxHShD9cXoboKEg0NymVuirI0m2Wp90nggudNl75SJIucED7hsQdxy2N0orQoFkERkaP1x5NGOo= 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 Clean up comments in include/linux/stackdepot.h and lib/stackdepot.c: 1. Rework the initialization comment in stackdepot.h. 2. Rework the header comment in stackdepot.c. 3. Various clean-ups for other comments. Also adjust whitespaces for find_stack and depot_alloc_stack call sites. No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- include/linux/stackdepot.h | 36 +++++------ lib/stackdepot.c | 120 ++++++++++++++++++------------------- 2 files changed, 78 insertions(+), 78 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index 267f4b2634ee..afdf8ee7b597 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -1,11 +1,11 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ /* - * A generic stack depot implementation + * Stack depot - a stack trace storage that avoids duplication. * * Author: Alexander Potapenko * Copyright (C) 2016 Google, Inc. * - * Based on code by Dmitry Chernenkov. + * Based on the code by Dmitry Chernenkov. */ #ifndef _LINUX_STACKDEPOT_H @@ -17,35 +17,37 @@ typedef u32 depot_stack_handle_t; /* * Number of bits in the handle that stack depot doesn't use. Users may store - * information in them. + * information in them via stack_depot_set/get_extra_bits. */ #define STACK_DEPOT_EXTRA_BITS 5 /* - * Every user of stack depot has to call stack_depot_init() during its own init - * when it's decided that it will be calling stack_depot_save() later. This is - * recommended for e.g. modules initialized later in the boot process, when - * slab_is_available() is true. + * Using stack depot requires its initialization, which can be done in 3 ways: * - * The alternative is to select STACKDEPOT_ALWAYS_INIT to have stack depot - * enabled as part of mm_init(), for subsystems where it's known at compile time - * that stack depot will be used. + * 1. Selecting CONFIG_STACKDEPOT_ALWAYS_INIT. This option is suitable in + * scenarios where it's known at compile time that stack depot will be used. + * Enabling this config makes the kernel initialize stack depot in mm_init(). * - * Another alternative is to call stack_depot_request_early_init(), when the - * decision to use stack depot is taken e.g. when evaluating kernel boot - * parameters, which precedes the enablement point in mm_init(). + * 2. Calling stack_depot_request_early_init() during early boot, before + * stack_depot_early_init() in mm_init() completes. For example, this can + * be done when evaluating kernel boot parameters. + * + * 3. Calling stack_depot_init(). Possible after boot is complete. This option + * is recommended for modules initialized later in the boot process, after + * mm_init() completes. * * stack_depot_init() and stack_depot_request_early_init() can be called - * regardless of CONFIG_STACKDEPOT and are no-op when disabled. The actual - * save/fetch/print functions should only be called from code that makes sure - * CONFIG_STACKDEPOT is enabled. + * regardless of whether CONFIG_STACKDEPOT is enabled and are no-op when this + * config is disabled. The save/fetch/print stack depot functions can only be + * called from the code that makes sure CONFIG_STACKDEPOT is enabled _and_ + * initializes stack depot via one of the ways listed above. */ #ifdef CONFIG_STACKDEPOT int stack_depot_init(void); void __init stack_depot_request_early_init(void); -/* This is supposed to be called only from mm_init() */ +/* Must be only called from mm_init(). */ int __init stack_depot_early_init(void); #else static inline int stack_depot_init(void) { return 0; } diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 684c2168bed9..02bb6cdb69dc 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -1,22 +1,26 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Generic stack depot for storing stack traces. + * Stack depot - a stack trace storage that avoids duplication. * - * Some debugging tools need to save stack traces of certain events which can - * be later presented to the user. For example, KASAN needs to safe alloc and - * free stacks for each object, but storing two stack traces per object - * requires too much memory (e.g. SLUB_DEBUG needs 256 bytes per object for - * that). + * Stack depot is intended to be used by subsystems that need to store and + * later retrieve many potentially duplicated stack traces without wasting + * memory. * - * Instead, stack depot maintains a hashtable of unique stacktraces. Since alloc - * and free stacks repeat a lot, we save about 100x space. - * Stacks are never removed from depot, so we store them contiguously one after - * another in a contiguous memory allocation. + * For example, KASAN needs to save allocation and free stack traces for each + * object. Storing two stack traces per object requires a lot of memory (e.g. + * SLUB_DEBUG needs 256 bytes per object for that). Since allocation and free + * stack traces often repeat, using stack depot allows to save about 100x space. + * + * Internally, stack depot maintains a hash table of unique stacktraces. The + * stack traces themselves are stored contiguously one after another in a set + * of separate page allocations. + * + * Stack traces are never removed from stack depot. * * Author: Alexander Potapenko * Copyright (C) 2016 Google, Inc. * - * Based on code by Dmitry Chernenkov. + * Based on the code by Dmitry Chernenkov. */ #define pr_fmt(fmt) "stackdepot: " fmt @@ -50,7 +54,7 @@ (((1LL << (DEPOT_POOL_INDEX_BITS)) < DEPOT_POOLS_CAP) ? \ (1LL << (DEPOT_POOL_INDEX_BITS)) : DEPOT_POOLS_CAP) -/* The compact structure to store the reference to stacks. */ +/* Compact structure that stores a reference to a stack. */ union handle_parts { depot_stack_handle_t handle; struct { @@ -62,11 +66,11 @@ union handle_parts { }; struct stack_record { - struct stack_record *next; /* Link in the hashtable */ - u32 hash; /* Hash in the hastable */ - u32 size; /* Number of frames in the stack */ + struct stack_record *next; /* Link in the hash table */ + u32 hash; /* Hash in the hash table */ + u32 size; /* Number of stored frames */ union handle_parts handle; - unsigned long entries[]; /* Variable-sized array of entries. */ + unsigned long entries[]; /* Variable-sized array of frames */ }; static bool stack_depot_disabled; @@ -317,7 +321,7 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) return stack; } -/* Calculate hash for a stack */ +/* Calculates the hash for a stack. */ static inline u32 hash_stack(unsigned long *entries, unsigned int size) { return jhash2((u32 *)entries, @@ -325,9 +329,9 @@ static inline u32 hash_stack(unsigned long *entries, unsigned int size) STACK_HASH_SEED); } -/* Use our own, non-instrumented version of memcmp(). - * - * We actually don't care about the order, just the equality. +/* + * Non-instrumented version of memcmp(). + * Does not check the lexicographical order, only the equality. */ static inline int stackdepot_memcmp(const unsigned long *u1, const unsigned long *u2, @@ -340,7 +344,7 @@ int stackdepot_memcmp(const unsigned long *u1, const unsigned long *u2, return 0; } -/* Find a stack that is equal to the one stored in entries in the hash */ +/* Finds a stack in a bucket of the hash table. */ static inline struct stack_record *find_stack(struct stack_record *bucket, unsigned long *entries, int size, u32 hash) @@ -357,27 +361,27 @@ static inline struct stack_record *find_stack(struct stack_record *bucket, } /** - * __stack_depot_save - Save a stack trace from an array + * __stack_depot_save - Save a stack trace to stack depot * - * @entries: Pointer to storage array - * @nr_entries: Size of the storage array - * @alloc_flags: Allocation gfp flags + * @entries: Pointer to the stack trace + * @nr_entries: Number of frames in the stack + * @alloc_flags: Allocation GFP flags * @can_alloc: Allocate stack pools (increased chance of failure if false) * * Saves a stack trace from @entries array of size @nr_entries. If @can_alloc is - * %true, is allowed to replenish the stack pool in case no space is left + * %true, stack depot can replenish the stack pools in case no space is left * (allocates using GFP flags of @alloc_flags). If @can_alloc is %false, avoids - * any allocations and will fail if no space is left to store the stack trace. + * any allocations and fails if no space is left to store the stack trace. * - * If the stack trace in @entries is from an interrupt, only the portion up to - * interrupt entry is saved. + * If the provided stack trace comes from the interrupt context, only the part + * up to the interrupt entry is saved. * * Context: Any context, but setting @can_alloc to %false is required if * alloc_pages() cannot be used from the current context. Currently - * this is the case from contexts where neither %GFP_ATOMIC nor + * this is the case for contexts where neither %GFP_ATOMIC nor * %GFP_NOWAIT can be used (NMI, raw_spin_lock). * - * Return: The handle of the stack struct stored in depot, 0 on failure. + * Return: Handle of the stack struct stored in depot, 0 on failure */ depot_stack_handle_t __stack_depot_save(unsigned long *entries, unsigned int nr_entries, @@ -392,11 +396,11 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, /* * If this stack trace is from an interrupt, including anything before - * interrupt entry usually leads to unbounded stackdepot growth. + * interrupt entry usually leads to unbounded stack depot growth. * - * Because use of filter_irq_stacks() is a requirement to ensure - * stackdepot can efficiently deduplicate interrupt stacks, always - * filter_irq_stacks() to simplify all callers' use of stackdepot. + * Since use of filter_irq_stacks() is a requirement to ensure stack + * depot can efficiently deduplicate interrupt stacks, always + * filter_irq_stacks() to simplify all callers' use of stack depot. */ nr_entries = filter_irq_stacks(entries, nr_entries); @@ -411,8 +415,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, * The smp_load_acquire() here pairs with smp_store_release() to * |bucket| below. */ - found = find_stack(smp_load_acquire(bucket), entries, - nr_entries, hash); + found = find_stack(smp_load_acquire(bucket), entries, nr_entries, hash); if (found) goto exit; @@ -441,7 +444,8 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, found = find_stack(*bucket, entries, nr_entries, hash); if (!found) { - struct stack_record *new = depot_alloc_stack(entries, nr_entries, hash, &prealloc); + struct stack_record *new = + depot_alloc_stack(entries, nr_entries, hash, &prealloc); if (new) { new->next = *bucket; @@ -454,8 +458,8 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, } } else if (prealloc) { /* - * We didn't need to store this stack trace, but let's keep - * the preallocated memory for the future. + * Stack depot already contains this stack trace, but let's + * keep the preallocated memory for the future. */ depot_init_pool(&prealloc); } @@ -463,7 +467,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, raw_spin_unlock_irqrestore(&pool_lock, flags); exit: if (prealloc) { - /* Nobody used this memory, ok to free it. */ + /* Stack depot didn't use this memory, free it. */ free_pages((unsigned long)prealloc, DEPOT_POOL_ORDER); } if (found) @@ -474,16 +478,16 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, EXPORT_SYMBOL_GPL(__stack_depot_save); /** - * stack_depot_save - Save a stack trace from an array + * stack_depot_save - Save a stack trace to stack depot * - * @entries: Pointer to storage array - * @nr_entries: Size of the storage array - * @alloc_flags: Allocation gfp flags + * @entries: Pointer to the stack trace + * @nr_entries: Number of frames in the stack + * @alloc_flags: Allocation GFP flags * * Context: Contexts where allocations via alloc_pages() are allowed. * See __stack_depot_save() for more details. * - * Return: The handle of the stack struct stored in depot, 0 on failure. + * Return: Handle of the stack trace stored in depot, 0 on failure */ depot_stack_handle_t stack_depot_save(unsigned long *entries, unsigned int nr_entries, @@ -494,13 +498,12 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, EXPORT_SYMBOL_GPL(stack_depot_save); /** - * stack_depot_fetch - Fetch stack entries from a depot + * stack_depot_fetch - Fetch a stack trace from stack depot * - * @handle: Stack depot handle which was returned from - * stack_depot_save(). - * @entries: Pointer to store the entries address + * @handle: Stack depot handle returned from stack_depot_save() + * @entries: Pointer to store the address of the stack trace * - * Return: The number of trace entries for this depot. + * Return: Number of frames for the fetched stack */ unsigned int stack_depot_fetch(depot_stack_handle_t handle, unsigned long **entries) @@ -535,11 +538,9 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, EXPORT_SYMBOL_GPL(stack_depot_fetch); /** - * stack_depot_print - print stack entries from a depot - * - * @stack: Stack depot handle which was returned from - * stack_depot_save(). + * stack_depot_print - Print a stack trace from stack depot * + * @stack: Stack depot handle returned from stack_depot_save() */ void stack_depot_print(depot_stack_handle_t stack) { @@ -553,17 +554,14 @@ void stack_depot_print(depot_stack_handle_t stack) EXPORT_SYMBOL_GPL(stack_depot_print); /** - * stack_depot_snprint - print stack entries from a depot into a buffer + * stack_depot_snprint - Print a stack trace from stack depot into a buffer * - * @handle: Stack depot handle which was returned from - * stack_depot_save(). + * @handle: Stack depot handle returned from stack_depot_save() * @buf: Pointer to the print buffer - * * @size: Size of the print buffer - * * @spaces: Number of leading spaces to print * - * Return: Number of bytes printed. + * Return: Number of bytes printed */ int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size, int spaces) From patchwork Fri Feb 10 21:16:06 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: 13136467 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 C119DC636D4 for ; Fri, 10 Feb 2023 21:19:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C18F6B01A3; Fri, 10 Feb 2023 16:19:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 54A3B6B01A4; Fri, 10 Feb 2023 16:19:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39CA66B01A5; Fri, 10 Feb 2023 16:19:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 22FD66B01A3 for ; Fri, 10 Feb 2023 16:19:25 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DC39AAB7DE for ; Fri, 10 Feb 2023 21:19:24 +0000 (UTC) X-FDA: 80452648248.05.828DF06 Received: from out-248.mta1.migadu.com (out-248.mta1.migadu.com [95.215.58.248]) by imf03.hostedemail.com (Postfix) with ESMTP id E04A82001C for ; Fri, 10 Feb 2023 21:19:22 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=s10+K4Rz; spf=pass (imf03.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.248 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=1676063963; 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=FT29KRMbRE0UIrHSR8VL9ToKxsY1mNQpa5JLen40C60=; b=RazQX8TA9MwwHjJSN3odNzUFQOhVyjgl6IVF1WyyQ2L7zPJS5lEWtg+j6IvVa+T3va/x6l uNP7TBTcuVtuQyC3sKh7O4D2uD7a3HMb2C414J9IkFnJU9usaFfs1bU2tzk/iqPJxmp94i qFWSnxCRfpeiJsiFCt2WQOL5OrE/+xQ= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=s10+K4Rz; spf=pass (imf03.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.248 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676063963; a=rsa-sha256; cv=none; b=ksGe3MrifN6UWQbDGrE1erJ2oTbim5ZaIdpwC4a8aPlkg31bys/RIR122KjLffWukm3oJj Gskz9Wfrb3Viqxd0y0Mgl0+xdTA877L3R55P1R85nBnEMsLMUwOziq8fGqfO4UzwbttG8V IB0Ph7Hgossln+650fDS3/ct2sGeZys= 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=1676063961; 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=FT29KRMbRE0UIrHSR8VL9ToKxsY1mNQpa5JLen40C60=; b=s10+K4Rzc2sALXbIT+1TmOUw/81gMdFkCt3qDr6ED6IWbAlMmTt/KRQMXBw6qBCR6MobWg d3HivIkbrsLLO9p7S+4pHdXxB1gdQs2OLVS4TRFlC/4OfM+P1PI3uxfXCz9h5ocVbc3BCx Y061miA3dkscw+XnPpB5bNkpLLfQj4s= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 18/18] lib/stackdepot: move documentation comments to stackdepot.h Date: Fri, 10 Feb 2023 22:16:06 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: E04A82001C X-Stat-Signature: yxhgj3m68peed1fho6qg67njomr7c3q6 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1676063962-830932 X-HE-Meta: U2FsdGVkX190qWl1AtRbuIsgM8ViVI66HBhVDfcRUcQBHrGyyfo2pjnVpxi0oEgMdBoNnPPCVCXixCTgmovONFXmK+asImwMaXOk6uSEC1Ge7VIWxKZ7uirbpCRhiiriPSAJu+UV/3WQ2j10scnlr9l0lRgDSLEeYMiFUopAuTb2g63eTdP4/eesdFW22oz6dmyeCyvTqtoJKt56u2wHsuuAvmVEv3CcFxaHfssWq5RpiTWMD843033Z8jcCvZdKKZoF2cYHs+YKS2Pds0g5RHZURueurgoyJR3Ub+YSoJU4YwwFC4VIFh+vzqfpt1QSmnJPGFDMh2NoqtbkUzXoZy46CGuyFL6YShwpOdNP+CLRXaiLDWRjJIZKaRVtkfw/GNmg8Tbm9LeGnCMCGIybApQgkRfUcD6VJ1K2gjSHFx2z54yKB/FAXNHReM8aqGT0dIhUHr1j1ekmCbozT4UM0XsCoc7URfPHZx1buEwXoTjspN34msAP4oQwh4gY7FnWsA/hubzSX6ySEFkt4ObOzGlye60ZZEs74eg3TBUh0/+MpqI988WyNVScyqk8NsBE+UHz+bQUr7R51WhUu17rHc84Qcs0IrTHgTlk0cyFNn23nxMvbbXnIJsgNspO7LiyM+jwBmAOIzj4SD+u/XILFN8smhgGIaevoNlbpuA9+2dECkZxT2TzBn0gdAhAS7xzDfVbxE+VycTLzf5Vte2rclO22aFqU7+6WBc3FXCdzm2DYfYeYO90dZoZQ3/sBIk6CZ+aGlpsaL2eqZIuzTox2+UVkUadocEHsDR2W+eKv1AUS4FRCgfuNfBhgzfLRnl3ZHSsErHy5q9iM9JZUtY2fv07kiVkDpFTsvrop6L39HkcpLDlmrXaDuz8p0aqD/iDywEXdmsjfcjkcOcjSMuLoDmUst0Ps+P0qnWvExzQuJtDwFfaWZgk26Y5Vu47ND/qlRDEmexhkwPrQspJgdj hXEJ97aF WhWFmhVFbw4PpKFoRIS+aGn2Nv/LNKRhtDjokE7XCX/VZYQe7SQfOU5ELcjls2GTcG7S7x7hpW+S09AmCdJzRz1PvFn+nv8ONjFKh 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 Move all interface- and usage-related documentation comments to include/linux/stackdepot.h. It makes sense to have them in the header where they are available to the interface users. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- include/linux/stackdepot.h | 87 ++++++++++++++++++++++++++++++++++++++ lib/stackdepot.c | 87 -------------------------------------- 2 files changed, 87 insertions(+), 87 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index afdf8ee7b597..91f038829eaa 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -2,6 +2,17 @@ /* * Stack depot - a stack trace storage that avoids duplication. * + * Stack depot is intended to be used by subsystems that need to store and + * later retrieve many potentially duplicated stack traces without wasting + * memory. + * + * For example, KASAN needs to save allocation and free stack traces for each + * object. Storing two stack traces per object requires a lot of memory (e.g. + * SLUB_DEBUG needs 256 bytes per object for that). Since allocation and free + * stack traces often repeat, using stack depot allows to save about 100x space. + * + * Stack traces are never removed from stack depot. + * * Author: Alexander Potapenko * Copyright (C) 2016 Google, Inc. * @@ -57,24 +68,100 @@ static inline void stack_depot_request_early_init(void) { } static inline int stack_depot_early_init(void) { return 0; } #endif +/** + * __stack_depot_save - Save a stack trace to stack depot + * + * @entries: Pointer to the stack trace + * @nr_entries: Number of frames in the stack + * @alloc_flags: Allocation GFP flags + * @can_alloc: Allocate stack pools (increased chance of failure if false) + * + * Saves a stack trace from @entries array of size @nr_entries. If @can_alloc is + * %true, stack depot can replenish the stack pools in case no space is left + * (allocates using GFP flags of @alloc_flags). If @can_alloc is %false, avoids + * any allocations and fails if no space is left to store the stack trace. + * + * If the provided stack trace comes from the interrupt context, only the part + * up to the interrupt entry is saved. + * + * Context: Any context, but setting @can_alloc to %false is required if + * alloc_pages() cannot be used from the current context. Currently + * this is the case for contexts where neither %GFP_ATOMIC nor + * %GFP_NOWAIT can be used (NMI, raw_spin_lock). + * + * Return: Handle of the stack struct stored in depot, 0 on failure + */ depot_stack_handle_t __stack_depot_save(unsigned long *entries, unsigned int nr_entries, gfp_t gfp_flags, bool can_alloc); +/** + * stack_depot_save - Save a stack trace to stack depot + * + * @entries: Pointer to the stack trace + * @nr_entries: Number of frames in the stack + * @alloc_flags: Allocation GFP flags + * + * Context: Contexts where allocations via alloc_pages() are allowed. + * See __stack_depot_save() for more details. + * + * Return: Handle of the stack trace stored in depot, 0 on failure + */ depot_stack_handle_t stack_depot_save(unsigned long *entries, unsigned int nr_entries, gfp_t gfp_flags); +/** + * stack_depot_fetch - Fetch a stack trace from stack depot + * + * @handle: Stack depot handle returned from stack_depot_save() + * @entries: Pointer to store the address of the stack trace + * + * Return: Number of frames for the fetched stack + */ unsigned int stack_depot_fetch(depot_stack_handle_t handle, unsigned long **entries); +/** + * stack_depot_print - Print a stack trace from stack depot + * + * @stack: Stack depot handle returned from stack_depot_save() + */ void stack_depot_print(depot_stack_handle_t stack); +/** + * stack_depot_snprint - Print a stack trace from stack depot into a buffer + * + * @handle: Stack depot handle returned from stack_depot_save() + * @buf: Pointer to the print buffer + * @size: Size of the print buffer + * @spaces: Number of leading spaces to print + * + * Return: Number of bytes printed + */ int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size, int spaces); +/** + * stack_depot_set_extra_bits - Set extra bits in a stack depot handle + * + * @handle: Stack depot handle returned from stack_depot_save() + * @extra_bits: Value to set the extra bits + * + * Return: Stack depot handle with extra bits set + * + * Stack depot handles have a few unused bits, which can be used for storing + * user-specific information. These bits are transparent to the stack depot. + */ depot_stack_handle_t __must_check stack_depot_set_extra_bits( depot_stack_handle_t handle, unsigned int extra_bits); +/** + * stack_depot_get_extra_bits - Retrieve extra bits from a stack depot handle + * + * @handle: Stack depot handle with extra bits saved + * + * Return: Extra bits retrieved from the stack depot handle + */ unsigned int stack_depot_get_extra_bits(depot_stack_handle_t handle); #endif diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 02bb6cdb69dc..ec772e78af39 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -2,21 +2,10 @@ /* * Stack depot - a stack trace storage that avoids duplication. * - * Stack depot is intended to be used by subsystems that need to store and - * later retrieve many potentially duplicated stack traces without wasting - * memory. - * - * For example, KASAN needs to save allocation and free stack traces for each - * object. Storing two stack traces per object requires a lot of memory (e.g. - * SLUB_DEBUG needs 256 bytes per object for that). Since allocation and free - * stack traces often repeat, using stack depot allows to save about 100x space. - * * Internally, stack depot maintains a hash table of unique stacktraces. The * stack traces themselves are stored contiguously one after another in a set * of separate page allocations. * - * Stack traces are never removed from stack depot. - * * Author: Alexander Potapenko * Copyright (C) 2016 Google, Inc. * @@ -360,29 +349,6 @@ static inline struct stack_record *find_stack(struct stack_record *bucket, return NULL; } -/** - * __stack_depot_save - Save a stack trace to stack depot - * - * @entries: Pointer to the stack trace - * @nr_entries: Number of frames in the stack - * @alloc_flags: Allocation GFP flags - * @can_alloc: Allocate stack pools (increased chance of failure if false) - * - * Saves a stack trace from @entries array of size @nr_entries. If @can_alloc is - * %true, stack depot can replenish the stack pools in case no space is left - * (allocates using GFP flags of @alloc_flags). If @can_alloc is %false, avoids - * any allocations and fails if no space is left to store the stack trace. - * - * If the provided stack trace comes from the interrupt context, only the part - * up to the interrupt entry is saved. - * - * Context: Any context, but setting @can_alloc to %false is required if - * alloc_pages() cannot be used from the current context. Currently - * this is the case for contexts where neither %GFP_ATOMIC nor - * %GFP_NOWAIT can be used (NMI, raw_spin_lock). - * - * Return: Handle of the stack struct stored in depot, 0 on failure - */ depot_stack_handle_t __stack_depot_save(unsigned long *entries, unsigned int nr_entries, gfp_t alloc_flags, bool can_alloc) @@ -477,18 +443,6 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, } EXPORT_SYMBOL_GPL(__stack_depot_save); -/** - * stack_depot_save - Save a stack trace to stack depot - * - * @entries: Pointer to the stack trace - * @nr_entries: Number of frames in the stack - * @alloc_flags: Allocation GFP flags - * - * Context: Contexts where allocations via alloc_pages() are allowed. - * See __stack_depot_save() for more details. - * - * Return: Handle of the stack trace stored in depot, 0 on failure - */ depot_stack_handle_t stack_depot_save(unsigned long *entries, unsigned int nr_entries, gfp_t alloc_flags) @@ -497,14 +451,6 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, } EXPORT_SYMBOL_GPL(stack_depot_save); -/** - * stack_depot_fetch - Fetch a stack trace from stack depot - * - * @handle: Stack depot handle returned from stack_depot_save() - * @entries: Pointer to store the address of the stack trace - * - * Return: Number of frames for the fetched stack - */ unsigned int stack_depot_fetch(depot_stack_handle_t handle, unsigned long **entries) { @@ -537,11 +483,6 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, } EXPORT_SYMBOL_GPL(stack_depot_fetch); -/** - * stack_depot_print - Print a stack trace from stack depot - * - * @stack: Stack depot handle returned from stack_depot_save() - */ void stack_depot_print(depot_stack_handle_t stack) { unsigned long *entries; @@ -553,16 +494,6 @@ void stack_depot_print(depot_stack_handle_t stack) } EXPORT_SYMBOL_GPL(stack_depot_print); -/** - * stack_depot_snprint - Print a stack trace from stack depot into a buffer - * - * @handle: Stack depot handle returned from stack_depot_save() - * @buf: Pointer to the print buffer - * @size: Size of the print buffer - * @spaces: Number of leading spaces to print - * - * Return: Number of bytes printed - */ int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size, int spaces) { @@ -575,17 +506,6 @@ int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size, } EXPORT_SYMBOL_GPL(stack_depot_snprint); -/** - * stack_depot_set_extra_bits - Set extra bits in a stack depot handle - * - * @handle: Stack depot handle returned from stack_depot_save() - * @extra_bits: Value to set the extra bits - * - * Return: Stack depot handle with extra bits set - * - * Stack depot handles have a few unused bits, which can be used for storing - * user-specific information. These bits are transparent to the stack depot. - */ depot_stack_handle_t __must_check stack_depot_set_extra_bits( depot_stack_handle_t handle, unsigned int extra_bits) { @@ -600,13 +520,6 @@ depot_stack_handle_t __must_check stack_depot_set_extra_bits( } EXPORT_SYMBOL(stack_depot_set_extra_bits); -/** - * stack_depot_get_extra_bits - Retrieve extra bits from a stack depot handle - * - * @handle: Stack depot handle with extra bits saved - * - * Return: Extra bits retrieved from the stack depot handle - */ unsigned int stack_depot_get_extra_bits(depot_stack_handle_t handle) { union handle_parts parts = { .handle = handle };