Commit Graph

858 Commits

Author SHA1 Message Date
simbit18
68593448d7 mm: Fix Kconfig style
- Remove spaces from Kconfig

- Add TABs

Signed-off-by: simbit18 <simbit18@gmail.com>
2026-03-12 09:08:18 +08:00
zhanxiaoqi
975968db1b mm/mempool: fix the entry condition for semaphore during mempool allocation
When the mempool uses the waitsem semaphore for memory allocation,
the flowing two conditions must be satisfied simultaneously:
its wait variable is set to true, and the expandsize variable is set to 0

Signed-off-by: zhanxiaoqi <zhanxiaoqi@bytedance.com>
2026-02-28 00:24:54 +08:00
zhanxiaoqi
4b09f34a45 mm/mempool: The wait variable of the memory pool is controlled by macros
The wait variable of the memory pool is modified to be controlled by macros, facilitating dynamic adjustment of its value via configuration macros.

Signed-off-by: zhanxiaoqi <zhanxiaoqi@bytedance.com>
2026-02-26 20:48:12 +08:00
zhanxiaoqi
28749b8797 mm/mempool: Optimize undefined behavior in memory pool allocation
The wait member variable of the memory pool structure is not initialized, leading to undefined behavior of the memory pool.

Signed-off-by: zhanxiaoqi <zhanxiaoqi@bytedance.com>
2026-02-26 20:48:12 +08:00
anjiahao
3770c0871c mm:use mm_malloc inside of mm_memalign
Test build breadxavr:nsh:

➜ size nuttx_with_mm_memalgin
   text    data     bss     dec     hex filename
  53018      91     556   53665    d1a1 nuttx_with_mm_memalgin
~/work/nuttxwork/nuttx
➜ size nuttx
   text    data     bss     dec     hex filename
  51580      91     556   52227    cc03 nuttx

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2026-02-24 19:58:17 +08:00
SPRESENSE
72b67832ea Makefile: Remove make depend files by make distclean
Intermediate files of make depend like .ddc and .dds may remain
when make is interrupted. Remove them using make distclean.

Signed-off-by: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com>
2026-02-16 16:27:57 +01:00
liang.huang
64d191d32e mm/mm_gran: fix data truncation by using size_t for mask
Use size_t instead of unsigned int for 'mask' to avoid address truncation,
especially when memory addresses exceed 32 bits.

Signed-off-by: liang.huang <liang.huang@houmo.ai>
2026-02-06 08:16:33 -05:00
ganjing
1c1cf74491 mm/tlfs: Account initial size of struct mm_heap_s
and then initialize it.

Signed-off-by: ganjing <ganjing@xiaomi.com>
2026-01-27 21:27:53 +08:00
ganjing
e8bbf496ee mm: Call mm_free_delaylist in mm_mallinfo
and remove it from meminfo_read to enuse caller
always get get accuracy memory information.

Signed-off-by: ganjing <ganjing@xiaomi.com>
2026-01-27 21:27:53 +08:00
ganjing
e941b18e29 mm/umm: Allow customizing the implementation of umm heap
and migrate arch/sim from the customized mm_heap to
umm_heap, so the default mm_heap implementation can
still be used(e.g. shared memory in OpenAMP).

Signed-off-by: ganjing <ganjing@xiaomi.com>
2026-01-27 21:27:53 +08:00
wangzhi16
4f33a32e36 mm/kasan: Remove unnecessary critical sections in mm/kasan.
Remove unnecessary critical sections in mm/kasan.

Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
2026-01-27 17:59:07 +08:00
anpeiyun
3c1712c66d kasan/hook.c: prevent recursive report overflow
Stop the report handler from re-entering KASAN by halting checks when printing.
Reuse the dump_only flag so read/write panic toggles only emit stack traces.
Retain stack dumps for panic-disabled paths without risking another overflow.

Signed-off-by: anpeiyun <anpeiyun@xiaomi.com>
2026-01-21 10:27:02 +08:00
Bowen Wang
239130c1fd 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>
2026-01-19 14:18:27 +08:00
Bowen Wang
e686a3ac42 mm/mm_heap: use struct mm_heap_config_s to init the memory heap
To avoid add new parameters to the mm_initialize_heap() and
mm_initialize_pool()

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2026-01-19 14:18:27 +08:00
anjiahao
6ed4ea63d8 mm: support mm_initialize_heap to specify a specific heap pointer
Support user pass it own heap struct to the mm_initialize_heap() to
avoid the heap struct is reserved from the heap range

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2026-01-19 14:18:27 +08:00
wenquan1
8f9f31fb69 mm/iob:support iob queue concat to another iob queue
add interface support to merge iob queues, providing support for
subsequent features.

Signed-off-by: wenquan1 <wenquan1@xiaomi.com>
2026-01-01 17:03:29 +08:00
gaohedong
a5a29bdbbb net/ethernet: update all iob information in the iob_update_pktlen
Update io_len to 0 when pktlen is 0. otherwise, io_pktlen and io_len will be inconsistent, cause free check failure.

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
2025-12-29 14:40:26 +08:00
zhanghongyu
48e9b4fc7a mm/iob: limit the alignment length of IOB to no less than sizeof(uinptr_t)
avoid crashes caused by four-byte alignment issues.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-25 08:40:02 -03:00
zhanghongyu
6ad864ff0c mm/iob: add iob_init method to support external buffer init as iob structure
Some checks failed
Build Documentation / build-html (push) Has been cancelled
This interface allows different protocol modules to use their own unique IOB
buffer sources and allocation strategies without interfering with each other.
Representative examples are the IP protocol and the CAN protocol. The IP
protocol generally transmits packets of varying lengths and requires
relatively high peak throughput. In this case, to ensure higher performance,
IOB_BUFSIZE is often configured to be relatively large, such as greater than
500. The CAN protocol generally transmits short packets of fixed length.
In this case, to improve memory utilization, IOB_BUFSIZE is often configured
to be relatively small, such as 16 or 64. To optimize the memory utilization
when the IP protocol and the CAN protocol share the same core,
this interface was added.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2025-12-25 10:08:49 +08:00
anjiahao
ee052a4570 mempool:fix bug, Misjudged the condition of interrupt memory release
We don't need to subtract the block size; we only need to determine if it's within the interrupt memory range.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2025-12-22 15:14:26 +08:00
anjiahao
92f26a98dd mm:use Kconfig to control sequence number to save memory
One memory block can save sizeof(size_t) size.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2025-12-20 09:47:22 -03:00
raiden00pl
f22436ae46 mm/: remove reference to non-existent readme
remove reference to non-existent readme in mm/

Pointing to the documentation page doesn't make sense in this case,
because it doesn't explain the use of `#undef XXX` for this case anyway.

Signed-off-by: raiden00pl <raiden00@railab.me>
2025-10-11 17:07:51 -04:00
wangmingrong1
750ae961a8 kasan watchpoint: Fix judgment problem
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-07-01 09:04:03 -03:00
cuiziwei
4de718f98f kasan: Fix assert judgment condition to correctly detect out-of-bounds causing trampling.
Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2025-07-01 09:04:03 -03:00
wangmingrong1
aead1981a7 kasan: Potential recursive registration shadow area error
When initializing a memory block, the shadow area record of the first
memory block is used first.When uninitializing, unpoison is required, otherwise the memory will be marked incorrectly.
The following case will cause problems:
    void *mem = malloc(1024);
    struct mm_heap_s *a = mm_initialize("hello", mem, 1024);
    int *b = mm_malloc(a, sizeof(int *));
    *b = 100;
    printf("Hello, World!! %d\n", *b);
    mm_free(a, b);
    mm_uninitialize(a);
    free(mem);

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-07-01 09:04:03 -03:00
wangmingrong1
0a71cbe542 fix kasan_bypss compile unused error
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-06-30 18:19:38 +08:00
buxiasen
c5bfc4d233 mm/kasan: fix wanring expression result unused
nuttx/mm/mm_heap/mm_malloc_size.c:77:16: error: expression result unused [-Werror,-Wunused-value]
  kasan_bypass(flag);
               ^~~~
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2025-06-30 18:19:38 +08:00
wangmingrong1
acfe9b2c15 sw_tags: Remove duplicate definitions
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-06-30 18:19:38 +08:00
wangmingrong1
6ac72fa7f1 kasan: Add configurable kasan initialization variable location
This can avoid crashes caused by uninitialized accesses to initialized variables in non-chip memory.

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-06-30 18:19:38 +08:00
wangmingrong1
8f541d2ef2 mte/kasan: Implementing KASAN memory protection for ARM64 hardware MTE
1. Add hw_tags.c, which will call arm64_mte to implement tagging of memory blocks by operating registers
2. It has been able to run normally on the default NX memory allocator, excluding mempool and tlsf
3. On more complex configurations, memory tests such as memstress can run normally without system crashes

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-06-30 18:19:38 +08:00
wangmingrong1
448ace4761 kasan: fix realloc memcpy tags check error
When the size of the new realloc is larger than the old one and can be expanded forward and backward, the tag of oldmem needs to be set to the same as newmem, otherwise memcpy will report a kasan error.

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-06-30 18:19:38 +08:00
wangmingrong1
c6da553788 kasan: kasan_reset_tag rename kasan_clear_tag
The clear tag is more explicit than the reset tag.

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-06-30 18:19:38 +08:00
wangmingrong1
9af2f0ee82 mempool: Support mempool address and size alignment by setting CONFIG_MM_NODE_GUARDSIZE
Setting a reasonable CONFIG_MM_NODE_GUARDSIZE can ensure absolute alignment of usersize

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-06-26 20:33:29 +08:00
wangmingrong1
e6f77d7f14 mempool: Use the same magic with mmheap
mmheap magic: #define MM_INIT_MAGIC    0xcc #define MM_ALLOC_MAGIC   0xaa #define MM_FREE_MAGIC    0x55

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-06-26 20:33:29 +08:00
wangmingrong1
a98f3f2417 mm: Support CONFIG_MM_NODE_GUARDSIZE configuration
After it is not zero, the preceding member of the next node will no longer belong to the valid area of the previous alloc node.
Due to the existence of precedence, the memory block size of the node can only be aligned with sizeof(mmsize_t).
This configuration will be applied in the following scenarios when set 8:
	ARM64 MTE hardware tag KASan, which requires the tag's memory address to be 16-byte aligned and the memory size must also be 16-byte aligned

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-06-26 20:33:29 +08:00
Lars Kruse
3ce85ca54e style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
Lars Kruse
4568110d63 fix misspelled names in locally scoped code
These misspelled words are used in strictly local scopes.
Renaming these variables should not cause any problems.
2025-05-15 10:12:12 +08:00
buxiasen
1de87953e6 mm/gran: add gran_alloc_align API
for arm-v7a, possible region with 4K and need align with 16K.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2025-05-12 15:01:37 +08:00
chao an
52482219c8 libc/elf: rename modlib to libelf
Renaming "modlib" to "libelf" is more in line with the implementation content,
which makes it easier for individual developers to understand the capabilities of this module.

CONFIG_LIBC_MODLIB -> CONFIG_LIBC_ELF

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-04-11 09:43:22 +08:00
simbit18
5c02379548 Fix Kconfig style
Remove spaces from Kconfig files
Add TABs
2025-01-23 23:01:54 +08:00
Jukka Laitinen
19fe41cb1b mm/kmap/kmm_map.c: Fix argument to gran_free
Fix a memory corruption & deadlocks while calling gran_free.

The function expects a GRAN_HANDLE as a paramter, not a pointer to it.

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2025-01-15 17:10:57 +08:00
wangmingrong1
df7d062713 kasan/kconfig: Add config CONFIG_MM_KASAN_INSTRUMENT
Some checks failed
Build Documentation / build-html (push) Has been cancelled
It will be used to distinguish between hardware KASan and software KASan. Hardware KASan does not need to use plug-in

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-01-14 14:01:48 +08:00
wangmingrong1
9b4cd4e0a4 kasan: Extract kasan's kconfig separately
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-01-14 14:01:48 +08:00
wangmingrong1
2149d89336 macro/align: Use ALIGN_UP and ALIGN_DOWN uniformly
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-01-12 16:48:35 +08:00
wangmingrong1
aa0aecbd80 mempool: addbacktrace should be before kasan_unpoison
If thread 1 is executing kasan_unpoison but a scheduling occurs and the block is trampled upon, the displayed backtracking may still be from the previously allocated backtracking

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-01-12 01:29:14 +08:00
wangmingrong1
91c71ed00a mm: Add mm_lock_irq, mm_unlock_iq
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-01-11 12:28:30 +08:00
wangmingrong1
11d54b34a7 Revert "mm_heap: double malloced memory default alignment (4 -> 8, 8 -> 16)"
This reverts commit 3e971d2e6d.
2025-01-09 00:00:11 +08:00
wangmingrong1
c5655d5a11 arm64/tbi: Unified TBI flags for MTE and software kasan
The TCMA flag is not critical, it will be set separately in "arm64_mte.c"

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-01-07 21:44:18 +08:00
wangmingrong1
b27dc9ee7f mm: Unified memory management alignment length
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-12-30 19:49:00 +08:00
Zhe Weng
035fdb4951 net: Refresh config dependency of NET_READAHEAD
ICMP(v6) uses IOB queue as readahead, but TCP/UDP don't now.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2024-12-20 20:01:19 +08:00