Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6753939rdb; Tue, 2 Jan 2024 12:08:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IESoQC6alpWZR6t+h59OZHcVU7gK1w2LMT1/qIR+mZ6Yj6NbgYFEPU9fndZq43mm8KjyxhA X-Received: by 2002:ad4:4307:0:b0:67f:dee9:3700 with SMTP id c7-20020ad44307000000b0067fdee93700mr15815793qvs.72.1704226082676; Tue, 02 Jan 2024 12:08:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704226082; cv=none; d=google.com; s=arc-20160816; b=M/cZ90LXh0PzCvVO/bRoOGLtGfNMx8ycJynYRclG2LSEFEIMWviGDdVU2JxzNIqDax 1QnoGv8H+9FQPDrHKDhMQ3+4x9V2YlCFuJ5XglW07hsZsJCJ4ZD2OemHcMYGa2+1h5lx 0wJQTPx7U5mpRCGzJHoTkf4Ees0zl0rmgK+2LDFYeCz5Iq+NxeeVUfimOnxMk3rU46xY uqkN6OPcfBOgGO2vJipSIgliz+ODaK7Vn4uzZeYlNiQFb/xsac7MR3AMMkIgG6WcpOK1 V3hxIxmzsiMdTPVXBA6iEYW2XabCRg6DzLepE9Itrr0Qk1n8HmSY5ADFbfsvd8RVMAMt nOVg== ARC-Message-Signature: i=1; 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=jcac+gyGZD2lOdKTwLHmvHWXTE+UAEIIci8Kz3Z6L5c=; fh=KtmhezHLadpBu5ciHnX8CrMPr3RbK3cOlKQKoLcBA7Y=; b=CIjf6S71CpQyqgOpUkqLcUi59g4S2LvbvylHl+KKKxADIq97Ho8QvFqR9ChnGmXGaX lEueaRUemNkoMJrIvFCyT8iVO9pp9FQW4PQWHlCM9PlatB/FkwDWgUMRhyoCblWjpnJ2 j+plOSQvNUhIXtjNMTbSrSihV1gd8TiB0O1IimneFj8y+Yt9JNVWOw9wmnV0TKvaVuRC VesSLA850b4aXPEON0MLZVCmgr0txcjrzqxJP4yQPSyDKGaIRmuOsRA63fi5DGl6WCCP AUzgbkUT2YWH//nXsNGXAvzlCng6708dxeNcGUHU93/3vOmsMfxQUv6LtwZLBv2JhVzu 4Duw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14793-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m22-20020a05620a291600b007816c894164si14343543qkp.370.2024.01.02.12.08.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 12:08:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14793-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14793-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 6E7B01C22A3A for ; Tue, 2 Jan 2024 20:08:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4B7831640B; Tue, 2 Jan 2024 20:07:57 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org 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 D65EC16403 for ; Tue, 2 Jan 2024 20:07:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DCCDC433C8; Tue, 2 Jan 2024 20:07:55 +0000 (UTC) Date: Tue, 2 Jan 2024 20:07:52 +0000 From: Catalin Marinas To: Chris von Recklinghausen Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH] don't record leak information on allocations done between kmemleak_init and kmemleak_late_init Message-ID: References: <20240102153428.139984-1-crecklin@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: <20240102153428.139984-1-crecklin@redhat.com> On Tue, Jan 02, 2024 at 10:34:28AM -0500, Chris von Recklinghausen wrote: > If an object is allocated after kmemleak_init is called but before > kmemleak_late_init is called, calls to kmemleak_not_leak or > kmemleak_ignore on the object don't prevent a scan from reporting the > object as a leak. This may be true but what is the reason for this? Can you give some example of false positives you get? > Avoid this situation by only registering objects in kmemleak_alloc when > kmemleak_initialized is set. I wouldn't do this, kmemleak needs to track all the early allocations, otherwise it will lead to lots of false positives. However, looking at your patch, it looks like it doesn't touch kmemleak_alloc() at all and it does something completely different. > diff --git a/mm/kmemleak.c b/mm/kmemleak.c > index 5501363d6b31..0c8a5f456874 100644 > --- a/mm/kmemleak.c > +++ b/mm/kmemleak.c > @@ -1117,7 +1117,8 @@ void __ref kmemleak_free_part(const void *ptr, size_t size) > { > pr_debug("%s(0x%px)\n", __func__, ptr); > > - if (kmemleak_enabled && ptr && !IS_ERR(ptr)) > + if (kmemleak_enabled && kmemleak_late_initialized && ptr && > + !IS_ERR(ptr)) > delete_object_part((unsigned long)ptr, size, false); > } This leaves some memory to still be tracked by kmemleak when it was actually freed. Later when it is reallocated, you'll get some errors and kmemleak will disable itself. > EXPORT_SYMBOL_GPL(kmemleak_free_part); > @@ -1135,7 +1136,8 @@ void __ref kmemleak_free_percpu(const void __percpu *ptr) > > pr_debug("%s(0x%px)\n", __func__, ptr); > > - if (kmemleak_free_enabled && ptr && !IS_ERR(ptr)) > + if (kmemleak_free_enabled && kmemleak_late_initialized && ptr && > + !IS_ERR(ptr)) > for_each_possible_cpu(cpu) > delete_object_full((unsigned long)per_cpu_ptr(ptr, > cpu)); Same here. > @@ -1189,7 +1191,8 @@ void __ref kmemleak_not_leak(const void *ptr) > { > pr_debug("%s(0x%px)\n", __func__, ptr); > > - if (kmemleak_enabled && ptr && !IS_ERR(ptr)) > + if (kmemleak_enabled && kmamleak_late_initialized && ptr && ^^^ I guess you haven't compiled this patch. Does it actually fix the problem you are reporting? > + !IS_ERR(ptr)) > make_gray_object((unsigned long)ptr); > } This change doesn't help at all with your problem statement. > EXPORT_SYMBOL(kmemleak_not_leak); > @@ -1207,7 +1210,8 @@ void __ref kmemleak_ignore(const void *ptr) > { > pr_debug("%s(0x%px)\n", __func__, ptr); > > - if (kmemleak_enabled && ptr && !IS_ERR(ptr)) > + if (kmemleak_enabled && kmamleak_late_initialized && ptr && > + !IS_ERR(ptr)) > make_black_object((unsigned long)ptr, false); > } > EXPORT_SYMBOL(kmemleak_ignore); Neither does this. Also if you re-post, please cc linux-mm as well. Andrew Morton tends to pick up the kmemleak patches (once acked). -- Catalin