diff mbox series

[022/200] mm/slab: rerform init_on_free earlier

Message ID 20201215030433.7QkafHjX1%akpm@linux-foundation.org (mailing list archive)
State New, archived
Headers show
Series [001/200] kthread: add kthread_work tracepoints | expand

Commit Message

Andrew Morton Dec. 15, 2020, 3:04 a.m. UTC
From: Alexander Popov <alex.popov@linux.com>
Subject: mm/slab: rerform init_on_free earlier

Currently in CONFIG_SLAB init_on_free happens too late, and heap objects
go to the heap quarantine not being erased.

Lets move init_on_free clearing before calling kasan_slab_free().  In that
case heap quarantine will store erased objects, similarly to CONFIG_SLUB=y
behavior.

Link: https://lkml.kernel.org/r/20201210183729.1261524-1-alex.popov@linux.com
Signed-off-by: Alexander Popov <alex.popov@linux.com>
Reviewed-by: Alexander Potapenko <glider@google.com>
Acked-by: David Rientjes <rientjes@google.com>
Acked-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/slab.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Alexander Potapenko Dec. 15, 2020, 4:45 p.m. UTC | #1
On Tue, Dec 15, 2020 at 4:04 AM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> From: Alexander Popov <alex.popov@linux.com>
> Subject: mm/slab: rerform init_on_free earlier

Nit: s/rerform/perform

>
> Currently in CONFIG_SLAB init_on_free happens too late, and heap objects
> go to the heap quarantine not being erased.
>
> Lets move init_on_free clearing before calling kasan_slab_free().  In that
> case heap quarantine will store erased objects, similarly to CONFIG_SLUB=y
> behavior.
>
> Link: https://lkml.kernel.org/r/20201210183729.1261524-1-alex.popov@linux.com
> Signed-off-by: Alexander Popov <alex.popov@linux.com>
> Reviewed-by: Alexander Potapenko <glider@google.com>
> Acked-by: David Rientjes <rientjes@google.com>
> Acked-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
> Cc: Christoph Lameter <cl@linux.com>
> Cc: Pekka Enberg <penberg@kernel.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
>
>  mm/slab.c |    5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> --- a/mm/slab.c~mm-slab-perform-init_on_free-earlier
> +++ a/mm/slab.c
> @@ -3417,6 +3417,9 @@ free_done:
>  static __always_inline void __cache_free(struct kmem_cache *cachep, void *objp,
>                                          unsigned long caller)
>  {
> +       if (unlikely(slab_want_init_on_free(cachep)))
> +               memset(objp, 0, cachep->object_size);
> +
>         /* Put the object into the quarantine, don't touch it for now. */
>         if (kasan_slab_free(cachep, objp, _RET_IP_))
>                 return;
> @@ -3435,8 +3438,6 @@ void ___cache_free(struct kmem_cache *ca
>         struct array_cache *ac = cpu_cache_get(cachep);
>
>         check_irq_off();
> -       if (unlikely(slab_want_init_on_free(cachep)))
> -               memset(objp, 0, cachep->object_size);
>         kmemleak_free_recursive(objp, cachep->flags);
>         objp = cache_free_debugcheck(cachep, objp, caller);
>         memcg_slab_free_hook(cachep, &objp, 1);
> _
Alexander Popov Dec. 15, 2020, 8:46 p.m. UTC | #2
On 15.12.2020 19:45, Alexander Potapenko wrote:
> On Tue, Dec 15, 2020 at 4:04 AM Andrew Morton <akpm@linux-foundation.org> wrote:
>>
>> From: Alexander Popov <alex.popov@linux.com>
>> Subject: mm/slab: rerform init_on_free earlier
> 
> Nit: s/rerform/perform

Right, thanks, Alexander!

Andrew, should I resend the patch?
Alexander Popov Dec. 15, 2020, 9:08 p.m. UTC | #3
On 15.12.2020 23:46, Alexander Popov wrote:
> On 15.12.2020 19:45, Alexander Potapenko wrote:
>> On Tue, Dec 15, 2020 at 4:04 AM Andrew Morton <akpm@linux-foundation.org> wrote:
>>>
>>> From: Alexander Popov <alex.popov@linux.com>
>>> Subject: mm/slab: rerform init_on_free earlier
>>
>> Nit: s/rerform/perform
> 
> Right, thanks, Alexander!
> 
> Andrew, should I resend the patch?

Hm, this typo is not from my patch.
I guess my resending is not needed.

Best regards,
Alexander
diff mbox series

Patch

--- a/mm/slab.c~mm-slab-perform-init_on_free-earlier
+++ a/mm/slab.c
@@ -3417,6 +3417,9 @@  free_done:
 static __always_inline void __cache_free(struct kmem_cache *cachep, void *objp,
 					 unsigned long caller)
 {
+	if (unlikely(slab_want_init_on_free(cachep)))
+		memset(objp, 0, cachep->object_size);
+
 	/* Put the object into the quarantine, don't touch it for now. */
 	if (kasan_slab_free(cachep, objp, _RET_IP_))
 		return;
@@ -3435,8 +3438,6 @@  void ___cache_free(struct kmem_cache *ca
 	struct array_cache *ac = cpu_cache_get(cachep);
 
 	check_irq_off();
-	if (unlikely(slab_want_init_on_free(cachep)))
-		memset(objp, 0, cachep->object_size);
 	kmemleak_free_recursive(objp, cachep->flags);
 	objp = cache_free_debugcheck(cachep, objp, caller);
 	memcg_slab_free_hook(cachep, &objp, 1);