2021-02-01 19:49:26

by Andrey Konovalov

[permalink] [raw]
Subject: [PATCH 04/12] kasan: clean up setting free info in kasan_slab_free

Put kasan_stack_collection_enabled() check and kasan_set_free_info()
calls next to each other.

The way this was previously implemented was a minor optimization that
relied of the the fact that kasan_stack_collection_enabled() is always
true for generic KASAN. The confusion that this brings outweights saving
a few instructions.

Signed-off-by: Andrey Konovalov <[email protected]>
---
mm/kasan/common.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/mm/kasan/common.c b/mm/kasan/common.c
index a7eb553c8e91..086bb77292b6 100644
--- a/mm/kasan/common.c
+++ b/mm/kasan/common.c
@@ -350,13 +350,11 @@ static bool ____kasan_slab_free(struct kmem_cache *cache, void *object,

kasan_poison(object, cache->object_size, KASAN_KMALLOC_FREE);

- if (!kasan_stack_collection_enabled())
- return false;
-
if ((IS_ENABLED(CONFIG_KASAN_GENERIC) && !quarantine))
return false;

- kasan_set_free_info(cache, object, tag);
+ if (kasan_stack_collection_enabled())
+ kasan_set_free_info(cache, object, tag);

return kasan_quarantine_put(cache, object);
}
--
2.30.0.365.g02bc693789-goog


2021-02-02 23:27:14

by Marco Elver

[permalink] [raw]
Subject: Re: [PATCH 04/12] kasan: clean up setting free info in kasan_slab_free

On Mon, Feb 01, 2021 at 08:43PM +0100, Andrey Konovalov wrote:
> Put kasan_stack_collection_enabled() check and kasan_set_free_info()
> calls next to each other.
>
> The way this was previously implemented was a minor optimization that
> relied of the the fact that kasan_stack_collection_enabled() is always
> true for generic KASAN. The confusion that this brings outweights saving
> a few instructions.
>
> Signed-off-by: Andrey Konovalov <[email protected]>

Reviewed-by: Marco Elver <[email protected]>

> ---
> mm/kasan/common.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> index a7eb553c8e91..086bb77292b6 100644
> --- a/mm/kasan/common.c
> +++ b/mm/kasan/common.c
> @@ -350,13 +350,11 @@ static bool ____kasan_slab_free(struct kmem_cache *cache, void *object,
>
> kasan_poison(object, cache->object_size, KASAN_KMALLOC_FREE);
>
> - if (!kasan_stack_collection_enabled())
> - return false;
> -
> if ((IS_ENABLED(CONFIG_KASAN_GENERIC) && !quarantine))
> return false;
>
> - kasan_set_free_info(cache, object, tag);
> + if (kasan_stack_collection_enabled())
> + kasan_set_free_info(cache, object, tag);
>
> return kasan_quarantine_put(cache, object);
> }
> --
> 2.30.0.365.g02bc693789-goog
>