From patchwork Tue Dec 19 21:19:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 181262 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2234549dyi; Tue, 19 Dec 2023 13:21:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLwt8bXwyRGh2VeVwdbSS2wQtdzEQV6bVxL7kQYqC63slcbBS9ISMclAOS59ii8bWkmkcg X-Received: by 2002:a05:6a20:1483:b0:18c:9855:e949 with SMTP id o3-20020a056a20148300b0018c9855e949mr14393558pzi.15.1703020860002; Tue, 19 Dec 2023 13:21:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703020859; cv=none; d=google.com; s=arc-20160816; b=uwFwWCtNqIt9kBP9d1/HHtUKLaSzChDfJVcAbGPuoIUc3QWEZiL/0VUFaN1lhKtEqj v5BDZCi+7G5v49DDZV+OnJbpu/0xI9TKPkKRuEEDuliGlWpAF4kxPKu9k3OcNIeh1b0M eD6Pp2/nojhmi+4X4EzRGD/Ws0BZK1UVwgSwNnM5WpcC7/W9xU+d2SHlu4FkX+g3Z+cZ WXXqiP5ntQ1HJO0MocOCEyvfiv4KpsM4J6mH5CRFpcbQF6QHZUXOrg8br49/786yvlq5 DSY8NOuwlNWB+kNjmZAHNgrvHwN7xq7jE7ToFgd12ndewWUR3harQiHQAozj3dpLIWAq DH6Q== 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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5959-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id fc29-20020a056a002e1d00b006d0a6b4b95dsi14134698pfb.384.2023.12.19.13.20.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Dec 2023 13:20:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-5959-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::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-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-5959-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C1CA8287841 for ; Tue, 19 Dec 2023 21:20:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE9E040BE4; Tue, 19 Dec 2023 21:20:03 +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 X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785746801550215148 X-GMAIL-MSGID: 1785746801550215148 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);