Message ID | 20221121135024.1655240-2-feng.tang@intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1600896wrr; Mon, 21 Nov 2022 05:57:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf45br0dTMuVl9nPQiDdJxc58/2QCHVrjZNmEfaW8yESbTsrVkBO4zO/rCZXzlF2/NHGQINZ X-Received: by 2002:aa7:cc93:0:b0:462:6b8e:1ddb with SMTP id p19-20020aa7cc93000000b004626b8e1ddbmr16124471edt.276.1669039038206; Mon, 21 Nov 2022 05:57:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669039038; cv=none; d=google.com; s=arc-20160816; b=ti5sqxOSrBHTr6S+5jLTGl2YTay0/eYguYdH/7AsWkSsmw6aYKwKZzaz/KCfVaxIB+ LubpKkjLZNaiY+BPsbCcGP2/m1hFGf3QW2SofSjccujRuGPM+//Qg8JCKaZ9cVnr9tLI zdjxuIrKGNaxGCJ6Xw71oC7Taxu4V99ERuiLjeChlfskJ9H6eVM5RThvlGxrgRwoyQQ9 Xyak0XDg3qiFf+OJXNSjCAf+T6CTNmRwxPJ2O6r5rulfvHw7wlKm/yJ+OCZ51KbZQq49 7HlaNRoYXq9leXHIpNbtJW0hj38Uw3WFzgUqELcJAgaFzJAscxzzT3vw/Aj9h9Zj/dWE zv9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qGPUeE4ITf2p+O2BZkcAmNpuuPsa1nAB6HxRM2M3MtI=; b=uhWCMosFhwbsJwwiYv+emwg68t1Tl0BKkPeCvwhthBNzn38zYxPxvExkN1X0Zc2sB5 WU2o2w49RxYooxG3k3WE0s9kk9zRQu1n++YKnUHOkVcqdkE5TkB+HVzDzs2szDcK7kZB vVFEISRzs6bfLEpIRAWnKI5ipbh+odnvOf1jawF2MWr9YmJrII/wEeSL1EqVS+/5FEeb z7LjqGCcwOtXeRv0VG3D4f46/HXp08VvJ4KzPIns5Wf14MmS+UGDiX4hq6PDV50eAuVB bzNx3VmOg0q4/Jwjs+EcUSG6rz7KTIzACqoqUL9UMLhEyFDCYGc5vIiylX+2JIfZHO11 qy/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BBXMjNn1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xb14-20020a170907070e00b007b28c6790edsi10006791ejb.205.2022.11.21.05.56.49; Mon, 21 Nov 2022 05:57:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BBXMjNn1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231335AbiKUNxf (ORCPT <rfc822;cjcooper78@gmail.com> + 99 others); Mon, 21 Nov 2022 08:53:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbiKUNxb (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 21 Nov 2022 08:53:31 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F101B94AE for <linux-kernel@vger.kernel.org>; Mon, 21 Nov 2022 05:53:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1669038810; x=1700574810; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xAgBqOEUMmWoQfbkuo6RneBuqFILZ8nL3SYVkdsI98s=; b=BBXMjNn1G6DZ7lRQKRZAUM6N+9CBmlwTI5MkcZu1sHgxL7wpYd6wkpKA QoBR3DzvnHMtYaIISy6rYqK5fSxAISFVW3N4ByEs5iObMXmKit3iP5cJI C9tfbMSZOfIVc3xOk1YrTILOZ+CIDDjUz8Q/T7SNEO//+yoyxLvoKsgsn USY09+bweTQjQgvkADb7O+wVlIaJ+FSTCoIpZWLcTPc9GNZWBDLUYdbCn pbkQCYp8uLE+zu/fTyA+hrLqAZfxKjfbpf/cq+LV9rS9C5AjXFxcuzp3E jcbKaKHYFf6udyxj+LdZXnq+iYX039HEh9hpbMcH2Dv0i7chTme5QdVgL g==; X-IronPort-AV: E=McAfee;i="6500,9779,10538"; a="312261165" X-IronPort-AV: E=Sophos;i="5.96,181,1665471600"; d="scan'208";a="312261165" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Nov 2022 05:53:30 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10537"; a="886125108" X-IronPort-AV: E=Sophos;i="5.96,181,1665471600"; d="scan'208";a="886125108" Received: from feng-clx.sh.intel.com ([10.238.200.228]) by fmsmga006.fm.intel.com with ESMTP; 21 Nov 2022 05:53:26 -0800 From: Feng Tang <feng.tang@intel.com> To: Andrew Morton <akpm@linux-foundation.org>, Vlastimil Babka <vbabka@suse.cz>, Christoph Lameter <cl@linux.com>, Pekka Enberg <penberg@kernel.org>, David Rientjes <rientjes@google.com>, Joonsoo Kim <iamjoonsoo.kim@lge.com>, Roman Gushchin <roman.gushchin@linux.dev>, Hyeonggon Yoo <42.hyeyoo@gmail.com>, Andrey Konovalov <andreyknvl@gmail.com>, Dmitry Vyukov <dvyukov@google.com>, Andrey Ryabinin <ryabinin.a.a@gmail.com>, Alexander Potapenko <glider@google.com>, Vincenzo Frascino <vincenzo.frascino@arm.com> Cc: linux-mm@kvack.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, Feng Tang <feng.tang@intel.com> Subject: [PATCH -next 2/2] mm/kasan: simplify is_kmalloc check Date: Mon, 21 Nov 2022 21:50:24 +0800 Message-Id: <20221121135024.1655240-2-feng.tang@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221121135024.1655240-1-feng.tang@intel.com> References: <20221121135024.1655240-1-feng.tang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750114278647681113?= X-GMAIL-MSGID: =?utf-8?q?1750114278647681113?= |
Series |
[-next,1/2] mm/slab: add is_kmalloc_cache() helper macro
|
|
Commit Message
Feng Tang
Nov. 21, 2022, 1:50 p.m. UTC
Use new is_kmalloc_cache() to simplify the code of checking whether
a kmem_cache is a kmalloc cache.
Signed-off-by: Feng Tang <feng.tang@intel.com>
---
include/linux/kasan.h | 9 ---------
mm/kasan/common.c | 9 ++-------
mm/slab_common.c | 1 -
3 files changed, 2 insertions(+), 17 deletions(-)
Comments
On Mon, Nov 21, 2022 at 09:50:24PM +0800, Tang, Feng wrote: > Use new is_kmalloc_cache() to simplify the code of checking whether > a kmem_cache is a kmalloc cache. > > Signed-off-by: Feng Tang <feng.tang@intel.com> > --- > include/linux/kasan.h | 9 --------- > mm/kasan/common.c | 9 ++------- > mm/slab_common.c | 1 - > 3 files changed, 2 insertions(+), 17 deletions(-) > > diff --git a/include/linux/kasan.h b/include/linux/kasan.h > index dff604912687..fc46f5d6f404 100644 > --- a/include/linux/kasan.h > +++ b/include/linux/kasan.h > @@ -102,7 +102,6 @@ struct kasan_cache { > int alloc_meta_offset; > int free_meta_offset; > #endif > - bool is_kmalloc; > }; > > void __kasan_unpoison_range(const void *addr, size_t size); > @@ -129,13 +128,6 @@ static __always_inline bool kasan_unpoison_pages(struct page *page, > return false; > } > > -void __kasan_cache_create_kmalloc(struct kmem_cache *cache); > -static __always_inline void kasan_cache_create_kmalloc(struct kmem_cache *cache) > -{ > - if (kasan_enabled()) > - __kasan_cache_create_kmalloc(cache); > -} > - > void __kasan_poison_slab(struct slab *slab); > static __always_inline void kasan_poison_slab(struct slab *slab) > { > @@ -252,7 +244,6 @@ static inline void kasan_poison_pages(struct page *page, unsigned int order, > bool init) {} > static inline bool kasan_unpoison_pages(struct page *page, unsigned int order, > bool init) { return false; } > -static inline void kasan_cache_create_kmalloc(struct kmem_cache *cache) {} > static inline void kasan_poison_slab(struct slab *slab) {} > static inline void kasan_unpoison_object_data(struct kmem_cache *cache, > void *object) {} > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index 1f30080a7a4c..f7e0e5067e7a 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -122,11 +122,6 @@ void __kasan_poison_pages(struct page *page, unsigned int order, bool init) > KASAN_PAGE_FREE, init); > } > > -void __kasan_cache_create_kmalloc(struct kmem_cache *cache) > -{ > - cache->kasan_info.is_kmalloc = true; > -} > - > void __kasan_poison_slab(struct slab *slab) > { > struct page *page = slab_page(slab); > @@ -326,7 +321,7 @@ void * __must_check __kasan_slab_alloc(struct kmem_cache *cache, > kasan_unpoison(tagged_object, cache->object_size, init); > > /* Save alloc info (if possible) for non-kmalloc() allocations. */ > - if (kasan_stack_collection_enabled() && !cache->kasan_info.is_kmalloc) > + if (kasan_stack_collection_enabled() && is_kmalloc_cache(cache)) Sorry, it should be: - if (kasan_stack_collection_enabled() && !cache->kasan_info.is_kmalloc) + if (kasan_stack_collection_enabled() && !is_kmalloc_cache(cache)) Thanks, Feng > kasan_save_alloc_info(cache, tagged_object, flags); > > return tagged_object; > @@ -372,7 +367,7 @@ static inline void *____kasan_kmalloc(struct kmem_cache *cache, > * Save alloc info (if possible) for kmalloc() allocations. > * This also rewrites the alloc info when called from kasan_krealloc(). > */ > - if (kasan_stack_collection_enabled() && cache->kasan_info.is_kmalloc) > + if (kasan_stack_collection_enabled() && is_kmalloc_cache(cache)) > kasan_save_alloc_info(cache, (void *)object, flags); > > /* Keep the tag that was set by kasan_slab_alloc(). */ > diff --git a/mm/slab_common.c b/mm/slab_common.c > index 8276022f0da4..a5480d67f391 100644 > --- a/mm/slab_common.c > +++ b/mm/slab_common.c > @@ -663,7 +663,6 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, > > create_boot_cache(s, name, size, flags | SLAB_KMALLOC, useroffset, > usersize); > - kasan_cache_create_kmalloc(s); > list_add(&s->list, &slab_caches); > s->refcount = 1; > return s; > -- > 2.34.1 >
On Mon, Nov 21, 2022 at 2:53 PM Feng Tang <feng.tang@intel.com> wrote: > > Use new is_kmalloc_cache() to simplify the code of checking whether > a kmem_cache is a kmalloc cache. > > Signed-off-by: Feng Tang <feng.tang@intel.com> Hi Feng, Nice simplification! > --- > include/linux/kasan.h | 9 --------- > mm/kasan/common.c | 9 ++------- > mm/slab_common.c | 1 - > 3 files changed, 2 insertions(+), 17 deletions(-) > > diff --git a/include/linux/kasan.h b/include/linux/kasan.h > index dff604912687..fc46f5d6f404 100644 > --- a/include/linux/kasan.h > +++ b/include/linux/kasan.h > @@ -102,7 +102,6 @@ struct kasan_cache { > int alloc_meta_offset; > int free_meta_offset; > #endif > - bool is_kmalloc; > }; We can go even further here, and only define the kasan_cache struct and add the kasan_info field to kmem_cache when CONFIG_KASAN_GENERIC is enabled. > > void __kasan_unpoison_range(const void *addr, size_t size); > @@ -129,13 +128,6 @@ static __always_inline bool kasan_unpoison_pages(struct page *page, > return false; > } > > -void __kasan_cache_create_kmalloc(struct kmem_cache *cache); > -static __always_inline void kasan_cache_create_kmalloc(struct kmem_cache *cache) > -{ > - if (kasan_enabled()) > - __kasan_cache_create_kmalloc(cache); > -} > - > void __kasan_poison_slab(struct slab *slab); > static __always_inline void kasan_poison_slab(struct slab *slab) > { > @@ -252,7 +244,6 @@ static inline void kasan_poison_pages(struct page *page, unsigned int order, > bool init) {} > static inline bool kasan_unpoison_pages(struct page *page, unsigned int order, > bool init) { return false; } > -static inline void kasan_cache_create_kmalloc(struct kmem_cache *cache) {} > static inline void kasan_poison_slab(struct slab *slab) {} > static inline void kasan_unpoison_object_data(struct kmem_cache *cache, > void *object) {} > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index 1f30080a7a4c..f7e0e5067e7a 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -122,11 +122,6 @@ void __kasan_poison_pages(struct page *page, unsigned int order, bool init) > KASAN_PAGE_FREE, init); > } > > -void __kasan_cache_create_kmalloc(struct kmem_cache *cache) > -{ > - cache->kasan_info.is_kmalloc = true; > -} > - > void __kasan_poison_slab(struct slab *slab) > { > struct page *page = slab_page(slab); > @@ -326,7 +321,7 @@ void * __must_check __kasan_slab_alloc(struct kmem_cache *cache, > kasan_unpoison(tagged_object, cache->object_size, init); > > /* Save alloc info (if possible) for non-kmalloc() allocations. */ > - if (kasan_stack_collection_enabled() && !cache->kasan_info.is_kmalloc) > + if (kasan_stack_collection_enabled() && is_kmalloc_cache(cache)) > kasan_save_alloc_info(cache, tagged_object, flags); > > return tagged_object; > @@ -372,7 +367,7 @@ static inline void *____kasan_kmalloc(struct kmem_cache *cache, > * Save alloc info (if possible) for kmalloc() allocations. > * This also rewrites the alloc info when called from kasan_krealloc(). > */ > - if (kasan_stack_collection_enabled() && cache->kasan_info.is_kmalloc) > + if (kasan_stack_collection_enabled() && is_kmalloc_cache(cache)) > kasan_save_alloc_info(cache, (void *)object, flags); > > /* Keep the tag that was set by kasan_slab_alloc(). */ > diff --git a/mm/slab_common.c b/mm/slab_common.c > index 8276022f0da4..a5480d67f391 100644 > --- a/mm/slab_common.c > +++ b/mm/slab_common.c > @@ -663,7 +663,6 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, > > create_boot_cache(s, name, size, flags | SLAB_KMALLOC, useroffset, > usersize); > - kasan_cache_create_kmalloc(s); > list_add(&s->list, &slab_caches); > s->refcount = 1; > return s; > -- > 2.34.1 >
On Mon, Nov 21, 2022 at 04:15:32PM +0100, Andrey Konovalov wrote: > On Mon, Nov 21, 2022 at 2:53 PM Feng Tang <feng.tang@intel.com> wrote: > > > > Use new is_kmalloc_cache() to simplify the code of checking whether > > a kmem_cache is a kmalloc cache. > > > > Signed-off-by: Feng Tang <feng.tang@intel.com> > > Hi Feng, > > Nice simplification! > > > --- > > include/linux/kasan.h | 9 --------- > > mm/kasan/common.c | 9 ++------- > > mm/slab_common.c | 1 - > > 3 files changed, 2 insertions(+), 17 deletions(-) > > > > diff --git a/include/linux/kasan.h b/include/linux/kasan.h > > index dff604912687..fc46f5d6f404 100644 > > --- a/include/linux/kasan.h > > +++ b/include/linux/kasan.h > > @@ -102,7 +102,6 @@ struct kasan_cache { > > int alloc_meta_offset; > > int free_meta_offset; > > #endif > > - bool is_kmalloc; > > }; > > We can go even further here, and only define the kasan_cache struct > and add the kasan_info field to kmem_cache when CONFIG_KASAN_GENERIC > is enabled. Good idea. thanks! I mainly checked the kasan_cache related code, and make an add-on patch below, please let me know if my understanding is wrong or I missed anything. Thanks, Feng --- diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 0ac6505367ee..f2e41290094e 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -96,14 +96,6 @@ static inline bool kasan_has_integrated_init(void) } #ifdef CONFIG_KASAN - -struct kasan_cache { -#ifdef CONFIG_KASAN_GENERIC - int alloc_meta_offset; - int free_meta_offset; -#endif -}; - void __kasan_unpoison_range(const void *addr, size_t size); static __always_inline void kasan_unpoison_range(const void *addr, size_t size) { @@ -293,6 +285,11 @@ static inline void kasan_unpoison_task_stack(struct task_struct *task) {} #ifdef CONFIG_KASAN_GENERIC +struct kasan_cache { + int alloc_meta_offset; + int free_meta_offset; +}; + size_t kasan_metadata_size(struct kmem_cache *cache, bool in_object); slab_flags_t kasan_never_merge(void); void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h index f0ffad6a3365..39f7f1f95de2 100644 --- a/include/linux/slab_def.h +++ b/include/linux/slab_def.h @@ -72,7 +72,7 @@ struct kmem_cache { int obj_offset; #endif /* CONFIG_DEBUG_SLAB */ -#ifdef CONFIG_KASAN +#ifdef CONFIG_KASAN_GENERIC struct kasan_cache kasan_info; #endif diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h index f9c68a9dac04..4e7cdada4bbb 100644 --- a/include/linux/slub_def.h +++ b/include/linux/slub_def.h @@ -132,7 +132,7 @@ struct kmem_cache { unsigned int *random_seq; #endif -#ifdef CONFIG_KASAN +#ifdef CONFIG_KASAN_GENERIC struct kasan_cache kasan_info; #endif
On Tue, Nov 22, 2022 at 7:56 AM Feng Tang <feng.tang@intel.com> wrote: > > On Mon, Nov 21, 2022 at 04:15:32PM +0100, Andrey Konovalov wrote: > > On Mon, Nov 21, 2022 at 2:53 PM Feng Tang <feng.tang@intel.com> wrote: > > > > > > Use new is_kmalloc_cache() to simplify the code of checking whether > > > a kmem_cache is a kmalloc cache. > > > > > > Signed-off-by: Feng Tang <feng.tang@intel.com> > > > > Hi Feng, > > > > Nice simplification! > > > > > --- > > > include/linux/kasan.h | 9 --------- > > > mm/kasan/common.c | 9 ++------- > > > mm/slab_common.c | 1 - > > > 3 files changed, 2 insertions(+), 17 deletions(-) > > > > > > diff --git a/include/linux/kasan.h b/include/linux/kasan.h > > > index dff604912687..fc46f5d6f404 100644 > > > --- a/include/linux/kasan.h > > > +++ b/include/linux/kasan.h > > > @@ -102,7 +102,6 @@ struct kasan_cache { > > > int alloc_meta_offset; > > > int free_meta_offset; > > > #endif > > > - bool is_kmalloc; > > > }; > > > > We can go even further here, and only define the kasan_cache struct > > and add the kasan_info field to kmem_cache when CONFIG_KASAN_GENERIC > > is enabled. > > Good idea. thanks! > > I mainly checked the kasan_cache related code, and make an add-on > patch below, please let me know if my understanding is wrong or I > missed anything. > > Thanks, > Feng > > --- > diff --git a/include/linux/kasan.h b/include/linux/kasan.h > index 0ac6505367ee..f2e41290094e 100644 > --- a/include/linux/kasan.h > +++ b/include/linux/kasan.h > @@ -96,14 +96,6 @@ static inline bool kasan_has_integrated_init(void) > } > > #ifdef CONFIG_KASAN > - > -struct kasan_cache { > -#ifdef CONFIG_KASAN_GENERIC > - int alloc_meta_offset; > - int free_meta_offset; > -#endif > -}; > - > void __kasan_unpoison_range(const void *addr, size_t size); > static __always_inline void kasan_unpoison_range(const void *addr, size_t size) > { > @@ -293,6 +285,11 @@ static inline void kasan_unpoison_task_stack(struct task_struct *task) {} > > #ifdef CONFIG_KASAN_GENERIC > > +struct kasan_cache { > + int alloc_meta_offset; > + int free_meta_offset; > +}; > + > size_t kasan_metadata_size(struct kmem_cache *cache, bool in_object); > slab_flags_t kasan_never_merge(void); > void kasan_cache_create(struct kmem_cache *cache, unsigned int *size, > diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h > index f0ffad6a3365..39f7f1f95de2 100644 > --- a/include/linux/slab_def.h > +++ b/include/linux/slab_def.h > @@ -72,7 +72,7 @@ struct kmem_cache { > int obj_offset; > #endif /* CONFIG_DEBUG_SLAB */ > > -#ifdef CONFIG_KASAN > +#ifdef CONFIG_KASAN_GENERIC > struct kasan_cache kasan_info; > #endif > > diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h > index f9c68a9dac04..4e7cdada4bbb 100644 > --- a/include/linux/slub_def.h > +++ b/include/linux/slub_def.h > @@ -132,7 +132,7 @@ struct kmem_cache { > unsigned int *random_seq; > #endif > > -#ifdef CONFIG_KASAN > +#ifdef CONFIG_KASAN_GENERIC > struct kasan_cache kasan_info; > #endif Yes, this looks good. Please resend as a v2 and I'll give a Reviewed-by. Thanks!
diff --git a/include/linux/kasan.h b/include/linux/kasan.h index dff604912687..fc46f5d6f404 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -102,7 +102,6 @@ struct kasan_cache { int alloc_meta_offset; int free_meta_offset; #endif - bool is_kmalloc; }; void __kasan_unpoison_range(const void *addr, size_t size); @@ -129,13 +128,6 @@ static __always_inline bool kasan_unpoison_pages(struct page *page, return false; } -void __kasan_cache_create_kmalloc(struct kmem_cache *cache); -static __always_inline void kasan_cache_create_kmalloc(struct kmem_cache *cache) -{ - if (kasan_enabled()) - __kasan_cache_create_kmalloc(cache); -} - void __kasan_poison_slab(struct slab *slab); static __always_inline void kasan_poison_slab(struct slab *slab) { @@ -252,7 +244,6 @@ static inline void kasan_poison_pages(struct page *page, unsigned int order, bool init) {} static inline bool kasan_unpoison_pages(struct page *page, unsigned int order, bool init) { return false; } -static inline void kasan_cache_create_kmalloc(struct kmem_cache *cache) {} static inline void kasan_poison_slab(struct slab *slab) {} static inline void kasan_unpoison_object_data(struct kmem_cache *cache, void *object) {} diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 1f30080a7a4c..f7e0e5067e7a 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -122,11 +122,6 @@ void __kasan_poison_pages(struct page *page, unsigned int order, bool init) KASAN_PAGE_FREE, init); } -void __kasan_cache_create_kmalloc(struct kmem_cache *cache) -{ - cache->kasan_info.is_kmalloc = true; -} - void __kasan_poison_slab(struct slab *slab) { struct page *page = slab_page(slab); @@ -326,7 +321,7 @@ void * __must_check __kasan_slab_alloc(struct kmem_cache *cache, kasan_unpoison(tagged_object, cache->object_size, init); /* Save alloc info (if possible) for non-kmalloc() allocations. */ - if (kasan_stack_collection_enabled() && !cache->kasan_info.is_kmalloc) + if (kasan_stack_collection_enabled() && is_kmalloc_cache(cache)) kasan_save_alloc_info(cache, tagged_object, flags); return tagged_object; @@ -372,7 +367,7 @@ static inline void *____kasan_kmalloc(struct kmem_cache *cache, * Save alloc info (if possible) for kmalloc() allocations. * This also rewrites the alloc info when called from kasan_krealloc(). */ - if (kasan_stack_collection_enabled() && cache->kasan_info.is_kmalloc) + if (kasan_stack_collection_enabled() && is_kmalloc_cache(cache)) kasan_save_alloc_info(cache, (void *)object, flags); /* Keep the tag that was set by kasan_slab_alloc(). */ diff --git a/mm/slab_common.c b/mm/slab_common.c index 8276022f0da4..a5480d67f391 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -663,7 +663,6 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, create_boot_cache(s, name, size, flags | SLAB_KMALLOC, useroffset, usersize); - kasan_cache_create_kmalloc(s); list_add(&s->list, &slab_caches); s->refcount = 1; return s;