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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A17BC433EF for ; Tue, 30 Nov 2021 14:34:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB6E16B0072; Tue, 30 Nov 2021 09:34:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E3E806B0074; Tue, 30 Nov 2021 09:34:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CB8996B0075; Tue, 30 Nov 2021 09:34:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0182.hostedemail.com [216.40.44.182]) by kanga.kvack.org (Postfix) with ESMTP id B68D36B0072 for ; Tue, 30 Nov 2021 09:34:03 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 704778F172 for ; Tue, 30 Nov 2021 14:33:53 +0000 (UTC) X-FDA: 78865840704.28.1F9E72F Received: from mail-io1-f52.google.com (mail-io1-f52.google.com [209.85.166.52]) by imf15.hostedemail.com (Postfix) with ESMTP id ABBF4D0000AC for ; Tue, 30 Nov 2021 14:33:45 +0000 (UTC) Received: by mail-io1-f52.google.com with SMTP id p23so26307882iod.7 for ; Tue, 30 Nov 2021 06:33:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KvFvndBl4Bydux7YEgvSu6yBLgLtvHPAwDkKBUzy3MQ=; b=DTpy4LJX5vuS+gtnzgO+ty8a1J2mBtBHacEvP1LZaKaTqkRDxbjFzJI99OAaZwlblU iw6pUW5DB/W9iWDF0Me9jj5mlzYr1J0dBOoIo1jVzH91TK4aAm5dCIZxVYZi7AxY67hn rJBiUcKmWm/L6g8qzPoZ+eTyDPND6CoPfEed1nSwAEoRwoWEOOmc3e5hU/9hPb/BnNwT zwO249C2NX6cb3rHF0JFCtBgXkmeuPOFs8dmi4nYHimvyTQ0X0jxcb6bWh7lrHDlA0Ii 2KY+nGNL9ug8Ny/6adOjhf2deqTWn7Gklh+KBZ4g3ix/akUO/VRb3NEB1YwjdoftvY2x yuhg== 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; bh=KvFvndBl4Bydux7YEgvSu6yBLgLtvHPAwDkKBUzy3MQ=; b=HNmO3VYRYYmy2Zl/eqAwHC0xs0FgSaJvxSrgfoSvqbFo/u/1IEWYMvf7yvrJm4OxrF trpkVeOoipd2xVdLj+SndRhN7WMvTtjWi2dF+476gK+5GONdhQAWCv65HqrJZ2jURlEk teF5L2M2ce4zy4/d5sxMYzRcXznMT6FMWpXnzF9g6hGDHiZUCJGwoMXBOHV3Y+6pGepF du5iZYiyHpFX+hy5NkQGLhVsijB82/GeZofucoP9rq+s1kP0GxXp4p9cGjxIlb5JtVJj m36Ke7Am2KFHcQImMfDuOtbfdNj0Z25UR+RhOqfABGRJemrKWbnFVKQgZhROh2M082+U jACA== X-Gm-Message-State: AOAM532juny0rqP99776KP6dla/0iJJQ4gKUr4oaQkSO/0iet8w4G1Gl +XpnhOB8aKQMQ2X74eIPRqk0VEu8Agr7jKoLJrQ= X-Google-Smtp-Source: ABdhPJzI7PIJq5HrCfzlxDRzoUVWPYEqe5LkOcdc3MqSXtKmXZp9CsxTy+8jedmlD8Ani/UF1Mfqt8vJbKVG0KUZqGI= X-Received: by 2002:a05:6638:2257:: with SMTP id m23mr72343928jas.17.1638282832252; Tue, 30 Nov 2021 06:33:52 -0800 (PST) MIME-Version: 1.0 References: <20211130095727.2378739-1-elver@google.com> In-Reply-To: <20211130095727.2378739-1-elver@google.com> From: Andrey Konovalov Date: Tue, 30 Nov 2021 15:33:41 +0100 Message-ID: Subject: Re: [PATCH] lib/stackdepot: always do filter_irq_stacks() in stack_depot_save() To: Marco Elver Cc: Andrew Morton , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Vlastimil Babka , Vijayanand Jitta , "Gustavo A. R. Silva" , Imran Khan , LKML , kasan-dev , Linux Memory Management List , Chris Wilson , Jani Nikula , Mika Kuoppala , dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: ABBF4D0000AC X-Stat-Signature: oqwb79aumo96n7w9m7ioa8uoj6cf6i8x Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=DTpy4LJX; spf=pass (imf15.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.166.52 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1638282825-882032 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 Tue, Nov 30, 2021 at 11:14 AM Marco Elver wrote: > > The non-interrupt portion of interrupt stack traces before interrupt > entry is usually arbitrary. Therefore, saving stack traces of interrupts > (that include entries before interrupt entry) to stack depot leads to > unbounded stackdepot growth. > > As such, use of filter_irq_stacks() is a requirement to ensure > stackdepot can efficiently deduplicate interrupt stacks. > > Looking through all current users of stack_depot_save(), none (except > KASAN) pass the stack trace through filter_irq_stacks() before passing > it on to stack_depot_save(). > > Rather than adding filter_irq_stacks() to all current users of > stack_depot_save(), it became clear that stack_depot_save() should > simply do filter_irq_stacks(). > > Signed-off-by: Marco Elver > --- > lib/stackdepot.c | 13 +++++++++++++ > mm/kasan/common.c | 1 - > 2 files changed, 13 insertions(+), 1 deletion(-) > > diff --git a/lib/stackdepot.c b/lib/stackdepot.c > index b437ae79aca1..519c7898c7f2 100644 > --- a/lib/stackdepot.c > +++ b/lib/stackdepot.c > @@ -305,6 +305,9 @@ EXPORT_SYMBOL_GPL(stack_depot_fetch); > * (allocates using GFP flags of @alloc_flags). If @can_alloc is %false, avoids > * any allocations and will fail if no space is left to store the stack trace. > * > + * If the stack trace in @entries is from an interrupt, only the portion up to > + * interrupt entry is saved. > + * > * Context: Any context, but setting @can_alloc to %false is required if > * alloc_pages() cannot be used from the current context. Currently > * this is the case from contexts where neither %GFP_ATOMIC nor > @@ -323,6 +326,16 @@ depot_stack_handle_t __stack_depot_save(unsigned long *entries, > unsigned long flags; > u32 hash; > > + /* > + * If this stack trace is from an interrupt, including anything before > + * interrupt entry usually leads to unbounded stackdepot growth. > + * > + * Because use of filter_irq_stacks() is a requirement to ensure > + * stackdepot can efficiently deduplicate interrupt stacks, always > + * filter_irq_stacks() to simplify all callers' use of stackdepot. > + */ > + nr_entries = filter_irq_stacks(entries, nr_entries); > + > if (unlikely(nr_entries == 0) || stack_depot_disable) > goto fast_exit; > > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index 8428da2aaf17..efaa836e5132 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -36,7 +36,6 @@ depot_stack_handle_t kasan_save_stack(gfp_t flags, bool can_alloc) > unsigned int nr_entries; > > nr_entries = stack_trace_save(entries, ARRAY_SIZE(entries), 0); > - nr_entries = filter_irq_stacks(entries, nr_entries); > return __stack_depot_save(entries, nr_entries, flags, can_alloc); > } > > -- > 2.34.0.rc2.393.gf8c9666880-goog > Reviewed-by: Andrey Konovalov