Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp3889098pxb; Tue, 7 Sep 2021 09:41:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXahRbT7zkcfoto9dn/XkmICbjS4PYLrhncNiKgtu5/PIe0TlKzyqZPAwvXJSyH7k3HZ1p X-Received: by 2002:aa7:dc19:: with SMTP id b25mr384026edu.23.1631032919419; Tue, 07 Sep 2021 09:41:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631032919; cv=none; d=google.com; s=arc-20160816; b=FWN7EwLABkKoRmZRWQQ5dJ/JoYXoqtCvvRoDPhjPVbgv6U6pOcghw7ybLLckMUjx4u bUJOcoCBXEZDnwLMpQhfjDM5Uqmw2dH698Yn460aiYolDs6UeTP+uAahrF/07TqY5xts kcm4gPZtqHAlLNhHIWRdEVHxG/uCf0MRjoYuODntBgYMjjfahcvBleAbO7MDz5iJTSxS mgyIozgpsonde8lfU3TNKySJlUDB8EAi1BmSqA3UzxauMMQKVN7b6lzAd6WDZx2eQCP9 4FXkyymBLfEwuU7FYHhEqfxwc0QIEpVgVfWe7xN8YdKtRngRQs1c8kwtHzWzHMvj58BZ 6gNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=9ggBt1/XcGMk1GgPoYY4NtuKRl2ZcdoZPPws/++QS6M=; b=LAPqQY1lr+K1zZn/d0rC6NXeIqJmjhFo9OYrCAzRRVlQM/OQYCuijU26MBnFYWHhRJ lJib4+h2H6vR/HBHIpp+y8DnWmRPYTlPNujgDJ4StE3VO16+P7qzNCB57FIVgeBsZPNO aplksqMY6NvSvVL39FFlITC+BGMUETotpNoeSoz2QHE6QlFhZoM8ZIsRscpCSYikuojt lFy6jZVezVdJAR1nhZ7ffqiRpBgjeD/eLpIY6im0kns2u5Oxy1xPpInjqZ15CDEWjg0i vI0Rv2XKs1crhwqBG9LU5Jm2kWVqGQgCeCNOXyQcXsGC7tE9ix4ILtagu6zDH1sQXdzn 6MWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="M/0bt3uV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y12si11540664edd.393.2021.09.07.09.41.35; Tue, 07 Sep 2021 09:41:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="M/0bt3uV"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343837AbhIGQkT (ORCPT + 99 others); Tue, 7 Sep 2021 12:40:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232588AbhIGQkT (ORCPT ); Tue, 7 Sep 2021 12:40:19 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D93B7C061575 for ; Tue, 7 Sep 2021 09:39:12 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id bg1so6156869plb.13 for ; Tue, 07 Sep 2021 09:39:12 -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=DPA+Ynt6EekQwrToT+74YxNDZa1UtMcYqyZzs2F4+wkn2WlnDKaA46bjzGJGlpOkc9 dSyQlHoQrfZ1eGsybadGg5EWIA4hVBR0IW7D1UfEw+mrTpaaDXIfirUM9CFPDOqNSQz6 9ltufTYEWWjVTlxx90dXkxfu6TiyAeIeAE5ndOqhSmcSTDc/QtogT7c7Kcf2Ac3YwZYk HZgwXdQnyld/Rxx9WTU5Y6I/AMapNJ+2pO5p7vxyBPP1829LF/CzwvdGcOT+889384Wf 8RPJDfywzsK/vLG0NuXpdNqBttsyGHstCBjypc8YEIHB+Oau3oobCKHBIUTcXiPABelv idSQ== X-Gm-Message-State: AOAM532C+wTmbhzGO5r2HJwbPOc1ymJPOD6lqDqcKB51Kv7+QLFl4IMT IZJZWwoF6DM40hsCvMpcogg= 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) Sender: Tejun Heo 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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