Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5684186rdb; Wed, 13 Dec 2023 16:48:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGyDKgKITW1TLsZowTZTFbErneqXsdV/HLrMoqmdeILuU7OlOi8X0V2dyCuBeqVR2ScvQS7 X-Received: by 2002:a05:6870:e305:b0:1fb:4d2:9d21 with SMTP id z5-20020a056870e30500b001fb04d29d21mr9588931oad.45.1702514907704; Wed, 13 Dec 2023 16:48:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702514907; cv=none; d=google.com; s=arc-20160816; b=q4xYeup9r7D/80UfSJs3ULxx3UJD0zoq5JpyfqpXLN2mxfPIA/TgBBYhlPyoZKgi58 2z6LvlYq6huxcJfr4xvleQRLVTkq7xEPu9JCbI/4RsLlR4ZWnAGqVfH2BOKeYK7pH3IX If1hy2s2zhvtU31APkxvHu/O8HiDGPKwLw1pJ2taw3l8u/D7sUT9ATlF9MSOuKfsOh8Y 8FHWMlXJ04sbYafH2Q9LHc57ivdyiHWv8zBjekJym1uJXxxgqbCyn737EnJmwIlzJwBU IhVauG05JGNkPTr8ZGWPakta1xayPbY6c/m2AJx3td9hB+xpJ9TxWpvBzVY3tKUTLMEw eSLA== 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=nejB0rN/5EGuA3SQQpabp67CuxIikS5y1NrnTFuMISI=; fh=R37Itr4vM4DSdM7nCVEJRaUzpyR01xRhpmD5Puf7xME=; b=LoJnllf2f9VTGO1GWSec1hDQgp2NJlrCu5TW8wrnZNwSEukrG9oUW9fd2xi2X6gqVl 3JRdRi1eTpzGMPgtnkTXuPYDMqiY0SL3TDvu8kFBSXW+bvahX3jTHXMIQDZom88FfB4O qzYCGyIUyUDEdmYx6bf7jYuTDseEuqD71bv+lvBBw3lFtWHywVpwgHoIrjQj1FsVXIMe 1MvtO0Bq3oA2zrrXg7o05pZywhdIwh4c4FsS1VngJ9pBEcWwy8xuU3+7m/bGxXgBBMtp 6FbfJwpugQHreas3XwQy2qAT2fLjBkXvCVjzZS5gATAuh9RkCpQvlvTMr5Krc7r1LEn0 pa/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=NsLzL58t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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. [23.128.96.35]) by mx.google.com with ESMTPS id q9-20020a63f949000000b005c1cc7273bcsi10395816pgk.731.2023.12.13.16.48.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 16:48:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=NsLzL58t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 B6FAC80236F8; Wed, 13 Dec 2023 16:48:22 -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 S1442903AbjLNAr5 (ORCPT + 99 others); Wed, 13 Dec 2023 19:47:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234083AbjLNArz (ORCPT ); Wed, 13 Dec 2023 19:47:55 -0500 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CC4FA3 for ; Wed, 13 Dec 2023 16:48:01 -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=1702514879; 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=NsLzL58tlPR9ugxKAnRyMd8DrRr+SxvUinNtJYzd6v9CkqeQBI6h1vLxoqNrpoCC29ye9N snkjrMQ3Lu297rvZMIzUP/4NoNDeq3Szl+q2xjymcO6Gf9ebqHjZLk5pBsolFcBwIiCaFX W97yEg6DpDpdzNXtnmn6OJ6I/lrlXyI= 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 -v2 mm 1/4] lib/stackdepot: add printk_deferred_enter/exit guards Date: Thu, 14 Dec 2023 01:47:51 +0100 Message-Id: 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]); Wed, 13 Dec 2023 16:48:22 -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/ 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