Message ID | ee33aa1d9c57c3f2b2c700e8f2c6c24db8703612.1605046662.git.andreyknvl@google.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | kasan: boot parameters for hardware tag-based mode | expand |
On Tue, Nov 10, 2020 at 11:20PM +0100, Andrey Konovalov wrote: > Rename kasan_poison_kfree() to kasan_slab_free_mempool() as it better > reflects what this annotation does. This function is again so simple, and now it seems it's mempool specific, can't we just remove it and open-code it in mempool.c? > No functional changes. > > Signed-off-by: Andrey Konovalov <andreyknvl@google.com> > Reviewed-by: Dmitry Vyukov <dvyukov@google.com> > Link: https://linux-review.googlesource.com/id/I5026f87364e556b506ef1baee725144bb04b8810 > --- > include/linux/kasan.h | 16 ++++++++-------- > mm/kasan/common.c | 16 ++++++++-------- > mm/mempool.c | 2 +- > 3 files changed, 17 insertions(+), 17 deletions(-) > > diff --git a/include/linux/kasan.h b/include/linux/kasan.h > index 779f8e703982..534ab3e2935a 100644 > --- a/include/linux/kasan.h > +++ b/include/linux/kasan.h > @@ -177,6 +177,13 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, unsigned > return false; > } > > +void __kasan_slab_free_mempool(void *ptr, unsigned long ip); > +static inline void kasan_slab_free_mempool(void *ptr, unsigned long ip) > +{ > + if (kasan_enabled()) > + __kasan_slab_free_mempool(ptr, ip); > +} > + > void * __must_check __kasan_slab_alloc(struct kmem_cache *s, > void *object, gfp_t flags); > static inline void * __must_check kasan_slab_alloc(struct kmem_cache *s, > @@ -217,13 +224,6 @@ static inline void * __must_check kasan_krealloc(const void *object, > return (void *)object; > } > > -void __kasan_poison_kfree(void *ptr, unsigned long ip); > -static inline void kasan_poison_kfree(void *ptr, unsigned long ip) > -{ > - if (kasan_enabled()) > - __kasan_poison_kfree(ptr, ip); > -} > - > void __kasan_kfree_large(void *ptr, unsigned long ip); > static inline void kasan_kfree_large(void *ptr, unsigned long ip) > { > @@ -263,6 +263,7 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, > { > return false; > } > +static inline void kasan_slab_free_mempool(void *ptr, unsigned long ip) {} > static inline void *kasan_slab_alloc(struct kmem_cache *s, void *object, > gfp_t flags) > { > @@ -282,7 +283,6 @@ static inline void *kasan_krealloc(const void *object, size_t new_size, > { > return (void *)object; > } > -static inline void kasan_poison_kfree(void *ptr, unsigned long ip) {} > static inline void kasan_kfree_large(void *ptr, unsigned long ip) {} > > #endif /* CONFIG_KASAN */ > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > index 819403548f2e..60793f8695a8 100644 > --- a/mm/kasan/common.c > +++ b/mm/kasan/common.c > @@ -336,6 +336,14 @@ bool __kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip) > return ____kasan_slab_free(cache, object, ip, true); > } > > +void __kasan_slab_free_mempool(void *ptr, unsigned long ip) > +{ > + struct page *page; > + > + page = virt_to_head_page(ptr); > + ____kasan_slab_free(page->slab_cache, ptr, ip, false); > +} > + > static void set_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) > { > kasan_set_track(&kasan_get_alloc_meta(cache, object)->alloc_track, flags); > @@ -427,14 +435,6 @@ void * __must_check __kasan_krealloc(const void *object, size_t size, gfp_t flag > flags, true); > } > > -void __kasan_poison_kfree(void *ptr, unsigned long ip) > -{ > - struct page *page; > - > - page = virt_to_head_page(ptr); > - ____kasan_slab_free(page->slab_cache, ptr, ip, false); > -} > - > void __kasan_kfree_large(void *ptr, unsigned long ip) > { > if (ptr != page_address(virt_to_head_page(ptr))) > diff --git a/mm/mempool.c b/mm/mempool.c > index f473cdddaff0..b1f39fa75ade 100644 > --- a/mm/mempool.c > +++ b/mm/mempool.c > @@ -104,7 +104,7 @@ static inline void poison_element(mempool_t *pool, void *element) > static __always_inline void kasan_poison_element(mempool_t *pool, void *element) > { > if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) > - kasan_poison_kfree(element, _RET_IP_); > + kasan_slab_free_mempool(element, _RET_IP_); This is already a kasan-prefixed function, so if kasan_slab_free_mempool() is only ever called in this function, we should just call kasan_slab_free() here directly with the 2 extra args it requires open-coded. > else if (pool->alloc == mempool_alloc_pages) > kasan_free_pages(element, (unsigned long)pool->pool_data); > } Thanks, -- Marco
On Wed, Nov 11, 2020 at 7:53 PM Marco Elver <elver@google.com> wrote: > > On Tue, Nov 10, 2020 at 11:20PM +0100, Andrey Konovalov wrote: > > Rename kasan_poison_kfree() to kasan_slab_free_mempool() as it better > > reflects what this annotation does. > > This function is again so simple, and now it seems it's mempool > specific, can't we just remove it and open-code it in mempool.c? The simplification introduced in the previous patch is based on a false assumption and will be reverted. Thus will keep this as a separate function. > > > No functional changes. > > > > Signed-off-by: Andrey Konovalov <andreyknvl@google.com> > > Reviewed-by: Dmitry Vyukov <dvyukov@google.com> > > Link: https://linux-review.googlesource.com/id/I5026f87364e556b506ef1baee725144bb04b8810 > > --- > > include/linux/kasan.h | 16 ++++++++-------- > > mm/kasan/common.c | 16 ++++++++-------- > > mm/mempool.c | 2 +- > > 3 files changed, 17 insertions(+), 17 deletions(-) > > > > diff --git a/include/linux/kasan.h b/include/linux/kasan.h > > index 779f8e703982..534ab3e2935a 100644 > > --- a/include/linux/kasan.h > > +++ b/include/linux/kasan.h > > @@ -177,6 +177,13 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, unsigned > > return false; > > } > > > > +void __kasan_slab_free_mempool(void *ptr, unsigned long ip); > > +static inline void kasan_slab_free_mempool(void *ptr, unsigned long ip) > > +{ > > + if (kasan_enabled()) > > + __kasan_slab_free_mempool(ptr, ip); > > +} > > + > > void * __must_check __kasan_slab_alloc(struct kmem_cache *s, > > void *object, gfp_t flags); > > static inline void * __must_check kasan_slab_alloc(struct kmem_cache *s, > > @@ -217,13 +224,6 @@ static inline void * __must_check kasan_krealloc(const void *object, > > return (void *)object; > > } > > > > -void __kasan_poison_kfree(void *ptr, unsigned long ip); > > -static inline void kasan_poison_kfree(void *ptr, unsigned long ip) > > -{ > > - if (kasan_enabled()) > > - __kasan_poison_kfree(ptr, ip); > > -} > > - > > void __kasan_kfree_large(void *ptr, unsigned long ip); > > static inline void kasan_kfree_large(void *ptr, unsigned long ip) > > { > > @@ -263,6 +263,7 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, > > { > > return false; > > } > > +static inline void kasan_slab_free_mempool(void *ptr, unsigned long ip) {} > > static inline void *kasan_slab_alloc(struct kmem_cache *s, void *object, > > gfp_t flags) > > { > > @@ -282,7 +283,6 @@ static inline void *kasan_krealloc(const void *object, size_t new_size, > > { > > return (void *)object; > > } > > -static inline void kasan_poison_kfree(void *ptr, unsigned long ip) {} > > static inline void kasan_kfree_large(void *ptr, unsigned long ip) {} > > > > #endif /* CONFIG_KASAN */ > > diff --git a/mm/kasan/common.c b/mm/kasan/common.c > > index 819403548f2e..60793f8695a8 100644 > > --- a/mm/kasan/common.c > > +++ b/mm/kasan/common.c > > @@ -336,6 +336,14 @@ bool __kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip) > > return ____kasan_slab_free(cache, object, ip, true); > > } > > > > +void __kasan_slab_free_mempool(void *ptr, unsigned long ip) > > +{ > > + struct page *page; > > + > > + page = virt_to_head_page(ptr); > > + ____kasan_slab_free(page->slab_cache, ptr, ip, false); > > +} > > + > > static void set_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) > > { > > kasan_set_track(&kasan_get_alloc_meta(cache, object)->alloc_track, flags); > > @@ -427,14 +435,6 @@ void * __must_check __kasan_krealloc(const void *object, size_t size, gfp_t flag > > flags, true); > > } > > > > -void __kasan_poison_kfree(void *ptr, unsigned long ip) > > -{ > > - struct page *page; > > - > > - page = virt_to_head_page(ptr); > > - ____kasan_slab_free(page->slab_cache, ptr, ip, false); > > -} > > - > > void __kasan_kfree_large(void *ptr, unsigned long ip) > > { > > if (ptr != page_address(virt_to_head_page(ptr))) > > diff --git a/mm/mempool.c b/mm/mempool.c > > index f473cdddaff0..b1f39fa75ade 100644 > > --- a/mm/mempool.c > > +++ b/mm/mempool.c > > @@ -104,7 +104,7 @@ static inline void poison_element(mempool_t *pool, void *element) > > static __always_inline void kasan_poison_element(mempool_t *pool, void *element) > > { > > if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) > > - kasan_poison_kfree(element, _RET_IP_); > > + kasan_slab_free_mempool(element, _RET_IP_); > > This is already a kasan-prefixed function, so if > kasan_slab_free_mempool() is only ever called in this function, we > should just call kasan_slab_free() here directly with the 2 extra args > it requires open-coded. > > > else if (pool->alloc == mempool_alloc_pages) > > kasan_free_pages(element, (unsigned long)pool->pool_data); > > } > > Thanks, > -- Marco
diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 779f8e703982..534ab3e2935a 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -177,6 +177,13 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, unsigned return false; } +void __kasan_slab_free_mempool(void *ptr, unsigned long ip); +static inline void kasan_slab_free_mempool(void *ptr, unsigned long ip) +{ + if (kasan_enabled()) + __kasan_slab_free_mempool(ptr, ip); +} + void * __must_check __kasan_slab_alloc(struct kmem_cache *s, void *object, gfp_t flags); static inline void * __must_check kasan_slab_alloc(struct kmem_cache *s, @@ -217,13 +224,6 @@ static inline void * __must_check kasan_krealloc(const void *object, return (void *)object; } -void __kasan_poison_kfree(void *ptr, unsigned long ip); -static inline void kasan_poison_kfree(void *ptr, unsigned long ip) -{ - if (kasan_enabled()) - __kasan_poison_kfree(ptr, ip); -} - void __kasan_kfree_large(void *ptr, unsigned long ip); static inline void kasan_kfree_large(void *ptr, unsigned long ip) { @@ -263,6 +263,7 @@ static inline bool kasan_slab_free(struct kmem_cache *s, void *object, { return false; } +static inline void kasan_slab_free_mempool(void *ptr, unsigned long ip) {} static inline void *kasan_slab_alloc(struct kmem_cache *s, void *object, gfp_t flags) { @@ -282,7 +283,6 @@ static inline void *kasan_krealloc(const void *object, size_t new_size, { return (void *)object; } -static inline void kasan_poison_kfree(void *ptr, unsigned long ip) {} static inline void kasan_kfree_large(void *ptr, unsigned long ip) {} #endif /* CONFIG_KASAN */ diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 819403548f2e..60793f8695a8 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -336,6 +336,14 @@ bool __kasan_slab_free(struct kmem_cache *cache, void *object, unsigned long ip) return ____kasan_slab_free(cache, object, ip, true); } +void __kasan_slab_free_mempool(void *ptr, unsigned long ip) +{ + struct page *page; + + page = virt_to_head_page(ptr); + ____kasan_slab_free(page->slab_cache, ptr, ip, false); +} + static void set_alloc_info(struct kmem_cache *cache, void *object, gfp_t flags) { kasan_set_track(&kasan_get_alloc_meta(cache, object)->alloc_track, flags); @@ -427,14 +435,6 @@ void * __must_check __kasan_krealloc(const void *object, size_t size, gfp_t flag flags, true); } -void __kasan_poison_kfree(void *ptr, unsigned long ip) -{ - struct page *page; - - page = virt_to_head_page(ptr); - ____kasan_slab_free(page->slab_cache, ptr, ip, false); -} - void __kasan_kfree_large(void *ptr, unsigned long ip) { if (ptr != page_address(virt_to_head_page(ptr))) diff --git a/mm/mempool.c b/mm/mempool.c index f473cdddaff0..b1f39fa75ade 100644 --- a/mm/mempool.c +++ b/mm/mempool.c @@ -104,7 +104,7 @@ static inline void poison_element(mempool_t *pool, void *element) static __always_inline void kasan_poison_element(mempool_t *pool, void *element) { if (pool->alloc == mempool_alloc_slab || pool->alloc == mempool_kmalloc) - kasan_poison_kfree(element, _RET_IP_); + kasan_slab_free_mempool(element, _RET_IP_); else if (pool->alloc == mempool_alloc_pages) kasan_free_pages(element, (unsigned long)pool->pool_data); }