From patchwork Thu Sep 23 10:47:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12512395 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 B8A79C433EF for ; Thu, 23 Sep 2021 10:48:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 549E260F21 for ; Thu, 23 Sep 2021 10:48:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 549E260F21 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 7CA7F6B006C; Thu, 23 Sep 2021 06:48:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 77AAF6B0071; Thu, 23 Sep 2021 06:48:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 642F1900002; Thu, 23 Sep 2021 06:48:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0090.hostedemail.com [216.40.44.90]) by kanga.kvack.org (Postfix) with ESMTP id 544616B006C for ; Thu, 23 Sep 2021 06:48:13 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EC09D2D4BD for ; Thu, 23 Sep 2021 10:48:12 +0000 (UTC) X-FDA: 78618513624.18.F7BDA96 Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by imf22.hostedemail.com (Postfix) with ESMTP id B80DB1901 for ; Thu, 23 Sep 2021 10:48:12 +0000 (UTC) Received: by mail-qk1-f202.google.com with SMTP id m10-20020a05620a290a00b004334bcdf1f4so19152476qkp.2 for ; Thu, 23 Sep 2021 03:48:12 -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=T9tewya8iK1bzbkFhOsP6uZciKvGiqobRhQCuQcyJJA=; b=rz5x5gdFAfKsoOzOeKiiiw9rsoxpiAT/+SfjAaRlku3ENBJ6Sv0bng2d3pu+fdqZIO 6h9mMsK4wjmjPVPWDdN42QwiYm/VAkRWB/wDHQ7BFkGCSB5Q+mgGnNuAYMzXckFFJ++v CCpGy9XMb/VnOu8LDath5dmTQrSEzUjTcqeEpaioullCZ7Wl5gc4wIc6yVpNdhgXEV0G SUOhnGc+j9tGco+Y98HL0n70SkvSP4gCKhOXf/7TqjWz1kAEDNIGxk9Dq3ZSsK7OaBsf mt0yhfYMwV7cHsUD5TG1G+7vKd0RK6U+43SAEHj0vmYvVUIjNj+yfsuZG/hzu5x4aDZX e6ug== 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=T9tewya8iK1bzbkFhOsP6uZciKvGiqobRhQCuQcyJJA=; b=wt22PMxMs1tXF3p3KZ/XY0kpIj8JQLJBc8XOGUqm9pjyQVav0K/t2LUa6edOEd3gEi YFL7QGnGLRqZWhwlN6L/dJm1H3VOd8E+sgqQ1c1w9rJfoIvAzq6yG/pF5RmWMDkSPPOX MlplRbUepMwHtl0IUTnGYZlmEuRoi05puSB8w3a/nDrkzoPNFSlAtCYU9zn14XNsIMol LctNrr7ZAMjkjzPnZKioaFvdGZ4pi6bv35Wv0OFNYGWN/Q2dXxM2Sy+JP35XaC5tXMgQ LPGkIsfPFE9Nw51BPUMmcRL9WyiiCA1LI1JODM12YPub2P9KKu3aMbVSyhOgcRojTF1x JARw== X-Gm-Message-State: AOAM533E73RbUB0EyOQf4TFACFatgIX5+HFwOWB+9fnBesxQvhk8+1ye Fsvq2dU211vWe/ECfugZqHlSlGRQaQ== X-Google-Smtp-Source: ABdhPJyhS9WtvLwD9LcVlaSbGlll/fGP2M2LJrAHSg0KxHef3g2hDkeZjXjFmpCG748ujbqPd5iOXPnIqw== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:bd72:fd35:a085:c2e3]) (user=elver job=sendgmr) by 2002:a05:6214:4c9:: with SMTP id ck9mr3692117qvb.52.1632394091933; Thu, 23 Sep 2021 03:48:11 -0700 (PDT) Date: Thu, 23 Sep 2021 12:47:59 +0200 Message-Id: <20210923104803.2620285-1-elver@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.0.464.g1972c5931b-goog Subject: [PATCH v3 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-Stat-Signature: 7ybh7697j615ypgsdy8zp6moyfkfhrax Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=rz5x5gdF; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf22.hostedemail.com: domain of 3a1tMYQUKCGQGNXGTIQQING.EQONKPWZ-OOMXCEM.QTI@flex--elver.bounces.google.com designates 209.85.222.202 as permitted sender) smtp.mailfrom=3a1tMYQUKCGQGNXGTIQQING.EQONKPWZ-OOMXCEM.QTI@flex--elver.bounces.google.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: B80DB1901 X-HE-Tag: 1632394092-442083 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 Acked-by: Alexander Potapenko --- v3: * Rebase to -next due to conflicting stackdepot changes. 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 ee03f11bb51a..c34b55a6e554 100644 --- a/include/linux/stackdepot.h +++ b/include/linux/stackdepot.h @@ -30,8 +30,6 @@ int stack_depot_snprint(depot_stack_handle_t handle, char *buf, size_t size, void stack_depot_print(depot_stack_handle_t stack); -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 69c8c9b0d8d7..b437ae79aca1 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -20,7 +20,6 @@ */ #include -#include #include #include #include @@ -417,26 +416,3 @@ depot_stack_handle_t stack_depot_save(unsigned long *entries, return __stack_depot_save(entries, nr_entries, alloc_flags, true); } 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);