Received: by 2002:a05:7412:d008:b0:f9:6acb:47ec with SMTP id bd8csp187401rdb; Tue, 19 Dec 2023 13:20:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZCF/+ORjBCknhLbH9AoA3lu4ZbbrG05s4iG7nTORt3Lfa2Dba5zNj2iLlQN59NAPfhulA X-Received: by 2002:a05:6808:180d:b0:3bb:68ad:f81c with SMTP id bh13-20020a056808180d00b003bb68adf81cmr1056623oib.15.1703020822484; Tue, 19 Dec 2023 13:20:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703020822; cv=none; d=google.com; s=arc-20160816; b=uMCoHEHiLXfZE0Bsx5ZLAANDF10fAcH/OMgo5wQyrCHwyzIqpM9q82ABoWXfCWlSAX zP5MVFT87ZQwd8XYq201u8C+UAhOpjeYO0gZeZ5rSEezQxqaeJf1VKosNvWriMOOnOMf BFpVStYXLvM3NxAFCTwCePx2/ntlR4Pf6in+QQAcePJPZv4LCOonNrqzNLoCkQoaoSrh v1z0/D4luojaRcG9EWFPLvPuJ0vOOUAAAjwTHqkiKuHvLrYAFWYoc5eyL6rNdrKVrWhU XX5XV3ZUYFL5yVIOM5RgGZshE8C3/RNbu6j1VOOcoXub0Q154CmmHy21CCcuz4rYWiAN cG6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=nejB0rN/5EGuA3SQQpabp67CuxIikS5y1NrnTFuMISI=; fh=R37Itr4vM4DSdM7nCVEJRaUzpyR01xRhpmD5Puf7xME=; b=GoA42XFK+nKqUE682rZ6rZ1eQsFi0Wg/FGuian5gBWcMrLjyQNJc8tvbTsrT2BHcnJ Lro29cGnadWyUemhWmeEEYC++asfg3vbpVeqZ+hh2iUzJoYLBSL/0f1o56JO0ni5/gd6 iMxIcBaXlyl7fWcMTLTTfqeQZPW/dAkBVlb0z/ON6OO3etaiyFXsQQk3nJYQkWElAYY9 yJlDb7jdAhF9JjLtjZ4ufRZVrorACChr5bREnCR6hbxX25eUd5j5Tql8HAaQfro906cA xB56zXCwxgD3A0AuFKxceUiVNhum8nLtuwrDX2OG6Tl4tiWE1qsLWaEtOGUjD/08Sysy zWuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=elb7wJjm; spf=pass (google.com: domain of linux-kernel+bounces-5959-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5959-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id x6-20020a0cc506000000b0067f32e92d37si7455334qvi.31.2023.12.19.13.20.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 13:20:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5959-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=elb7wJjm; spf=pass (google.com: domain of linux-kernel+bounces-5959-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5959-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3AEA91C251AF for ; Tue, 19 Dec 2023 21:20:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D51713DB80; Tue, 19 Dec 2023 21:20:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="elb7wJjm" X-Original-To: linux-kernel@vger.kernel.org Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 151F83D0AB for ; Tue, 19 Dec 2023 21:19:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev 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=1703020797; 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=nejB0rN/5EGuA3SQQpabp67CuxIikS5y1NrnTFuMISI=; b=elb7wJjmHVmMnqrahneo3nmWE9hHEyTRVGuiSBGymfQVeOW15J6gqNykSrIgFdw9PIMbZF ta1kf9P/xFptBLk6yUizJYveQGUO6hzXz1/PIciaF5j55mJ3tEib32Ug4OJ35XYc+zlmf1 5OklhsBMYdcTGxBkNXOkqzloDUn2vJw= 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 v3 mm 1/4] lib/stackdepot: add printk_deferred_enter/exit guards Date: Tue, 19 Dec 2023 22:19:50 +0100 Message-Id: <82092f9040d075a161d1264377d51e0bac847e8a.1703020707.git.andreyknvl@google.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 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/ Fixes: 108be8def46e ("lib/stackdepot: allow users to evict stack traces") Fixes: cd11016e5f52 ("mm, kasan: stackdepot implementation. Enable stackdepot for SLAB") Reviewed-by: Marco Elver 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