Commit Graph

762 Commits

Author SHA1 Message Date
xuxingliang
dceb26c7b2 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-25 19:04:02 +08:00
xuxingliang
7e89ff5d11 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-25 19:04:02 +08:00
xuxingliang
c2bcc56546 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-25 19:04:02 +08:00
yinshengkai
cff121bc23 mm: fix memory statistics error
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-25 19:04:02 +08:00
yinshengkai
2c0e2ac36b 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-25 19:04:02 +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
wangmingrong
ae3facda53 kasan: Implementation of Kasan based on software tags.
Currently, only aarch64 is supported

Signed-off-by: wangmingrong <wangmingrong@xiaomi.com>
2024-09-19 03:15:29 +08:00
Xiang Xiao
9c6bed4b00 mm: Move kasan.h from mm/kasan to include/nuttx/mm
so other parts of the system can use it.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-09-19 03:15:29 +08:00
Xiang Xiao
47ffb9019f mm: Support the different kasan implementation
Split kasan.c to incorporate label based kasan:
hook.c: Implement compiler instrumentation function
generic.c: Implementation software kasan algorithm

Signed-off-by: wangmingrong <wangmingrong1@xiaomi.com>
2024-09-19 03:15:29 +08:00
anjiahao
70b9f63985 kasan:fix arch_xxx size is 0,kasan report
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-19 03:15:29 +08:00
anjiahao
e26e1ab2ab kasan:fix bug if kasan_mem_to_shadow mod size is 0 just return
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-19 03:15:29 +08:00
anjiahao
745611f800 kasan:fix bug for kasan_mem_to_shadow
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-19 03:15:29 +08:00
anjiahao
780abec239 kasan:support kasan_mem_to_shadow can check any size
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-19 03:15:29 +08:00
zhangshoukui
8e4e09be2d shm: The limits have been made in Make.defs and remove useless macro in code
ifeq ($(CONFIG_MM_SHM),y)
CSRCS += shmat.c shmctl.c shmdt.c shmget.c

DEPPATH += --dep-path shm
VPATH += :shm
endif

Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2024-09-18 13:42:11 +08:00
Masayuki Ishikawa
df298c186f Revert "build depend:Revert Make.dep intermediate ddc file"
This reverts commit ddc3119c4e.
2024-09-15 19:29:47 +08:00
xuxin19
ddc3119c4e build depend:Revert Make.dep intermediate ddc file
Revert "Parallelize depend file generation"
This reverts commit d5b6ec450f.

parallel depend ddc does not significantly speed up compilation,
intermediately generated .ddc files can cause problems if compilation is interrupted unexpectedly

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-09-15 10:01:58 +08:00
Alin Jerpelea
339457dda3 mm: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-09-13 08:49:05 +08:00
Daniel Jasinski
7dbb887f07 build: fix memory manager compile options for CMake
This enables CMake based build for sim:ostest. Flags which
are set by set_source_files_properties are not reflected in
final build. Changing these to target_compile_options makes
CMake build runnable.

Signed-off-by: Daniel Jasinski <jasinskidaniel95szcz@gmail.com>
2024-09-10 16:00:56 +08:00
hujun5
198630a809 sched: use this_task replace nxsched_self
reason:
We can reduce a function call to improve performance.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-05 09:33:50 -03:00
ligd
c75886b8f8 kasan: add new API kasan_init_early()
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-08-30 01:35:09 +08:00
wangmingrong
64cbafeaa0 mm/kasan: Delete the lock when adding regions
Signed-off-by: wangmingrong <wangmingrong@xiaomi.com>
2024-08-30 01:35:09 +08:00
wangjianyu3
fa5d843aa9 assert in kasan_set_poison() if size is zero
e.g. mm_realloc() => kasan_poison() => kasan_set_poison()
  _assert: Assertion failed p != ((void*)0): at file: kasan/kasan.c:239 task: nsh_main process: nsh_main 0x4402caa5
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2024-08-30 01:35:09 +08:00
yinshengkai
5d0ffdf44e mm: add disable kasan panic configuration
In some cases we hope to be able to find errors without affecting the running of the program

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-08-30 01:35:09 +08:00
yinshengkai
a9afed96b9 mm/kasan: print memory around poisoned address
Print shadow memory following asan format.
==3118004==ERROR: AddressSanitizer: global-buffer-overflow on address 0x5618ac32a100 at pc 0x5618ac32727f bp 0x7ffe5f3e66f0 sp 0x7ffe5f3e66e0
WRITE of size 4 at 0x5618ac32a100 thread T0

#0 0x5618ac32727e in main /home/baerg/vela/x4b/asan_test.c:12
#1 0x7f221ce29d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
#2 0x7f221ce29e3f in __libc_start_main_impl ../csu/libc-start.c:392
#3 0x5618ac327144 in _start (/home/baerg/vela/x4b/asan_test+0x1144)
0x5618ac32a100 is located 0 bytes to the right of global variable 'buffer' defined in 'asan_test.c:5:6' (0x5618ac32a0e0) of size 32
SUMMARY: AddressSanitizer: global-buffer-overflow /home/baerg/vela/x4b/asan_test.c:12 in main
Shadow bytes around the buggy address:
0x0ac39585d3d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ac39585d3e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ac39585d3f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ac39585d400: 00 00 00 00 00 00 00 00 f9 f9 f9 f9 f9 f9 f9 f9
0x0ac39585d410: f9 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 00 00 00 00
=>0x0ac39585d420:[f9]f9 f9 f9 00 00 00 00 00 00 00 00 00 00 00 00
0x0ac39585d430: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ac39585d440: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ac39585d450: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ac39585d460: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ac39585d470: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-08-30 01:35:09 +08:00
yinshengkai
84333881d7 mm: add mm_largest api to get the current largest available memory block
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-08-25 23:09:28 +08:00
yinshengkai
2cdfda149a mm: memory pressure support returns the maximum available memory
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-08-25 23:09:28 +08:00
yinshengkai
49d1b4198f mm: add memory pressure notification support
Add mm_heap_free interface to pass remaining memory to memory pressure

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-08-25 23:09:28 +08:00