All of lore.kernel.org
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Zhongqiu Han <zhongqiu.han@oss.qualcomm.com>
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
Date: Tue, 3 Feb 2026 18:00:07 +0000	[thread overview]
Message-ID: <aYI3pzddATnKSbvZ@arm.com> (raw)
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 <zhongqiu.han@oss.qualcomm.com>
> ---
>  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 <catalin.marinas@arm.com>


      reply	other threads:[~2026-02-03 18:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-30  9:37 [PATCH 0/2] mm/kmemleak: Improve scan_should_stop() implementation Zhongqiu Han
2026-01-30  9:37 ` [PATCH 1/2] mm/kmemleak: Remove unreachable return statement in scan_should_stop() Zhongqiu Han
2026-02-03 17:55   ` Catalin Marinas
2026-01-30  9:37 ` [PATCH 2/2] mm/kmemleak: Use PF_KTHREAD flag to detect kernel threads Zhongqiu Han
2026-02-03 18:00   ` Catalin Marinas [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aYI3pzddATnKSbvZ@arm.com \
    --to=catalin.marinas@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=zhongqiu.han@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.