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: 13121812 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60BA1C636CD for ; Mon, 30 Jan 2023 20:49:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE8B46B0071; Mon, 30 Jan 2023 15:49:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D00A96B0073; Mon, 30 Jan 2023 15:49:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B77896B0072; Mon, 30 Jan 2023 15:49:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9EC156B0071 for ; Mon, 30 Jan 2023 15:49:50 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7639A1A04F3 for ; Mon, 30 Jan 2023 20:49:50 +0000 (UTC) X-FDA: 80412656940.27.0A1B711 Received: from out-35.mta1.migadu.com (out-35.mta1.migadu.com [95.215.58.35]) by imf22.hostedemail.com (Postfix) with ESMTP id 84F3CC0020 for ; Mon, 30 Jan 2023 20:49:48 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="l/E56Ec3"; spf=pass (imf22.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.35 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111788; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vpL8/NdYX1/weZXFrNrkU0jpgSm404fZwOGAfIO2ueo=; b=SRVPrC2w9/rH60s3z2cVaxiwOwaWkRxxvi7MWr+Yanq6X8EmYkN+ghrxZ0JOPcuKu/p4Vv R+emEXqZlJGdjPv/nhzmQHLdJpON8ylDXC3BK9xKyj8g4BiVQCBz8mqaKd2EtP0Tri/WWI 5kNc7CBNSyVBu1+bsYB+2/QWqVZcJZA= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="l/E56Ec3"; spf=pass (imf22.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.35 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111788; a=rsa-sha256; cv=none; b=WQL2aJyYKwogBGdb1qHueKCWJIdZnPglKB9WWvcEhsSdeyqKWV+UyjTzAGXTQdbOrgn37b KALxdNKgViQl37ng77FZFKqQzuFF4HgOOi/5aYYFuWgSrFCKpESzNWl+BUoZEtchhdTZL0 XjYvJjicbNlRMz5C8MCsnJqvpx2toYE= 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-Stat-Signature: z97a9cz3zsgkh7nruiirbuo9isbbiayy X-Rspam-User: X-Rspamd-Queue-Id: 84F3CC0020 X-Rspamd-Server: rspam06 X-HE-Tag: 1675111788-375484 X-HE-Meta: U2FsdGVkX19qb5pqjyGUySpGxrH34HhETyVupLn4gl65F/nLv3rE70uFMietY5XQFOuk48kBLTaEYz+dURhy0ODxj6KQmkyxjwZd2JoCmvqOPbIcz/TJ4wxCt59CHeTEl3gczn/bOEuewlWipK7C1VgrRJmsybjNao9eteN1YEFy8XBDOoIgwceHdm8n4g9zavAQ3rut+GPf89qJKkukp8HpIdhQ1EwFYaXVPXQt8//41Jr+G25xaYL6wUiCnBsI8EWw5iYVJotXu1j4WZZ8JeKT6pYYIZ5kG2W5cw9tnNXO/ARveR5wOM2VY7fDoaf4bFJGn2yppW59mYU0DwU5rArakNeUGaLlxx0ulyKdjbwZ0NJriksv19ZyIdTfl653tq8lbFMbnrouxSLXedxq19YuYlLP+ZDW2pTnqJJmz1nshl/7L7IgQIsCHbLxTHrf3ag5tBSgr12BcSNNtZ0hT99o0oZeTeHfbq0+/9LNqgEV4Izfexw84hdoUQz+Rzeuh+X9UHxcNRoTv4K+roV3tnfvk3qtiYb47OKw28Zncznx5wrP/UQM59StqttlE2CXTh1LEwyhStMIUwopc2f01ZGcYkU1GBM9xZq8r1MUOfHPG5WOwo0crXzqfLhtpz0azgDXgYwfpvZeG4g+4QczcuZX6tFazyjf2657C+BDuhYgTq0EpoydEyCVBDivLT60s8euHhkqZ22eXOiRI3WunAmoGyoyhHxEpblNizEJln11MaKPNfMDmLwmIMh6fpNIjJa+vxzfkIh76NpJDoOn11JwK254tr9+JY2yMCaHErtaUVnbdSViWhdQsyc2kivYmmILEvdZT5Icq33VwlxQrqsT/KFqMiCNbwmQYbypzPba6KxUhiSDhL3O7ZZh806SrxYEgPb+o9xGvz49tI3OTTLfqFUjtYqANj7KvnDZRW0fF7sXl9DOHGofZiujJZVuN8zAHxL1kDw2gcbXdHb o9qjNq26 cOXua+VGZuJ/GNEAQ7XCf7bxekzin/U6fWbzKyV0v6XRk3iJJdh87Q5tX1ujkOzkF2pecHxBrjplwnpTqZO9gDQR2pbhTSycsBGdibR3Nohe4izEkHnD5W+aGGk5eqWtmaTeq1MDebN50e9Cc61KSYc0poQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov 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: 13121813 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D36AFC636D3 for ; Mon, 30 Jan 2023 20:49:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D1136B0072; Mon, 30 Jan 2023 15:49:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 77F446B0073; Mon, 30 Jan 2023 15:49:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 647366B0075; Mon, 30 Jan 2023 15:49:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4F23A6B0072 for ; Mon, 30 Jan 2023 15:49:51 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E4EFF120BB0 for ; Mon, 30 Jan 2023 20:49:50 +0000 (UTC) X-FDA: 80412656940.23.FC8A78D Received: from out-237.mta1.migadu.com (out-237.mta1.migadu.com [95.215.58.237]) by imf27.hostedemail.com (Postfix) with ESMTP id 35C3D40012 for ; Mon, 30 Jan 2023 20:49:48 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="Oa/CuJOa"; spf=pass (imf27.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.237 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111789; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qcsUnulCBN0ghXL+bzeFYdD4TQnNlpFLy99BvSyy4/8=; b=O6o+AV82IK7JYdMmHkDZlZobnXX95a4j1pvcRk/X0c4ZuKJenLD+z0AOLAhIxKPETYAYMi LdF7UQx8wmM4i/9kLLyiTfvShSQx9qEB501ie3y85xrSi7wOv2CyyxhPkYMOO7hWYfjxVj XrFa0uWFi4xOBugY8OCHE7+cyoQsBmQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="Oa/CuJOa"; spf=pass (imf27.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.237 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111789; a=rsa-sha256; cv=none; b=7iTwWogByR8veuIJoeb3UklhqblrFNyUMwCjWPbE6dpeg5075IcM8wJwe5GF+vML7FMgF7 TOtrxTfjGEgwUstJ066jW2ThXTHUI+b7PrNQ3cQbdQL/vvB8lMvFqE0R+KaNhsRhXS3GqW 7rOf2RNM7vzZsTAwMqpbJxczzg+o7tg= 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-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: uwuft1b3gek6eyyc5srh8ryfahgtraqj X-Rspamd-Queue-Id: 35C3D40012 X-HE-Tag: 1675111788-721332 X-HE-Meta: U2FsdGVkX1/RdBKm9kgcC90Q2L+MRLS9u1/p9zFeMhpxTWiOBvKP6UXXV9Ni0myAT0sniqyBN1I2rTo0/cMmfqJh+JHCosiUcUKNAg0rcmhWJxPUvL9ld2OsFvwq+kX/uKZoAb/9edT5rp05ffVaCNKZOsQ4YUuWhM81riuec6qJjjUTwZO+YYAFQh3cKLoooal7+Vx7qetc3eNgXjU+07SXEAKv2EOAJX6GjfJSkcrInBZkuen3Zbpufp9QvfUD+Lh2yhmFY3rbWf0QzFtabeaFx2zzACf8rU/o9r91kje1e2dHQT+OjC/6hPB4LCk4V4rcZEA43bQLg88f19hnA9Ck5PH2qA9HK415gSFXgV0IDOVyUWUqO8Cdd2Y50z3C1GAnhEsHK5dCHKYBHcFxurxnp2wLsyn4shf6gyNVuTQmpft1vnsBI6CVD1TX+23+LqfBKl80p4/0fKouzHJzw+K6zRpigtZBeeCSYWi+6Mn/yHAjOHHNwf42CLB/hVmWqHloNqbVIdk/m0S+fSybvNEX4Wk+hHo0VHH0uhSDKcE1xJCYfX9YMwpG3Sqi1d+fRPsOphv/C90oC+GREsXOezje+kHkaQ/HRTGthYhG8K36IHCNUE7xQy8HVKXnydL+ejXeKV2Uw8nYSSxtdsK56zVo6XvzBb5HMlk0Go2i+iJGnTqi/91iWWEhhDJ6B2aWsVZIZMh0tHG9FFZqIV/otHW9J2pWfT2vFQMEOg5mteZLih/xdhq+PGHpMJ6qqKF2/kwS8myEQCPnOtm9eKIXRrWajILpZpjnviBoItDrCcpA9OWjv/UmT2gd0xWfYepbki2YE46CXebJ8/BhfcnyPf8ea6EH3AQhTQ9Jg5ROWmmCRGpgdiCZ/nev4lrHnS3tbXJePBABzRNHOoeyPlj9lprWzoSidhwM45Z4DAYFvwoqlrERjSA8W1olM8H2dOWDujFSWkwbH/w98G2MkY/ NU5P8IBQ s3wyhSvlfEWgDh7XhBiMSgPFnwiXuaVKrqeris+BYASB9tQQ+DLvsIIogTAdWSpsIVHjOKqdgk21V7tgAycbbh6bD9v78RRa72As9 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Put stack depot functions' declarations and definitions in a more logical order: 1. Functions that save stack traces into stack depot. 2. Functions that fetch and print stack traces. 3. stack_depot_get_extra_bits that operates on stack depot handles and does not interact with the stack depot storage. No functional changes. 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: 13121814 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81FE3C636CD for ; Mon, 30 Jan 2023 20:49:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E60B16B0073; Mon, 30 Jan 2023 15:49:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E10176B0075; Mon, 30 Jan 2023 15:49:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C62576B0081; Mon, 30 Jan 2023 15:49:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A0BE16B0073 for ; Mon, 30 Jan 2023 15:49:51 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5C9591209DA for ; Mon, 30 Jan 2023 20:49:51 +0000 (UTC) X-FDA: 80412656982.20.DE54555 Received: from out-143.mta1.migadu.com (out-143.mta1.migadu.com [95.215.58.143]) by imf01.hostedemail.com (Postfix) with ESMTP id A095A40021 for ; Mon, 30 Jan 2023 20:49:49 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=SpOJ60TV; spf=pass (imf01.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.143 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111789; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=l0DgDHv6v1bes9QPJYpLqp7kkvT0kapBOv6TW2IBB/k=; b=oz+gtbzDzmE0oQFf9UFqYfSWwS7cjB1qHuXCYYSLD8RrnSYG0LmGFvcJMqI1eDKwqVhp/7 LYePC+un80gL3nQd8kSYXEPtKRMhGI5J/+lp46W26QwuxDvAtkl5AwThpwaI1Rw1e9Xaos vUYODdIgFKbazRIdmfGn3KV3e5Y5tho= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=SpOJ60TV; spf=pass (imf01.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.143 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111789; a=rsa-sha256; cv=none; b=KW3lsjrvOKt6JtG7ah2Hv3FnRDnEN/bm+O2k2qeRIN3pq5CSCOab/7i+CILZmn9/iOzkAa ZlIhLK0InIrgZGnpstBY7S2tR0Rp+7hNiWYI5svL21O6P0AVtLJlhK/x/I87rk0DT7cbld yxnPdvrrNPPQiG1T4qWXBj1750xTeJs= 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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: A095A40021 X-Stat-Signature: 7wqfbdk7hs3we4kmzgzwaffhrjbt5k3i X-Rspam-User: X-HE-Tag: 1675111789-28114 X-HE-Meta: U2FsdGVkX1+1uNr9qa+75lrw285Hh1xDhSIoVUtL7cU/ddqJQQ5bsP+183SroDJobTMSCIfj5+P2tY/u6lByPcQS/KnRFDW9McL73EOpGub4mbwCrEgMUsJ7iyn+V9uEJCWvRjjkyUsvFNcsvhrd3uO3SzWfgrZ0x7ka/+QKNXNiXSmQmc+NSxMFvMptnYVHJ5UIhFUJF1hEN9Z5fKMsLSrKhG+yF+heR/T0cqezjV1xzaEr2BOfP9Ldd3aF7SPC9ClxZ1LrJS3Pq4UXjvTsHkCPQEUuDNULJ8yljFjwp1uYImX3fuLTqUZEcosIZQ7QturlqW8loSj4+Llil+YoHeFo+cBmg5aNtnLftAofxILYRA6UeRWQFnVfG7u0rCXxYUYalqEtoufnkmTMn/11FhutjYGtUvhLcqIeMRiot7yLznBxwsqVgUkOQQDz5762izbzq3Dzf78hqQlRQn2/HS1rrnV/A5BXozKsXpW+NS+l3MMDSUzK74dEf1dDQBfSs2EZwnIWcSxs/CMCkZkkSs01G7fGf6vxPsfQUzM7p/OFfAifdq5dSL7mVC9hzUNgaK6Ga8Qmq5RIQ9eBT2Ljui+TRYFh5SMLV3vGqFNVbU41JlRmGZKhMgo6xHLu5gRezumWuvOpq0GdKytzlRpE2d99LUvIfRhQ97n65pana4NCVFiNvveG31irDPvqchCp2ddsaXcaOKZrrdBvCAw0QKnttq34DBQnFuFOa4G57ASJCfoo463ybNtq5vtgdxC0MOACrO4pJCCGaqn7/LJAVpdthos7cQPQvY4okszqILozn0dR0ZfEh7L9B7F1Wdd7sy0ihBRhtxItzffoFzJwMF0/Rz8i4xdE2dOMUn41BYTlUp8W0ulD5dQB2ED1xCkpc6ENpWXWp61UPHsb80pXWAy/C+PR7eT7uXDmlo01woCRhRFSI7ViomsozZMoFM52JaLCnzQc+oQlmXBsZ2l CsKIRbJV yF5SzZMEzjgh8NW083z5QjVJ7V9MreZ3Z+Ezi/37lf/mTbilo2LJ0olFG+60zxJKnV+YEIwuBflrpyrTjcvbLnkJxUwIE9OMjegu+xcPp50D2IprMp3jl1+F7MqcqCl3xCVGlooJsMlJM28nkI1i6n+M/jQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Use pr_fmt to define the format for printing stack depot messages instead of duplicating the "Stack Depot" prefix in each message. 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: 13121815 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1C89C54EAA for ; Mon, 30 Jan 2023 20:49:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 401016B0075; Mon, 30 Jan 2023 15:49:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 392AC6B0081; Mon, 30 Jan 2023 15:49:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2507B6B0082; Mon, 30 Jan 2023 15:49:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0A08F6B0081 for ; Mon, 30 Jan 2023 15:49:52 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D7AF2C0B97 for ; Mon, 30 Jan 2023 20:49:51 +0000 (UTC) X-FDA: 80412656982.15.92B1C29 Received: from out-149.mta1.migadu.com (out-149.mta1.migadu.com [95.215.58.149]) by imf13.hostedemail.com (Postfix) with ESMTP id 18AE020015 for ; Mon, 30 Jan 2023 20:49:49 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="cW/knli1"; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.149 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111790; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ePKn7wp1b3FbqZznSS/x2B/da1B4by5dKxtQzEtZAxA=; b=0A/c5OztnicyV5gEzas+oYD9I1jm4mV4YF1ychSZKZC/CGypA1jGpV/1i/lwt03BfHznmR 1ruBjnzYhQ8EvYrLKeugQDDHoZt2rJr5xDxo+jS6J7oYr/QdfDP5/GYL5eMkRWr0ygiiMx 5KcVO+2C/NmoaLpjHxV384GPfJtmvYs= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="cW/knli1"; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.149 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111790; a=rsa-sha256; cv=none; b=XWBPUehj9mPcun6zd9Bu88YMGpRMDC8cp7XZwVF69khI3rwOYzGfr9roTvrLUUHuZ3yGHV Qom15LDcPv0O+I5189gk6zQveXvnQcCbXa+Rb3VzbaQVHTyAcb26rcl2IyGWcWCc37QyAq hFDmBA0Ufc3wRIiETGx8/O/aLAKHUlo= 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-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: e87f98bkywch3d1f9czssr34qciywh43 X-Rspamd-Queue-Id: 18AE020015 X-HE-Tag: 1675111789-512888 X-HE-Meta: U2FsdGVkX18G7QfL81mQT+LFjfkiFmMZn25OzCHdO3Oi/vS25huRKFLje07hR0hkFe/9+ajDQ8otGFkD9ISV6b/o3ib8mODhkcMbNdipMLYtYgt8EWCouDlE5Lxb1kysc4NE4aK4Pj9dUtW/P8ZgFcf/pyyBrdqzeCrEKNIPLrzKOEnNrViw9D3873LEys/4ZVONvV+i5L1/nMFfAdw+WJST7+f3vH4QU8Ndo5JLNrshaw0ZDW+KGPBFgCLRzLq+mKkmgb8TJn3Yud19T8PEGrSsUgeZVSeZLhTru2WRGxnTkW9TaJEaSy+QT7md2KFlgHnsCkrreGQY1vlhunFaqcVy7znTxKOyZ5PwTh7W9DPDzMrMaVkDQOya0nvz7kXJui2Sm2DDuegzx7hf6t2fVALctUwqInaYOnQtIFplIXSbqgWKiZOIrE1Oykq5GoaSl5VZ0YLiVb5Rrssmd/XvqUx/3s/aZSh6UHquK5pq2TJFd9OP2QZd4XkPlYBxuYXjJBKrS5Kj9aCBmme4SOtOswKplk+MaFypi4tQhnQDZ6dme+kpngmFtyCQhKffTpPwn6uYa2to0SxowgfD3Sq7fgqkcrd2aXAcqT6WeHbm0MufraYAnB21Eo8reQFy3/9j/ak3PXDd1qAnZ2Ao2RH1VaD4WlC3863rj7n5uynhmNGgrM8z/na4SkmRvNUr0Iy8X21nfbMOrsJLk40LEqqIg/iurVphXhRx3vFPYiWy6DXeJ0tj3/MGBTLaUzHa/oA+UKVdswZw+PNVw3SUpx8DjM87lVZ881H4J/rUZs8YE4JycO0s/CRuFTlPmmMWBW097u7LYGysMkXQfYtzmGHbW8fyw6tIaWd/RIw6PoQmykCnEE/ojPmTAvIiZq16dyBCIQg0AzlmEGFiJqmhGZ4wDPiwU5c3T5BHLcYkRo9g3cea0z0CjLBJFKIQpIo/BXOS0T9QueSpT4StkM8RODd 9l2PYskA q9SmL7pNXVwynQNYaGApFciaVgH0A2HJOpvbDJk2D6FhUxo7ZZIjn2ZOy0MSXw27Ldkor6S8eRJoG0Rt8JKrnrOU0RUNgkSm3sLWAPClhNCCsM9RwZ9L1e9f47pO1QKy6QC9v7U/Djy/tIpxCtLTgTUA3lQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Rename stack_depot_want_early_init to stack_depot_request_early_init. The old name is confusing, as it hints at returning some kind of intention of stack depot. The new name reflects that this function requests an action from stack depot instead. No functional changes. 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: 13121816 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DFFFC636D6 for ; Mon, 30 Jan 2023 20:49:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FB4B6B0081; Mon, 30 Jan 2023 15:49:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5ABB06B0082; Mon, 30 Jan 2023 15:49:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44E936B0083; Mon, 30 Jan 2023 15:49:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 34A786B0081 for ; Mon, 30 Jan 2023 15:49:53 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D4CEB160184 for ; Mon, 30 Jan 2023 20:49:52 +0000 (UTC) X-FDA: 80412657024.08.DD591B1 Received: from out-45.mta1.migadu.com (out-45.mta1.migadu.com [95.215.58.45]) by imf06.hostedemail.com (Postfix) with ESMTP id 9ABE9180009 for ; Mon, 30 Jan 2023 20:49:50 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=iZ2SF3e9; spf=pass (imf06.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.45 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111790; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=c95lndz29O0di2fe/164kz+dHAmKL4r6SFIURNRPYhs=; b=TbK4RNegW86w3k2MM8Pd1WKSRYFS0E6itsQsOgE7FVIGGtsm0R+jGrIiyOip9bJwN1NJ+O glIsCFLbsEyxoi70AbEVEx7TnZ4hw6TYo16BDQG5QhS6BxlqiAbpdIfmakaB6b9MupboIw 6w/L7QuR5ByfXBQLZuON6ZwWuA8eaA0= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=iZ2SF3e9; spf=pass (imf06.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.45 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111790; a=rsa-sha256; cv=none; b=XKHpWokDQD1d9n2rzY0CzQ5bxexwXuhtlvG6NYKTdvKNIM/IIrkaIuX6vQZnliu8GaaDRm FGt7Wb3fVp9JwCMrZvMdjDEvaRCpI9TqB/7q7czchtM8LFw30EWsfZkYeLPrrpoy30ahff qvSH+2+7mREHTWO4Ag4VMAY4psudQGc= 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-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: d9ixz9dsw7wex8fr6yxneqq86oft5ku7 X-Rspamd-Queue-Id: 9ABE9180009 X-HE-Tag: 1675111790-620970 X-HE-Meta: U2FsdGVkX18GB4wN1+eS5NpTDujhelYahsL4EaVxVcBnb0HOdlB+aXA04e0OluLyxTjcCx3V4QGZeCkB3RNl6VJASVyj83N1T+475hdlc+CP58cl/MHOVhkytQOycLvmfh2YUD8K9BOt8EQW+2cKO22ODinfh6snsLStJ5VqzXsdYoOX9GboStEbkfMngP2Pr2n4B+O29kHG6xbdHsdGDMe1LWGmZABB327fw6zedpOs+pOJwpSBHpF1sWanXqqxRCrP9DB+i3Ol8GJxVBVu+hwqbDhMvy3TzfsyyTMieoehyJpGuPQPmT6dCO/PtbXkdO5Vwa0I9FHMTuVqb64Mlqk0ziDl1s2869NRuWFDjbwmqEtJZYwyoxecNQYkW7H/b/gfqAfbIXLtnoac9AgpiOLQgJ6Cx9bVA3qPfqAiOBr5qr5EO0NIu1SwJWzc9ggyu8uX9KtvNBwC1YaEItLzsUKzSu42TdYsueUaPLUHw5L37hvuXwGwdBUxxLrz8HxFmmH9O7P/8gDSCoOtEze4fUbikD4OuclhElkR3Jh1dhNWXu3WEXOyyeGGLJFqkrHMVTcKnB4OG5RH3IRtgC0ERUthcEbbR7UkVG9Wzjnk700ETUwV1+n4638Gxb2Q43UgfKEuUJpR6yCq9t9sTljf43SjVRKYEERysNDbtRz7klzU0CzMIlMB2oHpBWADA06U/pCl6RUjg/jK1aCEdNfwKo2EuMQNKKohB7mzrvF0PFWVMR72G9JrD69wb/booJBy1p2Me2UJMibWXCrjWrK7cPle5l6LEs8cJX7CgTpC0R6kwwIh2nz9bNjPzwQtvkWsexVTu26QuICbTDgNAi50kgpwNFPlJZWcfIT1tyVt4ILsSKXD308zr7ykfO2MFWd3L0xuk7JQA5Bfox3HHHnAXPioLTm7dDlyZm0V7iLvxx4SvILtq6bKYOv6A2TxsU4Q1rUJ4o/X45CtC5DeSwa jw/BiKo5 L2yJ5Eno4tgYcjAiID3n5Ut5qB4QY0zxOwjJlcN3sFj4CM1MUYrG6LSXcZdnS+m4C5GdhaYK5uNnkI4IisA46QC8CjPdi689gPB7w57z0zHtoq7NFMk6aUWY7Uvl7O46LmxvC5xBxu2SxreeIDc1sUBCOQQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Rename stack_depot_disable to stack_depot_disabled to make its name look similar to the names of other stack depot flags. Also put stack_depot_disabled's definition together with the other flags. Also rename is_stack_depot_disabled to disable_stack_depot: this name looks more conventional for a function that processes a boot parameter. No functional changes. 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: 13121820 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 28A6AC63797 for ; Mon, 30 Jan 2023 20:50:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A1FD26B0078; Mon, 30 Jan 2023 15:50:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 890186B0082; Mon, 30 Jan 2023 15:50:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5371B6B0078; Mon, 30 Jan 2023 15:50:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3FF896B0075 for ; Mon, 30 Jan 2023 15:50:56 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2425AC0B98 for ; Mon, 30 Jan 2023 20:50:56 +0000 (UTC) X-FDA: 80412659712.29.99CB872 Received: from out-87.mta0.migadu.com (out-87.mta0.migadu.com [91.218.175.87]) by imf01.hostedemail.com (Postfix) with ESMTP id 665594000E for ; Mon, 30 Jan 2023 20:50:53 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="qTAqH/h3"; spf=pass (imf01.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.87 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111853; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TXUvy5WDZhr7BlKZ84VBiDQ9FKi0bXR5FVmrmN5uemo=; b=Wq35vyI/i5C+LYwMbMFf8l2yCEtbbqBAeee4aW0aWsOOwuINf3Pz3TVPJsbtAjwEa1DN03 5JtnmAwJCzuk8oJ2oUM95+DT46rLc/Yx47BDycf506MInQvIb3P3eTntNSNLtHl3Kv0/QI /D2WSpASHZbd7TXJ7Y9ueUd8vL1Am5g= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="qTAqH/h3"; spf=pass (imf01.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.87 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111853; a=rsa-sha256; cv=none; b=h7DM8Hamc+ayT1NKwhgDqUFzodnT0ps5PWmUN1JBSYQNsRAr2uknAFScL4det4bG3KMfgR SBUW4ctl4I3WkzUZjaBk867ZHHg+gvJdgyLbfuRj6P7JHzMwnhJWkeOnCzR6Kqjk26FCLe JPnl+XJhcCC2u8MTEaGGUl9GsNCWi68= 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-Stat-Signature: hh3hit4hbiwg6eu44j7pdxrfwo8z41kw X-Rspam-User: X-Rspamd-Queue-Id: 665594000E X-Rspamd-Server: rspam06 X-HE-Tag: 1675111853-871900 X-HE-Meta: U2FsdGVkX1/OI3KioJNmw3BI5i7+bflAc5OEv1b0nFUndMBcQTnvMP8KDSW04GwbJ7wvvk2FQdyyeDSsYQMZWJIMquJdsihVdJK9vk193ociWi0vMdAhotEZuZt4Mpu+RiW+uReQrcwibtJg5fV/9Hn0iZXVY+IdWvX8T5t5QopZlbKyQlX3olKpDITxCmap2DMI/BpwguuSGIMq43usPiw3BJ5hPOokn+D8BGU/vWGRcXq/0YrvyQfJqQhOTDa5yTsHaXBJnKyTp7WBke7uFgugqFS5TBNiVvpAsFyFWJ4g6fsFGP0fWnwI/zWPb7+QMqxCtusErcJwQp7LxaE8IB8vv9VHFi1nWfUrNtEaqo5MQnWCfoTGVx5/qykv1WZPAxglI9/u4PU4OtEokUJoLKdS//jobR/bMQcXKtnxlC5x4xECEtsbe/dpOZFRS9g9eQ7yRAQgJj8oWka4LxanLMeV4iWZBAowXb7PeGwc7rOE8D1ukJRc2xkxr0RUiNbshAYpOhmV84V7TS52L9G0VTy81KVrxACG7QUioj47coKFuyFfd+bDn4r5vTSSMK73rbX26x1UkKs/SqBeJthf2TT4vVQkoeqDTtGLdog8ASFXxDdKAEhWxgq5yhBzoYL1yC+5+azUYCUkzqsdyQ7+0Ep+efLcKBNF7wXFOzwtZlKOZyP85lDIRIxIGQlYMK3pdvA12PuJMWP9fF9TPyCBb706u8YpKtVfE0VRL0vSMtOhb6od+mYOyw5ctyTxrwPzvN2cGGbuOm2RwEFzs8yb/xhkL6QIxPu7EKMK4G2/21Sc8dbQ8A3ZxjWlDkCMlUZ2iC+pxia75Be55GDVXQkdrLc/sx3AoY8g7PDSOndWor4Tw9phzFj1fXRhCD98CeQc8qta/cqBrz3ZVbGfHf5U+kuMVO618PmbS6kDVgJ3FPWCs7DGgWzXE/mBR6wV4bcqcpDYoSWqylK4evUwh1O 4Zp/QmHR +QYHjLkzxpESmJqCeMPjtKIx2494K77IvO/Di9wmM5LSk+IwNO/NZwu+Xoph80IL4nUPPb8NTyjMfsiLjdkfHChLt/Ynt16HOnpdS X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Add comments to stack_depot_early_init and stack_depot_init to explain certain parts of their implementation. Also add a pr_info message to stack_depot_early_init similar to the one in stack_depot_init. Also move the scale variable in stack_depot_init to the scope where it is being used. 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: 13121818 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04DD7C636CD for ; Mon, 30 Jan 2023 20:50:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E1796B0071; Mon, 30 Jan 2023 15:50:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 890BF6B0072; Mon, 30 Jan 2023 15:50:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 758916B0073; Mon, 30 Jan 2023 15:50:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 641706B0071 for ; Mon, 30 Jan 2023 15:50:55 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3C040140462 for ; Mon, 30 Jan 2023 20:50:55 +0000 (UTC) X-FDA: 80412659670.12.4C601C5 Received: from out-38.mta0.migadu.com (out-38.mta0.migadu.com [91.218.175.38]) by imf27.hostedemail.com (Postfix) with ESMTP id 7546640003 for ; Mon, 30 Jan 2023 20:50:53 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=OaUFrjC9; spf=pass (imf27.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.38 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111853; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tjOybIkwS91rz6SeT9/1Q1LG8Upe4qgP6MFeV739ipg=; b=z96PzhfQuuHd3qGWW4mlehSOaJKODtwqVjIwNtoVNAvSkRzWBJoxrr25EfPl+EV61bymj8 Q5DmwG2t+0y+5Ecswny5d7YnmAaAaUWIfejOYP47Zo+2Ovr7qhl4E9Jt2kCjyxC4DUnjC9 2uz5jt0fSVK37Jd8H46+wJCVFsg1NDE= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=OaUFrjC9; spf=pass (imf27.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.38 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111853; a=rsa-sha256; cv=none; b=mbNnYfcoJtZf82YwBUc91c9jq2des30Uzs5KmFk/nQQrvmOLwBDhL2qqEwF8+hhTzUiadV NPZQibK4W3Chi8SyBrrW09u5yPB/o+CdBQPkQxe8HjD1uuIHtXZ+6M5arAQSl1Qurltl8q r1UIBGIhhSBQhk5CFCdvv0Rm2dF6zeY= 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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7546640003 X-Stat-Signature: aexwkmdhuk619rdtyey5hpqwk6yqi5kx X-Rspam-User: X-HE-Tag: 1675111853-263877 X-HE-Meta: U2FsdGVkX1/umiT4aO7Sku5Fl8RRjQVmsyj36kiBqM90xEPnr8jG2c4SgZhW05yJm1bSOujHjGB1mkZVQEBWKEznhSRlePKgEFamDSzDWDW5KmYva+ll3Xt0SlgEQmZiy/Fo/Epp3z8eaP77Je+PsSjlBeuYaFELAsnWsZD5WSQm0+SMDv0boiTF1aFx19rD8CbVg5dyVJM4X1diEinvOl6cO3LddlDctPtC2ECqmEVD9wwUFmuFg4UIwfZvGHJXcKJLlV4h7lG2i9cNJX1WOykJRh//9YGKKxucdJ4frH8M9/d1Urj0h9karJQQt5Pcjm0WJNXMv1o4RGBA7ufvfs3nR92GQZLV7kFkJCqW9nkMuQzj+t+Q8gS768pbd2hK4Rc4LH5aprTCnPnra7Z5fr26x5itSTXMCD0OHMy28PX0800P/r98CHKyncfBQYIxlrxYRI/QghP948+OXoGmSQuAVDDOZuQzQEuxsuR65Nk57otdGSm8IU7/SAP5B7d+pBOhLcup7ziRhycAF+NywbwBeYXP8+x8HtQXDpZ4EtV4FHESQcGjlod8mh5nziWALhBAW5r8E3rjx2Wa/8vcbaykTtBo+TKJosq21hgp3AJXpDiXN/01Gibkhmg8kW5tb0ZhlYpSoQUujMbsye0WF0wlA+LZn5ZPJ/a72lPNl5a8N6Ne5uWVrKdr724/Idmnabb1/rcHZQtPII72xziRPQm0HOyT6qnm3ePjeB0na4iCsQZ3nLZIJtNqGUt+YPpuCdEwzC3SzvJlfNEyqgm0iaGRm/aemeNjj51qNusEa0rEt79Ts8+RJA9uBmTTejzTLqV0AfTG4Ogd6nCAa2809brWE0J3WmopXAQb4TuSCDHrV+Aeb6SWnjYXJL3L2PuvRLCw/vhzB8NPEdl/Y9vD9Rly1pG22JB4jm4iz9LoCuJXaAix2sB8BjwiNKLi44HDkEr84D2sg+ssdifa0EG CdnFuswY Foa4VRxHYuMkn/klIcw79oDEqur0BTe8v9jtKY+pN13tc07m7MIdHjdvyecnYU49G3zjQFRPiufty2vQ/2Px7dFh4/PtSoAx0pZbz6PNtVc/0ACJiDWdiHCMaFzPn7P0kGd27p83pjp0V+7IHHNhJOrP3Jg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov stack_depot_init does most things inside an if check. Move them out and use a goto statement instead. No functional changes. 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: 13121817 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98EB8C54EAA for ; Mon, 30 Jan 2023 20:50:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D02706B0072; Mon, 30 Jan 2023 15:50:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CAF776B0073; Mon, 30 Jan 2023 15:50:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB8056B0078; Mon, 30 Jan 2023 15:50:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9DA296B0073 for ; Mon, 30 Jan 2023 15:50:55 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 77F60A0BC2 for ; Mon, 30 Jan 2023 20:50:55 +0000 (UTC) X-FDA: 80412659670.08.3EC7F96 Received: from out-77.mta0.migadu.com (out-77.mta0.migadu.com [91.218.175.77]) by imf13.hostedemail.com (Postfix) with ESMTP id AD70A20019 for ; Mon, 30 Jan 2023 20:50:53 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=X7HUu+4V; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.77 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111853; a=rsa-sha256; cv=none; b=bU3b2ypwHD4Wicdfa8MntAKPp4tUQMBLmJi8QRGxM0EqgMMFgZhCm4YD4o42ZsgaUZPtOP UjNHfjznteEsOzsd15vA4O3iujVcxLiBTR7WpLb95xHdWAHnCeFy9NNNUKnIhgC8oWE+Ac IH7hqLpkEfi68xDRjSPeehs5wP5hNr8= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=X7HUu+4V; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.77 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111853; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OedhC/9cTS2mJq0ENA72OMR4Ifsg2rHWEhi+f8KNzJM=; b=AYsr8HLx/+I6lorzdmK+LDQEXWA3+mfZb56ZCE55FfzR7AGxWkPlKTIc7fBXZ7xJqUv374 oyT8eR67YG4AigRb5fZHdzaWVe5aqKscQKzJjRO3DD47LDQtryqO3w7sPAqtS13/7Xe2n2 ifnVTomD1loPux6H6foMxSa+oKLNfS0= 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-Rspam-User: X-Rspamd-Queue-Id: AD70A20019 X-Rspamd-Server: rspam01 X-Stat-Signature: cnioc7u4qx71hjeciuuxhpqf9jydwd7w X-HE-Tag: 1675111853-178430 X-HE-Meta: U2FsdGVkX18+GAtutDkcZKOSW5R8bVgMNsH96YU/KM0wfoujhWy+5srLgLHRvvf1q3qOv46ckCFdIuKjHkWW35Cy89TfkFfHHa2tOLG2lVINd6nxVWP2zfUa2vQ0l7GF76RrapELlLX8k5uMCC48K0IlL5p5wyqvYzh32SV5pltTSLO5RNXtzMBsrSpQVyOXBrFlpDLT9CfgG1tk1O+y+D2sUuhMciqNyCJPEvyAiGrPH4qyKODPShcmuzVzrSJYgiTOi2sIQqLo2mdWpq+t5SnMa5I6hqlF76i3yemAvf77kZc7S2bYuBt1qDyEePp31dqIea5lS8eji059A8TCgdlqzPwGnSunhOxhO+5d4jk15aImuB1yHvK25Vb1SzBtLLW5Em5k0W1jr1TI781P4tjWiKXw23dXSx4nvD8cOvZTMOWwcC2nwMTZsUT3MKd8t8E1Y4cNFhz1x2rQs47kGMjjE1dZe5zhgFf8Rbo8iX6KlAD2xxZkDXK6Sb5zd4r8AoalK74Qk53aiP/al+DQBdfdIOVjXACp9zLEj1tHNXiWuHHUYkenrhShSxoHVOlpMtVkwkYyIyCIzymTVnOC/Ven0ctxmYoxI2+peF+jlZ99I1B7v1fqzqfj0e1wv+o3hxJDj7V2pa/RZN2KP/biOEhRWWTt8YuJcuLXuIKzy7iwoMNVDKirQlC7gzGqnE6fhIjVpc8PL63UBheG1hYALW9rg/CGcAU7ym7LMOOxIk1ZqazytWDF2eOleztob8+43Ml8WjMSHxjUVpeLgjatIkfWPPLZ9R2s+7ZIeItShr5q0GIa0w8w4cAsU+vIuw8xnI/Av0x9XKtYaWCvO0dVY9xhjjl9qBnXNrAQ5RkSqwyZhIlpeXqtkSNGSKitulNr4F+S+pVYLOH4kxYju8uAJuBU0nqob0/KoxZqfRqZOQR0yNq5Aw2XbmyeMFCI11VT7vpbHt31Zsp/cuUbQuN 6o3WBhGx IePwv4ULdGx4Dv7aX6SPg0NEPQvKMw/mbKEygmsE64fujy6S1RNOUcO5H6Ua+gpR2serX0cs/t6bwolRvRBHsyuEcXNCqGyE9iTUt X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Group stack depot global variables by their purpose: 1. Hash table-related variables, 2. Slab-related variables, and add comments. Also clean up comments for hash table-related constants. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 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: 13121819 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA1F6C636D6 for ; Mon, 30 Jan 2023 20:50:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E6006B0073; Mon, 30 Jan 2023 15:50:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 694496B0075; Mon, 30 Jan 2023 15:50:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49A9A6B0081; Mon, 30 Jan 2023 15:50:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 32AF96B0073 for ; Mon, 30 Jan 2023 15:50:56 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 05F40C0B94 for ; Mon, 30 Jan 2023 20:50:56 +0000 (UTC) X-FDA: 80412659712.06.52C9A4A Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) by imf25.hostedemail.com (Postfix) with ESMTP id 2DA23A0008 for ; Mon, 30 Jan 2023 20:50:53 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=oaNF1e2Z; spf=pass (imf25.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.174 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111854; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4ThIc/E8It52Ai7wF9nGezLQDQ6i5NEX+ZonMvNBuyU=; b=tTFrKAkfdIkdI/APPOJrVfGoxJ5BV9gD6LIdRUNzwbIkPpYRCeCL5Wcns9ZUEBr9U/OTmI cKI5/88aMPuoZ0CVyOcpTuNjENbldqp3opH9Ad/gpW1ZZ8ZiNGETq9scsWLwvQs2RsauLu wYEP83jQDM4Q3eDk+WEtNuDsAl47h3s= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=oaNF1e2Z; spf=pass (imf25.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.174 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111854; a=rsa-sha256; cv=none; b=4Sj/7Kh1PY/qNXcTBeDEQXbVuGZByppADQ8S+U13DGV2ZWNHRZf4PoGi6YhGWgHG69ZUa7 mgfzN/mrqN+To/JLzxAJ83e0MAjFfJ4q30Wzh1JUH+ZZjNqQ4lP7YJP7IMJTEvZgDl5Dqf ueNaMtFCxxQHLj70lx55fDtaYPg0s54= 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-Stat-Signature: h3qcb6cxkhe5ahb5hs7zs8d4usk7s3xz X-Rspam-User: X-Rspamd-Queue-Id: 2DA23A0008 X-Rspamd-Server: rspam06 X-HE-Tag: 1675111853-712852 X-HE-Meta: U2FsdGVkX19DDp4za27l8QiQkv1L0fDmjzWQyNU/hTL64FvChgn5bXcwvNo5nK0HAc2NuFMejWt1j5qcWNpLBzj73sNDr6zUYPae+Pg0DJ/G/GyWsdTTfu6z3JIRkg8cg9Ed09542Fq0XlLF4/s8tOvCs2Six9kKe21Chj1aivMNQHhqOxFLLP+/mi6f/qAqKeuRQOqykw1+iW69FxtqObKxToHVsSfkyxPOerkrVjBczR/zmNKD2nsZo5NNEBmNG3G4UBnjfXz0CJYowHC12/IBc6yghkCjl/SXGYD472J6yE2zcVqzhBsoAcjcjRkmRobuNdoekOrmsIinrkZJ0FFBEuCwzTCKAOh+J2jCdqGCMibNUpo9D3KCJf85axJgswp3AuDTuDXA/FU6gsot+8Tz+uJov0BD27eoe0RkuT+zKhCD8X1KRfirmGpvyoNGlLvR9jACQB5FnFQA6KUv3IVEum+/g6zFpJhGn2Ma+AIVI+NiiKkiyMDRXbvzCobSeQpX+URyrtEqVBvBZSnIImROvwLiH0LSPOQZd7tSJiOeMSTiJ9cgo7ppEfMO4ltZowppN4bGG1x8RXbXjL10bsF3AgdB0L44xnh+A9gF7jWhA8is22RwtIkqfcBJAuyjIGNwtF5QT1jITbYhTngjSB6ejmk477AE+z9h1IvooJAPtmbfZKkmd+yAVKsGvmhRKFqsaqSWsmwShIquArev0blAzI5jGpCKUrBGlPiRdHMAC1cEU5WfYKN8TeQr0QSfaWj8n2oUH8MhplDgwnWjLcPdVD6psXyydtCVcXwQe+bfNljQLiV5JIK/KNpAwDd9AveTUU3najZiRMls3y264c/Po6Zpn8sD7mwEWbIMuRty2PXT3EouQhqBdun5jNDItt3VQB0FMZBRxDlojAhtY/XKPcBTy+qGrMeXhDrq7aczOcjGnaCA7v3zcT2V4ALEDtGrA/sTaAm9+/uJopB liDLvX+t kBtiFZ3X/MNs0D1lQRn8UHGf5WQamqg1mhvwrdhDnETT0IdkyyiiXr7MtV71RbOYK9paSEKDhCZzGCIblR9pLsFCvrOQG1uDuxY63+amtsuOQneM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Give more meaningful names to hash table-related constants and variables: 1. Rename STACK_HASH_SCALE to STACK_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: 13121821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81D1EC636CD for ; Mon, 30 Jan 2023 20:51:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 080F56B0075; Mon, 30 Jan 2023 15:50:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D766B6B0081; Mon, 30 Jan 2023 15:50:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B063E6B0083; Mon, 30 Jan 2023 15:50:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 946386B0075 for ; Mon, 30 Jan 2023 15:50:56 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 577511C631E for ; Mon, 30 Jan 2023 20:50:56 +0000 (UTC) X-FDA: 80412659712.30.6C9C9DB Received: from out-30.mta0.migadu.com (out-30.mta0.migadu.com [91.218.175.30]) by imf01.hostedemail.com (Postfix) with ESMTP id 9F59440023 for ; Mon, 30 Jan 2023 20:50:54 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=tFaC4h3n; spf=pass (imf01.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.30 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111854; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=57d540mJERXvBQP3H394VQ1KkYAn0jgbzOXp+cklDfk=; b=Z4GcwZN+F9J7wtLLJNq1waiT8FwtPXulkolZaJOHs8htcAHQYlJX6fzosLvfxxhXBa86qX GSMGtaf/gbjlABGPtEGJ5ZKnDID/GJHGCg/es5tyEB2w/m/CDxtt9riVrYQskwMVtidVIR e8Thv2mS6IDUjL+1A3RQ6/R7hRsh+BM= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=tFaC4h3n; spf=pass (imf01.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.30 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111854; a=rsa-sha256; cv=none; b=cl84Xi2RfzYu3Hr9qmKLBrCtXCZ+VC027u1EeyqwxAhS8ZRZMwpH48W7mG30UtSdpfP/WJ CXSTGcJDdmBtz4LsHqGtig0XawZYnw9QJvfxzCwQNb7u+okdtPGDNGIOoX4DDfVTkppNaj 0uGUznjM5AQGYOr3LsMFZgaJ3ZCLAY8= 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-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: j7udhc1c9cbhp8co6kh3t33zjyxn3gt7 X-Rspamd-Queue-Id: 9F59440023 X-HE-Tag: 1675111854-854412 X-HE-Meta: U2FsdGVkX1+0tItH9CUlA8wjCVsSF8ecQ5n+XODYRD1S6wsS4yYWTMy4MXUsOCorVslToOJGwojpZZuv3MxochwRSzxQu92LbeBVNIg2lXtlqzu99en5vSp8vwe12IyHPT/gftwJeSuq0iH8dVudiRn+O6oHVFTQdpRxawed0IOna6DXcLdJtOE9QEZOD5NxPlAEURcNi4WNRA6rU95MXWCuNdbTi3EC3OvI0Cmt45CjBIX3DCGoE1H7EBhqJiHaNwVpNK0D1iz0ht5Flyg/OURVrAUA3fFfHRjGf569YxqbrRPBy0Cj32YYhb7nF/A+w3HH4AvEWdkuGZ6D/Co879aV6o6EAu7V0lg9WJfPnVULFW3OjJq5+/Rp2tPgkohwuD7cK8PaH1QcpBgQpJlasn8qw2SGwxS3bH0g80SUVmB1TYzt9CvTakjLUaGS/mr/tV0DTBxldG8igEdLCcsmNufyz1ngmbv7KGZ5vHWGbAbhJ+KX8EkBSqZcLwa+DuOR9xlDLyBpR3dcvgSzM+fRjAoBOWqLGlYUF8nw+ZLnFusSfUBZ/HYvbKykgSnOaWHDcaI5AlN/JCETuHviVX6VWIQNTNlF8TQAmBJ6ObGwub2S91pW9cB0tcZ6q5buZecxyq7wIaLYFoX8gm9eAREPf0WkkwRj4mJxgcg0cEPdrPMZQR3B9X9TJ+R+dstsfmU0tgWoL+MpANTAKf2JI8PkPet+LNDGsp5wqP/pnQ4+VEnXh5RtatyALmm8PiTbMeUTWQmfambUClvEt3EZ/Rvh+rMU64OsiwvHa1fdBjiM1gVVvgWfCVUR9dM9devsK9A1bPJ/e19yZsQhm3RvvhekitMW1MYPUS2J+VgvGFdoepGG965zNukS0hI48Gfdk/2wvmRMLbInemttDHRHfHiHs7wWR/m9UD7G9S1dK9gh2O0WdphhqZxzYqKjUUp+syZZCpxED8zbsALtalqejb7 UovHuBC9 Zgu2HWa+Kpxuphd93PELKMzIqhCBVMdtwx/QIeevslH+2kov1U+qnqlFoXVjF5/T61QuYijB741YzrwbLjiXvqbEpsLrIdnvueVUB/apHihtkmSnZ/6KzmtnYIgmXb6pGZNFISO1Y7njAzeKwDG/7ENsh6A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Rename init_stack_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: 13121822 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5C00C636D6 for ; Mon, 30 Jan 2023 20:51:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B05C76B0081; Mon, 30 Jan 2023 15:50:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AB4196B0082; Mon, 30 Jan 2023 15:50:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 957856B0083; Mon, 30 Jan 2023 15:50:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 752EF6B0081 for ; Mon, 30 Jan 2023 15:50:57 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5079C40191 for ; Mon, 30 Jan 2023 20:50:57 +0000 (UTC) X-FDA: 80412659754.17.A466A50 Received: from out-196.mta0.migadu.com (out-196.mta0.migadu.com [91.218.175.196]) by imf15.hostedemail.com (Postfix) with ESMTP id 10DF1A0013 for ; Mon, 30 Jan 2023 20:50:54 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=H0xZx4zS; spf=pass (imf15.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.196 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111855; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iXlgsoHOs+BLuKG+iZUfAdscpmKEgHjXPVNxwccGfOc=; b=WpCZoCJHUOvDFVaeGf1Xpym1fLd+fVfgKbRt9pILlzO0uWqr7vCrhnhPaVgSckrZH9tOSX DNRRnGAMPv+FakatyGhYwJzxuN1UGC5HFG42Wy+H3S5YiHQSRcNoq6z5xezb84OZXtWJSb Yi2e/Ldspxa/0K/Bb5TKbtYLsQ/jANs= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=H0xZx4zS; spf=pass (imf15.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.196 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111855; a=rsa-sha256; cv=none; b=X1UquFYH3FccIMQ/etZLSQIx5Jl8OrPOd2XxLLrUtQKagcOsp+8O9mLXJU3lM5mTQgIq70 qexhYHh1RcMR+d/N7jBwvsGxHmKglFobRLGB4G+BDRy+kBd2e8TYtPWdwIYC8bls7+sQbb EBJEVkpH//BEwtv+UDMI+4eoM5bhyO4= 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-Stat-Signature: xarhzej8b8tin7w94iur1o56wamfszsb X-Rspam-User: X-Rspamd-Queue-Id: 10DF1A0013 X-Rspamd-Server: rspam06 X-HE-Tag: 1675111854-26281 X-HE-Meta: U2FsdGVkX19J+7mLrDpAzU0fxHKTRh4ldOrmM1ZMfUfpwQlIUfUo6GrlewBfWuoHYa9Zwg+E0eWSScgt3DDlLb7hGZ3xeNZXnUYq5rFmVbcbKCGSt4rI0IDdzGkzR4RPNJ6jnbOMVYmA/He+qQ40AfSAXEFb0Xro13a9S6JCh0fg2q8Kq/lemU+rFtR4/k57TjDWvZ+KM1PE/dJa8lA7zRGv5yDSkgssllkFyop2wSade743TIYoRWRktO2zu4cLwzga0SFDZhL7GFvNZ5gDVbhYAKFmNyS9CLyUPFkdLmZRvZd437kZuWmqiH/f2xt8BNYcmjv3ySw3nydXIWnIP25xvQQCpadwj+4Kkq0LknbpD0V7sPWlnwIHsCwdAiQVjfggyaF3PsWKgL8w6Kiomc38GPJBkeMzOKcLk3/EfM7G7GLMTefDZFsfTpogOJTPU8DRJcLPjpqnWDGK1GpoFtq++wBQj4sWE5AGQDPBVYlQVN5PCp+Laz1PxHx9Z4hIbhDB9OEb/0o+kmKTSZP9RE5LmL1J8iI8QRW23vctC9QyfDuVjkgKZqVHjPbzQDqRHmcp4YsZEnOpcT1bvrDU/5m3pQFmVvupf780LkZeSsoc38w4qwgcpY1wLEgFwN1RJHgMWSo0vog2a8Ps0vHglIYwFm8SNmljPXk5okcY/wTvDquQ0WAII9vzqTT2HPmyywV38dNZKq9MMWMBEiZDEbiGvgkzJzdP8OAXYiaBEfqw1DL9fNQ7q/AF0fn3Kxmie7AWItFDsf0R7O7DCIDllO8l1gf/bFystRArPy5h02wgVLx6rGvOSuBWtMATbo5+VvapgRlZ1k2WcZCdw5MCvmQa2cWrNbLkfikPX+EuRh04XiVmJ/G5J+IahEwNsrU9ndGFp9CADCD9gBcsUwlSv/u2o7cCJzy0MONKzzM+q2v2AzjfZ+8IISMGBQy9BXJjlb4+yHrYlTFOcVwJrS+ 8r+1NA3c eZqcUApPt4OcpLO/l2e1WqLbTnXnWDpAg0rh7YgTU+RjMGHuev8HXurwm5YnxcOh7Yq3fIqPm3srE6AYfur8wSqUsGL59ayRahQts5ZXydP7IDhU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Give 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: 13121823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A596EC636CD for ; Mon, 30 Jan 2023 20:51:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D6CD6B0071; Mon, 30 Jan 2023 15:51:58 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 387046B007B; Mon, 30 Jan 2023 15:51:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24EDE6B007D; Mon, 30 Jan 2023 15:51:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 15E5B6B0071 for ; Mon, 30 Jan 2023 15:51:58 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E32C81C6324 for ; Mon, 30 Jan 2023 20:51:57 +0000 (UTC) X-FDA: 80412662274.15.59937B8 Received: from out-111.mta0.migadu.com (out-111.mta0.migadu.com [91.218.175.111]) by imf10.hostedemail.com (Postfix) with ESMTP id 3540EC0014 for ; Mon, 30 Jan 2023 20:51:55 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=nfu6OwnD; spf=pass (imf10.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.111 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111916; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Z64aIL/3pnEFiG6bV8LdN1R6x92gKwWr8osFMwIva5I=; b=fZ/CstHNLfAw5R7a6LY7D4l3rE+Blpf4NYxTLHNWjy4ZADAavXQHHizqyy/cAu/dd+1Pmo rb92wxIW5j4/2pKUfu2ILmbxWwnOVEWYwpzzul1uC539iG+kzujYCcpbzBzb7xnZ2eSYND zwIzNGyPWcp6dXGgu0USzMUirOwyF3U= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=nfu6OwnD; spf=pass (imf10.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.111 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111916; a=rsa-sha256; cv=none; b=1NggxT37I6XhYtKAspLJoSrjF7GNYEuIZCwZxZe9N+gRlmzz8bxN2A9YgYKFhZ8P7NxWSI CP96R1TkEwgTIkuue3p9p9LQSAgGumIZ+GQK5IRbhVhTWqpG14EN+Of4Z/FfbucZH395Xa qZo/2TuJtJPNFsOA0SlSI47SUkfxtyU= 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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 3540EC0014 X-Stat-Signature: gx7nrx7du3sgbno8pkgxc76w6piigmu6 X-Rspam-User: X-HE-Tag: 1675111915-453741 X-HE-Meta: U2FsdGVkX19S1h51eAUsMOHTWlJhmqexkIQRX3UOcIggL1YJS6Mp1yw6khWjiqug/ydVhn99bgudSlJoF85/KZpHf7KHq4cjy9BpNXG3FNZRVz8kmDD1OSLDH86kxOui+q1GpCn7CNV2mwUD9oFPajpzSm8+5PJeJTGfrueuYVm2KGUCPjcABLRsRSLE5YHf7ZIF7KdFwm1eVPdE1J1/+LIE+QbVUBLgMvMijY016Ct8y8McCnlwJnn0deObEI6e1rOQ6te2iGPJiOyE/Q6QnyZ/odyvunb4ct6Kv/CbDHv1Apo+oWMglj0TqvD8id2EMRFXbWN4pWesEjJis0RjhluUsOhmdMPgJsayMcN3X9xpixgSthKA04KwqE6ZVCUslFZnB3BGqGsD+pbdpdq0DGZgrtrL4bsZY0gwKlQrsnTZvYC4PeyaRPVlelvetqZbrj5yQQRmdRP6lD6EF2GwDGTg13g+ANjZ87VHJLXgBA2Opiek0DSp9lqkDtjjNTDxhCxHIn4JuO+WUyex+/cvwK9IM5JazWIfLBWb55rVrCjUdsmg0a5G892H/Rrp0TJkAscMVjroavBJwpaZzn8Ujc60B0dY0nwwruQK2iiYTVgVe48XnjMGqIvBtrvKIlf+Oy3Abcetp9jS69dn+nWGHzjlQTysMfzYEXIx6lv3rbteOqWc9LZ19o5qy6SbHfY5dtyEAA34lJ90Y4R+m0TcIxSPYtEck//yP/v/s675ioN88iXfBo+tjE/XoqBjP/Ox3JRbbZUsy0c5NqR9nqmK76t18uHfLySYa2TgyjUb3sjrHaseI+ZHtEL6aDse6p1ikl5Nc5iXS/u3osrm91gCJAp9zT94rABSspVrfIRn2HdxAvwpd3fszlsxu+eqMzl+FcZZVt3KXTVDWU2x68Xs6KJT0xFdllRnaP0Jk/+KyAwL4tBAvd/JIklSDUJt/5sc8lZQAy+8lwonQRrbl6E 1P6g+PT4 JgaF9L9sIoJijEiPoaoIFTieu+iYuziU+AQwbzU6yow8zwVhC44/swq2l/ojfhV9Lpjh290RwhvfQ98fFs4oZDA9ttg6HHcpaTliljtBoH00zNJQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Change the "STACK_ALLOC_" prefix to "DEPOT_" for the constants that define the number of bits in stack depot handles and the maximum number of 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: 13121825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EB3FC636D3 for ; Mon, 30 Jan 2023 20:52:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFA876B007B; Mon, 30 Jan 2023 15:51:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A907D6B0087; Mon, 30 Jan 2023 15:51:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F49B6B0085; Mon, 30 Jan 2023 15:51:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 64A686B007B for ; Mon, 30 Jan 2023 15:51:59 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 35F1BAB0AE for ; Mon, 30 Jan 2023 20:51:59 +0000 (UTC) X-FDA: 80412662358.10.BAC58E7 Received: from out-3.mta0.migadu.com (out-3.mta0.migadu.com [91.218.175.3]) by imf03.hostedemail.com (Postfix) with ESMTP id 8496320018 for ; Mon, 30 Jan 2023 20:51:56 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=eYNx9UpT; spf=pass (imf03.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.3 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111916; a=rsa-sha256; cv=none; b=K89u/yTdK30ldGepZIZDHar83Ef4sQA4l8w5D2PkgfAy8Go2A0xbxW85i3GejwSyAV8A/j BD8+rswT7g0wuyMfTsOZeFQVcjD9pXXHwxwNPPFLgqccBc+lZ3me2LIivozyUNO1LHfz99 4D4lCDtTZs3Kbf4vUI0bShGxEcckphE= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=eYNx9UpT; spf=pass (imf03.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.3 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111916; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RlJNrgwkJjY9MAGqUmKKlmI8AUnL0lcVfhP1HY83LkM=; b=f46J91CfIhynKJA3PTSPogGZCAbdaKgm64zHnTmbwQz0v+0s9a3qjxTS9eUWJRurkB7Vdn 0p6m+GUbsyYD8bOfg+1kPElLI0tFSeo9ZMAyHBcDeogpWDuE/aaAoKTj7vCpjLV0UtVemK ye1vv9ObzDs0V9yAsPQfWNAMGw5xy80= 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-Rspam-User: X-Rspamd-Queue-Id: 8496320018 X-Rspamd-Server: rspam01 X-Stat-Signature: 5tkaeqhgtgb8xshj5355fop5a5cenx5a X-HE-Tag: 1675111916-76719 X-HE-Meta: U2FsdGVkX1/6e+wEqwm3i0XL92s0mT+fbL7fpd4Lc1J+ngGVx8NbhzR+hUb+yHb9E6c8zISugbg8bG4KQUBc6itYNZ5dSSSM6PfBk5a/RY+YUS8V4Qxap3CkyuxWpw4M92P8m3JOXE9X1FyKrrepI4x35jVwJ3+3jaCjErmcKn6l1uglKa6W+68zERZnD4fbrPgMfKY5piMphuy72BQWxVWc0I61svHBKvw7pRyFdvNdsr7GQGux9Wxt0u2AgbVnBbAWzl+ctAoA99vGf7pb5qSJCB5h8EjAkXGpTFzkPgu41hmuQ/xvHuzFOqQ7ixdjV3pl6XgAWjqVhG57NGMvSX6s0C/zRLyt47ukC/tLTjtPVxuLJ0RQ3b0fw7231BdO35gJCf9g0C2yIXlnujcX6MUaewPqoNsl7twtEBwGvwe1D6rFBOjDFmuQOLWjU6Jrd1gxAeOIZ8yMmvjL880MX0XwgdhlUzdiyIEvO1gFMBWnZMX3ta3hLC8yuWr8oNGM7k2AMDYXkncmljgAy1KoGCisFVkmR6EoqdovkH7XgkxKgVFUs4J1kGnHT03LkcTc8e909PCoRbSJlM94L+jk/qDKcosfhuWkvcV6ophxc3tuqDY/Vs7dNF751ypbLkmMu7kHeGdrxBsh0Bl9U8GQqbFj3nJ6Hfd4obJ2LFUml7fwgG5OcAeMub531fe1Aa66zZY468yxNE3YqkI2APa3Gyt42AJRf836Xux3s9iBUX+SsOpZzIC/SJqovAV2SDPVTPI/D9Gb434oblsNhlnDxBIoZno0fOAZmTwO+pbkdAVxNW18g5gWr64Rkd90KFdQPsjfog3QQlgmpNAorL9G5Wv0ZBZQKQQyJFa1MWWx3Nz1cKiGiMHYz4B25JmK8Fz3bf5y+KbCcxvvVp+Q+FoPLcMnyg8YVBcpxMp/7nrQNoL5zbwCmf/twP+Cmmyk78kdXFpsCyp2dRCZe4hlxcg jVt2KaOI rgAUvVpUGVy8NHlT6soJ8xro94U3aaSpS35OVSJV7aXrGOB1hN5PF2I0a4oe1KZbwQnxIbsXrEQxZxz9mfr/gJ0e2vmHyQPNssK3xjP23RWH9UII+0dE1d9L1i/EiIVV78v4vaQTSKeOr8i/XjhIYeuk4Dw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov depot_init_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: 13121824 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26796C54EAA for ; Mon, 30 Jan 2023 20:52:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 909146B007E; Mon, 30 Jan 2023 15:51:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 841FC6B007B; Mon, 30 Jan 2023 15:51:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D0C56B007E; Mon, 30 Jan 2023 15:51:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 4E5856B007B for ; Mon, 30 Jan 2023 15:51:59 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 18C8E160BF3 for ; Mon, 30 Jan 2023 20:51:59 +0000 (UTC) X-FDA: 80412662358.09.DFCC362 Received: from out-121.mta0.migadu.com (out-121.mta0.migadu.com [91.218.175.121]) by imf13.hostedemail.com (Postfix) with ESMTP id 0FDD520015 for ; Mon, 30 Jan 2023 20:51:56 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="g5/h01z3"; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.121 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111917; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=n2WDy/mEQLvnsHLslgORbsPKJysJoBtCH/6FUJBS3Gs=; b=fHr/KW/AnN1Ss902qSMTgnrDv8BG3dpz13fOMzTYP1oGSA8C19dCKCXj21HQ46U0/SJVuB 7I5pmKEEDlMFAoi/8xnLbstok8yMs6bzs/LyafCIAD9ReRtnzWksts600cdvv5nWCn/w+N hn4f8QzDT4xYW8uHm5ZUS5BPdgGodkQ= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b="g5/h01z3"; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.121 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111917; a=rsa-sha256; cv=none; b=kCvQMjgYXl2TK7iEBxZllQzlERHNY07Hr274+ZYXlS2sXWxuYxxekrobwSi8+T+9s/W5Gr wTjZeDbPX7BBCF6wBQ4L9XuMg4ajeibQe+33Dl3RFgWSPhBT9qwF8Dy4YM0dXmP9YXJqfj 0MmJSVu94gPue7uMrAxRLBnP+K+Tpzg= 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-Stat-Signature: bpkic8xq8gxctb1pgy6ncyr88ftebfy5 X-Rspam-User: X-Rspamd-Queue-Id: 0FDD520015 X-Rspamd-Server: rspam06 X-HE-Tag: 1675111916-46548 X-HE-Meta: U2FsdGVkX18sfTf1sn/unpqKkLSBseYcB18Jd+9XHLTrbvOGWAZ1j6f72C40m29BmUGpoCsBezZzFP5E7ELmIvR6vlbt3Nl9zN8aoltbQR7EsVGSRTymB7MjOi/xh7lJ03o7jVS111i3EBcDuzYOcwto38lI3VdKQRfX7IqyFq1J0jEKM3Q+CHYfNMo1g89W6SN2ZJwFaLFYOi//nM84nMbkeV9h7nlX5i0ISt4kqU/KYc5ZO/6S3dmlbbG+7t4lUqrZovKXgz6nkG22SOv/CCQNGE1HZn+Ilvg2ZYj9PgQNkAc+wU0LmvyqWONruDCCCRMlCdXljHo2HT1FqEJJ4TLfqEj3Sb9UMTbO9rJqqTuV7vYWnEYkirhGVsi3y3fHw7OTHGO4mm3jkJ8kdxA2v9PUXwI5ezCBrIk/3oHT0PFVwva6hEvxLs4mWkPY8Qg5KRTQQIHrc0LIzYZ2g5GhCNri4v3H897UfbNyE3k+drercUADaPgm5MqRYav97txZfuowEses7q9Pt/JMODd+E800uXMEx+O9jETUL5WCMiwxOI2qsR1SA9wLzo4jdjxyTXuSF9lNNv0vT8UfLt5RlYy/kTqojx8BCNzedvsf0r2RPo5hG70zvmFf6dAocRyDL/HgbrzauU8h6I4tKAO84wnwAxggfd/I1RsbOHslVVTwiU52mUMUDQQREK3hN2ixhKwZeyJhktfRbuqicg//qoVsC4HKl831W3MhRpripJvTfpIIew0fUDrkDrE8CWzO0PGcl366R30aMykV+vcHv5v91WVqHNj/UMnOw+iJD77IxTjuf6iWsGA+6VUrJtVHi9P5F2GDbs406H+U/2RGDrSQ+0SzsyPklYYbbhYJtu8RvMXRNt8m49kEAsAXxFdEYwRjwHZ74AxFxq3o/uzPII4Dow8Rn162mKV2JP70wzQmlDLTZjFG8hJGhxju9X8R5Se3N+JnfQw4RwmCeSu MdLvzYB1 d3WWPmjcmRc7F6HN21Nt9Rt4vpPXrsAsdHmpnEQr/hu3nZS8zROY6hNC1dZcKVh17nJS7AjubgviPI/JLChwKvmuEfiZWuFR2o9A3zVwpOOSkZE74OJa7H6y04oKceF93WDZWkBj15rmYnVxN7AS+FJQyeA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Clean up the exisiting comments and add new ones to depot_init_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: 13121826 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3EF72C636CD for ; Mon, 30 Jan 2023 20:52:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E25266B007D; Mon, 30 Jan 2023 15:51:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D72236B0080; Mon, 30 Jan 2023 15:51:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEC4A6B0085; Mon, 30 Jan 2023 15:51:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8C9586B007D for ; Mon, 30 Jan 2023 15:51:59 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 629B5AAF94 for ; Mon, 30 Jan 2023 20:51:59 +0000 (UTC) X-FDA: 80412662358.10.1EAF362 Received: from out-187.mta0.migadu.com (out-187.mta0.migadu.com [91.218.175.187]) by imf12.hostedemail.com (Postfix) with ESMTP id 8EBE240023 for ; Mon, 30 Jan 2023 20:51:57 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=TCrjIwKJ; spf=pass (imf12.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.187 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111917; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GaiPOQJQg/3eaR9Q8OYjD4xHiibeiKzRxzXBSSG583E=; b=kxUlw0ODE+d0AzNiXDRsWBboiOr7FFQwTOwsDzIJvOHITMq7zZIsp46yW/+EpL7GYF9jPC /kf4lst/nZjJbZM+vffDWuXtNlYs6ujgF5Uha/wkRX9Z0UUl/LbqPccgKuUKDGbmb/LUQ8 dWw/zV/0/7zfuzZds/CuZwId5gMVZ1I= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=TCrjIwKJ; spf=pass (imf12.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.187 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111917; a=rsa-sha256; cv=none; b=otu7ZnoxuKuoo36fteDFfW9nVs4RzGkSfIOmU+QQipwJGRWcFaqaQ0tRNVBSoUPcS59Jf3 WjMNKpcKyCtDM3TzdMwivwJIN3FQDKvy681YgraZS1NP6lLvwhatrySwQYYwqz0Ohae8g+ fhe7lvHVHtyYgEXtoELc6pMoeMGlNhs= 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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 8EBE240023 X-Stat-Signature: 6c8guxfwj4cxu6a5oqpgtj7u65bm5bz1 X-Rspam-User: X-HE-Tag: 1675111917-821325 X-HE-Meta: U2FsdGVkX189FPMG8AqF74KJKw0zfCQwBdcDidljYvqRqVYrcUTtXoJgHUnWehRca5MGBd0N7VsP2+/YOy2L9hOdGGrcREl/RP/0c35KjzdwUBk4ljEk9f1iU6uSPaADH4V066OmoTOfwPyApixomHtShlYYXDYGJL8vmCTgXfhpFoo8Kd/uxTOIv0a+MSrihRn5/TCowL7bodOzzrsJu9BGhd4i/sCh9iI574Oog6RMkJ3e2BHbA+xQ8ndBOIuqxheeRA819QCgKi13NqhMmxBNIgQt+JK/64pOIMovO5cMQFJSBhIwKSXd3jhSi3yIj8XqWxiihEmhm7ImW/oOEiGi37p3xKd4zbAV/x9syrr2srH91TPtKszp2Nv/Dr0te5fR8dXRycCNJUNbJE2yGvZ3A7l2/NYft31FLfVWTQfaQ13dm37C4sz4Dvo+F4zLHb/iIECVDhCs7STkj1C0KBisEXnKDoWgNZcqeb+sNVXMYeABTPNozO7c2DaaHEVCOTOKIKeJQy1mz0Ho2oDXO4Jld7BEEBYIJ24liHGNQcui2pxkwb1U6oACkEA5gNgcnFAw4ecKsTfyHQrgznZy6rm7U2YPGG3olC/zoYD21h937jF43ZnEnhkw8WSrPFHeLVfqngWeMt/qafQL8CqURx/0uVmPYwsnvz0mweFWxvt27U8h5YFkactzeLzX/wdqtCp1MXcMjA1nvIigtqwkGmhoyrS569l4nlgPKhzLY/TRwB3294SZ5MNAYPff0hEPAe8u4k0CJFsJZ59AUrW3xAt6N8r94ChTt3dupO8/kLTHM1+3Z+SD0fBbex+PKz6LJB8K/rWNxFPf8+fG7I7RsihYPkuXoUvRUF4/VdBbYtzrd8UdJ03E6paJgxoRQ3KNJM8tQEIccDrerp7t2TBa2ZfHu2HEfMUgGo+A3I3zuu+UbJwQwg6UYBUsyrMZnnv0k/9CYi5s4coDZqzMwua k5L4pAjd tBc0dH2inVQFYWrmizyDqJDhzjsHwnAgjgJpeAwzjXIvHchjKhJ6J1OtQinDOdPi8dGIHEVLApTtb9r9v6auY31pmxE36wdQvpaQPDZ9C/Kdu/h6FXb8KrpykE+NzjpVxwYgjj8eyRbSi2NSmiy+RVkmA/Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov The current implementation of the extra_bits interface is confusing: passing extra_bits to __stack_depot_save makes it seem that the extra bits are somehow stored in stack depot. In reality, they are only embedded into a stack depot handle and are not used within stack depot. Drop the extra_bits argument from __stack_depot_save and instead provide a new stack_depot_set_extra_bits function (similar to the exsiting stack_depot_get_extra_bits) that saves extra bits into a stack depot handle. Update the callers of __stack_depot_save to use the new interace. This change also fixes a minor issue in the old code: __stack_depot_save does not return NULL if saving stack trace fails and extra_bits is used. Signed-off-by: Andrey Konovalov --- 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: 13121827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63ACFC54EAA for ; Mon, 30 Jan 2023 20:52:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 847B56B0080; Mon, 30 Jan 2023 15:52:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 70B786B0085; Mon, 30 Jan 2023 15:52:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 474F16B0087; Mon, 30 Jan 2023 15:52:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 30C3F6B0080 for ; Mon, 30 Jan 2023 15:52:01 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E9B59C03C9 for ; Mon, 30 Jan 2023 20:51:59 +0000 (UTC) X-FDA: 80412662358.29.74F6374 Received: from out-14.mta0.migadu.com (out-14.mta0.migadu.com [91.218.175.14]) by imf24.hostedemail.com (Postfix) with ESMTP id 2E15F180002 for ; Mon, 30 Jan 2023 20:51:57 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=wXtDfrkY; spf=pass (imf24.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.14 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111918; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=HatpIAXF9ywMATjIlRO5zkwkJoWVcZESn/qWFP01cUE=; b=czzdGzdZBnICvRqiavSp1vhttbl4lcauZzthOQgeZZWuv84mUGeJV09vCHQvCtXqTs06M5 v9f1UEGJWJXEXD6tqksffq4vuNEzDdrCJNpf7RkIxGGhhBZBZqVEGD8eO3VrXa4+dWO9+Y gkSaTDY0LeHGIeaPDwqsKFL1eW1Kjjs= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=wXtDfrkY; spf=pass (imf24.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.14 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111918; a=rsa-sha256; cv=none; b=DVAjSRdiTkr9kNPjv6xaSv7As/NRXjqakS6P0QBC6c7xef8bP1HzZG95Q+/cq7YrnQc05+ 7iTygQ8IqY0OSyHil7o7B8k3SZLjwifjqbVRMDQ0dNLy6k6bbUAziCDSf5OEYIkSlSuylr msBKXZzLW48bmZNGWMXBNrWDTO58P6Y= 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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 2E15F180002 X-Stat-Signature: npe6b3bpgrpkpku1yn7eb43o5babqd1p X-Rspam-User: X-HE-Tag: 1675111917-451044 X-HE-Meta: U2FsdGVkX1+v0qAcZlGonVIn1sPsqrdSU65ffC/bS0LmJc4RruTnTJhbw5C2ynlrNMKaIU7/GpMyKUbGwVKSwwoMdgdU+FmYFp2jzVE8byVhM7t/V55/M7NhPsi1RQHD/zrKVo3eIbzS3jRvmQFNesQ/0BKmzvH4yiDzmYt+tD6nVYAs/YgBekdrgfmR+hUrVjisqi+63zbafclFRPUP+hb8epe43a9WT+yHZnM1WVIuLaQpn3B9YubNeEFxbvYvmIUkpyFTuzfWmDlq8V+iOB9xJiO+A3fB7cnTsrZbRLwK15GONW1CsKTyOnVykVav9LQu0jCsDx1OCSEY7088zVWEUHkHmxvDUYR2zk51HgLK6dROb2ZKyniFJh9TVwoRPRtwl33pMn+ExIvF9lsRzlZnLJsgUvegK6wZWjUzu0V3yiJT4T7eSFWjeC/fHQeSRqwFeJ+QUtBuhq29WdGRBu5K6xEb4uODFR1Tk6EPrecHg3uEuZqQ00sCKSlilUtwosPyEzBstK600Y/Y0fMfb5s2yTi13pIpeu42AJLjFjP4bHUvaLhBFkApP+ygZN2+9PJqs+rV5Ivv3sIRsX4B073B87ltqgspimKXnKyprM70cKHGFOSKNejDDds8Ed6TIJL5VbbCnLM3c+8wOvDnSdjHwDTtiwn0SlzOvGjLDQxz6pjpwXOVt2dA6kHtQzQw65fnCn30Bdw6KGdCjosHrdONVjRBRrFxTRAEVCrfEkgmgTzj+9WNQ84uOJkdtgprnceZ7zN4licR6ufXYo00hQMdedhdMUCOP62ynwNjG7NM6659Z17tV2ddANVKugAp+Mc2Cm7mxozJRj3Yui1X6R12L7KUC/tqoUR2++9zNvYhCKWMl0u2D8T8ipFPQtvtpUNBLXLHGQxEeFCVGifPlWIq2glEkNjv1TvWh609tRbq8q5Cf3WlTD/sjYEFlBdufENG/QOPqsqb8pdVAaK lJSZ45gA v4Arzl5wa0x9f3a3nM5/ptFqsDpMMmCtU+oF7jklPA7ynpnTB72EdI/AIX7767XoVOJkUQuaeNmJiMNMzlq1+4uF53VVkgFhVMsi8+L/SsH4Sp4BbbMCgQSyYYKETKwMGjdktx9WkGiTgRqpxYj31pPLvUQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Accesses to 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: 13121828 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A121DC636D3 for ; Mon, 30 Jan 2023 20:52:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F3846B0085; Mon, 30 Jan 2023 15:52:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 956EB6B0087; Mon, 30 Jan 2023 15:52:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75A856B0088; Mon, 30 Jan 2023 15:52:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 54BA36B0085 for ; Mon, 30 Jan 2023 15:52:02 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1FA0414039E for ; Mon, 30 Jan 2023 20:52:02 +0000 (UTC) X-FDA: 80412662484.10.A013703 Received: from out-167.mta0.migadu.com (out-167.mta0.migadu.com [91.218.175.167]) by imf13.hostedemail.com (Postfix) with ESMTP id B858920011 for ; Mon, 30 Jan 2023 20:51:58 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=N0ZO7gPg; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.167 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111919; a=rsa-sha256; cv=none; b=K19Tm3eoXAnwy2/Jwbk+UqeCXEdy5f2yCeuw1e+SCvw7OhLfa7J329FNW062Kv1BMhJRFK PYHpIAnfw9QIWVp7FlkKqTRLTJ4irCTp9OK6P+15nnxWWQECTvxHKT63nbiK49ypeYYMRv tK79c3tEexU7NDrMcTSbiNf6obYi+3U= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=N0ZO7gPg; spf=pass (imf13.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.167 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111919; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=f1IK6xrmRNNY97ld0D9rdSaArRx+XdmL+DdOqeJXePk=; b=Xd4L8HP1UBQIPgyCGm+X6+HflZJTwUTjMXxf7Lyz5wtEMImM3WAZTgLxptPWW6kurofHiZ 16571s0qSk6zZZUaQrRuJ6RmvPVZOYQwkKGKVh7DaLdcslCzTc8VUYX/TGiHzjjHapwPpM t3DvAsS6dm7AiIx2yriJ5sW6yWXKQ9s= 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-Rspam-User: X-Rspamd-Queue-Id: B858920011 X-Rspamd-Server: rspam01 X-Stat-Signature: 5dh6twzno481umt6sjuh391ks7ang9hy X-HE-Tag: 1675111918-536881 X-HE-Meta: U2FsdGVkX1+eHKfuDyXDevtvaQw0exRqmb5yoD3kN248gGNfyQaQnvaNPjjh8iVy3eKnfSRCFnFzG593SfcSuHGrr/N9z4zc/s6u2raiBYhmtY0bu12FBRDDhGDMgaA7/F72Vri1IHwuwmkzdujNFMy7+BZA244HgxlK3sUTs9rvfW19h+JmS01QUXj8JItzeU26fsILRyo0uckO/8ctMfMpoEqy1Lig5j0OrbuNpKTluWatR88gy3+7aC5hX2HzoMb8SaXlki8tXefw+PrnJvD1A3Zh5z9ho+6ZToaiuSbMEbELZrkBeYi+2gmyN6fHEopWcqGUl1Y4UTqxJ+XORY+di0hdRCb3m/o2iW6NHC/iePp+XMi9IhhcxQlHa73SBc/l45WDvFpI3j3UZR6hXOwkK2kmpkv6v96aD+SphQuJyPFtmsq+4DjDpj6eVotMjTEAcULZhiZJN+7DGbreLGRHP93i9T8FXxuxqiFBgaehC2SyBpE5FKXAzgG7Q9lbCQBWpXgHYcKJiZIlNj5YFpvikgipbpLkpcKpau8Ep6E3RvrhxKepA+OEgBjvzGMh/Kz7MQfodCBHzqyU8KE2XQr7K5V+RarctsL8fPPd9zYRlE23FufNqBi9aZSOyM7yN+NnuXpoRtiAyYYNO48x6i3eOMT36BSteULQdks18je4Ey31VdPkGfdvdne0m8choasZv/0KGpWK7EB915ziZJyzoMz+dTU/t5LCtpH4WVq1xTMW7RDzbYL4cBx6B4mWjYUHMve0ST8u6pmVk+7dvkyvSe6YBc2DE8kkfC+tDrKNYXGwOQSal53CuPbGEYX/kSfwkhkTC7rCLBdRuMQ9JWx2PauWsPC1+u8t376v4zNNHWw89lt569zYWsklJbRJLa1chLNO7Ivb6hZCiTaBmKDKedwkWT009ao1sR49kb8zQOVjyw2TTSinNDpjaGsQXIi9Qya/NQHQYUXEfHC /c7BVAbs JWIM48kRGXwllQ0wg/jwxgR2Y3i4ytzT8HSuLlsfSeXzglpfBB1RmR/aGM8N0lqsiWbOYeBQ3KFycjvSKS1pf6clksmFX1hS5H+jjmtYreT0+BwA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Clean up comments in include/linux/stackdepot.h and lib/stackdepot.c: 1. Rework the initialization comment in stackdepot.h. 2. Rework the header comment in stackdepot.c. 3. Various clean-ups for other comments. Also adjust whitespaces for find_stack and depot_alloc_stack call sites. No functional changes. Signed-off-by: Andrey Konovalov --- 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: 13121829 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8741C636CD for ; Mon, 30 Jan 2023 20:53:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2C4F46B0071; Mon, 30 Jan 2023 15:53:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 274DD6B007D; Mon, 30 Jan 2023 15:53:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13D156B007E; Mon, 30 Jan 2023 15:53:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 04F956B0071 for ; Mon, 30 Jan 2023 15:53:02 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id DF3F3C0AE9 for ; Mon, 30 Jan 2023 20:53:01 +0000 (UTC) X-FDA: 80412664962.16.3A17E2F Received: from out-229.mta0.migadu.com (out-229.mta0.migadu.com [91.218.175.229]) by imf30.hostedemail.com (Postfix) with ESMTP id 98B268000C for ; Mon, 30 Jan 2023 20:52:59 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=g+SFAUpU; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf30.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.229 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675111980; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1w0jiNXlV5BHI7ghVa1ATPJTlO9YwfzPGkwsURa7liM=; b=3JYqxNgLN/BvOy8eOPHxJhQtXB5/9v7J/iPQ+80LQIpu+cvx5Ybk7OMLX1QNx4h8EfTonP ofbd3kQ67eVhdqWNfsE+bLwCj+q1KxEEaJ3vLATF0QgVLeDCTyQrkVY8uuE5vtjYHQ6pHT wi/aQTUXeA0Aqx1rsCPvpDZ0y7JkQ4U= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=g+SFAUpU; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf30.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.229 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675111980; a=rsa-sha256; cv=none; b=TzbTcLNR1z8RrLeAE+1/oy2/tRkqnEa+6buaccWXJV6p/Gll36UklR3cOOwZVMNgKVSaYn 06pgL4ZGTP/jmhzxWuEHF/FheSHno6zGPXyXmYxEKfsBLKit1DdgIUyTRQ9I6XZI7grR6L bqSFCYinmiLyLs+l0HZUesPigtDzU98= 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-Rspamd-Queue-Id: 98B268000C X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: xi6yk9bhrq5bgyazrz65bc66i6yxhosb X-HE-Tag: 1675111979-609083 X-HE-Meta: U2FsdGVkX1/Qn9IvJwavX/8kZhWjvLXzgxyrlx1NTb++XT5Yean7UbBQmEo4rOKAFhsf6mhAESeEd4E8qGpnFqtZQwdOK5jmbdBr+CRakj9GluecM+wCb0lFYpeG8BKyWbMS07iD+8PsfOMdZnlkjK69Y2swLLBwKpEDe8tFJOh9TVa8deD1fR3DzNojR1a96A4Wy0O5GkRIx/i4TSEWawK3KY/klzSs0Aep4xcwmlNk2YsYXlFxgUc5Q0MnJ/ewxE5Rm5lUH1jFu9+66RNSgU5tPCRAmMh8zIDMrrRGodL9mdFVRFmEgMlndDSJAr0JbpSFd46V3EOV+dQFn7oyqxdMz/sD4PUv5cE6Ap/H96DRcz7ocjGgxG26T1fstRmVA4kpqAifBuiwWDHeN8w1/X80zGEFnURjE9FFX0WCCXtKz2QSUUBhXP7BqYktxGFlodZk7UhybXOdUCcX4ABGi2HpS3YPrJj+RhyL/mO8lY+mpCBWDzE9cTKMTxSlxx5Cx72gFYgegg+Cd3TAKlAWfkMWa+oEr92soW4FangzxditeQxbxSs7k9mQIVQmKvaTTJLLrWlGUqLILCtKnXronf+M8w5i8S93sBYAx5YcL/vHkO1cKMhCR9VDnuK0yCnAVmwNKRAnvvyzHXiswXT5tzFY6yvjJQzmelgWQKQdXT9rEFENcmZrjC1jf2XE7XO6dcS16ECIyqVS/S9M3F/euCtVX++IMmzOsA007xg8sMYC3uCYZJnWgrpYtgAoeshwiBAK86NgxXoHGASnFrNSX9z6gSZrIJNt9DQGZrss5mWxbdhx+c8R8f6LI/MA5RUVvcno2dcOsJvwc0EW/e7zL/4eF5mY+KzNFob5dvnf3PcUg70xcC77ry+HcsEeIh3hmZznP9BAUoboWiBcupzlAH8M4XlS9kCrH9l74K9kURl0qGuLlVHx5RBnNVOYbIHR0dozC9NwCzZWfxstiSG g91OJXtO KVevD5ww6X6MqdPLpN34lkkoCS/BYj4LzcCxSCicTuQipBVuO1iaZ8TGXSYifprNUyuyakkNRqw2xdXK1TS2qyWvyJPo7aWQeldgjnwhoW4zs7jE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Andrey Konovalov Move all interface- and usage-related documentation comments to include/linux/stackdepot.h. It makes sense to have them in the header where they are available to the interface users. Signed-off-by: Andrey Konovalov --- 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 };