From mboxrd@z Thu Jan 1 00:00:00 1970 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=-23.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_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 19001C433EF for ; Thu, 23 Sep 2021 11:15:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9715561107 for ; Thu, 23 Sep 2021 11:15:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9715561107 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 2A25F6B006C; Thu, 23 Sep 2021 07:15:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 25209900002; Thu, 23 Sep 2021 07:15:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 140AC6B0072; Thu, 23 Sep 2021 07:15:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0169.hostedemail.com [216.40.44.169]) by kanga.kvack.org (Postfix) with ESMTP id 058926B006C for ; Thu, 23 Sep 2021 07:15:16 -0400 (EDT) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id A79BF182067A5 for ; Thu, 23 Sep 2021 11:15:14 +0000 (UTC) X-FDA: 78618581748.10.CB5A658 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) by imf20.hostedemail.com (Postfix) with ESMTP id 6D6F4D0000AD for ; Thu, 23 Sep 2021 11:15:14 +0000 (UTC) Received: by mail-qt1-f173.google.com with SMTP id w17so5759423qta.9 for ; Thu, 23 Sep 2021 04:15:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=lqxtxP5+e+pk1U3fha6q3vivDTvYwQzQQPvtliibVDE=; b=L4y/1Lm4ytNJF6JNKYdVL8tcAFh1WWnHlnFZtx8mQFlyjrIPxYhsCO2n1NhBJ1z96f toZvW/UeILZLfvF/s/CmZgWt6xT9FmAtDOlnfIM8UrgJKSTI5CXLLYIraUilr6wMl+kj wpYLx8yY0b0E6xRlwbWKPSz6JGD2DbAG0jnWjv+luUgLxUZqnvBxb0zWBDI/2Y/p/wAb ZTQPfyU1W10X8q5pTuJOa9nes1SdHsi3Fh/ZfjkCYtKMhnOmFAz4l5TmF3VojI4i/Mdq WZWr7lUn3R8zD8uegvHMnHXszFAp0WnbV/73soEd0jWhcF2mNKf2lb1puj5M+TaTfp6u 7FCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=lqxtxP5+e+pk1U3fha6q3vivDTvYwQzQQPvtliibVDE=; b=atEt4cuzNJYgINP/XNsIoPV6ChqfU0tByuzh6wkUjaVRDUyBh/n24dlxBciDNXEHbf 7XNSbs5heha9+5Vls/WGrPu8tEdkgiHZ0ZlTpB4ZpmKNyB5ut5daWEwicd16xES12LUx g45EfSBAFNcXNw2Sq/B/iL87/6w6TOh3cm6ZaDOBGcDwMDqvhF/ZfXBnZ/16sPlSsp9S 3ZYBrgTJqPA7+48myC4fC7rKFc6rOwpagOYfkCtdIuZd+CRA4+2kM+C328/Ycn9V77Zq dWvfu8jiCD+p2b45cZpFhajUQfDy8Fw6s/VtGW85RjKUD1ENlhHvz8+p+tRzVSt2DE94 X9Tg== X-Gm-Message-State: AOAM530nuxR/JWACW8UpDVnLP7Vqvg+m062LotqwPdiFSV0xv0okPpNs +lWb4Dy/5V/V3JKxKHdw3yVOzswUMxJy5kvkUw6M9w== X-Google-Smtp-Source: ABdhPJz2u4j3X9ahIq9/HugIftpzeYB9Ri1uDJLz8KEDeMWAQCFa8lxV7bqUe/nJi++C9NGOnPwR6sGUN1fF7d4Qb9c= X-Received: by 2002:ac8:5c49:: with SMTP id j9mr4078733qtj.246.1632395713528; Thu, 23 Sep 2021 04:15:13 -0700 (PDT) MIME-Version: 1.0 References: <20210923104803.2620285-1-elver@google.com> In-Reply-To: <20210923104803.2620285-1-elver@google.com> From: Alexander Potapenko Date: Thu, 23 Sep 2021 13:14:36 +0200 Message-ID: Subject: Re: [PATCH v3 1/5] stacktrace: move filter_irq_stacks() to kernel/stacktrace.c To: Marco Elver Cc: Andrew Morton , Dmitry Vyukov , Jann Horn , Aleksandr Nogikh , Taras Madan , LKML , Linux Memory Management List , kasan-dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 6D6F4D0000AD Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="L4y/1Lm4"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of glider@google.com designates 209.85.160.173 as permitted sender) smtp.mailfrom=glider@google.com X-Stat-Signature: bxcgegsun3i7por9f5rcbg9q8jtbccgk X-HE-Tag: 1632395714-294703 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: On Thu, Sep 23, 2021 at 12:48 PM Marco Elver wrote: > > 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, ch= ar *buf, size_t size, > > void stack_depot_print(depot_stack_handle_t stack); > > -unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_e= ntries); > - > #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 *t= ask, > 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 si= ze); > +unsigned int filter_irq_stacks(unsigned long *entries, unsigned int nr_e= ntries); > > /* 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 *st= ore, unsigned int size) > #endif /* CONFIG_USER_STACKTRACE_SUPPORT */ > > #endif /* !CONFIG_ARCH_STACKWALK */ > + > +static inline bool in_irqentry_text(unsigned long ptr) > +{ > + return (ptr >=3D (unsigned long)&__irqentry_text_start && > + ptr < (unsigned long)&__irqentry_text_end) || > + (ptr >=3D (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_e= ntries) > +{ > + unsigned int i; > + > + for (i =3D 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 >=3D (unsigned long)&__irqentry_text_start && > - ptr < (unsigned long)&__irqentry_text_end) || > - (ptr >=3D (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 =3D 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); > -- > 2.33.0.464.g1972c5931b-goog > --=20 Alexander Potapenko Software Engineer Google Germany GmbH Erika-Mann-Stra=C3=9Fe, 33 80636 M=C3=BCnchen Gesch=C3=A4ftsf=C3=BChrer: Paul Manicle, Halimah DeLaine Prado Registergericht und -nummer: Hamburg, HRB 86891 Sitz der Gesellschaft: Hamburg