CV-Bowen opened a new pull request, #21722:
URL: https://github.com/apache/nuttx/pull/21722

   ## Summary
   
   `mm_heap_config_s.heap` lets the caller ask `mm_initialize_heap()` to
   allocate the `struct mm_heap_s` from another heap instead of carving it
   out of the new region. The struct is then allocated with
   `mm_malloc(config->heap, ...)` (`mm_memalign()` in tlsf), so the caller
   has to hand in a real `struct mm_heap_s *`. With
   `CONFIG_MM_UMM_CUSTOMIZE_MANAGER` (sim) the user heap is managed by
   sim_ummheap and there is no such struct to pass.
   
   Replace the pointer with a `bool allocheap` and allocate the struct with
   `lib_memalign()`, which resolves to `kmm_memalign()` in the kernel and
   `memalign()` otherwise. `KRN_HEAP` existed only to fill that field for
   rptun, so it is removed and rptun sets `allocheap = true`.
   
   - mm/mm_heap/mm_initialize: fix nxstyle errors (a missing blank line
     that master already has)
   - mm: replace mm_heap_config_s.heap with an allocheap flag
   
   ## Impact
   
   - API: `struct mm_heap_config_s` loses `heap` and gains `allocheap`;
     `KRN_HEAP` is removed. In tree the only user was drivers/rptun.
     Out-of-tree code that set `config.heap` must set `allocheap = true`
     instead.
   - Callers that zero the config (fs_heap, kmm/umm initialize) keep the
     in-region layout, unchanged.
   - No Kconfig change.
   
   ## Testing
   
   Host: Ubuntu 22.04.5 LTS x86_64, QEMU version 10.2.1, sim: cc (Ubuntu 
13.1.0-8ubuntu1~22.04) 13.1.0, qemu-armv8a: aarch64-none-elf-gcc (Arm GNU 
Toolchain 12.2.Rel1 (Build arm-12.24)) 12.2.1 20221205
   
   rptun is the only in-tree user of the allocate-the-struct path: each
   carveout in the resource table gets its own heap through
   `rptun_init_carveout()`. The rpmsg baseline exercises it on both
   managers:
   
   - sim:rpserver + sim:rpproxy: PASS
     - [x] `uname -a` (server)
     - [x] `rpmsg dump all` (server)
     - [x] `rpmsg ping all 10 1024 3 0` (server)
     - [x] `uname -a` (proxy)
     - [x] `rpmsg ping all 10 1024 3 0` (proxy)
     - [x] `mount -t rpmsgfs -o cpu=server,fs=/proc /sp` (proxy)
     - [x] `cat /sp/version` (proxy)
     - [x] `rpmsg dump all` (proxy)
   - qemu-armv8a:rpserver + qemu-armv8a:rpproxy: PASS
     - [x] `uname -a` (server)
     - [x] `uname -a` (proxy)
     - [x] `rpmsg dump all` (server)
     - [x] `rpmsg ping all 10 1024 3 0` (server)
     - [x] `rpmsg ping all 10 1024 3 0` (proxy)
     - [x] `mount -t rpmsgfs -o cpu=server,fs=/proc /sp` (proxy)
     - [x] `cat /sp/version` (proxy)
   
   Same baseline on sim:rpserver + sim:rpproxy with
   `CONFIG_MM_TLSF_MANAGER=y` (`CONFIG_MM_DEFAULT_MANAGER` unset) on both
   sides: 8/8 pass.
   
   Before/after with the custom user heap manager: sim:rpserver +
   sim:rpproxy, both with `CONFIG_MM_UMM_CUSTOMIZE_MANAGER=y` added, same
   baseline cases.
   
   | tree | result |
   | --- | --- |
   | master | server segfaults as soon as the proxy connects; 0/8 |
   | this PR | 8/8 pass |
   
   On master `rptun_init_carveout()` passes `KRN_HEAP` (`g_mmheap`) to
   `mm_initialize_heap()`, which calls `mm_malloc()` on it. Under the custom
   manager `g_mmheap` points to sim_ummheap's own `struct mm_heap_s`, so
   `mm_lock()` takes a field of it as a mutex:
   
   <details><summary>master, gdb on sim:rpserver</summary>
   
   ```
   Program received signal SIGSEGV, Segmentation fault.
   0x4001d659 in nxsched_add_prioritized (tcb=0x4014def8, list=0x401151a8 
<g_heap+8>) at nuttx/sched/sched/sched.h:512
   512         (next && sched_priority <= next->sched_priority);
   #0  0x4001d659 in nxsched_add_prioritized (tcb=0x4014def8, list=0x401151a8 
<g_heap+8>) at nuttx/sched/sched/sched.h:512
   #1  0x4001eaea in nxsem_wait_slow (sem=0x401151a0 <g_heap>) at 
nuttx/sched/semaphore/sem_wait.c:266
   #2  0x40015305 in nxsem_wait (sem=0x401151a0 <g_heap>) at 
nuttx/libs/libc/semaphore/sem_wait.c:201
   #3  0x4000bb88 in nxmutex_lock (mutex=0x401151a0 <g_heap>) at 
nuttx/include/nuttx/mutex.h:503
   #4  0x4001a51c in mm_lock (heap=0x401151a0 <g_heap>) at 
nuttx/mm/mm_heap/mm_lock.c:113
   #5  0x4001b00d in mm_malloc (heap=0x401151a0 <g_heap>, size=368) at 
nuttx/mm/mm_heap/mm_malloc.c:215
   #6  0x4001a311 in mm_initialize_heap (config=0x401a52b8) at 
nuttx/mm/mm_heap/mm_initialize.c:262
   #7  0x4000a5e8 in rptun_init_carveout (priv=0x4014ddc8, vdev=0x4018500c, 
shmname=0xf7c17088 "rng0_shm", shmbase=0xf7c17188, shmlen=65312) at 
nuttx/drivers/rptun/rptun.c:506
   #8  0x4000ab19 in rptun_create_device (priv=0x4014ddc8, vdev_=0x401a5390, 
index=0) at nuttx/drivers/rptun/rptun.c:681
   #9  0x4000ad71 in rptun_create_devices (priv=0x4014ddc8) at 
nuttx/drivers/rptun/rptun.c:829
   #10 0x4000b18e in rptun_start_thread (argc=3, argv=0x40194468) at 
nuttx/drivers/rptun/rptun.c:1022
   #11 0x4002484f in nxtask_start () at nuttx/sched/task/task_start.c:99
   #12 0x400374d9 in pre_start () at 
nuttx/arch/sim/src/sim/sim_initialstate.c:54
   #13 0x00000000 in ?? ()
   ```
   </details>
   
   Build only: sim:asan (`CONFIG_MM_UMM_CUSTOMIZE_MANAGER=y` in its
   defconfig).
   
   No regression in rpmsg: sim:rpserver/rpproxy and 
qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping, 
rpmsgfs; 15/15). qemu-armv8a was built with LIBC_ENVPATH and BINFMT_CHECKEXEC 
disabled, which current master needs for nxinit to start nsh there; unrelated 
to this change.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to