Re: [PATCH 1/3] kasan: deduplicate quarantine reduction logic

From: Andrey Konovalov

Date: Mon Jul 06 2026 - 11:18:48 EST


On Sat, Jul 4, 2026 at 11:20 AM Igor Putko <igorpetindev@xxxxxxxxx> wrote:
>
> Multiple allocation functions share the exact same conditional logic for
> reducing the KASAN quarantine size based on gfp flags.
> Introduce the kasan_quarantine_reduce_cond() helper to eliminate this
> boilerplate from the slab, kmalloc, kmalloc_large, and krealloc paths.
>
> Signed-off-by: Igor Putko <igorpetindev@xxxxxxxxx>
> ---
> mm/kasan/common.c | 18 ++++++++++--------
> 1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/mm/kasan/common.c b/mm/kasan/common.c
> index b7d05c2a6..34aa0fdce 100644
> --- a/mm/kasan/common.c
> +++ b/mm/kasan/common.c
> @@ -340,14 +340,19 @@ static inline void unpoison_slab_object(struct kmem_cache *cache, void *object,
> kasan_save_alloc_info(cache, object, flags);
> }
>
> +static inline void kasan_quarantine_reduce_cond(gfp_t flags)
> +{
> + if (gfpflags_allow_blocking(flags))
> + kasan_quarantine_reduce();
> +}

Not sure about this change: it's hiding the condition for when
kasan_quarantine_reduce() gets to execute and does not really improve
the code readability otherwise.






> +
> void * __must_check __kasan_slab_alloc(struct kmem_cache *cache,
> void *object, gfp_t flags, bool init)
> {
> u8 tag;
> void *tagged_object;
>
> - if (gfpflags_allow_blocking(flags))
> - kasan_quarantine_reduce();
> + kasan_quarantine_reduce_cond(flags);
>
> if (unlikely(object == NULL))
> return NULL;
> @@ -402,8 +407,7 @@ static inline void poison_kmalloc_redzone(struct kmem_cache *cache,
> void * __must_check __kasan_kmalloc(struct kmem_cache *cache, const void *object,
> size_t size, gfp_t flags)
> {
> - if (gfpflags_allow_blocking(flags))
> - kasan_quarantine_reduce();
> + kasan_quarantine_reduce_cond(flags);
>
> if (unlikely(object == NULL))
> return NULL;
> @@ -443,8 +447,7 @@ static inline void poison_kmalloc_large_redzone(const void *ptr, size_t size,
> void * __must_check __kasan_kmalloc_large(const void *ptr, size_t size,
> gfp_t flags)
> {
> - if (gfpflags_allow_blocking(flags))
> - kasan_quarantine_reduce();
> + kasan_quarantine_reduce_cond(flags);
>
> if (unlikely(ptr == NULL))
> return NULL;
> @@ -460,8 +463,7 @@ void * __must_check __kasan_krealloc(const void *object, size_t size, gfp_t flag
> {
> struct slab *slab;
>
> - if (gfpflags_allow_blocking(flags))
> - kasan_quarantine_reduce();
> + kasan_quarantine_reduce_cond(flags);
>
> if (unlikely(object == ZERO_SIZE_PTR))
> return (void *)object;
> --
> 2.47.3
>