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: 13492153 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 ACDAAC4332F for ; Thu, 14 Dec 2023 00:48:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3EF708D0082; Wed, 13 Dec 2023 19:48:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 39F3C8D0080; Wed, 13 Dec 2023 19:48:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2418E8D0082; Wed, 13 Dec 2023 19:48:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 115EA8D0080 for ; Wed, 13 Dec 2023 19:48:03 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id D6475C0BD2 for ; Thu, 14 Dec 2023 00:48:02 +0000 (UTC) X-FDA: 81563586804.14.CFE1815 Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) by imf18.hostedemail.com (Postfix) with ESMTP id 116D41C001C for ; Thu, 14 Dec 2023 00:48:00 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=NsLzL58t; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf18.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.182 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=1702514881; 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=egb4xss8WawqRXAQrR/gig4Rf0oQeqrHcfOBIa1JUsNHv4NgnRBmfQnX5Be41JCCGzDNpE N10jSLjTPgbTuAJfj+8wGXHu+BCy3KbFjaQU7L6RyMwESdKqyaxLc9LjjDGPFf4kFFR9Qd 6y+QQewg5vUzZI/WS2fitowYADVesII= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=NsLzL58t; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf18.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.182 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702514881; a=rsa-sha256; cv=none; b=yVnFBZEjHuEZ/fZ9yaCK3lN43flSjoZ82sc5w4qhuG8Ol4lUr6Sv+Hvtd4ieCuv5QCWSj2 bv5GKWZqOAyaLSvKYRKyymopLLfelrJUQnyG8xO4yiTyYNAkpNrWUk48XFfMjBXlvWPi5e jHs1D82DJnQTXp4kefK+Wqsr7CqKW6U= 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-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 116D41C001C X-Stat-Signature: dyxn5i9b4tio9iexinmitthqa6ax863m X-Rspam-User: X-HE-Tag: 1702514880-706932 X-HE-Meta: U2FsdGVkX18lqL44YSC2NqNCvk0dfouUg5GZ0DHwddD++Opm0YjmXCGhrexom0V963entZESEfkm7ZK07ERo/7Pr5O52v7CG67pJmpEw+O6SOcVToF0pQFMkyNWcarEgRL1LYdEa8QGWEzRJQ/MEM6KNKy2TMSTjP2RZuRAJrmi00p4uJQFxtOoWxVQGEogtRa9sCTraGpiKuCvmU4MPO8sW08cH9F/RwuF60cdakngOoZ7asP3UfyE0MCPwdMyCI2AmWwwICgXuDlx0zpjY9nT4X2hcfBXFpDwcqmTEHLhpK/o4Sbvp/5sxeAd/jB2O0O7pp3mJgdbwVLuuj84FIQZ2jIt+A+bsKr1LtCSHQwF+g+AGt/tbIBvjh2BTL0uZ+EI3Hbg4Ds7/jd0XhfKps7ARwRJTLGVjK18jYer0b7iu1XnoAJ5Ifvn2r+6nVy5UN+4ysSBmhq6HB0dGVZl9IHWjXw2kFYtqyKgAe4Ca6ZbdV+c7Z26pN42ZC811FIABmtgBHKvmW1v34PMJErpu+YfF6IZa5iarVIxa24iL40QCKQggTqXyKfvPtrRibzewNOQQvitA+aarTssSrM2k8Bc9ewtVc9127aqG1DuS1UbDm93IsgDpmK9sJCrzxzENon0iNuFkAn5yG2Ddb4lVHd7Mk7CP1DkIzgcLmDmX9e9AMB3Ca9DfryPQHx4Xi6B1g8AnXRJ1N7g6H+ZpQFR17J+EUJkianOQIhx+tZ/du8tfWmy0EK9tARwemtJpGZzw4d+76xWds3e9AB9LwzXPM8QOUypjE/H4eDTaYLtLOSq06rsvexf7SDaSd8y4cPuL3pXz5J2t+cEI3BYdNqSIMPHRCezhf0zhH7dj9hDpLBlfGbvuc3Z6pHO23pk7KyM3SnHPhozg+iqKd/BOTgOsn+SnJdigcarnphimssqoc3t2kF2+42fDVfQk+odn1AHXC60q8y9RRaCdGAhpCM7 GKxs8a/V ZOo0i5kfV4Hzrg70k93Cj48L3QAbJ4F6agAopqiYrRNhQZeA356Y5kgFJxyInaep+sKAdT5M7AQVC/9wZsqRXndgJ6ujJo4x2WhLb6bDTnyD8rIBaKnjLDHEBDV7iXUdjIQeZNvxQbduK006l+ZBg23nIun0ioIa6MbLYxISdcSfOTIo= 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);