linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: linux-kernel@vger.kernel.org, Shakeel Butt <shakeelb@google.com>,
	Marek Szyprowski <m.szyprowski@samsung.com>,
	linux-mm@kvack.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/1] mm: Fix memory leak on mm_init error handling
Date: Thu, 30 Mar 2023 12:42:30 -0700	[thread overview]
Message-ID: <20230330124230.9f3d4f63374eb15a3b990ff8@linux-foundation.org> (raw)
In-Reply-To: <20230330133822.66271-1-mathieu.desnoyers@efficios.com>

On Thu, 30 Mar 2023 09:38:22 -0400 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> wrote:

> commit f1a7941243c1 ("mm: convert mm's rss stats into percpu_counter")
> introduces a memory leak by missing a call to destroy_context() when a
> percpu_counter fails to allocate.
> 
> Before introducing the per-cpu counter allocations, init_new_context()
> was the last call that could fail in mm_init(), and thus there was no
> need to ever invoke destroy_context() in the error paths. Adding the
> following percpu counter allocations adds error paths after
> init_new_context(), which means its associated destroy_context() needs
> to be called when percpu counters fail to allocate.
> 
> ...
>
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -1171,6 +1171,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p,
>  fail_pcpu:
>  	while (i > 0)
>  		percpu_counter_destroy(&mm->rss_stat[--i]);
> +	destroy_context(mm);
>  fail_nocontext:
>  	mm_free_pgd(mm);
>  fail_nopgd:

Is there really a leak?  I wasn't able to find a version of
init_new_context() which performs allocation.



  parent reply	other threads:[~2023-03-30 19:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-30 13:38 Mathieu Desnoyers
2023-03-30 16:52 ` Shakeel Butt
2023-03-30 19:42 ` Andrew Morton [this message]
2023-03-30 19:55   ` Shakeel Butt
2023-03-30 19:56   ` Mathieu Desnoyers

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=20230330124230.9f3d4f63374eb15a3b990ff8@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=m.szyprowski@samsung.com \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=shakeelb@google.com \
    --cc=stable@vger.kernel.org \
    /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