From patchwork Tue Dec 12 00:14:00 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: 13488207 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 7FC1EC4332F for ; Tue, 12 Dec 2023 00:14:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F186F6B0259; Mon, 11 Dec 2023 19:14:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EC8E46B025A; Mon, 11 Dec 2023 19:14:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D90386B025B; Mon, 11 Dec 2023 19:14:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C8C316B0259 for ; Mon, 11 Dec 2023 19:14:12 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A2A4DC08CF for ; Tue, 12 Dec 2023 00:14:12 +0000 (UTC) X-FDA: 81556243944.11.D944569 Received: from out-179.mta1.migadu.com (out-179.mta1.migadu.com [95.215.58.179]) by imf08.hostedemail.com (Postfix) with ESMTP id C028D160014 for ; Tue, 12 Dec 2023 00:14:10 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ZFY0MXvU; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf08.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.179 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=1702340051; 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=vOaXJmSZ4mgcOuCRTmHs9viCNJ5mspLX8zhenk2W1qY=; b=HTvy3Ozw4PUfprfRS3p8wsLn0RCxH/IKBXObnFssHND4zqfH5X3wxmiuNnKb2h8mxGTJ52 iINzNMJ3aCYdpLf7gV2orVBj0T0KYYQz0xt2AEm9+j/I2FpvVGA4WlrVhrOedMN028swav neQ3cl8cOi8JwFTqOfqjIQWq32YiVmc= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=ZFY0MXvU; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf08.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.179 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702340051; a=rsa-sha256; cv=none; b=es3N3b7Lyb3buSIBADDKNMgJWYVETxwxiURsoX0NNeiMjx9HMB2HWegnNI4EA8BAI4BYEd e/GDjkvHOq+ipApVItWHFCa6r0YXj4sc1oAicWxKfpcp6Xo2sitIGifFUVXQQ+hP4Dglck XA02kQ3xsAKxXJxSOqzKKJWuo7EvVTg= 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=1702340049; 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=vOaXJmSZ4mgcOuCRTmHs9viCNJ5mspLX8zhenk2W1qY=; b=ZFY0MXvUwTln62U1tHBt6KK8Dqg+6tfH+i/GfcUa4eujPC2CC53JaDXpaZhT1eWOt98GO5 rQ36NXtwX/bnZpsUbbyhXz3bTvVFqA6FvpYHeqX+qP0YEUP3BL6KN8k/7Q6TNtfpTILzXF HbnIpR5duzaXmjUbV13x2oH9iQ3NxmE= 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 mm 1/4] lib/stackdepot: add printk_deferred_enter/exit guards Date: Tue, 12 Dec 2023 01:14:00 +0100 Message-Id: <6c38c31e304a55449f76f60b6f72e35f992cad99.1702339432.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: C028D160014 X-Stat-Signature: 7t9etemgps1i9kzzc7xhmfhag74ks7h4 X-HE-Tag: 1702340050-338247 X-HE-Meta: U2FsdGVkX1/NO4XaoIiTV3CNXMXeJD6xikIBb2IGEx0Foob9VWAYtxZgBZG5Q2WVsyhkoRWPYvEyc5vHcvYriT5qHDue9w+YqxrWV3ctaJo6te1ftdyCSiZn9n2vss+JVCLuB02Z/nt03OUiqV2FtEIDiV34ZEFBKCbFP+DNqhzk1H1lkxxpDCcTBzmQ1GndWwI7iiJP3dwcz2d255YSygXX5HZhFB7+YOWD3CpP1mpr1nxIlF6FNtZjBeslGS5hYWMRbuMOhWCsKom1O94auBtjdOJMwkTC1Q4w+NDbvzlfDWMncs7YsmsSb2LnllXfiIIP5eqx2TAxCb7unlkgjZLz1hnyTu19zmMS/qvQ3tyWPMXijpf2TLC/7uIbaZ+3RM2ZJMrlr6vy3SVTZziNf1k2XBZxGdfVAtTBmt79GVsbmfMKto/iSyVun+g9sy6qYgSTvAIIXXX8XV1w+xQZuerHJUBnY70dYdNn6+z40Tl/tLk+wkSjV43L81GuZzcHQpFG7g/TzCzPD9gzuokucCVXY2WKJMeORZWhnVv7W+wHeI346hEhSXzNNwxtVf/iubbeyKjSHDe6a1hKLEZY+fGStMl+Ob1J/A4Q/nsDSR9bSQjZD81jy6LtQLHHpzus3WJbvJFDp235LaVevftWuPRBv/Ar6boINleQ7WsSNdFLvYHvyvN0G5+UAzImMR+sB1ow2HfgnvVJOSKoQCWrPnD0DDfr5Fy5DQ0fqwhYVfp2LTZExN+0DMbzE2SmU5FgBVxY9yLaCGHXx5x/L7sZQxNSMhKpFdV8l+aIdv6TF2g0f4MVG06TYp3TewsFF1mXJaUu7s4blO0zagcjWXgtFVtrwY5KPdZBn87mUC/rJwrPqIsoDlkEMhELv0UdiG4BIqf6hnmWWZv7eFIlnQAJPirltTM0raBuMAp8/+YxXrGb6MVRaYHnrii2WX6RUQLCkfpY4ZmIfB4QjXON3k9 XfxGWbxW /2YLj4ASotOqhrU9FdDG67Z/GrykTdY1OrmnLMPhsQ2ICkipcxGXDyZzU41s9vLdHMPfn6mBWEhyXdA7KHIfvm8k4mikO1HiL6mjIBuJAvQqrn2boxbzZeZH0KiHaTPCJL/1DJTv0rrBd1dCuu8EdKYnIxuX5oNU7qYCunKNJ/L4OflY= 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/ Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver --- 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);