Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4323250rdb; Mon, 11 Dec 2023 16:14:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGHsBmZGM5jnjp2aJXm/mhuGggBo9SfwTJx9+lEUqUsHJ/zRkvZdaBNRdi9OcyKNwIUMXJn X-Received: by 2002:a05:6358:52c9:b0:170:e4c6:3a74 with SMTP id z9-20020a05635852c900b00170e4c63a74mr1373372rwz.30.1702340089998; Mon, 11 Dec 2023 16:14:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702340089; cv=none; d=google.com; s=arc-20160816; b=LA5So98RT3N48PoT7pMZil6IjJOnJsWMHlIst2FRjsEeT24D9arw0b7999m0JbP9js aq/Ge4vL0rmilcp8akuQHAaxwQ9SLn5vhg4Qw/JLlVXrBHbPFwDFvuaKqfY1D4Eg3J15 wtoUgEux9gqOtBL1yCsD4HqXrRe8AyQW+8tzADFbMx6Z8NLvaWB5VPszuXz72zohAliY YoI5TMWoij/mvH70ywIImnAoYWx0hoMJbz4xGilzb+NkYM7arxerOQfL+DbenlHM5zMQ Utv5gkYZLZJCXHfm+nY2rEst2ggIyzfCxpIafjF/9JO0SWdU+etv/CRkrMWk5CeRC3aB XS6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vOaXJmSZ4mgcOuCRTmHs9viCNJ5mspLX8zhenk2W1qY=; fh=R37Itr4vM4DSdM7nCVEJRaUzpyR01xRhpmD5Puf7xME=; b=zyqmPT8qb1cJBgyA++v0h+j00ipPt8GDg0Zv75adjvLUlX0uJ5hrybuyWWVnjAahiw nq87aJchjyuxhvXagVwNNf1gvDH64eRDfOAXUpH14jePLwXLMJ14v+qgICwFTTlQ2/mw OtWkuZieadHKwfCvDVmXGcjBYrCgrRnFVn/CBOgWG0W0GQz550qDtRREQ2mjCPVheql2 yEofm1dGKDYQ3N2/wjxgO9n3t55NMEq7Giy/qF7TL6yVmEsqRTREox9TLvcRDAQsAJ7U 4aPrBJst0d2AMY3HF3sVQvEr1w7W1QR8j3dh/BIaKS7QKfyUwsH+Oz9dkGzCDDoT3GHf gUoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZFY0MXvU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id o18-20020a656152000000b005c67dd98b13si6646492pgv.314.2023.12.11.16.14.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 16:14:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=ZFY0MXvU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 01CDE809B76C; Mon, 11 Dec 2023 16:14:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345425AbjLLAOG (ORCPT + 99 others); Mon, 11 Dec 2023 19:14:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345394AbjLLAOE (ORCPT ); Mon, 11 Dec 2023 19:14:04 -0500 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF517B8 for ; Mon, 11 Dec 2023 16:14:10 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702340049; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vOaXJmSZ4mgcOuCRTmHs9viCNJ5mspLX8zhenk2W1qY=; b=ZFY0MXvUwTln62U1tHBt6KK8Dqg+6tfH+i/GfcUa4eujPC2CC53JaDXpaZhT1eWOt98GO5 rQ36NXtwX/bnZpsUbbyhXz3bTvVFqA6FvpYHeqX+qP0YEUP3BL6KN8k/7Q6TNtfpTILzXF HbnIpR5duzaXmjUbV13x2oH9iQ3NxmE= From: andrey.konovalov@linux.dev To: Andrew Morton Cc: Andrey Konovalov , Marco Elver , Alexander Potapenko , Dmitry Vyukov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Tetsuo Handa , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 1/4] lib/stackdepot: add printk_deferred_enter/exit guards Date: Tue, 12 Dec 2023 01:14:00 +0100 Message-Id: <6c38c31e304a55449f76f60b6f72e35f992cad99.1702339432.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 11 Dec 2023 16:14:47 -0800 (PST) From: Andrey Konovalov Stack depot functions can be called from various contexts that do allocations, including with console locks taken. At the same time, stack depot functions might print WARNING's or refcount-related failures. This can cause a deadlock on console locks. Add printk_deferred_enter/exit guards to stack depot to avoid this. Reported-by: Tetsuo Handa Closes: https://lore.kernel.org/all/000000000000f56750060b9ad216@google.com/ Signed-off-by: Andrey Konovalov --- lib/stackdepot.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 870cce2f4cbd..a0be5d05c7f0 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -506,12 +506,14 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries, bucket = &stack_table[hash & stack_hash_mask]; read_lock_irqsave(&pool_rwlock, flags); + printk_deferred_enter(); /* Fast path: look the stack trace up without full locking. */ found = find_stack(bucket, entries, nr_entries, hash); if (found) { if (depot_flags & STACK_DEPOT_FLAG_GET) refcount_inc(&found->count); + printk_deferred_exit(); read_unlock_irqrestore(&pool_rwlock, flags); goto exit; } @@ -520,6 +522,7 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries, if (new_pool_required) need_alloc = true; + printk_deferred_exit(); read_unlock_irqrestore(&pool_rwlock, flags); /* @@ -541,6 +544,7 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries, } write_lock_irqsave(&pool_rwlock, flags); + printk_deferred_enter(); found = find_stack(bucket, entries, nr_entries, hash); if (!found) { @@ -562,6 +566,7 @@ depot_stack_handle_t stack_depot_save_flags(unsigned long *entries, depot_keep_new_pool(&prealloc); } + printk_deferred_exit(); write_unlock_irqrestore(&pool_rwlock, flags); exit: if (prealloc) { @@ -600,9 +605,11 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle, return 0; read_lock_irqsave(&pool_rwlock, flags); + printk_deferred_enter(); stack = depot_fetch_stack(handle); + printk_deferred_exit(); read_unlock_irqrestore(&pool_rwlock, flags); *entries = stack->entries; @@ -619,6 +626,7 @@ void stack_depot_put(depot_stack_handle_t handle) return; write_lock_irqsave(&pool_rwlock, flags); + printk_deferred_enter(); stack = depot_fetch_stack(handle); if (WARN_ON(!stack)) @@ -633,6 +641,7 @@ void stack_depot_put(depot_stack_handle_t handle) } out: + printk_deferred_exit(); write_unlock_irqrestore(&pool_rwlock, flags); } EXPORT_SYMBOL_GPL(stack_depot_put); -- 2.25.1