From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC67B3659E7 for ; Tue, 3 Feb 2026 18:00:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770141613; cv=none; b=NkF+iI9CoaNGB71CwKV/W1nq2biOcuK5Oqtbk9x6MG8f8619n+FQFKy8uA6/KgsDicRGNmKcqc5pOLXMSD2SagrHrmCPiLSyQDOlgvUzQZfWfeT4BOfzTS2m+g63/gl69iHid/+KY/shVmHhOm9pB8+pWCb7KVw7+m4VPgFQUK4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770141613; c=relaxed/simple; bh=CynqQD+9e9WBobrLWYiYg4V++PdgNVz7F8OfpEhKx2Q=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=vFG2hWMjpXlJWYnhlfYvFz3EObmYWYqWlFCPsFXHx9BkQgnVs3m2QRIWKY/L/HcwF3+pHfME0qTyS0UuKaMvbB5j9Ejj3tmzg8YoGHX7qfqHHQ5N7Yai5uaqG4vSry6m9NE37s6CyQgkiEj4lYaDfBxYBq9dBTkIGT4Ki5JXCKc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B7C90339; Tue, 3 Feb 2026 10:00:04 -0800 (PST) Received: from arm.com (arrakis.cambridge.arm.com [10.1.197.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3BD113F740; Tue, 3 Feb 2026 10:00:10 -0800 (PST) Date: Tue, 3 Feb 2026 18:00:07 +0000 From: Catalin Marinas To: Zhongqiu Han Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] mm/kmemleak: Use PF_KTHREAD flag to detect kernel threads Message-ID: References: <20260130093729.2045858-1-zhongqiu.han@oss.qualcomm.com> <20260130093729.2045858-3-zhongqiu.han@oss.qualcomm.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: <20260130093729.2045858-3-zhongqiu.han@oss.qualcomm.com> On Fri, Jan 30, 2026 at 05:37:29PM +0800, Zhongqiu Han wrote: > Replace the current->mm check with PF_KTHREAD flag for more reliable > kernel thread detection in scan_should_stop(). The PF_KTHREAD flag is the > standard way to identify kernel threads and is not affected by temporary > mm borrowing via use_mm() (although kmemleak does not currently encounter > such cases, this makes the code more robust). Nitpick: it's called kthread_use_mm() now. But you are right, this function is either called in a user thread context (via a sysfs write) or from the kthread that kmemleak created which would not use kthread_use_mm(). > No functional change. > > Signed-off-by: Zhongqiu Han > --- > mm/kmemleak.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/mm/kmemleak.c b/mm/kmemleak.c > index fb0022f34393..eb2ffbaf2f7e 100644 > --- a/mm/kmemleak.c > +++ b/mm/kmemleak.c > @@ -1507,10 +1507,10 @@ static int scan_should_stop(void) > * This function may be called from either process or kthread context, > * hence the need to check for both stop conditions. > */ > - if (current->mm) > - return signal_pending(current); > + if (current->flags & PF_KTHREAD) > + return kthread_should_stop(); > > - return kthread_should_stop(); > + return signal_pending(current); Acked-by: Catalin Marinas