All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Putko <igorpetindev@gmail.com>
To: ryabinin.a.a@gmail.com, glider@google.com, andreyknvl@gmail.com,
	dvyukov@google.com, vincenzo.frascino@arm.com,
	akpm@linux-foundation.org
Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, Igor Putko <igorpetindev@gmail.com>
Subject: [PATCH 1/3] kasan: deduplicate quarantine reduction logic
Date: Sat,  4 Jul 2026 12:20:05 +0300	[thread overview]
Message-ID: <20260704092007.3483-2-igorpetindev@gmail.com> (raw)
In-Reply-To: <20260704092007.3483-1-igorpetindev@gmail.com>

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@gmail.com>
---
 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();
+}
+
 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


  reply	other threads:[~2026-07-04  9:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-04  9:20 [PATCH 0/3] kasan: common: cleanups and deduplication Igor Putko
2026-07-04  9:20 ` Igor Putko [this message]
2026-07-06 14:13   ` [PATCH 1/3] kasan: deduplicate quarantine reduction logic Andrey Konovalov
2026-07-04  9:20 ` [PATCH 2/3] kasan: common: use ALIGN_DOWN macro for stack alignment Igor Putko
2026-07-06 14:13   ` Andrey Konovalov
2026-07-04  9:20 ` [PATCH 3/3] kasan: common: replace magic number with KASAN_TAG_KERNEL Igor Putko
2026-07-06 14:13   ` Andrey Konovalov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260704092007.3483-2-igorpetindev@gmail.com \
    --to=igorpetindev@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ryabinin.a.a@gmail.com \
    --cc=vincenzo.frascino@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.