From patchwork Tue Sep 21 10:10:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12507481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 463F5C433EF for ; Tue, 21 Sep 2021 10:10:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D75E361184 for ; Tue, 21 Sep 2021 10:10:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D75E361184 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 11E0E6B0071; Tue, 21 Sep 2021 06:10:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A6036B0072; Tue, 21 Sep 2021 06:10:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6029900002; Tue, 21 Sep 2021 06:10:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0086.hostedemail.com [216.40.44.86]) by kanga.kvack.org (Postfix) with ESMTP id CE9E36B0071 for ; Tue, 21 Sep 2021 06:10:22 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 70E1F181AF5C1 for ; Tue, 21 Sep 2021 10:10:22 +0000 (UTC) X-FDA: 78611160684.18.8F2043E Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf28.hostedemail.com (Postfix) with ESMTP id 28A2E90000A4 for ; Tue, 21 Sep 2021 10:10:22 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id v14-20020a05620a0f0e00b0043355ed67d1so29681106qkl.7 for ; Tue, 21 Sep 2021 03:10:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=5N9Nfc2PvxnVX00ioD06NDULEqZan2ouEAVATALDM/U=; b=re1MeyZD4441wN+l0v9OO/U4fqURpUvI2RpDEHeFN3hdbo/USuNsEaCZ0cLijsB8U5 COFjC4fXuvReQMBjNdF2tW+Ruw7giKzv05JpGkMObQY/3aFvxjzLh1ATERUSlzZC4mdG 9/457Fs+MssoO6tUNOrwJVHTiiHsfIOfdI1Yc3yOW/2D/yBxOtC5zN210YghPexjGRA8 Et/pA5inMv0QoXyoDfVohlgF+x9yfHuJh/9AjdjlYPeeHR6ce4nvakK2m12XxtsFgJRM jpNNPjZn3ZWw0x1BhcL3o/71jlesZOCRKzC2maIrS7BlucGmLlSQqjz4qp8JJq4AIGRU VGEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=5N9Nfc2PvxnVX00ioD06NDULEqZan2ouEAVATALDM/U=; b=5BjsOVdz9O51deyz0HJ+C7EgZ6bdKGfnheZwgsvQy9iJCrM/Ln1Dsr1wdkPzVxVewk sBdaS5sUq5HEoQRaqgXdK+qT8h/TsaflplGv4MFMZojSM/aEgqUTXp7tFIK00z1H8wOY 7aiRru3SDnIllwBLmbkAU4y5Ogy8OLINTcptitDNzOsQ6p4vfkJ5HbDp3GbUUIQDIWbB kO2n0Gw+joQqU+i5w01PzPQ4Ep0+XerhxNaFdkNc31fxPxMFEd9NDlHcBvNm+krSEIZl 6Hst8lrf8XmIJtsuKHHmdd7HNIaMM2azzxUvJuvKx/0a2qT77uqQgIthoyf77NKDAJ/p 5MOw== X-Gm-Message-State: AOAM533Iz5w1uq+r0RrqrT03tssDrVj4zypsTN3oxJdD0b3904uVaH9S 5/HXib0l7hEUQWDhb3d/49f2D7eq1w== X-Google-Smtp-Source: ABdhPJw9K0h/Lxwq8gDPZCrvBxtJlDkV0TFyKit97kyILId+bErwqAKAwWm+rn+bPumqtf/fbZqQIAPJtQ== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:dd03:c280:4625:60db]) (user=elver job=sendgmr) by 2002:a05:6214:490:: with SMTP id ay16mr30085392qvb.25.1632219021369; Tue, 21 Sep 2021 03:10:21 -0700 (PDT) Date: Tue, 21 Sep 2021 12:10:10 +0200 Message-Id: <20210921101014.1938382-1-elver@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog Subject: [PATCH v2 1/5] stacktrace: move filter_irq_stacks() to kernel/stacktrace.c From: Marco Elver To: elver@google.com, Andrew Morton Cc: Alexander Potapenko , Dmitry Vyukov , Jann Horn , Aleksandr Nogikh , Taras Madan , linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 28A2E90000A4 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=re1MeyZD; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf28.hostedemail.com: domain of 3ja9JYQUKCCQELVERGOOGLE.COMLINUX-MMKVACK.ORG@flex--elver.bounces.google.com designates 209.85.222.201 as permitted sender) smtp.mailfrom=3ja9JYQUKCCQELVERGOOGLE.COMLINUX-MMKVACK.ORG@flex--elver.bounces.google.com X-Stat-Signature: e33ngjqebqbqwwzuokb3qryhhqxpfm39 X-HE-Tag: 1632219022-730211 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: filter_irq_stacks() has little to do with the stackdepot implementation, except that it is usually used by users (such as KASAN) of stackdepot to reduce the stack trace. However, filter_irq_stacks() itself is not useful without a stack trace as obtained by stack_trace_save() and friends. Therefore, move filter_irq_stacks() to kernel/stacktrace.c, so that new users of filter_irq_stacks() do not have to start depending on STACKDEPOT only for filter_irq_stacks(). Signed-off-by: Marco Elver Acked-by: Dmitry Vyukov --- v2: * New patch. --- include/linux/stackdepot.h | 2 -- include/linux/stacktrace.h | 1 + kernel/stacktrace.c | 30 ++++++++++++++++++++++++++++++ lib/stackdepot.c | 24 ------------------------ 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h index 6bb4bc1a5f54..22919a94ca19 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -19,8 +19,6 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, unsigned int stack_depot_fetch(depot_stack_handle_t handle, unsigned long **entries); -unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_entries); - #ifdef CONFIG_STACKDEPOT int stack_depot_init(void); #else diff --git a/include/linux/stacktrace.h b/include/linux/stacktrace.h index 9edecb494e9e..bef158815e83 100644 --- a/include/linux/stacktrace.h +++ b/include/linux/stacktrace.h @@ -21,6 +21,7 @@ unsigned int stack_trace_save_tsk(struct task_struct *task, unsigned int stack_trace_save_regs(struct pt_regs *regs, unsigned long *store, unsigned int size, unsigned int skipnr); unsigned int stack_trace_save_user(unsigned long *store, unsigned int size); +unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_entries); /* Internal interfaces. Do not use in generic code */ #ifdef CONFIG_ARCH_STACKWALK diff --git a/kernel/stacktrace.c b/kernel/stacktrace.c index 9f8117c7cfdd..9c625257023d 100644 --- a/kernel/stacktrace.c +++ b/kernel/stacktrace.c @@ -13,6 +13,7 @@ #include #include #include +#include /** * stack_trace_print - Print the entries in the stack trace @@ -373,3 +374,32 @@ unsigned int stack_trace_save_user(unsigned long *store, unsigned int size) #endif /* CONFIG_USER_STACKTRACE_SUPPORT */ #endif /* !CONFIG_ARCH_STACKWALK */ + +static inline bool in_irqentry_text(unsigned long ptr) +{ + return (ptr >= (unsigned long)&__irqentry_text_start && + ptr < (unsigned long)&__irqentry_text_end) || + (ptr >= (unsigned long)&__softirqentry_text_start && + ptr < (unsigned long)&__softirqentry_text_end); +} + +/** + * filter_irq_stacks - Find first IRQ stack entry in trace + * @entries: Pointer to stack trace array + * @nr_entries: Number of entries in the storage array + * + * Return: Number of trace entries until IRQ stack starts. + */ +unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_entries) +{ + unsigned int i; + + for (i = 0; i < nr_entries; i++) { + if (in_irqentry_text(entries[i])) { + /* Include the irqentry function into the stack. */ + return i + 1; + } + } + return nr_entries; +} +EXPORT_SYMBOL_GPL(filter_irq_stacks); diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 0a2e417f83cb..e90f0f19e77f 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -20,7 +20,6 @@ */ #include -#include #include #include #include @@ -341,26 +340,3 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, return retval; } EXPORT_SYMBOL_GPL(stack_depot_save); - -static inline int in_irqentry_text(unsigned long ptr) -{ - return (ptr >= (unsigned long)&__irqentry_text_start && - ptr < (unsigned long)&__irqentry_text_end) || - (ptr >= (unsigned long)&__softirqentry_text_start && - ptr < (unsigned long)&__softirqentry_text_end); -} - -unsigned int filter_irq_stacks(unsigned long *entries, - unsigned int nr_entries) -{ - unsigned int i; - - for (i = 0; i < nr_entries; i++) { - if (in_irqentry_text(entries[i])) { - /* Include the irqentry function into the stack. */ - return i + 1; - } - } - return nr_entries; -} -EXPORT_SYMBOL_GPL(filter_irq_stacks);