Received: by 2002:ab2:2997:0:b0:1ec:cbc4:63fb with SMTP id n23csp514316lqb; Thu, 29 Feb 2024 07:25:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVOdSJKj7P2L+N6OZOm9VGegVCzo49Cqytf5/TrusP7bCsrPG/ET8V1gHwFUf/I0Hu5m3qLZptOmlgzenBf7iZhl/x6s2sGW9sw2XtPhA== X-Google-Smtp-Source: AGHT+IEJzlhi/7GXChUrtTAv9nHnCiPh/OYAvPHcGvtsWBYSFw4AmG1tXULLAkZooDEtLaRJh/0A X-Received: by 2002:a17:902:edc2:b0:1dc:7856:220e with SMTP id q2-20020a170902edc200b001dc7856220emr1893550plk.39.1709220336049; Thu, 29 Feb 2024 07:25:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709220336; cv=pass; d=google.com; s=arc-20160816; b=gGVRQlD68r8ZbDcyia16DdJwaWsHuUxWMcmlLlOZ//UfRtASQuszmgV0G9toyeGGra jTRftidjcSLjYdm0HoV9Ic33P/oWs9ifoInqMn1wXf66HchwEC4RScrj6kRSalRQhiTt ZV9HblkwhSU5nV/E+mHYSEPFByIuavFzKzr8mX1gDvrWzt5FiD0+8/uL/x8NB4yHdH0p hIQE90xDGm7Kp22G8q1H3IfLoyiyI2gSpKZN/YDMQbjJ8O2peGlrvYgX1k3wM8AOzmpK wi98ul7aFeaG7e15c9DPtwi5Sy9wSC2GCvStXhISBRf5ZQzeqEOUNSZ4vd4k0OJZF3jm GwTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=NddWsksePxt/rhV2MH+AW0K4DAhsx1gDSIGFyAaV0Kc=; fh=VpO+0gcKzSS0x09o7aIL0+6GbjT6NBeM0ac+CmcIPt4=; b=InuWO70DnuWTGwn8r533ln0OXrSWAHtBPYzkxtOb/TBGfr9mlhdI28hgoQKmLCODl/ d1yOj/zh9MeqLILTZxloFJY9Unc153pKZlodig/vQiepPo8SRzXbC6Axj0ycr9edn9Fk hqLJakfDpcuGLrljL/72aC1MeBDUwxwpt6PuPfrFOa0H/EVTrxKTcSM6rWMOvtzIFT/U vJO2g3iFiTcmroOJyUU6k8sC7B8tzZHILHUOquf10yNdt/mDQXwR3gjtwJRsN8KoJTzs aP2U5TQCoZ93nN/U88F+fKWCaYiqQPPy1UOC8TWR9Y0e/RKP5KiLi5l151Krlb63V52W /icQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-86921-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86921-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x16-20020a170902ec9000b001dbe5c1f2eesi1536830plg.223.2024.02.29.07.25.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 07:25:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86921-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-86921-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86921-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B73E82888BB for ; Thu, 29 Feb 2024 15:25:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 91DAD1468EB; Thu, 29 Feb 2024 15:25:23 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E14613EFF6 for ; Thu, 29 Feb 2024 15:25:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709220323; cv=none; b=bSXDfYyQQHNzt04I0YWWS/LfFkwNXuo9aF6uHjXDLB3mP20DGGCMwXqEUlY5rOS0SKzHcyaxKPZTL5pgybZtf6YRJsjFklOdDWK0y0XcokXBwUtgEwmjuQ3zOla3DaI0NPPi6V0uaNC0JznCPwsNHyGc5LB9Hpaart4cJaXVXIk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709220323; c=relaxed/simple; bh=sHkcD/snZ9V2Xv3mBv4VaxRarjPZsfN4VaX4NZfL+Mg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cK26tGXIdTyoUGlvodVMWgWUIFM56qplCIr4GpQF6nAsiTMOHgUFdIqIZ7euZiNFHtndxolM560ifpxYQ+xC5B+f5Vhrw+vV3es2HzMRGNjkG8LxA2ZonRjEskPkyx8Rqr8hf5uu0+NNrrOu9W6EYHssAilphpgBs2liYjse8uA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240228191444.481048-1-longman@redhat.com> 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