From patchwork Tue Nov 30 09:57:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12646735 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 525E5C433EF for ; Tue, 30 Nov 2021 10:14:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE2A56B0073; Tue, 30 Nov 2021 05:14:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B91D66B0074; Tue, 30 Nov 2021 05:14:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A59916B0075; Tue, 30 Nov 2021 05:14:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0110.hostedemail.com [216.40.44.110]) by kanga.kvack.org (Postfix) with ESMTP id 9609E6B0073 for ; Tue, 30 Nov 2021 05:14:18 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 5D7318EC04 for ; Tue, 30 Nov 2021 10:14:08 +0000 (UTC) X-FDA: 78865186134.19.E3D60C7 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) by imf12.hostedemail.com (Postfix) with ESMTP id 071D5100009D for ; Tue, 30 Nov 2021 10:14:07 +0000 (UTC) Received: by mail-wm1-f73.google.com with SMTP id 205-20020a1c00d6000000b003335d1384f1so13517000wma.3 for ; Tue, 30 Nov 2021 02:14:07 -0800 (PST) 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=GIp7EQn2UnohoTj+yPMh1P0FmhJDYsjIC78ghQsH60U=; b=PGw1FmJ+9GtdWBnIbq7f+hljBVAL0lFbftpkYi1JLWLVMNYhLv7261fjg4MqiYs3kv R8poFfyshuoIbY13aW6fVh2RUJjOfFJqRKmb1Qu540Xuco19JGFOfU0aRxU0/gVTqb7L d+miGay8ofozSEpc9+9bgYsb4ZzIqZgdc5Lyqo/qUcinDbViru5aSfKjydYBhCxM9gSI /ZJxKOVZHWtHUmb0Gz7Q8CoK2/VjU2W0+ZJye7JyyG7XHPK4CLdYWyKbHAOZc3NTwBmJ bxHO1oIuPKFcdO7fehRy7s/817CNqQ968rheE0GoOAdmojCvdHngtz1Y4yINbTR0iKeN QJ9w== 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=GIp7EQn2UnohoTj+yPMh1P0FmhJDYsjIC78ghQsH60U=; b=1eBp8dhk5Q6tczEsyUvcW1asfpeKzhHYnArjqW3saMT5nTgVFQ8o3YwUn6knKEjdSe CXUsOcN3hJ9VTV7uNWyWIYTyfGng+4z9jBC64KhYM9hMkvw5EKhpNLB6dhWssm+A4P/g mAEOL9jqQ705+dBYywWTyfjPuScWHF19xrUVHxJkb4Q6GjJrkRfXBvePf0/Pn7R/zf1+ pBYYdzCEGWXTYOlv3cgP1VrhPFMd9Mwjj0/NH6BuZ+94cUy3clkryNO8y762a+kSk4ub mLgqCXZ39VlTxL/29Ux0RW9Eh0cNKCdLpnx4rU+p5jPSRocPnzvUYgVRyO5RjjlItFlJ 5u1g== X-Gm-Message-State: AOAM532q8M9ZslLf1U5igC6oGTPWatuiWG8QKXLStOfpjCtf98geR+8j kRbSP5HfLJYTbvYGzEdN4I75nUzoIw== X-Google-Smtp-Source: ABdhPJxZ/cQtxZDq13eLfl7Z5mw2/skPl5gwILIaBmKsGNdiwTMcLcVdLHag+IyGI45Qp/W/X+ZIkCuzcA== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:86b7:11e9:7797:99f0]) (user=elver job=sendgmr) by 2002:adf:dd0a:: with SMTP id a10mr39649481wrm.60.1638267246341; Tue, 30 Nov 2021 02:14:06 -0800 (PST) Date: Tue, 30 Nov 2021 10:57:27 +0100 Message-Id: <20211130095727.2378739-1-elver@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [PATCH] lib/stackdepot: always do filter_irq_stacks() in stack_depot_save() From: Marco Elver To: elver@google.com, Andrew Morton Cc: Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vlastimil Babka , Vijayanand Jitta , "Gustavo A. R. Silva" , Imran Khan , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, Chris Wilson , Jani Nikula , Mika Kuoppala , dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 071D5100009D X-Stat-Signature: a7qku84j96yxhi1uwodi6hjwn4e67o7h Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=PGw1FmJ+; spf=pass (imf12.hostedemail.com: domain of 3bvmlYQUKCA0ry8r4t11tyr.p1zyv07A-zzx8npx.14t@flex--elver.bounces.google.com designates 209.85.128.73 as permitted sender) smtp.mailfrom=3bvmlYQUKCA0ry8r4t11tyr.p1zyv07A-zzx8npx.14t@flex--elver.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1638267247-353199 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: 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 Reviewed-by: Alexander Potapenko Acked-by: Vlastimil Babka Reviewed-by: Andrey Konovalov --- 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); }