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=-8.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED 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 0D33EC433F5 for ; Tue, 7 Sep 2021 16:39:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 899386101C for ; Tue, 7 Sep 2021 16:39:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 899386101C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 0863E6B0071; Tue, 7 Sep 2021 12:39:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 035F06B0072; Tue, 7 Sep 2021 12:39:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E3F766B0073; Tue, 7 Sep 2021 12:39:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0224.hostedemail.com [216.40.44.224]) by kanga.kvack.org (Postfix) with ESMTP id D26326B0071 for ; Tue, 7 Sep 2021 12:39:13 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 871AD2D388 for ; Tue, 7 Sep 2021 16:39:13 +0000 (UTC) X-FDA: 78561337386.17.E586C58 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf17.hostedemail.com (Postfix) with ESMTP id 4D293F000136 for ; Tue, 7 Sep 2021 16:39:13 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id f11-20020a17090aa78b00b0018e98a7cddaso2514381pjq.4 for ; Tue, 07 Sep 2021 09:39:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=9ggBt1/XcGMk1GgPoYY4NtuKRl2ZcdoZPPws/++QS6M=; b=M/0bt3uVF/S98xnbmyKOSCrfR6OJRZ8a7V0/XeKbliG/m4etlFlvkR5SPf7pHssQ/O 61ITWuKkHQGMlzJFK0o4JNaJq8gzXoFNC2UX4d23udONpUN5Y9A/xDS21VQ3FrUzN4c8 ZKPHjI9vCVhePAXLiDFf26TGWwdUaiMJlyTEXxdKZ1t1DUylM/RqWIRfgU4rWWzdK2an FpJ7QEj0mVWmOu83p9aDoUG2UXqyT0GF3//x7S25otwLnBqc344OYSvEeU1wVkPdASip WvQESURIGFnvFCQIKwxtv7PFvC79zf4e7RLSNvgJtWAdGBzi7uWe5jafiZ0muLOngPVe gymQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=9ggBt1/XcGMk1GgPoYY4NtuKRl2ZcdoZPPws/++QS6M=; b=RwaYOIaZcDhSwITu+V4+udp84nMWhV00Z9AXsekDHRf8RVisUkFz4eOy6GhxlG6bx7 xGJFXlCTQMMnnUFTLXnO9Rrv4Dinxn8UMRTycjH59TUqoJGfKO+GESZeRQONhQ3tPQ1I jMT/CSc0kaX3uMBN8NEc4A4eE8QToUxQVQf7ZH1BLJ32mWp4mZ+YfsA68jo5S/voN+Ft Yf48UMg5uumVDY15Ccx710ZX5s/FxRcv1MR24JDHPE6+rCUZwZBhrliNlwMoMtoYZU4h Lz8Ky0KlXrK/qdMpHLZjIMeMZzKBKe+u8fdeYOyN6ctKyHwRfPENGMbw3Zi2TuN/bTS0 Ew3w== X-Gm-Message-State: AOAM530tCRGLK8YwHCgir1xXhoxWmRNM04NqdrjoLDe1z52ym8rPEgmm tVIZAnEX9IWZQskqm72GCQF6HUozyeM= X-Google-Smtp-Source: ABdhPJzZ1x983+WmHHXiknDxIoG/x56wROgmY8ow7uoOsy/TPLq1jvWmCXTf0c8UMALMcClEc3xjCg== X-Received: by 2002:a17:90b:1e4a:: with SMTP id pi10mr4393075pjb.135.1631032752193; Tue, 07 Sep 2021 09:39:12 -0700 (PDT) Received: from localhost (2603-800c-1a02-1bae-e24f-43ff-fee6-449f.res6.spectrum.com. [2603:800c:1a02:1bae:e24f:43ff:fee6:449f]) by smtp.gmail.com with ESMTPSA id 126sm14850350pgi.86.2021.09.07.09.39.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 09:39:11 -0700 (PDT) Date: Tue, 7 Sep 2021 06:39:10 -1000 From: Tejun Heo To: Marco Elver Cc: Andrew Morton , Shuah Khan , 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 Subject: Re: [PATCH 6/6] workqueue, kasan: avoid alloc_pages() when recording stack Message-ID: References: <20210907141307.1437816-1-elver@google.com> <20210907141307.1437816-7-elver@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210907141307.1437816-7-elver@google.com> Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="M/0bt3uV"; spf=pass (imf17.hostedemail.com: domain of htejun@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=htejun@gmail.com; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) X-Stat-Signature: 45ao7fazgzmbdt43py48ewhekjty3aae X-Rspamd-Queue-Id: 4D293F000136 X-Rspamd-Server: rspam04 X-HE-Tag: 1631032753-454471 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 07, 2021 at 04:13:07PM +0200, Marco Elver wrote: > Shuah Khan reported: > > | 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 ] > > The default kasan_record_aux_stack() calls stack_depot_save() with > GFP_NOWAIT, which in turn can then call alloc_pages(GFP_NOWAIT, ...). > In general, however, it is not even possible to use either GFP_ATOMIC > nor GFP_NOWAIT in certain non-preemptive contexts, including > raw_spin_locks (see gfp.h and ab00db216c9c7). > > Fix it by instructing stackdepot to not expand stack storage via > alloc_pages() in case it runs out by using kasan_record_aux_stack_noalloc(). > > While there is an increased risk of failing to insert the stack trace, > this is typically unlikely, especially if the same insertion had already > succeeded previously (stack depot hit). For frequent calls from the same > location, it therefore becomes extremely unlikely that > kasan_record_aux_stack_noalloc() fails. > > Link: https://lkml.kernel.org/r/20210902200134.25603-1-skhan@linuxfoundation.org > Reported-by: Shuah Khan > Signed-off-by: Marco Elver Acked-by: Tejun Heo Thanks. -- tejun