From patchwork Mon Jan 30 20:49:25 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: 50481 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2395188wrn; Mon, 30 Jan 2023 13:03:19 -0800 (PST) X-Google-Smtp-Source: AK7set/CgzCjDA5nOlf1tnVp0F+KuzwegQ1rt7R099hvNrSX7ZuAj/Fxj8h70k77JZZPYVLWsiTM X-Received: by 2002:a17:906:44d:b0:878:816f:8691 with SMTP id e13-20020a170906044d00b00878816f8691mr14929067eja.71.1675112598923; Mon, 30 Jan 2023 13:03:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675112598; cv=none; d=google.com; s=arc-20160816; b=cJ1aG2/7BbsopprEobNwT4EoIeK2H/s2Vyx61OwaZZBt6gUK24zYMbLRRH2XXRHOzY gQRMu7T+q91odaV8sVeuBDFe4VtwPJIZCRs39c2XMMFsRuJo19OTaESsSVZAUIpXMdgt RGos0B3YOVt6NB+QfqQwCjob48o6qV89ziLG2sxBm/LsW3N6BBrK5NqTNmp0krEN8sUh 8hC3JwLiOP1phHcf6RRKnaM0sokH8zBBr4j0SpvDLyLBBSprEORYJFydIGjfGtsmbJSu 6h/5N+jWk5CnjnZFeT88v5UVId7vd2DngiXP4NZHgjqq4WpaKEgCnT28D1lRqh7KQGLn lYVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vpL8/NdYX1/weZXFrNrkU0jpgSm404fZwOGAfIO2ueo=; b=aL/SU+DFR/GGN2TFi+Jf2P00xbD1ewdpdWAhQhg2ouHdriH0Y6/LYJMKjMxSOTSKj/ TUpb6vm+DjAbLJwCxEKhxJ5Q73pad237fQgKrfxnGleM2k8PX3qcge3n6GO3wZMIBNES nFRGqVEJMF8odhFhloRJqYDxR/DWxdEel3gKOUP6ZAMYEltSCoL7+DjpKC13NBu7PSok 8puY1303eNmF8l3LrQW9HDFfmCwpHKiwRHih3DHh0MSam78ztahrQ/hiOVcO6M7KQudy Rye/LGITHRDGBy8x9yUwPwGVg6VQvDmDh7c1v8gruxgzYarMHM50+xa14QD551m1V3VY ZcCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="l/E56Ec3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gk4-20020a17090790c400b00886971a7fc7si6384927ejb.732.2023.01.30.13.02.54; Mon, 30 Jan 2023 13:03:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="l/E56Ec3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229836AbjA3U4M (ORCPT + 99 others); Mon, 30 Jan 2023 15:56:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229546AbjA3U4L (ORCPT ); Mon, 30 Jan 2023 15:56:11 -0500 X-Greylist: delayed 382 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 30 Jan 2023 12:56:10 PST Received: from out-195.mta1.migadu.com (out-195.mta1.migadu.com [95.215.58.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A3182A15A for ; Mon, 30 Jan 2023 12:56:10 -0800 (PST) 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=1675111786; 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=vpL8/NdYX1/weZXFrNrkU0jpgSm404fZwOGAfIO2ueo=; b=l/E56Ec3WqQvEhqdZjl8IUp453ZZ1+XVexohawe9WXRwZLVX9lAj0fJNkLKpd1L0XbJ/cZ r7uaM/Wl4isiyHyMF6tbOKjX8DK6rY8u5FVwTS72y6me8Wdk0ledgHuQWb2LrJtfpWi2lC Ire9k++4IxKra40cnB4YNO9o09pIkPQ= 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 01/18] lib/stackdepot: fix setting next_slab_inited in init_stack_slab Date: Mon, 30 Jan 2023 21:49:25 +0100 Message-Id: <9fbb4d2bf9b2676a29b120980b5ffbda8e2304ee.1675111415.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482868511311815?= X-GMAIL-MSGID: =?utf-8?q?1756482868511311815?= From: Andrey Konovalov In commit 305e519ce48e ("lib/stackdepot.c: fix global out-of-bounds in stack_slabs"), init_stack_slab was changed to only use preallocated memory for the next slab if the slab number limit is not reached. However, setting next_slab_inited was not moved together with updating stack_slabs. Set next_slab_inited only if the preallocated memory was used for the next slab. Fixes: 305e519ce48e ("lib/stackdepot.c: fix global out-of-bounds in stack_slabs") Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 79e894cf8406..0eed9bbcf23e 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -105,12 +105,13 @@ static bool init_stack_slab(void **prealloc) 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); } - /* - * 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; } From patchwork Mon Jan 30 20:49:26 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: 50482 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2395348wrn; Mon, 30 Jan 2023 13:03:42 -0800 (PST) X-Google-Smtp-Source: AK7set+r94AMy63l+TVCvSd/ybF+r3o2UtJoJJj0gznbAEHQwih+d7NlRG9cJ0m0NhYmviW1tRdl X-Received: by 2002:a05:6a00:1483:b0:590:7616:41eb with SMTP id v3-20020a056a00148300b00590761641ebmr21888600pfu.30.1675112621930; Mon, 30 Jan 2023 13:03:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675112621; cv=none; d=google.com; s=arc-20160816; b=BI0ArGR0lc7DS0UR4Wk84EXCnFs0oS+zIyKowy2fxBZ8lio4tibaS7tMbXClc5na+I DvwYGMAZ4+7r2vItwxIm7y4FtIBwR6IexLdRF7Ib0ueBVdHaBUjQaRE3RXjoUvHilwAv QWmKNeRknSzUzHfky/0TDTH9UcLob1EZTmQBiCiByD5+UMmkQD/g62aqTVUC9RXy0Gna 1yj23GybaVBv9x41oYK1wYQyFvNfnbt4rT5DHku2lrWT/LISl88lZgpXg2IvzJt3GUEC YVrwHm+xsRuEg+TdyiCcdQ1X2X6a46JzhrI9Jl3MwYhSmtWnnBvhZaUmYhbry8hw9U7h Gagg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qcsUnulCBN0ghXL+bzeFYdD4TQnNlpFLy99BvSyy4/8=; b=w/HoJ8j4HejEYg2NRaLFjrUGVWMessrXa6o4EXcpY/V1Wz0/D+zkDYrJeyrPpEX0Wl Wr4GSCiJ3KuSTn55AUOAUFSdBGLBTrJv84Ho06jj8HJnMV0rN9uAXKxATfOD2gZDaG6g haKRz+Da+j32A+a+KEMk0u/BsdDRIR2MgCb8IqvZyKBnqKXxULZ/Z9VXebCpg9UL8mCB UxQGSlFhBMNqSanTpkfjdxiWauWrTkGHrILk2hyR5MKJVcvjTdyhMXoh5vuNsd/IwgWa yMHBvah9wSjyxQJQ28dgN30hYvbuPzfTZi3jO6IMj2nfS61RoZ+jCw0pqzASQhqXGYE8 +TTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="Oa/CuJOa"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a12-20020a056a000c8c00b00593a3c48465si7837047pfv.266.2023.01.30.13.03.29; Mon, 30 Jan 2023 13:03:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="Oa/CuJOa"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229693AbjA3U4R (ORCPT + 99 others); Mon, 30 Jan 2023 15:56:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230166AbjA3U4M (ORCPT ); Mon, 30 Jan 2023 15:56:12 -0500 Received: from out-32.mta1.migadu.com (out-32.mta1.migadu.com [95.215.58.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 948AF33460 for ; Mon, 30 Jan 2023 12:56:10 -0800 (PST) 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=1675111787; 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=qcsUnulCBN0ghXL+bzeFYdD4TQnNlpFLy99BvSyy4/8=; b=Oa/CuJOao/mJdTHw8cL7VpOXLoCP0ssTyb6Tb4Afcaf2iT1bMwfIzMn8VP90YhF+Kw1dn5 nlRen0XClp4mDU8OoBIH9A55gvf9AIpEUnPu3NprTuPLm5Oj48kdn+8rpZFRY69OwzrT5/ V6Mbai08U9sLTKUwkyeeYJiudqhoCR0= 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 02/18] lib/stackdepot: put functions in logical order Date: Mon, 30 Jan 2023 21:49:26 +0100 Message-Id: <632393332c364171c69b7c054b3b2233acbfa996.1675111415.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482892795290841?= X-GMAIL-MSGID: =?utf-8?q?1756482892795290841?= 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. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- include/linux/stackdepot.h | 15 +- lib/stackdepot.c | 316 ++++++++++++++++++------------------- 2 files changed, 166 insertions(+), 165 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 0eed9bbcf23e..23d2a68a587b 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -79,85 +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 */ @@ -271,6 +192,77 @@ 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) { @@ -310,85 +302,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 * @@ -534,3 +447,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 Mon Jan 30 20:49:27 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: 50484 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2395555wrn; Mon, 30 Jan 2023 13:04:13 -0800 (PST) X-Google-Smtp-Source: AK7set/VBElZz79iTIOmdKWEvWxNvcmkV2+GfHM97Ir0D0W3xElVhp68F9UmQwq4H+eZm66Phx1Q X-Received: by 2002:a05:6a21:3286:b0:be:afe7:cde with SMTP id yt6-20020a056a21328600b000beafe70cdemr2523344pzb.12.1675112652753; Mon, 30 Jan 2023 13:04:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675112652; cv=none; d=google.com; s=arc-20160816; b=UK7gCjdYeHrjKDGaDG6fWG2XR3+tk5nNvDOaCTiHg2cDnliIpzcreJHjvsARLMDE43 egBeHWeycnBkdqJyHCXbgoV1MjTo2ykZTyg18m1ExFpwBfc75JsgUj5yogqNjHKHaYM4 bPIfGxnysW172Qn6nNfi/kHbGNoL7oSGWFDSs2VQiFsxr2ffvqLBYOmTXFw6DZYD59cG wmWwNgi0Lz2zmcgau0vBhDidQLjpf2afepqBJvdlFG1vvCbt0EH7WLtZKL9p8N7e7w5u n/mLky2OEzzHVqWzTy37sxY/U/E8+4rP35elgFZjbTQ3G56ahEJPD3FVmuqV7wDmF849 Cwfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=l0DgDHv6v1bes9QPJYpLqp7kkvT0kapBOv6TW2IBB/k=; b=Z/cOJaZmNprNHWK9//KruV+tGyjsM0URK9Ll4+RNlnbC5Fa2n7V59MwuAxj6EFr9fp QMyf2Af6hKj+xnJCY+hWNULj12j57nozUSKKtE5NhZfWQHhjyIKfk9+032ccHl/FaT/N gkhugbEpu9jlI21ot5aS/FEbNA5P815kMFQsZYNbAOOlpitCSsYKhqfgrFj+pnL1jmmK QX4nuXpFJ5XNRpxRA8GumrPVygo9nzGQ3z1PuwqrA/R6psLu+w/hY1azfy0FQ0qs7e34 /YEVt/Hb6dtK4SSKAZexpsvM9vUCqzp47sQUf6Wf6KHhRdON83IWVqN8Oz//xnTVG6X7 lL/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=SpOJ60TV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l185-20020a633ec2000000b004ced8a013dbsi16068141pga.127.2023.01.30.13.03.58; Mon, 30 Jan 2023 13:04:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=SpOJ60TV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230250AbjA3U4X (ORCPT + 99 others); Mon, 30 Jan 2023 15:56:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230185AbjA3U4O (ORCPT ); Mon, 30 Jan 2023 15:56:14 -0500 X-Greylist: delayed 382 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 30 Jan 2023 12:56:11 PST Received: from out-151.mta1.migadu.com (out-151.mta1.migadu.com [IPv6:2001:41d0:203:375::97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46D1842DFD for ; Mon, 30 Jan 2023 12:56:11 -0800 (PST) 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=1675111788; 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=l0DgDHv6v1bes9QPJYpLqp7kkvT0kapBOv6TW2IBB/k=; b=SpOJ60TVzVtNFGeOaSWoGCVnRntGXp1f0lNFPUS22mPwdXy3FThUKBl7SnU05auY2/luej U9SfMepHYn2N9o3X7GDdHcULipCyR7H9ZY2KmHg7SPMUng4KqZBLC+Iovl8L0HP2Tv7Ojv sy1806UWb20v/N9S8fxWCNto4gVc1H8= 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 03/18] lib/stackdepot: use pr_fmt to define message format Date: Mon, 30 Jan 2023 21:49:27 +0100 Message-Id: <3600069e0b0b3df602999ec8a2d4fc14fcc56a01.1675111415.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482924581209723?= X-GMAIL-MSGID: =?utf-8?q?1756482924581209723?= 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. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 23d2a68a587b..90c4dd48d75e 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 Mon Jan 30 20:49:28 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: 50483 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2395352wrn; Mon, 30 Jan 2023 13:03:42 -0800 (PST) X-Google-Smtp-Source: AK7set/siv6jXLZPCcaIOGN9AKzihMZIvXK9kh9jrdYC+GPaemMO5C/c73lHK7H6A6pMHfEyL1MI X-Received: by 2002:a17:90b:3e83:b0:22b:f9c2:d1a0 with SMTP id rj3-20020a17090b3e8300b0022bf9c2d1a0mr11191078pjb.6.1675112622677; Mon, 30 Jan 2023 13:03:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675112622; cv=none; d=google.com; s=arc-20160816; b=AEkAYPspBSo03H2P2ASqOyzUWK1GJEOHjwZv89mkg5DpYtJr/L+iVRqRkG/bMsyOA0 RkSpuWbn4YseGtl/1w8SHaQUgvv+2fKoyT8hzasdIpOaCg8R5Ifg6KrtwME0GgKe/H8p QW8DBkMAkgGGKuNwFIR5rHgB55xWVcgQrImNIWbVYnb0efX2DYz04+tE1vte2o/Vu6MZ xxrzx9LwEyPolaekhm7l4i897KDr7+qK+olVAXAsR7sqeJOQOab2XunqTZlS4emIE4li hLdOOtzDXGarukpLqAhkGM3WeQd33P+jc537ofQPYs88nOli6o1ATXvZEApWLuHGCz1L q+fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ePKn7wp1b3FbqZznSS/x2B/da1B4by5dKxtQzEtZAxA=; b=D5SuvrnoGljJtahzpme0vev+u0JgTbUdf8jbxaH94JVDeQ9S2dRmTEkVkJg/selvvG GPoGxHsMRNUfJUZs/peBNUxrM4cpIw7gVbwNh+XbgxIVJzs/Yf08f2ogClB7n+y4PIcl 5haZDfnNrYvpgLzzZ4WtFekHvQ3DSBFlSK3VvMQp2ubO870kWdt8Dou7US5+MDLrp3Qm 9BzEoGxWSAq8+lGP91F8JXk0DQw/uhuEhKFbkBVSnOa2ksLNgC8SJxeOxiDaouiXU6vZ /KHcnFjrScGbgCotftYizyDkBgRZTz7xFpaFzO1DSGOqGJTcufcZP8ecfYrT9pFP9mkJ a32Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="cW/knli1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r25-20020a638f59000000b004e6c1e097e0si6410554pgn.729.2023.01.30.13.03.30; Mon, 30 Jan 2023 13:03:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="cW/knli1"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230244AbjA3U4T (ORCPT + 99 others); Mon, 30 Jan 2023 15:56:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230183AbjA3U4O (ORCPT ); Mon, 30 Jan 2023 15:56:14 -0500 Received: from out-151.mta1.migadu.com (out-151.mta1.migadu.com [95.215.58.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17D91402E6 for ; Mon, 30 Jan 2023 12:56:10 -0800 (PST) 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=1675111788; 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=ePKn7wp1b3FbqZznSS/x2B/da1B4by5dKxtQzEtZAxA=; b=cW/knli1mct1hN8VKhy84oK1lCkEnRxbrn0Bzq8wHyRAEtZylNL8NaxR82FYgXhxPOV45q TiG9opJh/CR4Dl6WT16EtZJq6GOEh34hNr0pi0fJZgIAo5qxMs/0msRB3R0d/2Og6PYwqq qlelPQSU7Sr1vmkhLpJj+wl66a2Q8a4= 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 04/18] lib/stackdepot, mm: rename stack_depot_want_early_init Date: Mon, 30 Jan 2023 21:49:28 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482893477726200?= X-GMAIL-MSGID: =?utf-8?q?1756482893477726200?= 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. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko Acked-by: Vlastimil Babka --- 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 90c4dd48d75e..8743fad1485f 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 Mon Jan 30 20:49:29 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: 50480 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2395169wrn; Mon, 30 Jan 2023 13:03:16 -0800 (PST) X-Google-Smtp-Source: AK7set9yxhyjMQSXCwWEbgkcV5KpElY6Pl3Aue3evjQeiySIN2kyX37Aj812JdyAvZJNZuSQUKu/ X-Received: by 2002:a17:902:cece:b0:195:e480:acec with SMTP id d14-20020a170902cece00b00195e480acecmr11788540plg.5.1675112596638; Mon, 30 Jan 2023 13:03:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675112596; cv=none; d=google.com; s=arc-20160816; b=ah0IW8izzNaU5vtO5rbLUlEqMcffbcSgmS2bDf9d1gwKjheLxapGZojA6WUjSXzxM9 fY1491TMAg+2bOWjUd+apCdjgRWWcS11nMFDC3xI6rDFVGAbgoBkTOvZW17iAzT014go Q7G1PoVX/plGJOj9XzaYSfQF/c2jaIwCGXvLgoJ39M/MsTGwkGmQm8z+q7e/jwQH31Vs DyndjTaZPkVF9gNxAKlwpGCHJxpxxIm58IaDGJQ5iuTuv9fIdLslh+3ORVg0A7h6NA0B uNjAMWLV9rZznyVxQaz+dJI/mZWE9gAilj4/lywGQ/R7+XdKyZ2We89V+P2lz6gvfokk DPfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=c95lndz29O0di2fe/164kz+dHAmKL4r6SFIURNRPYhs=; b=afBsuJgay2O1VTPfMl1YIqEzxKMvQaWOXrZvkOGzFgygCK0S2YjKNYDFZjSZ9qngMA Ve7o0uAVuuSStwH05OQN4S9lrdFfCd5BAsCWOCXvtOGgVraP7HWvZFRqudNnPRYuOyz0 oGSTWBraj5TvtpONFxDvZKfwAFuaqCXShagYg7pokv3pk5U9ui1xmKI/YjjGaNHUbiUm tKeHrXYmr+akZKw6Rhf4MoE11MthQQgaeEdWh+3GP7Opg9MuSrAl2YE5PxK/nPjDMO8t RXl8axSrimecoMKxQLH8aDaF1PpoQZoUraGRvJavl5m/XrsA7ixq6jVYCJL8AjW30wm2 tNTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=iZ2SF3e9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a170902e88400b001968bed5355si3086392plg.476.2023.01.30.13.03.03; Mon, 30 Jan 2023 13:03:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=iZ2SF3e9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbjA3U4P (ORCPT + 99 others); Mon, 30 Jan 2023 15:56:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230150AbjA3U4M (ORCPT ); Mon, 30 Jan 2023 15:56:12 -0500 Received: from out-85.mta1.migadu.com (out-85.mta1.migadu.com [95.215.58.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AC4241B47 for ; Mon, 30 Jan 2023 12:56:11 -0800 (PST) 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=1675111789; 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=c95lndz29O0di2fe/164kz+dHAmKL4r6SFIURNRPYhs=; b=iZ2SF3e9VXqpvKUr8HduRr1XOXKe7dSysCB1n/ECP4tg1ImAdKKoy2eqgkG+rRAub4slvK j7oGY2uIyxOmpcwpIzP6Xcn2HJ6z/TAb1IUyQWvHGGTzHFEIzfekx1C2191yTDtOsoVOMk 9aSD8JTfQNTK/XnjW9Emdd1TFDrL4xQ= 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 05/18] lib/stackdepot: rename stack_depot_disable Date: Mon, 30 Jan 2023 21:49:29 +0100 Message-Id: <293567627b0d59f1ae5a27ac9537c027a5ff729d.1675111415.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482865972245487?= X-GMAIL-MSGID: =?utf-8?q?1756482865972245487?= 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. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 8743fad1485f..6e8aef12cf89 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; @@ -354,7 +354,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 Mon Jan 30 20:49:30 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: 50464 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2390393wrn; Mon, 30 Jan 2023 12:52:39 -0800 (PST) X-Google-Smtp-Source: AK7set/ccuGhz/yg8KQrmDOjuxrgm3xlCciv1q/pl+1d/a+1hB2FirqFyYkXdzOZTQaJAUmo2OzY X-Received: by 2002:a05:6402:4403:b0:49e:cd82:cc73 with SMTP id y3-20020a056402440300b0049ecd82cc73mr987581eda.29.1675111958806; Mon, 30 Jan 2023 12:52:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675111958; cv=none; d=google.com; s=arc-20160816; b=Tnp+hCkGC7rT8YGAOUD0EIjRs/4DVXnaRpSNVuewZuG1spEfdrmDybAyIqwqhG/ja3 i22fHC0Z6bRRnVyXs/GhxOPCxQqdY7LZ847afhSpl1iXjzZIW+uFK56gRwlOSnQO/pO0 NGO5Rg/gUDRfcIZEtdQ7GoiIcDWKJNDa7ZAM59Bx7u/DTVpIpGJ4LzrYNCSJmL96+38D OOxuoB4I88MNKSrB3pr1lFAeVGR+dlZ6SPlPTFYeQJpDNCexd2TurMyCnnaMTGntWqdZ QTJXUgCYcVywevY+DuQBV1RkcwLb/FsxEYaEW8ogjQVb4wnozCzlYQ7Jl8zdBqcDu5aL xzvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TXUvy5WDZhr7BlKZ84VBiDQ9FKi0bXR5FVmrmN5uemo=; b=xRRLXJ3ih5vFCOpFiMKPoxKhI+J5cuv8FqpMj+qzot+ZNIwqDeNzGtOug/FQk4MDOj a+n7+uuCDGUqop1C+iQK26PhfYYv+TI6Ux44FAwavmibWBhfM0OqqL5Nxu+ESAwee680 Hi9+H0GCEzc5xJBkUuiFMEWHTWyyCv2fq3AkPPpua/F9xF8TUJAuZT0j0L14FpEwSN25 DGGSvquwH5HBh2cPiPvuZAh71gJ8c+DnnN2Zuz/MBzLWX2gwb7y4pWuFTWG8KcfgvU8+ a1odp3TdQ9ZfljFHsxK6Q8Xa1X6vP/YaPz/WG1uFkbgH560K5naZc6RMfiWAkRX2laVx l3ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="qTAqH/h3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w25-20020aa7d299000000b00499c63cd389si13928027edq.442.2023.01.30.12.52.14; Mon, 30 Jan 2023 12:52:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="qTAqH/h3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229583AbjA3Uu4 (ORCPT + 99 others); Mon, 30 Jan 2023 15:50:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbjA3Uuy (ORCPT ); Mon, 30 Jan 2023 15:50:54 -0500 Received: from out-223.mta0.migadu.com (out-223.mta0.migadu.com [IPv6:2001:41d0:1004:224b::df]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22A507ABF for ; Mon, 30 Jan 2023 12:50:53 -0800 (PST) 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=1675111851; 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=TXUvy5WDZhr7BlKZ84VBiDQ9FKi0bXR5FVmrmN5uemo=; b=qTAqH/h3lvp3LBinh9ZgKXdhYP02imBJEuB8uqH1iUms1FkvE7RqMS6kgwiVfxPo6dPFiZ INjsSD6+m11nC0jZlXtAXeRY8JnQiDDTw74kkvq8iy8WIY5f1IjA3puf+2wSsDQv7yH1KS kCzz9lKkR7o1ZLchiqq6nGUmdZMJN3g= 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 06/18] lib/stackdepot: annotate init and early init functions Date: Mon, 30 Jan 2023 21:49:30 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482197260768498?= X-GMAIL-MSGID: =?utf-8?q?1756482197260768498?= 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. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 6e8aef12cf89..b06f6a5caa83 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 kvmalloc. 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 Mon Jan 30 20:49:31 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: 50465 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2390441wrn; Mon, 30 Jan 2023 12:52:45 -0800 (PST) X-Google-Smtp-Source: AK7set97LVHiSi6SzgYqN4TATWeZVgBrdeHM9u01cqKXsdI6WQbAYKL8VyCJpHgrWNAuTc8np+1f X-Received: by 2002:a17:907:a2ca:b0:879:9bf4:b88a with SMTP id re10-20020a170907a2ca00b008799bf4b88amr16709822ejc.77.1675111965607; Mon, 30 Jan 2023 12:52:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675111965; cv=none; d=google.com; s=arc-20160816; b=X/Zvk2A9EJqGh12micydSmZRQb6VXZeqoZHw5suvuREqouDGwDz6diE8601wKtL4vA YH9sem0dvGy/VX4S9B+PqIvk8KXLcAxlEcD/SE78SzeFBvgdKpawhcPnolNGaoGSWFPb s/hI+AUAroKmvQo2JUmNsMhOkpU0chnTt24GpaOj4/E7NPy6minzh0FAb9Lae5eJkSoI x0rLy7/eu70G/XN1P7lTT9ymcWMweXy0r9Bmyc5q3L8wUpktfNrdBka6wz88luiGX0e0 KlfAfXFGiFkT+WoDXZGxeNF3vi9WSZhNqhmwB/epwj2MRCuPVu3hMrJvasOP2x9MnoXS e0RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tjOybIkwS91rz6SeT9/1Q1LG8Upe4qgP6MFeV739ipg=; b=L6W9VSBQzB1NTew4KkZfAMvCsNN0/++BfI1qbWwWP0Jb1m81tLKWWFZDD1cII3S3jX TGgumKIUXUhwxDv6xSqr+C3XFdULzJERs/6EpZtx/4Q0l9Rgxhrd7rIhYKJ3W88LZIld 03j08IQGVsrvAVlt0G222ljFkXQxWlN20mkp3T9KfRVemUtBARqGIDp6oCzR7AGROyzR BwoJG5BdOBVPR14vC3D7UnHuNd8727rFkGMq4ZxqOjuPDkQVNqNS4qAiTmjvV7XGjnH9 9HiDX6F9OlhS22iIDoPxhr3t8POk9bqSF7iFGDw15474bgD1Z1vFPz4jOa+jzVOT5zhN xmNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=OaUFrjC9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f3-20020a170906738300b00878272927e3si14468415ejl.285.2023.01.30.12.52.21; Mon, 30 Jan 2023 12:52:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=OaUFrjC9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229985AbjA3Uu6 (ORCPT + 99 others); Mon, 30 Jan 2023 15:50:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbjA3Uuy (ORCPT ); Mon, 30 Jan 2023 15:50:54 -0500 Received: from out-62.mta0.migadu.com (out-62.mta0.migadu.com [IPv6:2001:41d0:1004:224b::3e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C51C10AA2 for ; Mon, 30 Jan 2023 12:50:53 -0800 (PST) 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=1675111851; 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=tjOybIkwS91rz6SeT9/1Q1LG8Upe4qgP6MFeV739ipg=; b=OaUFrjC9mmR+C+LBAr653ALAA4e7MQZabwuqvf4knolohngrfhCy2mosvw6gzcWCNRkTMN e4lFrKKKYsFoufKHKOU+htEFWJY05stO+hGZZ42o5pGje6WBWk41AYL8bVD4znF7k68LuE CXnkNDDkYwdEcPDPk+BQYLTO4g/oDug= 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 07/18] lib/stackdepot: lower the indentation in stack_depot_init Date: Mon, 30 Jan 2023 21:49:31 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482204480302533?= X-GMAIL-MSGID: =?utf-8?q?1756482204480302533?= 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. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 70 +++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index b06f6a5caa83..cb098bc99286 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 Mon Jan 30 20:49:32 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: 50467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2390520wrn; Mon, 30 Jan 2023 12:52:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXvznyuKN86c9l8j6K/uX5oMUa4TUGkYnbjB4hzItAV4klZnRNGjckWlwpekhZ14JZovyUaH X-Received: by 2002:a05:6402:e94:b0:47e:d7ea:d980 with SMTP id h20-20020a0564020e9400b0047ed7ead980mr55008553eda.14.1675111978296; Mon, 30 Jan 2023 12:52:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675111978; cv=none; d=google.com; s=arc-20160816; b=XKMwtShUi4Me/aJZG7fONS9KtO6mIy/94TetfbTcy5w2JCopQ3W91KEe+WScZSgg2c shCOV4uVIPxUAyrAZEc62o1KnaB6vSGmQ6eud6b1cQJQBVwPAC/cuW4YK6P7FZvFrmsE qXbagqVA0kr5QFE9P9iZQKC6/NY3ThhxwDhu2YmSC2a5ZdziQKfUPAI7p6FIp5/luK7l uIvYBBUxr9D0c5kOMGlzKrBOdDmqLWrKG2NMHC8krSbkohGHDrG62mw2mpcA3EucKL+9 fnFgpECnYZRl2RTFkbDSt/Yhg8dLpvtc7eiobwaR07djwcAaHSZzcCLTeWXcztwrHuOV mEyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OedhC/9cTS2mJq0ENA72OMR4Ifsg2rHWEhi+f8KNzJM=; b=Dw1b4SGmh8m42B7Ap5EI6ev0ut8EXxqQLQ4iRrabyaYGwG8sZXau4joNkjafsydeyG 9wElXNaj9U4xqsd0AP2hXImcjef+WtpQkhTDqiuPWgR8JCyCUXuuGPFzM4N6beDZwBjb F6rfGgYPg+sKqn0saLm7eFuvo9JrpsDhTjw6IpKFdkYC48V/H4jStY0xqurESSV2whU0 Y9ZmgpBX+aaQ5zob7Ga+FkcAtlRVNIDeWAgJwlYmM1r7V6wdmazhge74e92i+FXmf4yE 6LDOU4LgE+YNfhtXLG5yspxVv4OA1LPaeXOnwmgtQUtO2FJ3uhcuqgdwy89ecS2JdD0r Zgyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=X7HUu+4V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bx5-20020a0564020b4500b0047ae036876fsi7555953edb.59.2023.01.30.12.52.35; Mon, 30 Jan 2023 12:52:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=X7HUu+4V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230061AbjA3UvI (ORCPT + 99 others); Mon, 30 Jan 2023 15:51:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229807AbjA3Uu5 (ORCPT ); Mon, 30 Jan 2023 15:50:57 -0500 Received: from out-200.mta0.migadu.com (out-200.mta0.migadu.com [IPv6:2001:41d0:1004:224b::c8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03AEA10AA2 for ; Mon, 30 Jan 2023 12:50:55 -0800 (PST) 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=1675111852; 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=OedhC/9cTS2mJq0ENA72OMR4Ifsg2rHWEhi+f8KNzJM=; b=X7HUu+4VKFLQaJcV8B6kbT97Jm9iANg+sHOULAtlvOJSDASHctA+opcf+7oIrknNH8pARg ZnVh8nbjs5qes+RW9pvG2fcJuq86Fn6L9IoAgFzfLRdGB/OQfojrMtYNskx0G2E5v3XKHj VqRPxgIzxVdiKqMCcMhLKgpakaL0HPw= 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 08/18] lib/stackdepot: reorder and annotate global variables Date: Mon, 30 Jan 2023 21:49:32 +0100 Message-Id: <4ed1d0828e837e15566a7cfa7688a47006e3f4b3.1675111415.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482217962478879?= X-GMAIL-MSGID: =?utf-8?q?1756482217962478879?= 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 cb098bc99286..89aee133303a 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 Mon Jan 30 20:49:33 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: 50471 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2390902wrn; Mon, 30 Jan 2023 12:53:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXsjDOVDpckyienoJeoBHSB/4TrBN2G2c/PbBc9rYa7W1ChAspzy+udqXJctYIxmo/fvVJ8q X-Received: by 2002:a05:6402:43c5:b0:499:b5fc:e56f with SMTP id p5-20020a05640243c500b00499b5fce56fmr59656145edc.19.1675112032927; Mon, 30 Jan 2023 12:53:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675112032; cv=none; d=google.com; s=arc-20160816; b=RWBd+Aj7mDX5VI67wNqzc6n6cx1hEB6UZOBj4r4hP/rPNSxCGDMuGuu8Q/iPzn/mCC D/mbO6zpyV2t3D8JmmhgQ6wbhHfEd5FEVxHpSSg2QGdeaeadv1Zbje0Z21Mws36TaSNq mUJL4QanErJZXWQmCoC+v7Fbh6mxFOa44SSE56CJjEBjhwviHFpiptTXi9LGHyfGNIAx pA8pyjyGaCqoo2L2r3ok78iTedtWb+4qU8Zf5+tLC9g6X88Q3TOv1xn+RWxe7zyp0A15 OO/T6UJoLNm014caYja4fqH7EHi7LZ4CPRD5fz0nbWvQRuKgTeKRaM9U7I5PyUNn0Fz8 /8Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4ThIc/E8It52Ai7wF9nGezLQDQ6i5NEX+ZonMvNBuyU=; b=o6cDITLPxf16vWeWE0m545Uay5CpxgV5KuUwg0+GquncuS8zmiMDjj5exJocdBZpwF fPtr6hiplPF87/QUkyyUU2JLkIXZNC66bhd38E6gM6ObkQINJtWv6MhAoy2iPDYaUnmy j1ebVfKyVUME/XMtg5I8QCFvXtKZX07mAE/3hWKQEQL9XcoCK/pDyYgXmxzBhodo6YWV pWDyuvKE+MzRlEkc1XRI7zT1HaIzMRGm+eVQl5nzdgASIifYCIobckfwdjBLVkOi+UsO 9dFAZ6kzXJKcTiLvhB/zMGoS8OOX4efeRHaE8vj+zwiADQVdYuHWVQDB3BvFMyRFhPx1 xDEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=oaNF1e2Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c9-20020a0564021f8900b0049ef6c755f4si16757468edc.423.2023.01.30.12.53.29; Mon, 30 Jan 2023 12:53:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=oaNF1e2Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230013AbjA3UvB (ORCPT + 99 others); Mon, 30 Jan 2023 15:51:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229496AbjA3Uu4 (ORCPT ); Mon, 30 Jan 2023 15:50:56 -0500 Received: from out-232.mta0.migadu.com (out-232.mta0.migadu.com [IPv6:2001:41d0:1004:224b::e8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96FBA2B0A5 for ; Mon, 30 Jan 2023 12:50:54 -0800 (PST) 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=1675111852; 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=4ThIc/E8It52Ai7wF9nGezLQDQ6i5NEX+ZonMvNBuyU=; b=oaNF1e2Zp8D74xhXSi9Xe8Em5fla04L3chl/gZgXxmenAMqSyBOC0TK0L+frAQoublm+D6 y3a+B2b/IEkOa1iD1H2U0A+sIMqhuheKhY5InYI2bt99cXYWbPbe8vQKOEBSspaWphgQIM onT6jzEMY8KySqyE2k0QGKr+jJVppcs= 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 09/18] lib/stackdepot: rename hash table constants and variables Date: Mon, 30 Jan 2023 21:49:33 +0100 Message-Id: <5456286e2c9f3cd5abf25ad2e7e60dc997c71f66.1675111415.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482275146210907?= X-GMAIL-MSGID: =?utf-8?q?1756482275146210907?= From: Andrey Konovalov Give more meaningful names to hash table-related constants and variables: 1. Rename STACK_HASH_SCALE to STACK_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 --- lib/stackdepot.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 89aee133303a..cddcf029e307 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_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_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_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 Mon Jan 30 20:49:34 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: 50468 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2390583wrn; Mon, 30 Jan 2023 12:53:09 -0800 (PST) X-Google-Smtp-Source: AK7set9JxXF09StHLo1LHFCAcmFvdtZN4Hlui0ya3js4DHEeUv+hKesHaaMsGXnN/levQzNWe1dR X-Received: by 2002:a17:906:4fd5:b0:889:5ca0:1470 with SMTP id i21-20020a1709064fd500b008895ca01470mr1049849ejw.69.1675111989668; Mon, 30 Jan 2023 12:53:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675111989; cv=none; d=google.com; s=arc-20160816; b=xjDuM/ovxjYc7FF2L8YnuXg0mtPdKIYx27sVcSlUU8DogNnNrXu8wK1zo9VK0zKign DqqhSmSYOLDycmCBigJNYpbZ70KicZKqowji1b2CotpFOD7IYV4U3IKwHtKq9BvS7Qf9 8z/Cak7GowxznvgAcUBJDLUDih8xbwGqA5zm/Q11zLspohlWmx5yhtwoR6j6JEkxhmou HZz792gDiiVMX7iinL9goXCtENXKtCNcN09xZ2QJFI+dlSVIhosCcUZBB/NDLX4uIjbk jp0k4RZ70MSL7jvgoXYW6PfG5lRqzIwXZksk+whdWCwxBFEaoSrlKgfrg2Rkr00g1CrH UMrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=57d540mJERXvBQP3H394VQ1KkYAn0jgbzOXp+cklDfk=; b=lzd+tdOh+RrtQeRshgO3da8DChK9od+k/i25m878IPtO13D4Zwd97yag4ngvDwj9cx gzID5glCWnB2vH79/SDrYhkmpC4p+oImKyOHnYQwWVsaXzgSMHlpANRTQmrWWfsXAcjG MnRLyNC2IiNIsFMZvHQPod5UFRVDZ+9Y5GSB6hYU4b6xJUkt3esWYtfHG1jXYw+1Kou7 XAPKyRgd7ey8UiaQ+LWhoTASLtOE7gMaP+s688UpMTDqGO1WsMP6/sodQzEs+fuNqNue Aqruwdmy4jEucKc/8JIcg9O4OLuLPvFORY6a+LkyCSmkYXNwu/Y27DYK+aAMJs9U2XlA 49Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=tFaC4h3n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gc29-20020a1709072b1d00b00885e13adf87si6061710ejc.929.2023.01.30.12.52.46; Mon, 30 Jan 2023 12:53:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=tFaC4h3n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230051AbjA3UvL (ORCPT + 99 others); Mon, 30 Jan 2023 15:51:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229973AbjA3Uu5 (ORCPT ); Mon, 30 Jan 2023 15:50:57 -0500 Received: from out-123.mta0.migadu.com (out-123.mta0.migadu.com [IPv6:2001:41d0:1004:224b::7b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 916272B0A5 for ; Mon, 30 Jan 2023 12:50:56 -0800 (PST) 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=1675111853; 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=57d540mJERXvBQP3H394VQ1KkYAn0jgbzOXp+cklDfk=; b=tFaC4h3ny4KHK6KzVpTLfphtX0wgv6hr2F1IlbR9lxqmNdFBdXy03CvsRXm9O6MKj4NsAn CTqvr8DlBi/FIBP/httW9sIeE7tRDO0I9xlzY7K90zPiYCGkwIi2vq/DRFu1UdbXz8pOf4 xyLsJWVX1RFdwNDIWgGGCX387z78BgY= 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 10/18] lib/stackdepot: rename init_stack_slab Date: Mon, 30 Jan 2023 21:49:34 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482229304365275?= X-GMAIL-MSGID: =?utf-8?q?1756482229304365275?= From: Andrey Konovalov Rename init_stack_slab to depot_init_slab to align the name with depot_alloc_stack. No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index cddcf029e307..69b9316b0d4b 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -220,7 +220,7 @@ int stack_depot_init(void) } EXPORT_SYMBOL_GPL(stack_depot_init); -static bool init_stack_slab(void **prealloc) +static bool depot_init_slab(void **prealloc) { if (!*prealloc) return false; @@ -268,12 +268,12 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) /* * smp_store_release() here pairs with smp_load_acquire() from * |next_slab_inited| in stack_depot_save() and - * init_stack_slab(). + * depot_init_slab(). */ if (depot_index + 1 < STACK_ALLOC_MAX_SLABS) smp_store_release(&next_slab_inited, 0); } - init_stack_slab(prealloc); + depot_init_slab(prealloc); if (stack_slabs[depot_index] == NULL) return NULL; @@ -402,7 +402,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, * lock. * * The smp_load_acquire() here pairs with smp_store_release() to - * |next_slab_inited| in depot_alloc_stack() and init_stack_slab(). + * |next_slab_inited| in depot_alloc_stack() and depot_init_slab(). */ if (unlikely(can_alloc && !smp_load_acquire(&next_slab_inited))) { /* @@ -438,7 +438,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_slab(&prealloc)); + WARN_ON(!depot_init_slab(&prealloc)); } raw_spin_unlock_irqrestore(&depot_lock, flags); From patchwork Mon Jan 30 20:49:35 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: 50466 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2390496wrn; Mon, 30 Jan 2023 12:52:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXsqjPRgz3u1BAfVu//ZSPaQ95u8OfO5Ojzl8QraIrlgg/KOUrh9qAiCSEGTu2R2khbee5rI X-Received: by 2002:a17:906:647:b0:86e:f59e:9cc0 with SMTP id t7-20020a170906064700b0086ef59e9cc0mr50409959ejb.18.1675111973574; Mon, 30 Jan 2023 12:52:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675111973; cv=none; d=google.com; s=arc-20160816; b=Ss/KcmSvf7sTxw0zkV54iuIOhNdiVXbobWAeLaDoh1m37eLwwa2un40aWOvpWxitXN SF6PK3xc7y81yY7z3+F/2a4qg717IO9p2FaeQUZtIqqeeULSEqWtOGHh6GR2LuAd5yrl AXSQANhJ1AbxkFvBNtg1kWjQ0AILbE8heyy1mBhK3p27wCJDdwggvxOP/qLw49DwMZTe 5y8Ui16kilpHqyfPgPlARqUiicKmAtBRdpjXuTHzNc1s12U/6i1WWAP5tOl9Qa1BTrUr Mrpm6tVNJZCxVYse280K5kUismkPhYX/hhtMtxODBszWMAAkZ697iVPN4RC2pau7cccn 4L+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=iXlgsoHOs+BLuKG+iZUfAdscpmKEgHjXPVNxwccGfOc=; b=KTT8YLWSZRfaDgEc9DbCYOLprpEpYHMbPBwYRGkxH26I+VO7DjI0z0jeoyodflY52K IVLDKwgjisQRhuim4UfMB7GnKK1vzJaIlUJiQc6XjXzVQPw/7Q6pFGT3ERTreiK1zXGt 45lceGBDtLtLDAsBwQ3NOs/uyLt74E64IlMF8B5Gxqnl9XA5qT1jb6ZAw3VZJnvuVcmo Ztgv5Hdujhvcl/7ryEiPK/DR+ZJicwIxPPH/bT1qs36tvb16YsY6toSDNPkkcxDx5o6C rPCpUZY5/KScnk1KEBF/HQ32udtnJ8wKq6OknEW6sGrpTGCQz/9dDE1lukVUNq9bqgCS wLxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=H0xZx4zS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mv16-20020a170907839000b008786508e28csi14616664ejc.1005.2023.01.30.12.52.30; Mon, 30 Jan 2023 12:52:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=H0xZx4zS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230026AbjA3UvF (ORCPT + 99 others); Mon, 30 Jan 2023 15:51:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229605AbjA3Uu4 (ORCPT ); Mon, 30 Jan 2023 15:50:56 -0500 Received: from out-216.mta0.migadu.com (out-216.mta0.migadu.com [IPv6:2001:41d0:1004:224b::d8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 747117ABF for ; Mon, 30 Jan 2023 12:50:55 -0800 (PST) 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=1675111853; 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=iXlgsoHOs+BLuKG+iZUfAdscpmKEgHjXPVNxwccGfOc=; b=H0xZx4zSVR5R1TTVo6Dq4Tk1fGJ1809Ce1jSVXVk9h7VH1pdC9UBrBWMfKmaJ+yvEFxCe1 vKFqnqMgtIUBw3xUT1K3M8gRABOsrDMGcGVAgNiniZRonGSGt7pdfEGXPOy46OlfwTgUum C1sqB4MBr5XwWI9FFgqUEkV0dRI3CPE= 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 11/18] lib/stackdepot: rename slab variables Date: Mon, 30 Jan 2023 21:49:35 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482212918104027?= X-GMAIL-MSGID: =?utf-8?q?1756482212918104027?= From: Andrey Konovalov Give better names to slab-related global variables: change "depot_" prefix to "slab_" to point out that these variables are related to stack depot slabs. Also rename the slabindex field in handle_parts to align its name with the slab_index global variable. No functional changes. Signed-off-by: Andrey Konovalov --- lib/stackdepot.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 69b9316b0d4b..023f299bedf6 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -56,7 +56,7 @@ union handle_parts { depot_stack_handle_t handle; struct { - u32 slabindex : STACK_ALLOC_INDEX_BITS; + u32 slab_index : STACK_ALLOC_INDEX_BITS; u32 offset : STACK_ALLOC_OFFSET_BITS; u32 valid : STACK_ALLOC_NULL_PROTECTION_BITS; u32 extra : STACK_DEPOT_EXTRA_BITS; @@ -93,11 +93,11 @@ 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; +static int slab_index; /* Offset to the unused space in the currently used slab. */ -static size_t depot_offset; +static size_t slab_offset; /* Lock that protects the variables above. */ -static DEFINE_RAW_SPINLOCK(depot_lock); +static DEFINE_RAW_SPINLOCK(slab_lock); /* Whether the next slab is initialized. */ static int next_slab_inited; @@ -230,13 +230,13 @@ static bool depot_init_slab(void **prealloc) */ if (smp_load_acquire(&next_slab_inited)) return true; - if (stack_slabs[depot_index] == NULL) { - stack_slabs[depot_index] = *prealloc; + if (stack_slabs[slab_index] == NULL) { + stack_slabs[slab_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 (slab_index + 1 < STACK_ALLOC_MAX_SLABS) { + stack_slabs[slab_index + 1] = *prealloc; *prealloc = NULL; /* * This smp_store_release pairs with smp_load_acquire() @@ -258,35 +258,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(slab_offset + required_size > STACK_ALLOC_SIZE)) { + if (unlikely(slab_index + 1 >= STACK_ALLOC_MAX_SLABS)) { WARN_ONCE(1, "Stack depot reached limit capacity"); return NULL; } - depot_index++; - depot_offset = 0; + slab_index++; + slab_offset = 0; /* * smp_store_release() here pairs with smp_load_acquire() from * |next_slab_inited| in stack_depot_save() and * depot_init_slab(). */ - if (depot_index + 1 < STACK_ALLOC_MAX_SLABS) + if (slab_index + 1 < STACK_ALLOC_MAX_SLABS) smp_store_release(&next_slab_inited, 0); } depot_init_slab(prealloc); - if (stack_slabs[depot_index] == NULL) + if (stack_slabs[slab_index] == NULL) return NULL; - stack = stack_slabs[depot_index] + depot_offset; + stack = stack_slabs[slab_index] + slab_offset; stack->hash = hash; stack->size = size; - stack->handle.slabindex = depot_index; - stack->handle.offset = depot_offset >> STACK_ALLOC_ALIGN; + stack->handle.slab_index = slab_index; + stack->handle.offset = slab_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; + slab_offset += required_size; return stack; } @@ -418,7 +418,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(&slab_lock, flags); found = find_stack(*bucket, entries, nr_entries, hash); if (!found) { @@ -441,7 +441,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, WARN_ON(!depot_init_slab(&prealloc)); } - raw_spin_unlock_irqrestore(&depot_lock, flags); + raw_spin_unlock_irqrestore(&slab_lock, flags); exit: if (prealloc) { /* Nobody used this memory, ok to free it. */ @@ -497,12 +497,12 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, if (!handle) return 0; - if (parts.slabindex > depot_index) { + if (parts.slab_index > slab_index) { WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n", - parts.slabindex, depot_index, handle); + parts.slab_index, slab_index, handle); return 0; } - slab = stack_slabs[parts.slabindex]; + slab = stack_slabs[parts.slab_index]; if (!slab) return 0; stack = slab + offset; From patchwork Mon Jan 30 20:49:36 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: 50474 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2391459wrn; Mon, 30 Jan 2023 12:55:13 -0800 (PST) X-Google-Smtp-Source: AMrXdXvPGdeUYJsINjU8rtNvRM6KdPgMwQwIXU+ddnkFrtMhDULE2hzjaJ8Y/XmVV8mYJmjAJHlo X-Received: by 2002:aa7:dd48:0:b0:497:233d:3ef7 with SMTP id o8-20020aa7dd48000000b00497233d3ef7mr54247678edw.7.1675112112840; Mon, 30 Jan 2023 12:55:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675112112; cv=none; d=google.com; s=arc-20160816; b=pxvycP1W3V1dWywfMOEEhbM1Rt0GAiDXvSKqmT0p913bRw21uDWh6KKD8LJ7IMFSdy CmtrEhgO5PKwlEtfwrzX1/+QgTvzujN26ig1w7DZIwwrTG3kESmzCNeN3RYfQjgEcy2w hi/HyNQAmoWx+ecvCZuioc/f+gJsLl749G0kMTdnnOT0mGblKk8HsPnEIHdUqjdiEsxj ic6VUkHBYnymuO5OTnq0StkgbWryaYuYtcPz8KOw8dLeeR94tp1EaI+ycdx0dMZOHCGh 20l9COi4WKi1C35vB0OZ4u1jiN9Q0PcE9t8GS1msiajZ7Chz9MuZUfoin5HF5rE/C7YL W9YQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Z64aIL/3pnEFiG6bV8LdN1R6x92gKwWr8osFMwIva5I=; b=dXwlFCdTztR/0pEu/B3tA3K4Yliudz6iVfzGduIr6F/Q38MXaGdS/TQuuNLRi5D2Ne ZQFClzG+8rN9wlxnJr/6yhB553kxghuGn0fc3PyJn+9JdV74p+gOTZSSzcYbGiEGZas0 GaOpgUebzrtXfNkF/s9PYOhPSND0bj26i08T2iF7z3lle8S5bMDIqFRHaW0FVWh/MHEd 8ogvU5FVnwP3NzIJ+IoK7s0grR2gaXZj883QdwQ6Va9KUCSuw4ytGBxyDZd5tg90oYtv dY/YbduMD5NxlGxu/TceDUpqt9HQtJitplzX62Yjccv9yzWfA8tMLWXDXRagOoV0sOnO tx6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=nfu6OwnD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f15-20020a1709063f4f00b00870ed0f7caasi15818526ejj.362.2023.01.30.12.54.48; Mon, 30 Jan 2023 12:55:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=nfu6OwnD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230109AbjA3UwT (ORCPT + 99 others); Mon, 30 Jan 2023 15:52:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229907AbjA3UwK (ORCPT ); Mon, 30 Jan 2023 15:52:10 -0500 X-Greylist: delayed 63 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 30 Jan 2023 12:51:56 PST Received: from out-62.mta0.migadu.com (out-62.mta0.migadu.com [91.218.175.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53A9D39B8C for ; Mon, 30 Jan 2023 12:51:56 -0800 (PST) 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=1675111914; 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=Z64aIL/3pnEFiG6bV8LdN1R6x92gKwWr8osFMwIva5I=; b=nfu6OwnDko1AKNqOQs12TRjWFH8CN3YRKYr2n98lnDMcdAtDTRf96kmqyCC0GgRU/w/evf HwHPm3R3lvim0v6dnV3z8SWxN4TpG9QvLzrWmN59lv13gbzTnZyVXd9w81iz5uKj4/obys 9aoIBAek+zEi9/NdwK4PCRLjc1Z/mw8= 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 12/18] lib/stackdepot: rename handle and slab constants Date: Mon, 30 Jan 2023 21:49:36 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482358708405345?= X-GMAIL-MSGID: =?utf-8?q?1756482358708405345?= 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 slabs. 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_SLAB_ORDER. No functional changes. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 56 +++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 023f299bedf6..b946ba74fea0 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 /* 'Slab' 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_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 DEPOT_HANDLE_BITS (sizeof(depot_stack_handle_t) * 8) + +#define DEPOT_VALID_BITS 1 +#define DEPOT_SLAB_ORDER 2 /* Slab size order, 4 pages */ +#define DEPOT_SLAB_SIZE (1LL << (PAGE_SHIFT + DEPOT_SLAB_ORDER)) +#define DEPOT_STACK_ALIGN 4 +#define DEPOT_OFFSET_BITS (DEPOT_SLAB_ORDER + PAGE_SHIFT - DEPOT_STACK_ALIGN) +#define DEPOT_SLAB_INDEX_BITS (DEPOT_HANDLE_BITS - DEPOT_VALID_BITS - \ + DEPOT_OFFSET_BITS - STACK_DEPOT_EXTRA_BITS) +#define DEPOT_SLABS_CAP 8192 +#define DEPOT_MAX_SLABS \ + (((1LL << (DEPOT_SLAB_INDEX_BITS)) < DEPOT_SLABS_CAP) ? \ + (1LL << (DEPOT_SLAB_INDEX_BITS)) : DEPOT_SLABS_CAP) /* The compact structure to store the reference to stacks. */ union handle_parts { depot_stack_handle_t handle; struct { - u32 slab_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 slab_index : DEPOT_SLAB_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_slabs[STACK_ALLOC_MAX_SLABS]; +static void *stack_slabs[DEPOT_MAX_SLABS]; /* Currently used slab in stack_slabs. */ static int slab_index; /* Offset to the unused space in the currently used slab. */ @@ -235,7 +233,7 @@ static bool depot_init_slab(void **prealloc) *prealloc = NULL; } else { /* If this is the last depot slab, do not touch the next one. */ - if (slab_index + 1 < STACK_ALLOC_MAX_SLABS) { + if (slab_index + 1 < DEPOT_MAX_SLABS) { stack_slabs[slab_index + 1] = *prealloc; *prealloc = NULL; /* @@ -256,10 +254,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(slab_offset + required_size > STACK_ALLOC_SIZE)) { - if (unlikely(slab_index + 1 >= STACK_ALLOC_MAX_SLABS)) { + if (unlikely(slab_offset + required_size > DEPOT_SLAB_SIZE)) { + if (unlikely(slab_index + 1 >= DEPOT_MAX_SLABS)) { WARN_ONCE(1, "Stack depot reached limit capacity"); return NULL; } @@ -270,7 +268,7 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) * |next_slab_inited| in stack_depot_save() and * depot_init_slab(). */ - if (slab_index + 1 < STACK_ALLOC_MAX_SLABS) + if (slab_index + 1 < DEPOT_MAX_SLABS) smp_store_release(&next_slab_inited, 0); } depot_init_slab(prealloc); @@ -282,7 +280,7 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) stack->hash = hash; stack->size = size; stack->handle.slab_index = slab_index; - stack->handle.offset = slab_offset >> STACK_ALLOC_ALIGN; + stack->handle.offset = slab_offset >> DEPOT_STACK_ALIGN; stack->handle.valid = 1; stack->handle.extra = 0; memcpy(stack->entries, entries, flex_array_size(stack, entries, size)); @@ -413,7 +411,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_SLAB_ORDER); if (page) prealloc = page_address(page); } @@ -445,7 +443,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_SLAB_ORDER); } if (found) retval.handle = found->handle.handle; @@ -490,7 +488,7 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, { union handle_parts parts = { .handle = handle }; void *slab; - size_t offset = parts.offset << STACK_ALLOC_ALIGN; + size_t offset = parts.offset << DEPOT_STACK_ALIGN; struct stack_record *stack; *entries = NULL; From patchwork Mon Jan 30 20:49:37 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: 50472 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2391288wrn; Mon, 30 Jan 2023 12:54:51 -0800 (PST) X-Google-Smtp-Source: AK7set9oJ84gl9yOfv1KCpDJah5ONx3DIVE2P2SMn3kvgHizF7T+S5M50uO5e1XbCVpB23VebuNB X-Received: by 2002:a17:907:8a13:b0:887:6c23:193f with SMTP id sc19-20020a1709078a1300b008876c23193fmr8358989ejc.44.1675112090936; Mon, 30 Jan 2023 12:54:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675112090; cv=none; d=google.com; s=arc-20160816; b=ccjvkZs0QsUVZ0HNSraFqfhdhK2ZA2V80vDn/SPMYDzlnIFl+UnfRn5GCJAP7PBi7n omfnmoSwk1Rl3n0gpdW9y6jxyFipgzUu1mSL3KjW8QNwYx7BFhRhb9tPcbUGojFUt+u4 qAAfYIWrPETiR5OweucoJBXBB8+FB3UlrnGjf4usCrrLdwUraaA/4czxFRc0Ftskeo8w 5tFi4zaETMgH0XP2qBV7mUfd3BcxO7ZT+6kKbMkmTAtu0btg5MwNnZ9zYfKbygxO1qR/ Jo3mf8Mxk/PeRn8GvJBaTCJNQ+ejadpR5zRm8hztY4Jrcb4uoiwIFsPzAZ54Mh/7sOBn OZAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RlJNrgwkJjY9MAGqUmKKlmI8AUnL0lcVfhP1HY83LkM=; b=Ta1AuIMEVRwrIB0jveqdwm4H7NAxdeoumWah8h9PsHZ0NpyvA7OQWp/G4UyC8/0gIk Y1HnryxkUgWOV61NQxm/PiuAvtvFaXSVsz4mrH5t/4AOs73X+P2ljZO97RB/FyEWSvRQ VwQcaueAr3dKS4st+EdAAfskMuyX+ZuLnD6z5a0Ltt6QX8laNNW90F25TxkgJWFjQ7bm tUF8UpngttuqiujWKxAU1LfQQ2IzO9ViLEzIlHTn41q2QK5NhnNQhDz3c28f9K6zU1eN /WcLHmGiKvXk0TTBDApI6GBCelK/+zF35Q3Gy4Fgi7cMNXxlmtFh058ePQsLFLYB1h34 ZX4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=eYNx9UpT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p13-20020a170907910d00b00889211619fasi3466667ejq.476.2023.01.30.12.54.26; Mon, 30 Jan 2023 12:54:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=eYNx9UpT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230092AbjA3UwQ (ORCPT + 99 others); Mon, 30 Jan 2023 15:52:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229559AbjA3UwK (ORCPT ); Mon, 30 Jan 2023 15:52:10 -0500 Received: from out-108.mta0.migadu.com (out-108.mta0.migadu.com [91.218.175.108]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 071E63B3F5 for ; Mon, 30 Jan 2023 12:51:56 -0800 (PST) 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=1675111915; 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=RlJNrgwkJjY9MAGqUmKKlmI8AUnL0lcVfhP1HY83LkM=; b=eYNx9UpTD8qASdAvQ2avXbDAzDV2XZyf2RCfcvrg11Z3tf9mCrYiiV6w1yAx9dx3/GBwYW pyvA7lWPKBOd+CbhHKC8yhjQP8SgvWhgeotaVOX7oF+PqX3R0B7OR1AjbnJRaZIq6CK/KL 3u69jMJaEnaHOynRgJBlAMbH9ZxnhRg= 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 13/18] lib/stacktrace: drop impossible WARN_ON for depot_init_slab Date: Mon, 30 Jan 2023 21:49:37 +0100 Message-Id: <7e7434a0d4e8a71138aec2c8a3c69a4eebf49935.1675111415.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482335722504960?= X-GMAIL-MSGID: =?utf-8?q?1756482335722504960?= From: Andrey Konovalov depot_init_slab 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_slab 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_slab to its first call site. Also change the return type of depot_init_slab to void as it now always returns true. Signed-off-by: Andrey Konovalov --- lib/stackdepot.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index b946ba74fea0..d6be82a5c223 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_slab(void **prealloc) +static void depot_init_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; + return; if (stack_slabs[slab_index] == NULL) { stack_slabs[slab_index] = *prealloc; *prealloc = NULL; @@ -244,7 +242,6 @@ static bool depot_init_slab(void **prealloc) smp_store_release(&next_slab_inited, 1); } } - return true; } /* Allocation of a new stack in raw storage */ @@ -271,7 +268,8 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) if (slab_index + 1 < DEPOT_MAX_SLABS) smp_store_release(&next_slab_inited, 0); } - depot_init_slab(prealloc); + if (*prealloc) + depot_init_slab(prealloc); if (stack_slabs[slab_index] == NULL) return NULL; @@ -436,7 +434,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_slab(&prealloc)); + depot_init_slab(&prealloc); } raw_spin_unlock_irqrestore(&slab_lock, flags); From patchwork Mon Jan 30 20:49:38 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: 50473 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2391458wrn; Mon, 30 Jan 2023 12:55:12 -0800 (PST) X-Google-Smtp-Source: AK7set8XGqlSH8KyDaTgfRPXc5W9xt9VBv6xwJxkJcZgo0TI6Rvx751F6O9EFz3Guf6//8MvEMQq X-Received: by 2002:aa7:c58b:0:b0:4a0:e237:2cef with SMTP id g11-20020aa7c58b000000b004a0e2372cefmr19253243edq.4.1675112112686; Mon, 30 Jan 2023 12:55:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675112112; cv=none; d=google.com; s=arc-20160816; b=AR7LAGOZrszeTtngp67ex2umNvFWuK+PCRtRywa+shp/f5OYzJ0GDlEiF5vHFKN5j8 YN/vGQF/daWr4/ds60BG9cTlasoLo+3HoNu4REK+j9GX3AOZRRiKGEKOhj3gmyfOg0zp ZGXpIew8y/TobZ+gWT/dgjVZqGTlIiQAG0hOuRuX9IZ0iAYLKoZ3RhaaxSnuRYypZtip zbbNSTMMJIppNilL6bPLGHOm5JIH40TEIXXDs+BpeyU9/znuaKJa7mEtJRGIb1IbVmcL MLN1jfkxmkCjcX85an96RU5mAl9gHjsLtqtsAra9+dHOyvzapxDzzOQTU3Hp5xoSdX+j jf3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=n2WDy/mEQLvnsHLslgORbsPKJysJoBtCH/6FUJBS3Gs=; b=ZtbwtoV7kVtGrpzDELC9mjf5QRAXHpOEJ+dxIzQvp8qrGrkQThqC5lkIVvIrTw139f /uT9w/zQTgmXFcnrP5B2JsN49pjdIK+caLZqSN9tfhacmv+TnTWwmI0E/JZ/v/0PgAxX HSkfN6nqs7tymZQJy75SJczFtfnXwwgkvkTbDs22PljntaoIMjj3Sq5V8OXaOOP2SfPc mq4+A5u0RQcx7wY5cGoS3cdag0Vh2FxiaX3OEDEqlsYRGd9ajAqenFYWgTl8ArxpY7QF XUkX8sucUxnUgCzgK8gXHkyDWskrDF/B+64Rdxd6t8JxNX60YjVazkLIkkkWMFSH4KjY rIlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="g5/h01z3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y7-20020a50e607000000b004a246ed9979si2620327edm.44.2023.01.30.12.54.48; Mon, 30 Jan 2023 12:55:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="g5/h01z3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230137AbjA3UwV (ORCPT + 99 others); Mon, 30 Jan 2023 15:52:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229624AbjA3UwL (ORCPT ); Mon, 30 Jan 2023 15:52:11 -0500 Received: from out-218.mta0.migadu.com (out-218.mta0.migadu.com [91.218.175.218]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6907941B47 for ; Mon, 30 Jan 2023 12:51:57 -0800 (PST) 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=1675111915; 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=n2WDy/mEQLvnsHLslgORbsPKJysJoBtCH/6FUJBS3Gs=; b=g5/h01z3OWfSRlw1beHiwIL6fNUDX0iYu6MtlD/gLSgQhBt5T1xVKAwPQBKGTXJyigmSNM i1fbZwHKtli9NOUEtpO14qb9rNz2hYzP/sRDzf5riZ9Kbzr72tKm+GajdMspGquHMwwfM7 HWQDdIeZPBmj+w12/quHXidzO+Bki8s= 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 14/18] lib/stackdepot: annotate depot_init_slab and depot_alloc_stack Date: Mon, 30 Jan 2023 21:49:38 +0100 Message-Id: <3cf68a23da43cef0f8737f7a2c07f35ce6d841a7.1675111415.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482358999950499?= X-GMAIL-MSGID: =?utf-8?q?1756482358999950499?= From: Andrey Konovalov Clean up the exisiting comments and add new ones to depot_init_slab 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 --- lib/stackdepot.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index d6be82a5c223..7282565722f2 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -218,33 +218,41 @@ int stack_depot_init(void) } EXPORT_SYMBOL_GPL(stack_depot_init); +/* Uses preallocated memory to initialize a new stack depot slab. */ static void depot_init_slab(void **prealloc) { /* - * This smp_load_acquire() pairs with smp_store_release() to - * |next_slab_inited| below and in depot_alloc_stack(). + * If the next slab is already initialized, 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_slab_inited)) return; + + /* Check if the current slab is not yet allocated. */ if (stack_slabs[slab_index] == NULL) { + /* Use the preallocated memory for the current slab. */ stack_slabs[slab_index] = *prealloc; *prealloc = NULL; } else { - /* If this is the last depot slab, do not touch the next one. */ + /* + * Otherwise, use the preallocated memory for the next slab + * as long as we do not exceed the maximum number of slabs. + */ if (slab_index + 1 < DEPOT_MAX_SLABS) { stack_slabs[slab_index + 1] = *prealloc; *prealloc = NULL; /* * This smp_store_release pairs with smp_load_acquire() - * from |next_slab_inited| above and in - * stack_depot_save(). + * above and in stack_depot_save(). */ smp_store_release(&next_slab_inited, 1); } } } -/* Allocation of a new stack in raw storage */ +/* Allocates a new stack in a stack depot slab. */ static struct stack_record * depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) { @@ -253,28 +261,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 slab. */ if (unlikely(slab_offset + required_size > DEPOT_SLAB_SIZE)) { + /* Bail out if we reached the slab limit. */ if (unlikely(slab_index + 1 >= DEPOT_MAX_SLABS)) { WARN_ONCE(1, "Stack depot reached limit capacity"); return NULL; } + + /* Move on to the next slab. */ slab_index++; slab_offset = 0; /* - * smp_store_release() here pairs with smp_load_acquire() from - * |next_slab_inited| in stack_depot_save() and - * depot_init_slab(). + * smp_store_release() here pairs with smp_load_acquire() in + * stack_depot_save() and depot_init_slab(). */ if (slab_index + 1 < DEPOT_MAX_SLABS) smp_store_release(&next_slab_inited, 0); } + + /* Assign the preallocated memory to a slab if required. */ if (*prealloc) depot_init_slab(prealloc); + + /* Check if we have a slab to save the stack trace. */ if (stack_slabs[slab_index] == NULL) return NULL; + /* Save the stack trace. */ stack = stack_slabs[slab_index] + slab_offset; - stack->hash = hash; stack->size = size; stack->handle.slab_index = slab_index; From patchwork Mon Jan 30 20:49:39 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: 50475 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2391491wrn; Mon, 30 Jan 2023 12:55:18 -0800 (PST) X-Google-Smtp-Source: AK7set/+87E22dao3nxqs5XjCUeCrtyuIv8VyQSb2uHFBFNhNT8s1VUVJBoHVWt1WnZeayOdQqLs X-Received: by 2002:a17:906:7c06:b0:7c0:d609:6f9b with SMTP id t6-20020a1709067c0600b007c0d6096f9bmr858318ejo.27.1675112118220; Mon, 30 Jan 2023 12:55:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675112118; cv=none; d=google.com; s=arc-20160816; b=sz4tzA+We6TOaTZhGDUER3wXXxWFMnPI0I9/bkEnZ9+mPXV3n4sXTCTr/Ry16bCfEU LyRzVfkbxX8JVkrH+b55qhdCCCfEBdOzJmWlNMQFFzkxtPgY0BDu+SYbD3GpedMIrQ6r Ed47Hdwed6oMekA8ok0n/MZKfXh/7tvmx5loSMrfLGydR15+t7HQypk6tJwIq1KYhyLc 0uIly9XxfCks95d+ppjvbdflAKWOxSb9asm4ZDieYVqoi8BgDdDMkEY8FLH3h8P695y6 JzWu7w/lt5QyB1UYQWVRdo4dFQFhxlGXZjFS1zGt6o35Ktzvtp0U5JAbjZkSSrG4NWOS f7Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GaiPOQJQg/3eaR9Q8OYjD4xHiibeiKzRxzXBSSG583E=; b=wLXZDXNPtNen1g28a83TOONCgG/SHzL/UaGiSEpGsysn/eUB7DRay7pETtF5ti55SE vcphbEM39BrPmoZc65gGdkeHHZrcnt1RtG7sKqtJPYueUPx9swLlOtMKrsP4vmwHsIUf OUxsCh45wcp/kXZMfwa8A1XhA/cJXJhjI5C8NaKC3P4q9LwqtMy35T2lIszF6oQw00rv biev1drTFvWimJ5UEHBZfrYh6f+pHNcN7vLULcK9ZOhQbqcLtm7EAxEB1RLOxcU+Ql1f nlz8x23G4vMhy0+ou0EXsBgYwVZfqGPIAgwQe4jJff4tqDLBNr2Glj1xX+LuOK+LrQJx cOVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=TCrjIwKJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l13-20020a170907914d00b0087bcda6943asi12319558ejs.881.2023.01.30.12.54.54; Mon, 30 Jan 2023 12:55:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=TCrjIwKJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229460AbjA3UwZ (ORCPT + 99 others); Mon, 30 Jan 2023 15:52:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230032AbjA3UwM (ORCPT ); Mon, 30 Jan 2023 15:52:12 -0500 Received: from out-62.mta0.migadu.com (out-62.mta0.migadu.com [IPv6:2001:41d0:1004:224b::3e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B05483FF28 for ; Mon, 30 Jan 2023 12:51:57 -0800 (PST) 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=1675111916; 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=GaiPOQJQg/3eaR9Q8OYjD4xHiibeiKzRxzXBSSG583E=; b=TCrjIwKJC099LsLvlkSDhNlxLio8XBKvK6arn50U5Oq0wu2cv8MUDulFrm51KAee5EAjRV +8Pv4cs88SApX9F3qPDdGLCnq06UnlNLhh0BLPrRijp6pc7Uu5IQaz/tKz9173gWqPhMOZ 7S15Mtx6lM2aMb0WH+SSEAdvCLMs5J4= 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 15/18] lib/stacktrace, kasan, kmsan: rework extra_bits interface Date: Mon, 30 Jan 2023 21:49:39 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482364077082975?= X-GMAIL-MSGID: =?utf-8?q?1756482364077082975?= 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 --- include/linux/stackdepot.h | 4 +++- lib/stackdepot.c | 38 +++++++++++++++++++++++++++++--------- mm/kasan/common.c | 2 +- mm/kmsan/core.c | 10 +++++++--- 4 files changed, 40 insertions(+), 14 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index c4e3abc16b16..f999811c66d7 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 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 7282565722f2..f291ad6a4e72 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -346,7 +346,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 slabs (increased chance of failure if false) * @@ -358,10 +357,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 @@ -371,7 +366,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; @@ -461,8 +455,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); @@ -483,7 +475,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); @@ -566,6 +558,34 @@ 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 + * @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 stack_depot_set_extra_bits(depot_stack_handle_t handle, + unsigned int extra_bits) +{ + union handle_parts parts = { .handle = handle }; + + 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 Mon Jan 30 20:49:40 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: 50478 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2393629wrn; Mon, 30 Jan 2023 13:00:35 -0800 (PST) X-Google-Smtp-Source: AMrXdXt/3D+xfZ/e+SOEC2AFLuslGnoQn2BRjw44oQKABzC9PNWzG8sbgx2C/cLo/zOIDLk/VyHK X-Received: by 2002:a05:6402:5299:b0:49c:5a27:c1fa with SMTP id en25-20020a056402529900b0049c5a27c1famr54671397edb.24.1675112435219; Mon, 30 Jan 2023 13:00:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675112435; cv=none; d=google.com; s=arc-20160816; b=k0WbirKaXK6JpkQAp+kNvUumvfDXWAnEW2laI6ItNxgxvJMzcMF7wGM7AdtcIivBm0 HaEIyml0HYEFx86ZPZ2fqhVWy2W/dy60S13SeY7brWHunjjmTfPwK4q7lMDuBGpWC4Lk JNuRT3KzdLfSx//sj0fQzFQgWVAH6ypFtWKdsbowMuZnYIsqEXfmGPejt8WVMkdYSEqJ nBD6FB6sDBuM12NoKgz9ifCKioJoVQter8UH+paM+cWiwKp9ONYeTMdMkO5B/0bpG3nQ 3/1W7jQnu0F51Q+E+iM7T7zghNGWV1QGfvbIhjlKzWosFTesWUPEgSupLojvu0YLAsA9 Ee/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HatpIAXF9ywMATjIlRO5zkwkJoWVcZESn/qWFP01cUE=; b=EWcNWdAqphhUQKz4Zc6et1l8yBTtfAxQFagNCMXRbdfovZI1syYJVFpKIpv6LzRM1d M4UMlpNP399UtDvlmzn1bXCT/4ka59VwtgP96CIQllFrYqch7/Qbx7HAF9A9zXGGOEmw mF2LRzGf+3EUkkaVarwFLqy0fZzlPOScSC2LA9IQ8BOGCjOJpATxhijKSi8aGR29xc5I lToyhTw5RyJILIHBM70cl38ZOhkyWn57LsCGi1wrxrLrckCKS4edjH4/u5V630z057CJ gxvjL5f5qgIDqC0zwlE3z4ERm72teMr0d0iioyKByWJ1I5gIV/lSbToIxsNv/F260z/P qH8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=wXtDfrkY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ui7-20020a170907c90700b00888a606c89esi3774805ejc.585.2023.01.30.13.00.10; Mon, 30 Jan 2023 13:00:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=wXtDfrkY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230071AbjA3Uw1 (ORCPT + 99 others); Mon, 30 Jan 2023 15:52:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230040AbjA3UwM (ORCPT ); Mon, 30 Jan 2023 15:52:12 -0500 Received: from out-80.mta0.migadu.com (out-80.mta0.migadu.com [91.218.175.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5741F45220 for ; Mon, 30 Jan 2023 12:51:58 -0800 (PST) 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=1675111916; 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=HatpIAXF9ywMATjIlRO5zkwkJoWVcZESn/qWFP01cUE=; b=wXtDfrkYlD8IpL/lQ8l++bN1YdtjxhnwL1anSh49Js2VOzOsVnOBIPbJSklgemF2REahtq DvdvaNag4m/GqwVZu03XHDBsOWpGjVLbIuihC73epl6av328Yy8aLHk/DlbB90DLAwCqg2 4Z44QfKvcXgws9zhTONc9RpzBkBuxac= 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 16/18] lib/stackdepot: annotate racy slab_index accesses Date: Mon, 30 Jan 2023 21:49:40 +0100 Message-Id: <19512bb03eed27ced5abeb5bd03f9a8381742cb1.1675111415.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482697313529542?= X-GMAIL-MSGID: =?utf-8?q?1756482697313529542?= From: Andrey Konovalov Accesses to slab_index are protected by slab_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 Signed-off-by: Andrew Morton --- lib/stackdepot.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index f291ad6a4e72..cc2fe8563af4 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -269,8 +269,11 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) return NULL; } - /* Move on to the next slab. */ - slab_index++; + /* + * Move on to the next slab. + * WRITE_ONCE annotates a race with stack_depot_fetch. + */ + WRITE_ONCE(slab_index, slab_index + 1); slab_offset = 0; /* * smp_store_release() here pairs with smp_load_acquire() in @@ -492,6 +495,8 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, unsigned long **entries) { union handle_parts parts = { .handle = handle }; + /* READ_ONCE annotates a race with depot_alloc_stack. */ + int slab_index_cached = READ_ONCE(slab_index); void *slab; size_t offset = parts.offset << DEPOT_STACK_ALIGN; struct stack_record *stack; @@ -500,9 +505,9 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, if (!handle) return 0; - if (parts.slab_index > slab_index) { + if (parts.slab_index > slab_index_cached) { WARN(1, "slab index %d out of bounds (%d) for stack id %08x\n", - parts.slab_index, slab_index, handle); + parts.slab_index, slab_index_cached, handle); return 0; } slab = stack_slabs[parts.slab_index]; From patchwork Mon Jan 30 20:49:41 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: 50476 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2392091wrn; Mon, 30 Jan 2023 12:56:48 -0800 (PST) X-Google-Smtp-Source: AMrXdXsafWH4A7UkfLrGSxxbjIHeW9I2R8lxTkFYy0UC0y5eYNzSn4hoBpFYacOzzCV1PVCbdXdV X-Received: by 2002:a17:906:608d:b0:872:a2ee:271d with SMTP id t13-20020a170906608d00b00872a2ee271dmr48892820ejj.53.1675112208042; Mon, 30 Jan 2023 12:56:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675112208; cv=none; d=google.com; s=arc-20160816; b=REMi9ProjtqSMYs6Z0EGZYJLKR2fdiTskcwwBtn6hoLJlO2FGPKvaouSw461si7xZG Hq44fjAS7jgr5V835y88pMAsx/AQHOBel+FgSYybVesKWt4vq/q1exQk4uNCdA5L82Jh ail3QgPJA7G/8AsOEi8bpXQLtjwE4m9O0faPcaRbl3fIqH2SUKehg7bQrXcc5QVLspfJ ASK+ZqqbQxxesVmDgFk4gVYxr9/XEjuwgec6JwXxPphnBMb2XO0iqYu6pj2mFTBWoyVR 068howkCwYd5QQcmbhkk4ZACFgZSUfcwjr7Bi8g94bPuTNd+9sA/Zm7xCkLBp3EzFc5l Vpjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=f1IK6xrmRNNY97ld0D9rdSaArRx+XdmL+DdOqeJXePk=; b=GEYU+9Ii+unWGzLK0tTChXCLDPGD55ISr9GSi2LaLRPdR8x/S1i6iG5nMr4cIbzbay Us0x98E2bV3aZnZOvaeHr3iBh1+rfq10ZBNx0CTXJw1vfAfCmrIP0m+aBEc4iF/oMyAp OPrpowuOqSMskLXLsyw8Q7NbotwzFRmHE/Rnxbaw/wKRpmOFQkygsc8lUvN7+cBSrorw eMXSfW0arN8ail7UPXjVucAnJ/iRIGsIdu2Pi9j5RQ9dxKUQI93Y+LO9N6oxYuVfGfM6 rTLC4jvTSzInq5Pqf3BZM29fEYBI/FzoXlc4KOjYVFk1i+hdBpzjDfKZHdHAQSdY4ZCC Kfxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=N0ZO7gPg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x2-20020a056402414200b004a20a775cd8si13236799eda.298.2023.01.30.12.56.22; Mon, 30 Jan 2023 12:56:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=N0ZO7gPg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230202AbjA3Uwa (ORCPT + 99 others); Mon, 30 Jan 2023 15:52:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230073AbjA3UwN (ORCPT ); Mon, 30 Jan 2023 15:52:13 -0500 Received: from out-38.mta0.migadu.com (out-38.mta0.migadu.com [91.218.175.38]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F20722F7AE for ; Mon, 30 Jan 2023 12:51:58 -0800 (PST) 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=1675111917; 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=f1IK6xrmRNNY97ld0D9rdSaArRx+XdmL+DdOqeJXePk=; b=N0ZO7gPgqsdvjfoPyEHM1M/4g1mQMy1nyep+nZYB85fu9/+taHsVg8HK0X2PLi8RvQGHqO rq+rLtZyEcgsm0wnNTECIM/mArPv2lN556mCiWgb6FLQeQVAiZ/y+BqWJjZ3IiuLdXsChe R7mZrLZFMf5+lGmc0Xsk9el5Wkl+ABw= 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 17/18] lib/stackdepot: various comments clean-ups Date: Mon, 30 Jan 2023 21:49:41 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482458600554810?= X-GMAIL-MSGID: =?utf-8?q?1756482458600554810?= 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 --- 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 f999811c66d7..173740987d8b 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 cc2fe8563af4..5128f9486ceb 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_SLAB_INDEX_BITS)) < DEPOT_SLABS_CAP) ? \ (1LL << (DEPOT_SLAB_INDEX_BITS)) : DEPOT_SLABS_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; @@ -305,7 +309,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, @@ -313,9 +317,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, @@ -328,7 +332,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) @@ -345,27 +349,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 slabs (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, stack depot can replenish the stack slab 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. + * 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, @@ -380,11 +384,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); @@ -399,8 +403,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; @@ -430,7 +433,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; @@ -443,8 +447,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_slab(&prealloc); } @@ -452,7 +456,7 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, raw_spin_unlock_irqrestore(&slab_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_SLAB_ORDER); } if (found) @@ -463,16 +467,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, @@ -483,13 +487,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) @@ -521,11 +524,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) { @@ -539,17 +540,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 Mon Jan 30 20:49:42 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: 50477 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2392130wrn; Mon, 30 Jan 2023 12:56:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXvE8NpU2dK6IyHPdxRNedsmoRVLbV8jSMHK6Bd3z+NEd4ILyBwYIwIxxslQ5v5DRYuipuGU X-Received: by 2002:a05:6402:413:b0:499:d199:6614 with SMTP id q19-20020a056402041300b00499d1996614mr53141608edv.36.1675112215332; Mon, 30 Jan 2023 12:56:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675112215; cv=none; d=google.com; s=arc-20160816; b=iQ8xwy1baxdGuRZwD6BSDbblLVLeHlYVn76jA2hiIDvXInn0SacKQkmE6vCR45DPS3 AXPX5q04+K25wKE8asllT7rdCXB0A3c4SAA/qquQ/yFJZ/7wPLHMVq72+3/E45WuFugz 2rwv2b19IyvQFc7oZ8sgHIKLqynXcZnewAdZz0uFJytczBmq++vRnc0E8LUJelLJqA0T Mklwnbr/obEd1BtUL9WQACwuKEkB+MWmqDDkTpry5glH9966L0IwOY0Uz+Kksv51J/DB 1dTLvPZZq7ISBTbyKA9flIqmQZFFAWahu+Bme1l8YSom8YAGjURF0hvgbwd5gjJRTtl3 FKtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1w0jiNXlV5BHI7ghVa1ATPJTlO9YwfzPGkwsURa7liM=; b=Xy8aOW+jm5wVmTXQKE2AGZLqQSwz2Aq3p8dzf/LZO6lcAN6lMuwcPmvMey2/9gmxNx 2qrIahIjl+acBIugtlZgfoKNYCor/pPysoLIH5Dmlek2z2pWAUoJaWSkCj/Barnomh6O /tEZpy3xKBrpsujMcvIEELLF/ussM4Ry7g5+FzwkknzfTSojoyXAFnhs69lLlLu97GQY LuSxLX6wMRz3QlQiduz1GdngNIkV3Bp6qL6x5Qb0sQaHfUiHAD1/B5W3ZZSdqbLIIQxs A6rmF9Uj7h2qiydYsxfD5vOtsAaUTbURC4bJ7/NdkkklGWYaspBxKMhe0B1C6pnF29yZ K7HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=g+SFAUpU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y9-20020a056402134900b0048a267dede9si7972160edw.133.2023.01.30.12.56.30; Mon, 30 Jan 2023 12:56:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=g+SFAUpU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230120AbjA3UxE (ORCPT + 99 others); Mon, 30 Jan 2023 15:53:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229503AbjA3UxC (ORCPT ); Mon, 30 Jan 2023 15:53:02 -0500 Received: from out-103.mta0.migadu.com (out-103.mta0.migadu.com [IPv6:2001:41d0:1004:224b::67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0205810A9E for ; Mon, 30 Jan 2023 12:52:59 -0800 (PST) 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=1675111978; 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=1w0jiNXlV5BHI7ghVa1ATPJTlO9YwfzPGkwsURa7liM=; b=g+SFAUpUe2mu88P1pEk70dv2uuPp0/I7xsYXHG/JpiRYYrZmJzuaCNQR1OX4/E+pnbYtxJ EieczeLK5iF1UZKQW572hf2o/Wa64u5xGs7oXn6EP9+t2RBaWPphopRDb4vnlDR1pBJuku 4pgNS4ge6XFwTqmjemf/XLPLdINSNno= 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 18/18] lib/stackdepot: move documentation comments to stackdepot.h Date: Mon, 30 Jan 2023 21:49:42 +0100 Message-Id: <341353394ec1134c5a92a2b298348ddc4c48c8a0.1675111415.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756482466489050876?= X-GMAIL-MSGID: =?utf-8?q?1756482466489050876?= 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 --- 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 173740987d8b..a828fbece1ba 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 slabs (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 slab pool 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 + * @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 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 5128f9486ceb..06bea439d748 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. * @@ -348,29 +337,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 slabs (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 slab pool 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) @@ -466,18 +432,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) @@ -486,14 +440,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) { @@ -523,11 +469,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; @@ -539,16 +480,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) { @@ -561,17 +492,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 - * @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 stack_depot_set_extra_bits(depot_stack_handle_t handle, unsigned int extra_bits) { @@ -582,13 +502,6 @@ depot_stack_handle_t stack_depot_set_extra_bits(depot_stack_handle_t 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 };