linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RT] mm/slub: close possible memory-leak in kmem_cache_alloc_bulk()
@ 2017-12-13 14:05 Sebastian Andrzej Siewior
  2017-12-13 14:46 ` Jesper Dangaard Brouer
  0 siblings, 1 reply; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2017-12-13 14:05 UTC (permalink / raw)
  To: linux-rt-users, Jesper Dangaard Brouer
  Cc: linux-kernel, tglx, Peter Zijlstra, Steven Rostedt,
	Vladimir Davydov, linux-mm

Under certain circumstances we could leak elements which were moved to
the local "to_free" list. The damage is limited since I can't find any
users here.

Cc: stable-rt@vger.kernel.org
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
Jesper: There are no users of kmem_cache_alloc_bulk() and kfree_bulk().
Only kmem_cache_free_bulk() is used since it was introduced. Do you
think that it would make sense to remove those?

 mm/slub.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mm/slub.c b/mm/slub.c
index ffd2fa0f415e..9053e929ce9d 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -3240,6 +3240,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
 	return i;
 error:
 	local_irq_enable();
+	free_delayed(&to_free);
 	slab_post_alloc_hook(s, flags, i, p);
 	__kmem_cache_free_bulk(s, i, p);
 	return 0;
-- 
2.15.1

--
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>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH RT] mm/slub: close possible memory-leak in kmem_cache_alloc_bulk()
  2017-12-13 14:05 [PATCH RT] mm/slub: close possible memory-leak in kmem_cache_alloc_bulk() Sebastian Andrzej Siewior
@ 2017-12-13 14:46 ` Jesper Dangaard Brouer
  2017-12-13 14:50   ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 3+ messages in thread
From: Jesper Dangaard Brouer @ 2017-12-13 14:46 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-rt-users, linux-kernel, tglx, Peter Zijlstra,
	Steven Rostedt, Vladimir Davydov, linux-mm, brouer, Rao Shoaib,
	Paul E. McKenney

On Wed, 13 Dec 2017 15:05:55 +0100
Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:

> Under certain circumstances we could leak elements which were moved to
> the local "to_free" list. The damage is limited since I can't find any
> users here.
> 
> Cc: stable-rt@vger.kernel.org
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> ---
> Jesper: There are no users of kmem_cache_alloc_bulk() and kfree_bulk().
> Only kmem_cache_free_bulk() is used since it was introduced. Do you
> think that it would make sense to remove those?

I would like to keep them.

Rao Shoaib (Cc'ed) is/was working on a patchset for RCU-bulk-free that
used the kfree_bulk() API.

I plan to use kmem_cache_alloc_bulk() in the bpf-map "cpumap", for bulk
allocating SKBs during dequeue of XDP frames.  (My original bulk alloc
SKBs use-case during NAPI/softirq was never merged).


>  mm/slub.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/mm/slub.c b/mm/slub.c
> index ffd2fa0f415e..9053e929ce9d 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -3240,6 +3240,7 @@ int kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t size,
>  	return i;
>  error:
>  	local_irq_enable();
> +	free_delayed(&to_free);
>  	slab_post_alloc_hook(s, flags, i, p);
>  	__kmem_cache_free_bulk(s, i, p);
>  	return 0;

I've not seen free_delayed() before... and my cscope cannot find it...

-- 
Best regards,
  Jesper Dangaard Brouer
  MSc.CS, Principal Kernel Engineer at Red Hat
  LinkedIn: http://www.linkedin.com/in/brouer

--
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>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH RT] mm/slub: close possible memory-leak in kmem_cache_alloc_bulk()
  2017-12-13 14:46 ` Jesper Dangaard Brouer
@ 2017-12-13 14:50   ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2017-12-13 14:50 UTC (permalink / raw)
  To: Jesper Dangaard Brouer
  Cc: linux-rt-users, linux-kernel, tglx, Peter Zijlstra,
	Steven Rostedt, Vladimir Davydov, linux-mm, Rao Shoaib,
	Paul E. McKenney

On 2017-12-13 15:46:54 [+0100], Jesper Dangaard Brouer wrote:
> > Jesper: There are no users of kmem_cache_alloc_bulk() and kfree_bulk().
> > Only kmem_cache_free_bulk() is used since it was introduced. Do you
> > think that it would make sense to remove those?
> 
> I would like to keep them.
> 
> Rao Shoaib (Cc'ed) is/was working on a patchset for RCU-bulk-free that
> used the kfree_bulk() API.
> 
> I plan to use kmem_cache_alloc_bulk() in the bpf-map "cpumap", for bulk
> allocating SKBs during dequeue of XDP frames.  (My original bulk alloc
> SKBs use-case during NAPI/softirq was never merged).

I see. So it may gain users in future you say.

> I've not seen free_delayed() before... and my cscope cannot find it...
It is PREEMPT RT only, mainline is not affected (that is why there is a
RT next to the PATCH in subject).

Sebastian

--
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>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-12-13 14:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-13 14:05 [PATCH RT] mm/slub: close possible memory-leak in kmem_cache_alloc_bulk() Sebastian Andrzej Siewior
2017-12-13 14:46 ` Jesper Dangaard Brouer
2017-12-13 14:50   ` Sebastian Andrzej Siewior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox