mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Weilin Tong <tongweilin@linux.alibaba.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] mm: kmemleak: serialize disable-time cleanup
Date: Tue, 10 Nov 2026 16:53:13 +0000	[thread overview]
Message-ID: <avNL-a2YoZ3zqnoi@arm.com> (raw)
In-Reply-To: <149d93f2cfe20d355f4d9882ce2bf99030217772.1793871596.git.tongweilin@linux.alibaba.com>

On Thu, Nov 05, 2026 at 05:52:49PM +0800, Weilin Tong wrote:
> kmemleak_do_cleanup() drops scan_mutex before removing tracked objects
> without kmemleak_lock. A concurrent clear command can therefore start
> another cleanup while the background cleanup is still running.
> 
> Keep scan_mutex held until the background cleanup completes, serializing
> its lockless removals with explicit clearing and report readers.
> 
> Fixes: 2abd839aa7e6 ("kmemleak: Do not corrupt the object_list during clean-up")
> Assisted-by: LLM
> Signed-off-by: Weilin Tong <tongweilin@linux.alibaba.com>
> ---
>  mm/kmemleak.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/kmemleak.c b/mm/kmemleak.c
> index 20c0eb41c..d959d11f6 100644
> --- a/mm/kmemleak.c
> +++ b/mm/kmemleak.c
> @@ -2507,12 +2507,13 @@ static void kmemleak_do_cleanup(struct work_struct *work)
>  	 * function.
>  	 */
>  	kmemleak_free_enabled = 0;
> -	mutex_unlock(&scan_mutex);
>  
> +	/* Serialize the lockless cleanup with report readers. */
>  	if (!kmemleak_found_leaks)
>  		__kmemleak_do_cleanup();
>  	else
>  		pr_info("Kmemleak disabled without freeing internal data. Reclaim the memory with \"echo clear > /sys/kernel/debug/kmemleak\".\n");
> +	mutex_unlock(&scan_mutex);
>  }

Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>

-- 
Catalin

  reply	other threads:[~2026-11-10 16:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05  9:52 [PATCH 0/2] mm: kmemleak: avoid long RCU read-side sections in reports Weilin Tong
2026-11-05  9:52 ` [PATCH 1/2] mm: kmemleak: serialize disable-time cleanup Weilin Tong
2026-11-10 16:53   ` Catalin Marinas [this message]
2026-11-05  9:52 ` [PATCH 2/2] mm: kmemleak: reschedule while reading reports Weilin Tong
2026-11-10  5:17 ` [PATCH 0/2] mm: kmemleak: avoid long RCU read-side sections in reports Andrew Morton
2026-11-10  8:18   ` Weilin Tong
2026-11-11  7:44   ` Weilin Tong

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=avNL-a2YoZ3zqnoi@arm.com \
    --to=catalin.marinas@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=tongweilin@linux.alibaba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®