From: Michal Hocko <mhocko@kernel.org>
To: Maninder Singh <maninder1.s@samsung.com>
Cc: jeyu@redhat.com, rusty@rustcorp.com.au,
akpm@linux-foundation.org, chris@chris-wilson.co.uk,
aryabinin@virtuozzo.com, joonas.lahtinen@linux.intel.com,
keescook@chromium.org, pavel@ucw.cz, jinb.park7@gmail.com,
anisse@astier.eu, rafael.j.wysocki@intel.com, zijun_hu@htc.com,
mingo@kernel.org, mawilcox@microsoft.com, thgarnie@google.com,
joelaf@google.com, kirill.shutemov@linux.intel.com,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
pankaj.m@samsung.com, ajeet.y@samsung.com,
hakbong5.lee@samsung.com, a.sahrawat@samsung.com,
lalit.mohan@samsung.com, cpgs@samsung.com,
Vaneet Narang <v.narang@samsung.com>
Subject: Re: [PATCH v2] module: check if memory leak by module.
Date: Wed, 29 Mar 2017 09:45:22 +0200 [thread overview]
Message-ID: <20170329074522.GB27994@dhcp22.suse.cz> (raw)
In-Reply-To: <1490767322-9914-1-git-send-email-maninder1.s@samsung.com>
On Wed 29-03-17 11:32:02, Maninder Singh wrote:
> This patch checks if any module which is going to be unloaded
> is doing vmalloc memory leak or not.
Hmm, how can you track _all_ vmalloc allocations done on behalf of the
module? It is quite some time since I've checked kernel/module.c but
from my vague understading your check is basically only about statically
vmalloced areas by module loader. Is that correct? If yes then is this
actually useful? Were there any bugs in the loader code recently? What
led you to prepare this patch? All this should be part of the changelog!
> Logs:-
> [ 129.336368] Module [test_module] is getting unloaded before doing vfree
> [ 129.336371] Memory still allocated: addr:0xffffc90001461000 - 0xffffc900014c7000, pages 101
> [ 129.336376] Allocating function kernel_init+0x1c/0x20 [test_module]
>
> Signed-off-by: Vaneet Narang <v.narang@samsung.com>
> Signed-off-by: Maninder Singh <maninder1.s@samsung.com>
> ---
> v1->v2: made code generic rather than dependent on config.
> changed pr_alert to pr_err.
>
> include/linux/vmalloc.h | 2 ++
> kernel/module.c | 22 ++++++++++++++++++++++
> mm/vmalloc.c | 2 --
> 3 files changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
> index 46991ad..5531af3 100644
> --- a/include/linux/vmalloc.h
> +++ b/include/linux/vmalloc.h
> @@ -29,6 +29,8 @@
> #define IOREMAP_MAX_ORDER (7 + PAGE_SHIFT) /* 128 pages */
> #endif
>
> +#define VM_VM_AREA 0x04
> +
> struct vm_struct {
> struct vm_struct *next;
> void *addr;
> diff --git a/kernel/module.c b/kernel/module.c
> index f953df9..98a8018 100644
> --- a/kernel/module.c
> +++ b/kernel/module.c
> @@ -2117,9 +2117,31 @@ void __weak module_arch_freeing_init(struct module *mod)
> {
> }
>
> +static void check_memory_leak(struct module *mod)
> +{
> + struct vmap_area *va;
> +
> + rcu_read_lock();
> + list_for_each_entry_rcu(va, &vmap_area_list, list) {
> + if (!(va->flags & VM_VM_AREA))
> + continue;
> + if ((mod->core_layout.base < va->vm->caller) &&
> + (mod->core_layout.base + mod->core_layout.size) > va->vm->caller) {
> + pr_err("Module [%s] is getting unloaded before doing vfree\n", mod->name);
> + pr_err("Memory still allocated: addr:0x%lx - 0x%lx, pages %u\n",
> + va->va_start, va->va_end, va->vm->nr_pages);
> + pr_err("Allocating function %pS\n", va->vm->caller);
> + }
> +
> + }
> + rcu_read_unlock();
> +}
> +
> /* Free a module, remove from lists, etc. */
> static void free_module(struct module *mod)
> {
> + check_memory_leak(mod);
> +
> trace_module_free(mod);
>
> mod_sysfs_teardown(mod);
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 68eb002..0166a0a 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -314,8 +314,6 @@ unsigned long vmalloc_to_pfn(const void *vmalloc_addr)
>
> /*** Global kva allocator ***/
>
> -#define VM_VM_AREA 0x04
> -
> static DEFINE_SPINLOCK(vmap_area_lock);
> /* Export for kexec only */
> LIST_HEAD(vmap_area_list);
> --
> 1.9.1
>
--
Michal Hocko
SUSE Labs
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2017-03-29 7:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20170329060315epcas5p1c6f7ce3aca1b2770c5e1d9aaeb1a27e1@epcas5p1.samsung.com>
2017-03-29 6:02 ` Maninder Singh
2017-03-29 7:45 ` Michal Hocko [this message]
2017-03-29 8:02 ` Miroslav Benes
[not found] ` <CGME20170329060315epcas5p1c6f7ce3aca1b2770c5e1d9aaeb1a27e1@epcms5p1>
2017-03-29 9:23 ` Vaneet Narang
2017-03-29 10:43 ` Michal Hocko
2017-03-31 6:49 ` Joel Fernandes
2017-03-31 8:00 ` Michal Hocko
2017-03-31 17:05 ` Joel Fernandes
2017-04-03 7:24 ` Michal Hocko
2017-03-31 22:18 ` Jessica Yu
2017-03-29 11:05 ` Andrey Ryabinin
2017-03-30 13:37 ` Pavel Machek
2017-03-30 14:31 ` Andrey Ryabinin
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=20170329074522.GB27994@dhcp22.suse.cz \
--to=mhocko@kernel.org \
--cc=a.sahrawat@samsung.com \
--cc=ajeet.y@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=anisse@astier.eu \
--cc=aryabinin@virtuozzo.com \
--cc=chris@chris-wilson.co.uk \
--cc=cpgs@samsung.com \
--cc=hakbong5.lee@samsung.com \
--cc=jeyu@redhat.com \
--cc=jinb.park7@gmail.com \
--cc=joelaf@google.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=keescook@chromium.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=lalit.mohan@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=maninder1.s@samsung.com \
--cc=mawilcox@microsoft.com \
--cc=mingo@kernel.org \
--cc=pankaj.m@samsung.com \
--cc=pavel@ucw.cz \
--cc=rafael.j.wysocki@intel.com \
--cc=rusty@rustcorp.com.au \
--cc=thgarnie@google.com \
--cc=v.narang@samsung.com \
--cc=zijun_hu@htc.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