mm/mm_heap: add nokasan flag in mm_heap_config_s structure

Support enable/disable the kasan when initialize the heap.
This requirement is from rptun, because rptun use share memory init
the heap and share memory is precious, so we need disable the kasan
feature for rptun's heap to save the share memory.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
This commit is contained in:
Bowen Wang
2025-05-24 13:21:12 +08:00
committed by GUIDINGLI
parent e686a3ac42
commit 239130c1fd
5 changed files with 33 additions and 7 deletions
+4 -3
View File
@@ -311,9 +311,10 @@ static int rptun_init_carveout(FAR struct rptun_priv_s *priv,
}
memset(&config, 0, sizeof(config));
config.name = shmname;
config.start = shmbase;
config.size = shmlen;
config.name = shmname;
config.start = shmbase;
config.size = shmlen;
config.nokasan = true;
carveout->base = shmbase;
carveout->size = shmlen;
+1
View File
@@ -195,6 +195,7 @@ struct mm_heap_config_s
FAR const char *name;
FAR void *start;
size_t size;
bool nokasan;
};
struct mempool_init_s
+4
View File
@@ -270,6 +270,10 @@ struct mm_heap_s
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
struct procfs_meminfo_entry_s mm_procfs;
#endif
/* Kasan is disable or enable for this heap */
bool mm_nokasan;
};
/* This describes the callback for mm_foreach */
+10 -2
View File
@@ -156,7 +156,10 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
* address alignment.
*/
kasan_register((void *)heapbase, &heapsize);
if (!heap->mm_nokasan)
{
kasan_register((void *)heapbase, &heapsize);
}
heapend = MM_ALIGN_DOWN((uintptr_t)heapbase + (uintptr_t)heapsize);
heapsize = heapend - heapbase;
@@ -266,6 +269,7 @@ mm_initialize_heap(FAR const struct mm_heap_config_s *config)
/* Set up global variables */
memset(heap, 0, sizeof(struct mm_heap_s));
heap->mm_nokasan = config->nokasan;
/* Initialize the node array */
@@ -385,7 +389,11 @@ void mm_uninitialize(FAR struct mm_heap_s *heap)
for (i = 0; i < CONFIG_MM_REGIONS; i++)
{
kasan_unregister(heap->mm_heapstart[i]);
if (!heap->mm_nokasan)
{
kasan_unregister(heap->mm_heapstart[i]);
}
sched_note_heap(NOTE_HEAP_REMOVE, heap, heap->mm_heapstart[i],
(uintptr_t)heap->mm_heapend[i] -
(uintptr_t)heap->mm_heapstart[i], heap->mm_curused);
+14 -2
View File
@@ -112,6 +112,10 @@ struct mm_heap_s
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MEMINFO)
struct procfs_meminfo_entry_s mm_procfs;
#endif
/* Kasan is disable or enable for this heap */
bool mm_nokasan;
};
#if CONFIG_MM_BACKTRACE >= 0
@@ -730,7 +734,10 @@ void mm_addregion(FAR struct mm_heap_s *heap, FAR void *heapstart,
/* Register to KASan for access check */
kasan_register(heapstart, &heapsize);
if (!heap->mm_nokasan)
{
kasan_register(heapstart, &heapsize);
}
DEBUGVERIFY(mm_lock(heap));
@@ -1035,6 +1042,7 @@ mm_initialize_heap(FAR const struct mm_heap_config_s *config)
}
memset(heap, 0, sizeof(struct mm_heap_s));
heap->mm_nokasan = config->nokasan;
/* Allocate and create TLSF context */
@@ -1674,7 +1682,11 @@ void mm_uninitialize(FAR struct mm_heap_s *heap)
for (i = 0; i < CONFIG_MM_REGIONS; i++)
{
kasan_unregister(heap->mm_heapstart[i]);
if (!heap->mm_nokasan)
{
kasan_unregister(heap->mm_heapstart[i]);
}
sched_note_heap(NOTE_HEAP_REMOVE, heap, heap->mm_heapstart[i],
(uintptr_t)heap->mm_heapend[i] -
(uintptr_t)heap->mm_heapstart[i], heap->mm_curused);