From patchwork Thu Dec 14 00:47:51 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: 178389 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8222778dys; Wed, 13 Dec 2023 16:48:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IH5C4b2mpesYS/Ew7BcQGHBuROgPRjLbvBDIf7WJf+LcScX2g4+hOwpPumPIGHiv1STAlpd X-Received: by 2002:a05:6358:7e83:b0:170:9559:4ffb with SMTP id o3-20020a0563587e8300b0017095594ffbmr6862236rwn.8.1702514897589; Wed, 13 Dec 2023 16:48:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702514897; cv=none; d=google.com; s=arc-20160816; b=LtUTsgmIJWAbFeVi+xCj29R9e1kRsMK9/4p1pA4qBb4KnaS8+tYXzLjD+721W4ImCH 10A5TrGX3R+NDhxIg16/TnJD6KShCgyl+ILhaf4HN2t8vKVlzh3n6GLFGnuLqd94w3Ks 3Gqyna2ZAYqal/b8Yr5mZ0uWaeOvJba2eOCWhwjdcEs7G3SqSmUwwWtiWu6crcfLCSHd MFNLyAe4iPEZSDZnCqtIktiiyXMnzWnqAX8ejhyfknGCY5JXU79AF4HmyFyxTySicrCV NYh5e/aLNZ9QzWjF6/ltNdBBHaAejHu3cpLYujp9Nj2rCSA3Z1gt3aQgtNU7+igHq7Ja aPcw== 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 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id n8-20020a17090a9f0800b0028acb4f3a23si2999533pjp.70.2023.12.13.16.48.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 16:48:17 -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=NsLzL58t; 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 A561180236F2; Wed, 13 Dec 2023 16:48:10 -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 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:10 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785216261521288981 X-GMAIL-MSGID: 1785216261521288981 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);