Commit Graph

783 Commits

Author SHA1 Message Date
xuxingliang a8b7d26db5 Use BACKTRACE_BUFFER_SIZE to declare backtrace buffer
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-15 01:07:21 +08:00
liwenxiang1 015a45517e mempool: add the minimum size configuration of mempool
The minimum size of mempool can be configured through CONFIG_MM_MPOOL_MINISIZE

Signed-off-by: liwenxiang1 <liwenxiang1@xiaomi.com>
2024-10-13 02:46:57 +08:00
xuxin19 351781d601 cmake:refine nuttx cmake build system fix CMake build missing part
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-10-13 02:25:06 +08:00
wangmingrong1 a5c0dbe772 mm/sw_tags: add config for no longer checking for tags 0
1. When dynamically loading, the read-only data of arm64 architecture is accessed through PC offset. When opening the tag kasan, because the PC value does not have a tag, accessing the read-only data will be detected with a tag mismatch error.
2. uninitial heap use 0xff poison, initial heap use 1-254 unpoison.

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-12 09:52:27 +08:00
buxiasen 4b315b3606 mm: dump more information when failed dump detail
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-12 09:32:44 +08:00
anjiahao c0d416584f malloc:if malloc filed need print leak memory detatls
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-12 09:32:44 +08:00
wangmingrong1 de1701c235 mm/kconfig: Remove unnecessary dependencies
If MM_KASAN judgment already exists

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-11 20:01:46 +08:00
Bowen Wang 8eabad52fd mm/Kconfig: fix build error when MM_BACKTRACE > 0 and disable mempool
mempool is always be compiled, so when enable BACKTRACE but not enable
memdpool, the MM_HEAP_MEMPOOL_BACKTRACE_SKIP is not defined
mempool_add_backtrace() will compiled failed.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-11 19:59:26 +08:00
Bowen Wang 313d6df787 include/nuttx.h: replace all the align macros to nuttx version
1. add IS_ALIGNED()  definitions for NuttX;
2. replace all the ALIGN_UP() and ALIGN_DOWN() to use common
   align implementation;

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-11 16:55:43 +08:00
yinshengkai c158ed2c32 mm/heap: memory alignment before executing kasan_register
The unaligned address is used in kasan_register, but the aligned address is used in kasan_unregister.
The mismatch between the addr value and mm_heapstart will result in a crash due to the inability to unregister correctly.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-10 23:11:37 +08:00
wangmingrong1 5c3025e2fb mm/mempool: Merge two memory requests
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-09 18:15:13 +08:00
wangmingrong1 dd57400e7b mm/mempool: Fix mempool tag kasan error
The address needs to be reset only when comparing addition, subtraction, multiplication and division addresses. Otherwise, the original address is always returned or saved.

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-09 18:15:13 +08:00
ligd 183ff9b6cc mm/mempool: fix mempool crash when use KASAN SW_TAG
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-09 18:15:13 +08:00
ligd 5258e48be6 mm/heap: fix heap crash when use KASAN SW_TAG
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-09 18:15:13 +08:00
Xiang Xiao b068e2357a circbuf: Move from mm/circbuf to libs/libc/misc
so that it can be used by userspace program.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-09 08:41:49 +08:00
buxiasen 8def44b65a mm/dump: pretty the log and thin dump call
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-08 23:55:59 +08:00
buxiasen 9f2b08a91a memdump: add dump for the orphan nodes(neighbor of free node)
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-08 23:55:59 +08:00
buxiasen fd9a9f67cc memdump: add biggest allocated node dump
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-08 23:55:59 +08:00
buxiasen fd6634ecb5 mm/dump: make macro more common, fix help prompt
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-08 23:55:59 +08:00
wangmingrong1 55c9697efe mm/kconfig: The default alignment of global variable out-of-bounds detection is 1
It is recommended to use 1 on qemu and 16 or even 32 on the device.

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-08 19:53:38 +08:00
xuxingliang 18d5ae20f5 drivers/segger: add heap data plot
Add heap current used to note.
Plot it in segger sysview data plot.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-07 17:34:59 +08:00
xuxingliang eac6a8597f sched/note: add note when mm add new region
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-07 17:34:59 +08:00
xuxingliang 0663ac1483 sched/note: specify note event for heap instrumentation
1. Add NOTE_HEAP_ prefix for heap note event.
2. Use note type as heap instrumentation parameter.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-07 17:34:59 +08:00
yinshengkai 8fecd0385b mm: fix memory statistics error
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-07 17:34:59 +08:00
yinshengkai 79eab8783f note: add memory tracing event support
Record all memory allocation and release, save to ram, used to analyze memory allocation rate and memory usage
Its absolute value is not trustworthy because the memory will be allocated in thread A and released in thread B

 netinit-5   [0]   0.105984392: tracing_mark_write: C|5|Heap Usage|96|free: heap: 0x606000000020 size:24, address: 0x603000000370
 netinit-5   [0]   0.105996874: tracing_mark_write: C|5|Heap Usage|24|free: heap: 0x606000000020 size:72, address: 0x6070000008e0
nsh_main-4   [0]   3.825169408: tracing_mark_write: C|4|Heap Usage|2177665|free: heap: 0x606000000020 size:424, address: 0x614000000840
nsh_main-4   [0]   3.825228525: tracing_mark_write: C|4|Heap Usage|14977|free: heap: 0x606000000020 size:2162688, address: 0x7f80a639f800
nsh_main-4   [0]   3.825298789: tracing_mark_write: C|4|Heap Usage|15189|malloc: heap: 0x606000000020 size:20, address: 0x6030000003a0

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-07 17:34:59 +08:00
Xiang Xiao 6e5c81e061 mm/heap: hold heap lock before access mm_nregions
to remove the race condition and rename IDX to idx

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-07 04:19:27 +08:00
wangmingrong1 469418f3c9 mm/kasan: Kasan global support setting alignment length
1. Similar to asan, supports single byte out of bounds detection
2. Fix the script to address the issue of not supporting the big end

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-20 21:47:23 +08:00
wangmingrong1 071af0c993 mm/kasan: Tag kasan and generic kasan use the same instrumentation options
1. Tested on QEMU, the two sockets were basically the same, and their performance was not affected. The size of the generated bin file was also the same
2. Extract global detection as a separate file, both types of Kasan support global variable out of bounds detection simultaneously

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-20 21:47:23 +08:00
wangmingrong1 5c511443fe mm/kasan: Using arrays instead of linked lists
1. Modify the Kasan global variable script to support array storage of region addresses
2. Due to the lack of formatting in the previous attempt, a formatting script was created

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-20 21:47:23 +08:00
wangmingrong1 7796161ee2 mm/kasan:Remove compiler restrictions
The latest version of clang also supports kasan

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-20 21:47:23 +08:00
wangmingrong1 23981cdf3d mm/kasan: Add branch prediction and constant prediction
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
wangmingrong1 63a371b261 mm/kasan: Change the init flag
predict_false(g_region_init == KASAN_INIT_VALUE))
   c:	e3003000 	movw	r3, #0
  10:	e3403000 	movt	r3, #0
  if (predict_false(size == 0) ||
  14:	e5932000 	ldr	r2, [r3]
  18:	e30e3adf 	movw	r3, #60127	; 0xeadf
if KASAN_INIT_VALUE is 0xdeadcafe, run function movw will again and load twice

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
wangmingrong1 b49eef7f4e mm/kasan: The complete implementation of inline instrumentation functions
1. Use always_inline_function instead of inline, inline does not take effect
2. Activate Kasan acceleration by 1/7

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
wangmingrong1 27f8f87331 mm/kasan: Fix the issue where Kasan Global cannot be used
1. The shadow area of global variables is different from heap
2. This modification has little impact on performance under O3 optimization

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
wangmingrong1 4473f2f847 mm/kasan: Increase size alignment
The following situations cannot be detected by Kasan:
On a 32-bit machine, only 12 bytes were poisoned, but 13 bytes were accessed. Due to the lack of upward alignment, only 3 bits were detected

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
wangmingrong1 430820e7ec mm/sw_tags: Add API for register
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
wangmingrong1 1da8cf8104 kasan: No citation removed
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai 87dc91b588 mm/kasan: add kasan watch point implementation
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai e154c6d071 mm/kasan: add null pointer access configuration
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
xuxingliang 38010adc02 nuttx/mm: fix cmake kasan flags
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai 496e44db7f mm: kasan supports checking 0 address access
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai ae7a3d7071 mm: move kasna_start/stop to hook.c
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
anjiahao 2d8b582ce6 kasan:add kasan_start/stop api to control kasan check
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai be86b03794 mm/kasan: support Disable Kasan read Panic
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai d365be9f2f kasan: remove kasan report recursive check
PANIC never returns and abort is called to exit the process after calling assert
When BOARD_RESET_ON_ASSERT < 2, the second kasan_report will not be executed.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai 5ee7c563a5 mm: add kasan_unregister implementaion
In mm_uninitialize should unregister kasan

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai 1771d233c9 mm/kasan: fix kasan_is_poisoned check error
When size is less than or equal to KASAN_SHADOW_SCALE, no check will be performed
We need to check whether the memory is accessible based on bit

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00
ligd 13a0682340 kasan: disable the built-in 'memset' function
In function kasan_set_poison:
{
  ...

  while (size--)
    {
      p[size] = value;
    }
}
This will optimize to 'memset' function when compile option > O2.

But the memset must be instrument by kasan, so there is recursive

Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-19 03:15:29 +08:00
ligd 8a272511d5 kasan: remove unused statement
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-19 03:15:29 +08:00
yinshengkai e0c8189818 mm/kasan: fix kasan false positives
When using memset via __asan_storeN check, not checking if all memory is accessible

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-09-19 03:15:29 +08:00