diff --git a/modules/cas_cache/context.c b/modules/cas_cache/context.c index 9b1b9a6..9b8e4b2 100644 --- a/modules/cas_cache/context.c +++ b/modules/cas_cache/context.c @@ -1,5 +1,5 @@ /* -* Copyright(c) 2012-2021 Intel Corporation +* Copyright(c) 2012-2022 Intel Corporation * SPDX-License-Identifier: BSD-3-Clause */ @@ -10,6 +10,7 @@ #include "utils/utils_gc.h" #include "utils/utils_mpool.h" #include "threads.h" +#include struct env_mpool *cas_bvec_pool; @@ -66,6 +67,7 @@ void *_cas_alloc_page_rpool(void *allocator_ctx, int cpu) _cas_page_set_priv(page); _cas_page_set_cpu(page, cpu); + return page_address(page); } @@ -103,6 +105,11 @@ ctx_data_t *__cas_ctx_data_alloc(uint32_t pages, bool zalloc) _cas_page_set_cpu(data->vec[i].bv_page, cpu); } else { data->vec[i].bv_page = alloc_page(GFP_NOIO); + if (data->vec[i].bv_page) { + /* Failed to get memory from rpool but backup allocation worked. + Need to keep track of this page as well */ + kmemleak_alloc(page_address(data->vec[i].bv_page), PAGE_SIZE, 1, GFP_NOIO); + } } if (!data->vec[i].bv_page) @@ -171,8 +178,11 @@ void cas_ctx_data_free(ctx_data_t *ctx_data) if (!(_cas_page_test_priv(page) && !cas_rpool_try_put( cas_bvec_pages_rpool, page_address(page), - _cas_page_get_cpu(page)))) + _cas_page_get_cpu(page)))) { __free_page(page); + /* It wasn't a page from rpool thus need to stop tracking it explicitly */ + kmemleak_free(page_address(page)); + } } env_mpool_del(cas_bvec_pool, data, data->size); diff --git a/modules/cas_cache/ocf_env.c b/modules/cas_cache/ocf_env.c index bdb66d2..701b535 100644 --- a/modules/cas_cache/ocf_env.c +++ b/modules/cas_cache/ocf_env.c @@ -1,10 +1,11 @@ /* -* Copyright(c) 2012-2021 Intel Corporation +* Copyright(c) 2012-2022 Intel Corporation * SPDX-License-Identifier: BSD-3-Clause */ #include "cas_cache.h" #include "utils/utils_rpool.h" +#include /* *** ALLOCATOR *** */ @@ -77,6 +78,9 @@ static void *env_allocator_new_rpool(void *allocator_ctx, int cpu) item->from_rpool = 1; item->cpu = cpu; } + /* As it isn't an actuall allocation but only a rpool preparation + kmemleak shouldn't track the allocated memory yet. */ + kmemleak_free(item); return item; } @@ -88,6 +92,7 @@ static void env_allocator_del_rpool(void *allocator_ctx, void *_item) BUG_ON(item->used); + kmemleak_alloc(item, allocator->item_size, 1, GFP_NOIO); kmem_cache_free(allocator->kmem_cache, item); } diff --git a/modules/cas_cache/utils/utils_rpool.c b/modules/cas_cache/utils/utils_rpool.c index 15a9f4c..d2de7c5 100644 --- a/modules/cas_cache/utils/utils_rpool.c +++ b/modules/cas_cache/utils/utils_rpool.c @@ -7,6 +7,7 @@ #include "utils_rpool.h" #include "ocf_env.h" #include "../cas_cache.h" +#include #define CAS_UTILS_RPOOL_DEBUG 0 #if 1 == CAS_UTILS_RPOOL_DEBUG @@ -216,6 +217,8 @@ void *cas_rpool_try_get(struct cas_reserve_pool *rpool_master, int *cpu) entry = RPOOL_ITEM_TO_ENTRY(rpool_master, item); list_del(item); atomic_dec(¤t_rpool->count); + /* The actuall allocation - kmemleak should start tracking page */ + kmemleak_alloc(entry, rpool_master->entry_size, 1, GFP_NOIO); } spin_unlock_irqrestore(¤t_rpool->lock, flags); @@ -248,6 +251,8 @@ int cas_rpool_try_put(struct cas_reserve_pool *rpool_master, void *entry, int cp item = RPOOL_ENTRY_TO_ITEM(rpool_master, entry); list_add_tail(item, ¤t_rpool->list); + /* Freeing memory chunk */ + kmemleak_free(entry); atomic_inc(¤t_rpool->count);