Received: by 2002:ab2:3319:0:b0:1ef:7a0f:c32d with SMTP id i25csp110751lqc; Thu, 7 Mar 2024 11:46:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWBQj0CSIb+XO+e99kulpAaZmh4dFSL7p2VQhRakhOECnL9EiuZeb7fKE2IArxsXAMwc5fgKUMMA0wy+Av08tsuuCfTlmsAf50NmXegHQ== X-Google-Smtp-Source: AGHT+IEoDBhzVUcrz0O99RyOCVgZJkvQkEOXIQsnwC8fscm5/kYqqSTjj2MuurUxjvMrVMjexEuQ X-Received: by 2002:a05:6359:4c2a:b0:17b:85ff:8fe6 with SMTP id kj42-20020a0563594c2a00b0017b85ff8fe6mr10484756rwc.25.1709840799254; Thu, 07 Mar 2024 11:46:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709840799; cv=pass; d=google.com; s=arc-20160816; b=kVCfwMmM1j1BLDigDI2jn73AlQ5r3svRdW6yZOlO42nWaY6ezh/r+JA3qkwi5pdAJg yrX8MBNRSFbJVXHmA/ov3UFsiZylZQW/Gf11basQpknvONgftQdV29rL4jE4RoJ3ldpK vWk+GIcT2vMe6UXDAqJHz0hrzdgwsaPDpEeNe0SE1ESQ5QsxiVtE9GjFL5dl7heEZopN esZrBujy8vUWek2CsBAT33Oa6ovTLUD3CyV59B9pUnFZXw8lNtZH+L2BxCR3YpO1t1NW oH75QAdmR8wTqBRO/+0zXAG+PpzAoLBal2sA9ITnkklbAfhCaG9H5bpGQ0/UJIKBHvea P7Kg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=YKVj3AmYdIGS1hS5Bx8ducYL25JEqQhDXqMSV9sIYvU=; fh=Kzus0XlNkanWzYluLLoYNrYpOD2nmNsTiIApEUKSWkk=; b=uIRp/5etwTyEr8GeHmnikP8xh/xAJ2weAsfn7EBgZGdclMkR/2UzX2vqHGhIpw6RnO vT387PNNeT0ulP9cq4TaaThenZOLgLcArW/CVygrRfy8i0jDsXVMP2uJRlnP1oiTZpUn n76lFrDxt38tZaZ2I9CahEf2hsjRBvZ+Ol+QYnjDx4RC61y68D+GZmu3MbCoPZVHwPwX EAhn0q4+O/J3UwdQwxNY6tTBLLUgwXlxXdEVh7A6qYzuRwYtqrbPM/TCni8TmuWlOEyU 0N8FRDOwVC5s1Q9wdu58disUg0hSYp42XvpHlJ6ksEyDvF6cp27bBlG9a0A/Be+6rTrl ekeQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=eauGu7pU; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-96126-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96126-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id gs13-20020a056214226d00b0068feccf8d45si17106330qvb.412.2024.03.07.11.46.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Mar 2024 11:46:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-96126-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=eauGu7pU; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-96126-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-96126-linux.lists.archive=gmail.com@vger.kernel.org" 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id F00BA1C20A58 for ; Thu, 7 Mar 2024 19:46:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 389D81369A4; Thu, 7 Mar 2024 19:46:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="eauGu7pU" 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 2590D41A88 for ; Thu, 7 Mar 2024 19:46:31 +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=1709840792; cv=none; b=o+nB1o7/vi/Ms5e+++3Zd9GJltrj5NLP6SQGFzJugMa56LiLxnuNCQkzccwRddhd52FtwzZoESJfPRv6umlFbpmj4PT9OOH6r9lLsKfnn3ofppHO1vHwZEFTTd27JC6lt6aqxkW+AcchI8sEnkBasK3mCInJk6Me9ZlcQwkO+zU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709840792; c=relaxed/simple; bh=ZkoLriIFMqvbtvNzCDlOVN4ynWY6JZVhyoE0r2/dOLc=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=iDV4W6O0qWg1tIJP09l3fYCEsTQ3TjEAMktNqBFxR7wr7Vd8eGxNfdb8V64u1RcSv+QGaHdL2lwu9Q49st9sqr54o2u9YmgLNgMxBc+DSORGWbnex7L+PqxDOmbObLnA0jPu6vhWAdXi3/JfISVKrj+T3802i58Tx4J77jX1LEc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=eauGu7pU; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65E5CC433C7; Thu, 7 Mar 2024 19:46:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1709840791; bh=ZkoLriIFMqvbtvNzCDlOVN4ynWY6JZVhyoE0r2/dOLc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=eauGu7pU2cnbm5PxdoOPGqcJrKJWzalQoLQXnotDT8SMjSUVteZDfVN0M4hjcp6h0 NkY5wvnlqgftIA9ras3eqMPnZ7Zl7YvRJSlUqpa8FE6Mb5kIbdDPnY6TuLkLieCcBR EGimGhHMtu4+jQFG2i4YN7Ri0mdT9wMGljK3Etdc= Date: Thu, 7 Mar 2024 11:46:30 -0800 From: Andrew Morton To: Waiman Long Cc: Catalin Marinas , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Audra Mitchell Subject: Re: [PATCH v2] mm/kmemleak: Don't hold kmemleak_lock when calling printk() Message-Id: <20240307114630.32702099ac24c182b91da517@linux-foundation.org> In-Reply-To: <20240307184707.961255-1-longman@redhat.com> References: <20240307184707.961255-1-longman@redhat.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) 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-Transfer-Encoding: 7bit On Thu, 7 Mar 2024 13:47:07 -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. > > An abbreviated lockdep splat is as follows: > > ... > > Fix this deadlock issue by making sure that printk() is only called > after releasing the kmemleak_lock. > > ... > > @@ -427,9 +442,19 @@ static struct kmemleak_object *__lookup_object(unsigned long ptr, int alias, > else if (untagged_objp == untagged_ptr || alias) > return object; > else { > + if (!get_object(object)) > + break; > + /* > + * Release kmemleak_lock temporarily to avoid deadlock > + * in printk(). dump_object_info() is called without > + * holding object->lock (race unlikely). > + */ > + raw_spin_unlock(&kmemleak_lock); > kmemleak_warn("Found object by alias at 0x%08lx\n", > ptr); > dump_object_info(object); > + put_object(object); > + raw_spin_lock(&kmemleak_lock); > break; Please include a full description of why this is safe. Once we've dropped that lock, the tree is in an unknown state and we shouldn't touch it again. This consideration should be added to the relevant functions' interface documentation and the code should be reviewed to ensure that we're actually adhering to this. Or something like that. To simply drop and reacquire a lock without supporting analysis and comments does not inspire confidence!