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=-18.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, 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 7678DC433EF for ; Tue, 7 Sep 2021 14:17:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1BCEB60F13 for ; Tue, 7 Sep 2021 14:17:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1BCEB60F13 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 ABFCE6B0071; Tue, 7 Sep 2021 10:17:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A483D6B0072; Tue, 7 Sep 2021 10:17:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C1816B0073; Tue, 7 Sep 2021 10:17:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0050.hostedemail.com [216.40.44.50]) by kanga.kvack.org (Postfix) with ESMTP id 7770B6B0071 for ; Tue, 7 Sep 2021 10:17:35 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 30CC18249980 for ; Tue, 7 Sep 2021 14:17:35 +0000 (UTC) X-FDA: 78560980470.09.0036D9E Received: from mail-oi1-f173.google.com (mail-oi1-f173.google.com [209.85.167.173]) by imf10.hostedemail.com (Postfix) with ESMTP id E0F9F6001986 for ; Tue, 7 Sep 2021 14:17:34 +0000 (UTC) Received: by mail-oi1-f173.google.com with SMTP id h133so12951879oib.7 for ; Tue, 07 Sep 2021 07:17:34 -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; bh=41eOpaggA77QHE2mPAqNRgEMJRJWSV+8azyguMYtpmM=; b=EtwIW0igagjseOSzp2URGEilPWeMajVqYIFW0ddiz6c/duZDJeehXvUdAzNVPS7yOE seaFsEEJXpwaLbHCWpGGsJJIlrufOmnEd8regUYsoQHTr+5ag/CfCf+LtMbsQ2iWzUr6 CvSe8W+Mro0dBHANjvzD5d6Z3ZttkEzk1uxBMQum1j4TeJiUl79hy8I6DkkCZfWPus5t H7VuHChcUpK6UnnjR8hBspqRb1EmTI5zAjYz02gMM7l51kfJqUMu6G8ib6L+lWZJUb4p +GRVDdaEYtyamjicCmfP7OTgeg20pMYkreUD2kfcisY+1DU48XYYl1LjbHAjzbm6prij Rcfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=41eOpaggA77QHE2mPAqNRgEMJRJWSV+8azyguMYtpmM=; b=bLjWH17ua3WsxgECovghgyhpsl+Jh9uBlF+QlhD7QATxcatoI7hahkp6swwq2biDmC 1dwcpdIM/qB55tWNFCeIjgxxhOIj9DlyTM7Rmmp1sFVtoz7i8of4J8lB8vZ3TiSOxmFs tfAwARtlJmtndHh/A4tptKci/pJ4SaLAMOnTQ6auMpIbRQCPz8CN2AcIJdGliuI/Nr4X TDJALY73kmbFrUnCUIXCfeMOLzUkKuue+3vWAD/M9/4GGBLczkRCfawxSGlbuXdOVimE q5r7HUd/9oO1EKHnpMDNSG+IyaT5SOVuEqYG4CihVsO6sAy7gtCFypnnrXair5jytrbn hv/g== X-Gm-Message-State: AOAM533aud5b0Rfx41v3VA7B02m+D4dwr90PTaI7KIJThg4IT3hK6ok/ sBSrLFdFpqWX/qdUU6r9nB8cnoOfVohXSEe0TN3eVA== X-Google-Smtp-Source: ABdhPJw24uKwJ66mYEDoqTBfJL7AR7WbHgTKwv/Kn2XnNEDj4FxfNFwauxvf89B5UPwsmABrzRX9KXpphcFtidc5SIU= X-Received: by 2002:aca:4589:: with SMTP id s131mr3105616oia.121.1631024253637; Tue, 07 Sep 2021 07:17:33 -0700 (PDT) MIME-Version: 1.0 References: <20210907141307.1437816-1-elver@google.com> In-Reply-To: <20210907141307.1437816-1-elver@google.com> From: Marco Elver Date: Tue, 7 Sep 2021 16:17:21 +0200 Message-ID: Subject: Re: [PATCH 0/6] stackdepot, kasan, workqueue: Avoid expanding stackdepot slabs when holding raw_spin_lock To: elver@google.com, Andrew Morton Cc: Shuah Khan , Tejun Heo , Lai Jiangshan , Andrey Konovalov , Walter Wu , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Vijayanand Jitta , Vinayak Menon , "Gustavo A. R. Silva" , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Aleksandr Nogikh , Taras Madan , Thomas Gleixner , Sebastian Andrzej Siewior Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: E0F9F6001986 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=EtwIW0ig; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of elver@google.com designates 209.85.167.173 as permitted sender) smtp.mailfrom=elver@google.com X-Rspamd-Server: rspam01 X-Stat-Signature: mh1ghgfdimo8to4ip17o7nxdgdtfx4cu X-HE-Tag: 1631024254-764680 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: [+Cc: Thomas, Sebastian] Sorry, forgot to Cc you... :-/ On Tue, 7 Sept 2021 at 16:14, Marco Elver wrote: > > Shuah Khan reported [1]: > > | When CONFIG_PROVE_RAW_LOCK_NESTING=y 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@linuxfoundation.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 > > 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 >