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: 13499115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAF71C41535 for ; Tue, 19 Dec 2023 21:20:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34FD76B0078; Tue, 19 Dec 2023 16:20:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DF696B007B; Tue, 19 Dec 2023 16:20:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12D666B007D; Tue, 19 Dec 2023 16:20:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id EA1756B0078 for ; Tue, 19 Dec 2023 16:20:00 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A98271C03DF for ; Tue, 19 Dec 2023 21:20:00 +0000 (UTC) X-FDA: 81584835360.15.5A939F8 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) by imf12.hostedemail.com (Postfix) with ESMTP id E6CA34001B for ; Tue, 19 Dec 2023 21:19:58 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=elb7wJjm; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703020799; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nejB0rN/5EGuA3SQQpabp67CuxIikS5y1NrnTFuMISI=; b=xJ5bVarqDpGyCyQCN92Wv5JaysHoAsDMS2mlbuuTPtH1JrWuZUZQZoeSK56L/vHhbBZnf9 /RiwB3O+8TzWv74JFT3BX27GoFCFjnBeupOLeqMqYfO+m3DMU705B/VbxfJ4XbHgMnaCBO u4Y2NFlyMRsAVG75XMKQ1UOCTQADF98= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=elb7wJjm; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf12.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703020799; a=rsa-sha256; cv=none; b=FzAZWwXD1Uyj9EcObhm137nKpZKpkk7HPEBdXZvoXPVdJOcImwlsHbdfg06uO2pady2qeP X65XrP+raB9TWYNDBI6B6IsfBNz12G6yz31/P5X5SBFVUWCcaJVlyjjXDQpjkd5y2eZx2Z eBhvU2VIqjVyWtQqy++xta4DvnNfH4s= 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: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: E6CA34001B X-Stat-Signature: s3camqy69ih9z3r1o18y97r38g7ppfhs X-HE-Tag: 1703020798-937322 X-HE-Meta: U2FsdGVkX1+dIegCAWc1wkrMHfKkUdZ3vMqNzt1kQC91o/yQnq5ygp0Cfm8qrFtAZnjh3TJ2r5hMTttNL+DeMMrFvIXL0oGnN324/2bnchzizoLTgKH/qrYac1RX1UUwYnSqJza5v2PFfmuwWN8aeK1M9z09YuS9PIg74w8TvVVTJywp8EIWlzWpaSMRJFC1T+4XMXYQV7UKItwdDb2ZUjDHqxixEHohuTnWnpLZOwwOq5YGLB2mc6fF6K5F5xUAk87eDfR0t9h4KA/tX7mlsNZGlUQe1/4sYWCWNGoZREp7Vnz2+sJF8MjkhiG9uQrzlWVpY2HbjE0LstlUatchbCDz9yNlwluuPJQJ6owixTrONDgBrjKeAWRLCzMiXa0XqL97bJUQpw02RsFXqiUu+NwkDvoBTXA/2RrZlWG/tcLUooaRVdDD51JJYCctJjis7XOFnKeuTEwtdxODIBvKrfUUB2Imd9487rKSvJJgW4jDp9t30R13NCijAWK8a4v7TgfSre1H7l5Qphhh6qRyvR8D3gv4Hj8VoLjrr4q23zQ6Yc9aQcwvZT0N++Ee32R+kFLspJCUoEDSah9zbtHhPBLjhcMD6yS3HNVjsA7Jvpg3kxoWgRTf8QpuCdcUBWCJNZC3D6G9d7PWzFLO9q/CTHlug25WkZHxMQNv/1KVnfMRDYNMM43UApsQUzBLP8ntGy3WhCzQle0P8v256xIQpNEOvkSzyEBhvksC5ZX7tSxOMJMPjaoJEGwH3wyzJIcmC0TWy6nvMRb+LlNu8YKycMDh/ETVenxH83bUnTLV46cTqSAH2QgmzL7hTCwD2sZJHr2+FxJ7cR3wPeHac1qowoU2R5ohaR1+eevDhjV6Q3d5laeNsWMSIK+6+pOe7iuEYFiRmoaERBjWHLigJXn5H3hteTKeOli+AGqJSY9kEPxppAapSVCuAT2xXefcg6IWAn7a0FUlJQMVE3w0i8b ZMEq70fr wAFjrCmEcT4jT2wVqnIAmJB+lCpUecHISfdw0crfN4hcnuyQ9OtUrNuUmu0FdLWTiPTwR2nbt2X7cWtC+3hRm158HQOTOUTGzSe8Q2FkmABS7/CsgoN10yC7WNz4f5qhqYcu1RW5MEwAtv2drQQYFVKWoXvVhWqpVuQa2Kj0E7ZyxJS4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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);