From mboxrd@z Thu Jan 1 00:00:00 1970 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 45407C54E41 for ; Thu, 29 Feb 2024 15:25:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC7D56B0095; Thu, 29 Feb 2024 10:25:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A77866B0098; Thu, 29 Feb 2024 10:25:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 964C06B0099; Thu, 29 Feb 2024 10:25:29 -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 844E86B0095 for ; Thu, 29 Feb 2024 10:25:29 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 22E8B4031D for ; Thu, 29 Feb 2024 15:25:29 +0000 (UTC) X-FDA: 81845215578.24.206AAAC Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf21.hostedemail.com (Postfix) with ESMTP id 19AE91C0009 for ; Thu, 29 Feb 2024 15:25:26 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf21.hostedemail.com: domain of cmarinas@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709220327; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NddWsksePxt/rhV2MH+AW0K4DAhsx1gDSIGFyAaV0Kc=; b=hRAKdX6jGFn3TJ0fImfd/3nuV+xll9NPhlSsDy8c8oOzWXoInPTKRInlK//KJQSPnSTLvW Ujz4pxae5dkgAb7CoMVkNbLh0eiE2kDlO+fBzOqA9VQTe9vZ8oZDgAjRyjr3cFsEiKdnUU tGVF8zzOoi3hku/JzAnQjdLsd8OSBMA= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf21.hostedemail.com: domain of cmarinas@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=cmarinas@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709220327; a=rsa-sha256; cv=none; b=GUDTjkc+vDH93EbQQV8sBjAPtwQPt6ZXtYLIsss5Q/exsM1q0vvJu5lG0A+Pc91cmCMWfI x9Gd0/vUYqVBDNSW9eMRmNsOo4AqI1bKmShWrFaUeSuBWsz6PRmxu6B3UR8F/RJHoFkguf gTSdrFWAPGLwt/QsQgBRNUBlqtg6NnY= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id B52F4CE1AEE; Thu, 29 Feb 2024 15:25:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C302FC43399; Thu, 29 Feb 2024 15:25:21 +0000 (UTC) Date: Thu, 29 Feb 2024 15:25:19 +0000 From: Catalin Marinas To: Waiman Long Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Audra Mitchell Subject: Re: [PATCH] mm/kmemleak: Don't hold kmemleak_lock when calling printk() Message-ID: References: <20240228191444.481048-1-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240228191444.481048-1-longman@redhat.com> X-Rspamd-Server: rspam09 X-R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xjZ53 kHpKL/xP GKS57pM8hbE0aXYc7RKUz/lmpn7FrxwdWnLeG+yZE3Q+oo9aOp7qAg+Ajhk6UnAOISZP/l3WKZDbT53qoERAfCOXf1A== 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: On Wed, Feb 28, 2024 at 02:14:44PM -0500, Waiman Long wrote: > When some error conditions happen (like OOM), some kmemleak functions > call printk() to dump out some useful debugging information while holding > the kmemleak_lock. This may cause deadlock as the printk() function > may need to allocate additional memory leading to a create_object() > call acquiring kmemleak_lock again. > > Fix this deadlock issue by making sure that printk() is only called > after releasing the kmemleak_lock. I can't say I'm familiar with the printk() code but I always thought it uses some ring buffers as it can be called from all kind of contexts and allocation is not guaranteed. If printk() ends up taking kmemleak_lock through the slab allocator, I wonder whether we have bigger problems. The lock order is always kmemleak_lock -> object->lock but if printk() triggers a callback into kmemleak, we can also get object->lock -> kmemleak_lock ordering, so another potential deadlock. -- Catalin