From patchwork Mon Nov 20 17:47:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13461820 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 985BAC2BB3F for ; Mon, 20 Nov 2023 17:48:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 316446B034D; Mon, 20 Nov 2023 12:48:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 29EF86B034B; Mon, 20 Nov 2023 12:48:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 140D06B034F; Mon, 20 Nov 2023 12:48:37 -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 E941D6B034B for ; Mon, 20 Nov 2023 12:48:36 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id ADAB5C08DE for ; Mon, 20 Nov 2023 17:48:36 +0000 (UTC) X-FDA: 81479067432.25.2A1F014 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) by imf11.hostedemail.com (Postfix) with ESMTP id E3F2540007 for ; Mon, 20 Nov 2023 17:48:34 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=v29OoaCr; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf11.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.180 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=1700502515; 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=pu1XFZGC+3mxYm/tNoBY6t9qKRkAeXfQVUMTHQNQJK8=; b=REHwa+2WNLymfnv+JB0aUl7pYSuwMtrDRAsPBLyKc3LOuukXoaZDvh2osfTzCRa5lI3sxw bkHJhU+4PWNecAr5z4UxT18gzr8AM3LCXJemIqVBxAtYmYAfnS/nqj44ZdVXsGcAV47YoB y5yEeLJobl8rWjuo+L33mu6gacQkCMs= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=v29OoaCr; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf11.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.180 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700502515; a=rsa-sha256; cv=none; b=tOIsibUgWeAgxKL4h9GbzrWuUTQyBF6RwYK2f9RoS19ksiVzSF3Hyb3BeS1oKbPTrPWIE4 qu6M0ox79YSGL9Ky6+5RoVDC+SUuwE5vDX9Y3LOukoEBJk7w2Zx/f14ODzisTFV5bH7Qbm +y5d4MmbWK77QAp6qIMKmDmLmrTYpco= 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=1700502512; 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=pu1XFZGC+3mxYm/tNoBY6t9qKRkAeXfQVUMTHQNQJK8=; b=v29OoaCrQAFVYXx8qE1accX78dCRXzOu4rgaHGTPoImCDsSRXsXJW7zty4lVMppXjkqcg3 cICBXUXycfKNBxolMNR9vSSUR3Qdi4ReyKaR9Gp00MSY7TEAkMubulEyKPVq2YOWSy/vMK Csf5CwyODxYj8dOCpaCpXMz38YUJonc= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Oscar Salvador , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v4 06/22] lib/stackdepot: use fixed-sized slots for stack records Date: Mon, 20 Nov 2023 18:47:04 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Stat-Signature: nr9oda4ksmm87o3wz8njot6acit3zda9 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E3F2540007 X-HE-Tag: 1700502514-775065 X-HE-Meta: U2FsdGVkX18EzvQc/qmWhfM9YdRfiL6x80H/FwkQ6i/kduEjDOWYkcnfLxQwJA7xlF9v607VI25KSxhkTz+mhaIBiZ8eW6+sarwODf8SSBpoaPjh6FwE86yq7iZxmCxkxQzKILHZJ+Nbt8tQ9KVnJQu/Z20ixdGmxyAN5WE6KJlULE1EtbxKn0pYJGTrwabP02CiIrYDcbgDjnukSwfCgKuTRqRXRH1eWGLyNLCTVKg1+kHmKwwHlv2pci3Fqw/UkKuLgwUyhpzQNUduOBFYVsb5nSofNo9/JnaV4yvDxF2umCrf6DfPK1WGzHbCYqhUJJOPpQZpr0PSawlvI4qk0IXTH/4UCfXMbnPxLDbfjAQXfoML9QEWKZiAzV7nAn0arKtqy1XgI3jfMjC2EwschRk2EmVLuTRKmgAZ0IWP+icQaX/v3OTT6jHbbY82qC3SQ3TjuxAtKVlTle7Ct5X1kz3LooEqCUunN5VONvn7tedPM4Fs7CJIg5rEipC76PIIGAvOBVhQpvUwu3wn1i5W4tl3FFmDY9A9QvDUFfcP4TOHCHmxybOH3G5EB26KtXrD/FIZFnzIGWb5wXPd5n3S27ES2aPbn+NgsFVcwlEHcT/v7YGtG2uoEWlN2l0BMrlGxJFH/1VvC9uaAdEFg/OLPLg4ApU2BmR5f5Z2VatceQxiW1ICsl/jwcpSGmRvUxXoQ2lrg6dDrgVLTnBStVzFI0GqoWyn94nhk2iiRGoW8q+4SKu4hxHZsmn0cu5S0GWrd0xuN1fr58MUKCi2bdDb4VxECw+RQFe1ircMXV4n696kCBIaKU7bK4iCD7rdtgYzmJkS76eRwFbC9VpiCPFdPH3+lyQklM1qXru2+LvSZp9p76hEMrjgFOj6Eo4TFLUbgFgbo5IHbU62KAVGaxxyxHFAnZocAj4piwoVL9i3fhOQa20bdO9gFeqzdksOHfWQ8KLejlOf+qzzhM18DuQ DvR+85nv 4Wa74DM/rWprAd01fHqOAMlrcGLMFGAUVi3/mMLhxZvr495vEF5a0DV0rjyJvYl81kqg4 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: List-Subscribe: List-Unsubscribe: From: Andrey Konovalov Instead of storing stack records in stack depot pools one right after another, use fixed-sized slots. Add a new Kconfig option STACKDEPOT_MAX_FRAMES that allows to select the size of the slot in frames. Use 64 as the default value, which is the maximum stack trace size both KASAN and KMSAN use right now. Also add descriptions for other stack depot Kconfig options. This is preparatory patch for implementing the eviction of stack records from the stack depot. Signed-off-by: Andrey Konovalov Reviewed-by: Oscar Salvador --- Changes v2->v3: - Keep previously existing Kconfig options not configurable by users. Changes v1->v2: - Add and use STACKDEPOT_MAX_FRAMES Kconfig option. --- lib/Kconfig | 10 ++++++++++ lib/stackdepot.c | 13 +++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/Kconfig b/lib/Kconfig index 3ea1c830efab..5ddda7c2ed9b 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -713,10 +713,20 @@ config ARCH_STACKWALK config STACKDEPOT bool select STACKTRACE + help + Stack depot: stack trace storage that avoids duplication config STACKDEPOT_ALWAYS_INIT bool select STACKDEPOT + help + Always initialize stack depot during early boot + +config STACKDEPOT_MAX_FRAMES + int "Maximum number of frames in trace saved in stack depot" + range 1 256 + default 64 + depends on STACKDEPOT config REF_TRACKER bool diff --git a/lib/stackdepot.c b/lib/stackdepot.c index e41713983cac..682497dbe081 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -58,9 +58,12 @@ struct stack_record { u32 hash; /* Hash in the hash table */ u32 size; /* Number of stored frames */ union handle_parts handle; - unsigned long entries[]; /* Variable-sized array of frames */ + unsigned long entries[CONFIG_STACKDEPOT_MAX_FRAMES]; /* Frames */ }; +#define DEPOT_STACK_RECORD_SIZE \ + ALIGN(sizeof(struct stack_record), 1 << DEPOT_STACK_ALIGN) + 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; @@ -264,9 +267,7 @@ 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 << DEPOT_STACK_ALIGN); + size_t required_size = DEPOT_STACK_RECORD_SIZE; /* Check if there is not enough space in the current pool. */ if (unlikely(pool_offset + required_size > DEPOT_POOL_SIZE)) { @@ -301,6 +302,10 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc) if (stack_pools[pool_index] == NULL) return NULL; + /* Limit number of saved frames to CONFIG_STACKDEPOT_MAX_FRAMES. */ + if (size > CONFIG_STACKDEPOT_MAX_FRAMES) + size = CONFIG_STACKDEPOT_MAX_FRAMES; + /* Save the stack trace. */ stack = stack_pools[pool_index] + pool_offset; stack->hash = hash;