Message ID | 20221220182704.181657-2-urezki@gmail.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [1/2] mm: vmalloc: Avoid a double lookup of freed VA in a tree | expand |
On Tue, Dec 20, 2022 at 07:27:04PM +0100, Uladzislau Rezki (Sony) wrote: > Currently a vm_unmap_ram() functions triggers a BUG() if an area > is not found. Replace it by the WARN_ON_ONCE() error message and > keep machine alive instead of stopping it. > > The worst case is a memory leaking. > > Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com> > --- > mm/vmalloc.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 0fc38c36e0df..e05a0dc79ac5 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -2255,10 +2255,12 @@ void vm_unmap_ram(const void *mem, unsigned int count) > } > > va = find_unlink_vmap_area(addr); > - BUG_ON(!va); > - debug_check_no_locks_freed((void *)va->va_start, > - (va->va_end - va->va_start)); > - free_unmap_vmap_area(va); > + > + if (!WARN_ON_ONCE(!va)) { > + debug_check_no_locks_freed((void *)va->va_start, > + (va->va_end - va->va_start)); > + free_unmap_vmap_area(va); > + } > } > EXPORT_SYMBOL(vm_unmap_ram); > > -- > 2.30.2 > Will send a v2. -- Uladzislau Rezki
On Tue, Dec 20, 2022 at 07:27:04PM +0100, Uladzislau Rezki (Sony) wrote: > Currently a vm_unmap_ram() functions triggers a BUG() if an area > is not found. Replace it by the WARN_ON_ONCE() error message and > keep machine alive instead of stopping it. > > The worst case is a memory leaking. > > Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com> > --- > mm/vmalloc.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 0fc38c36e0df..e05a0dc79ac5 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -2255,10 +2255,12 @@ void vm_unmap_ram(const void *mem, unsigned int count) > } > > va = find_unlink_vmap_area(addr); > - BUG_ON(!va); > - debug_check_no_locks_freed((void *)va->va_start, > - (va->va_end - va->va_start)); > - free_unmap_vmap_area(va); > + > + if (!WARN_ON_ONCE(!va)) { > + debug_check_no_locks_freed((void *)va->va_start, > + (va->va_end - va->va_start)); > + free_unmap_vmap_area(va); > + } > } > EXPORT_SYMBOL(vm_unmap_ram); > > -- > 2.30.2 > Absolutely in favour of this in principle (BUG_ON() is something we should resort to in only the direst of circumstances), one small nit - perhaps it'd be neater to simply make this a guard clause? E.g.:- if (!WARN_ON_ONCE(!va)) return; ...
On Tue, Dec 20, 2022 at 06:53:18PM +0000, Lorenzo Stoakes wrote: [snip > Absolutely in favour of this in principle (BUG_ON() is something we should > resort to in only the direst of circumstances), one small nit - perhaps it'd be > neater to simply make this a guard clause? E.g.:- > > if (!WARN_ON_ONCE(!va)) > return; > > ... Made a mistake here, meant to say if (WARN_ON_ONCE(!va)) return; Of course :) Apologies, only just noticed you are sending a v2, perhaps something to consider for it? But will hold off further review until you send it! :)
On Tue, Dec 20, 2022 at 06:56:38PM +0000, Lorenzo Stoakes wrote: > On Tue, Dec 20, 2022 at 06:53:18PM +0000, Lorenzo Stoakes wrote: > [snip > > Absolutely in favour of this in principle (BUG_ON() is something we should > > resort to in only the direst of circumstances), one small nit - perhaps it'd be > > neater to simply make this a guard clause? E.g.:- > > > > if (!WARN_ON_ONCE(!va)) > > return; > > > > ... > > Made a mistake here, meant to say > > if (WARN_ON_ONCE(!va)) > return; > Agree. This looks better. Less confusing :) I will post a v2. -- Uladzislau Rezki
diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 0fc38c36e0df..e05a0dc79ac5 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2255,10 +2255,12 @@ void vm_unmap_ram(const void *mem, unsigned int count) } va = find_unlink_vmap_area(addr); - BUG_ON(!va); - debug_check_no_locks_freed((void *)va->va_start, - (va->va_end - va->va_start)); - free_unmap_vmap_area(va); + + if (!WARN_ON_ONCE(!va)) { + debug_check_no_locks_freed((void *)va->va_start, + (va->va_end - va->va_start)); + free_unmap_vmap_area(va); + } } EXPORT_SYMBOL(vm_unmap_ram);
Currently a vm_unmap_ram() functions triggers a BUG() if an area is not found. Replace it by the WARN_ON_ONCE() error message and keep machine alive instead of stopping it. The worst case is a memory leaking. Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com> --- mm/vmalloc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)