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 CE98BC433F5 for ; Tue, 14 Sep 2021 12:56:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 74EE8610E6 for ; Tue, 14 Sep 2021 12:56:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 74EE8610E6 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 AE9616B006C; Tue, 14 Sep 2021 08:56:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A99996B0071; Tue, 14 Sep 2021 08:56:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9615C6B0072; Tue, 14 Sep 2021 08:56:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0022.hostedemail.com [216.40.44.22]) by kanga.kvack.org (Postfix) with ESMTP id 897776B006C for ; Tue, 14 Sep 2021 08:56:11 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4B23226DDE for ; Tue, 14 Sep 2021 12:56:11 +0000 (UTC) X-FDA: 78586176942.27.7133741 Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by imf11.hostedemail.com (Postfix) with ESMTP id D5585F0000BA for ; Tue, 14 Sep 2021 12:56:10 +0000 (UTC) Received: by mail-qt1-f182.google.com with SMTP id s15so11249364qta.10 for ; Tue, 14 Sep 2021 05:56:10 -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=473xgTZGiwHmobEJ6/SAUPmhRqqxJ35dz9Kf/VHgaaM=; b=R7A0fnkxJVpOuOKgRus4AqD4RTf/Qm6ltxgszYDlLTSOdn7rdR9HiDKXPAB8o/HElJ 9SLmLR5hhgFnc0o/wC1Hom/3v4+6hU5Jaf+rnP9orf7FDGHaVvZ4TZRsqq7znh1pWZr+ SX/SNki1DCzMXdD4y+q8CewjP6vBqEbeN5EYXEhTeXzbpn7lzCHXPcyp4PWeBDnFqRJM Yua5EsTt0BbuEDh8qmmMmEFQT3PmeUcsH9vv5imbDmv+zZK0Qpby1/FIEMqXXvUKdXLv p0Ie9v5VD3BxVtevHV63v5pl/b22tuBZWr1oKrz6jR235WrskaFg3Q9D/RB8vs8ncfsY Y1sg== 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=473xgTZGiwHmobEJ6/SAUPmhRqqxJ35dz9Kf/VHgaaM=; b=vGwW1Qk8+agQfU+VFxPGPIYLBOOlJ8SYVthLfR4h26xidKGilmgI1Xxz6EnTLQNLrH M3ayuuc0hATIt2V60j2PVwGcgrzmPdbJYuMa7sB/9zYfx+xDUf5dovd3cw2H7RCa2oGA r3flyfZYy3euLjBItxVmTMUP3wVTKvvXtqHXVLYoieSLYXfXfIeIC91Szf5yxvGgiBCt VFLnVNVtcxF633dYV7pelvjBoMpEiTpJPxv7v9vS7nSWvBnedn9Q+apwr32wziNVBYfl jv0Gwu7Anxj0ZQwFCrbmy3Y2HeWhpStrmeg466f3hoVzMDzomTWNp+GTqYvQZQ26jx02 Hqaw== X-Gm-Message-State: AOAM530RwGXk6WiL3pZEZyANLpRZYWpN9fOMN7tKtxnYo1591rlwgvZu 54BUloN4CMlRNMJn1QiM5yttrWkQ48HUSAAb7eHP5g== X-Google-Smtp-Source: ABdhPJzpwFpScSvyXLb64fpGC8STq+XZ2FvKKDr7h8qDk9CRc5YeUtRYqyuGHayHHqvZfki/vwuAjdSU7GZBSy985T0= X-Received: by 2002:a05:622a:394:: with SMTP id j20mr4535974qtx.196.1631624169952; Tue, 14 Sep 2021 05:56:09 -0700 (PDT) MIME-Version: 1.0 References: <20210907141307.1437816-1-elver@google.com> In-Reply-To: <20210907141307.1437816-1-elver@google.com> From: Alexander Potapenko Date: Tue, 14 Sep 2021 14:55:33 +0200 Message-ID: Subject: Re: [PATCH 0/6] stackdepot, kasan, workqueue: Avoid expanding stackdepot slabs when holding raw_spin_lock To: Marco Elver Cc: Andrew Morton , Shuah Khan , Tejun Heo , Lai Jiangshan , Andrey Konovalov , Walter Wu , Andrey Ryabinin , Dmitry Vyukov , Vijayanand Jitta , Vinayak Menon , "Gustavo A. R. Silva" , kasan-dev , LKML , Linux Memory Management List , Aleksandr Nogikh , Taras Madan Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=R7A0fnkx; spf=pass (imf11.hostedemail.com: domain of glider@google.com designates 209.85.160.182 as permitted sender) smtp.mailfrom=glider@google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: xh7he83idmqifioguobugky6fseiqw34 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: D5585F0000BA X-HE-Tag: 1631624170-384342 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, Sep 7, 2021 at 4:14 PM Marco Elver wrote: > > Shuah Khan reported [1]: > > | When CONFIG_PROVE_RAW_LOCK_NESTING=3Dy and CONFIG_KASAN are enabled, > | kasan_record_aux_stack() runs into "BUG: Invalid wait context" when > | it tries to allocate memory attempting to acquire spinlock in page > | allocation code while holding workqueue pool raw_spinlock. > | > | There are several instances of this problem when block layer tries > | to __queue_work(). Call trace from one of these instances is below: > | > | kblockd_mod_delayed_work_on() > | mod_delayed_work_on() > | __queue_delayed_work() > | __queue_work() (rcu_read_lock, raw_spin_lock pool->lock held= ) > | insert_work() > | kasan_record_aux_stack() > | kasan_save_stack() > | stack_depot_save() > | alloc_pages() > | __alloc_pages() > | get_page_from_freelist() > | rm_queue() > | rm_queue_pcplist() > | local_lock_irqsave(&pagesets.lock, flags= ); > | [ BUG: Invalid wait context triggered ] > > [1] https://lkml.kernel.org/r/20210902200134.25603-1-skhan@linuxfoundatio= n.org > > PROVE_RAW_LOCK_NESTING is pointing out that (on RT kernels) the locking > rules are being violated. More generally, memory is being allocated from > a non-preemptive context (raw_spin_lock'd c-s) where it is not allowed. > > To properly fix this, we must prevent stackdepot from replenishing its > "stack slab" pool if memory allocations cannot be done in the current > context: it's a bug to use either GFP_ATOMIC nor GFP_NOWAIT in certain > non-preemptive contexts, including raw_spin_locks (see gfp.h and > ab00db216c9c7). > > The only downside is that saving a stack trace may fail if: stackdepot > runs out of space AND the same stack trace has not been recorded before. > I expect this to be unlikely, and a simple experiment (boot the kernel) > didn't result in any failure to record stack trace from insert_work(). > > The series includes a few minor fixes to stackdepot that I noticed in > preparing the series. It then introduces __stack_depot_save(), which > exposes the option to force stackdepot to not allocate any memory. > Finally, KASAN is changed to use the new stackdepot interface and > provide kasan_record_aux_stack_noalloc(), which is then used by > workqueue code. > > Marco Elver (6): > lib/stackdepot: include gfp.h > lib/stackdepot: remove unused function argument > lib/stackdepot: introduce __stack_depot_save() > kasan: common: provide can_alloc in kasan_save_stack() > kasan: generic: introduce kasan_record_aux_stack_noalloc() > workqueue, kasan: avoid alloc_pages() when recording stack Acked-by: Alexander Potapenko for the whole series. > > include/linux/kasan.h | 2 ++ > include/linux/stackdepot.h | 6 +++++ > kernel/workqueue.c | 2 +- > lib/stackdepot.c | 51 ++++++++++++++++++++++++++++++-------- > mm/kasan/common.c | 6 ++--- > mm/kasan/generic.c | 14 +++++++++-- > mm/kasan/kasan.h | 2 +- > 7 files changed, 65 insertions(+), 18 deletions(-) > > -- > 2.33.0.153.gba50c8fa24-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