From patchwork Wed Sep 13 17:14: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: 139297 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp92752vqi; Wed, 13 Sep 2023 20:56:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEg10rhrDEgnLjCzOoraBfUCT+oaIjCbzRl9eLAIJ1la+NaV0k5X2W6RAkOU9BZDF+sX2p2 X-Received: by 2002:a67:fe13:0:b0:44d:4aa1:9d3f with SMTP id l19-20020a67fe13000000b0044d4aa19d3fmr4520259vsr.4.1694663803099; Wed, 13 Sep 2023 20:56:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694663803; cv=none; d=google.com; s=arc-20160816; b=fGqcOivnMMqYFW19pM5WeQ0OL39VWE1twlRRQvU4sb0Q/bldZcYzeQ32/rNwsrrOfj msp1jBSUW8iHy6n/vPTjcxVDzdMfb/xpV77KfOeRoAY0vRzg2SPui3Mh+T4rJGza8J90 4vTM+0VD8UJBb/YnNIJVl8+mbhgoV3rnQuaro/41duAkuP8mskuRSju6kiWCFJm03D6w /tbxU2B0v7nOYxwW+B05YjZhKVoBR3gAEyb9ROGIVBhKXFaXvDD2roxlsLVzwyrvGjDv Lg0vjEbyGKSG/GORfgIKlU/EnHSFPgyi4tRCwBl/wYIYgSaEKXawIayt83PvdDB5RfhN CC5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gml8DcgHPrqnYJfUQnrXQLUWDOAsSsS+HJ/vnfgqmKg=; fh=nfQSbTp1dWHt2Ier1Up8UhVNdXOqoJJLNvTrpT3jJEk=; b=XnzTm3Eq60zMQDr/rd0wIJ+kmLBBmZLVdaGfzvR05j6MoDytLzue93CUOsIO+Qy93B 7ElTSV+YbaUe0rGwmyo2yDG+FxFGGCkbA7YQvYLctTJyVCqNFFMUu3Cl2qprq1OBPiLs hAYbEvkphQjhULN/uFnkVLk8Syr87VcAIJHKq6pdTn/gVi4cmII1yPl4rSjgWDkEUBeB bNteOrJZJgcJwGwp5nmGpa/QH7JGPRaHDAcaeE+PVtzP4dQMqm4WCRFo6JXnY73zs5r7 vDYio7V6nCNVz2E+jqGH9ajJQrlZhFQgmHFTPGAxwWWJrjmOl+8WCBAdnYEK/ojc/jXl 3pOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=S9us7jlk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id s18-20020a639252000000b005776a454f49si622790pgn.460.2023.09.13.20.56.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 20:56:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=S9us7jlk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 676068225CB5; Wed, 13 Sep 2023 10:15:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230410AbjIMRPJ (ORCPT + 34 others); Wed, 13 Sep 2023 13:15:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230327AbjIMRO5 (ORCPT ); Wed, 13 Sep 2023 13:14:57 -0400 Received: from out-228.mta0.migadu.com (out-228.mta0.migadu.com [91.218.175.228]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05173DC for ; Wed, 13 Sep 2023 10:14:52 -0700 (PDT) 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=1694625291; 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=gml8DcgHPrqnYJfUQnrXQLUWDOAsSsS+HJ/vnfgqmKg=; b=S9us7jlkKOCVp2Io5I0Tx7rlmHRdUo7dp4fSfiusTxeMqFjArjUdWXOxPxa7TRsS+UTSGt szqyWIxKS4Bt5+b4uJDHImZmEPS4RWHjhTLuJQarfEMznDy8FYztx69TSQNHWeON9BhC+T q2mjKPkhq8D4BrojemcgDiouTfk4yj8= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Oscar Salvador , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 05/19] lib/stackdepot: use fixed-sized slots for stack records Date: Wed, 13 Sep 2023 19:14:30 +0200 Message-Id: <658f5f34d4f94721844ad8ba41452d54b4f8ace5.1694625260.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 13 Sep 2023 10:15:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776983792239275585 X-GMAIL-MSGID: 1776983792239275585 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 --- Changes v1->v2: - Add and use STACKDEPOT_MAX_FRAMES Kconfig option. --- lib/Kconfig | 10 ++++++++-- lib/stackdepot.c | 13 +++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/Kconfig b/lib/Kconfig index c686f4adc124..7c32f424a6f3 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -708,13 +708,19 @@ config ARCH_STACKWALK bool config STACKDEPOT - bool + bool "Stack depot: stack trace storage that avoids duplication" select STACKTRACE config STACKDEPOT_ALWAYS_INIT - bool + bool "Always initialize stack depot during early boot" select STACKDEPOT +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 depends on STACKTRACE_SUPPORT diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 9a004f15f59d..128ece21afe9 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; @@ -258,9 +261,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)) { @@ -295,6 +296,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;