Repository navigation
Conversation
tavip
left a comment
There was a problem hiding this comment.
Sorry for taking so long to review, and thanks for the fix! A couple of things before merging:
-
Commit message mismatch: Please update the commit message and PR description to match the diff — it currently mentions setting
FD_CLOEXEC(already guaranteed by POSIXshm_open()) and closing an existingshared_mem_fdinshmem_init(), neither of which is in the patch. -
Avoid putting
shm_unlink()insideassert()(tools/lkl/lib/posix-host.c):-DNDEBUGcompiles it out completely. Please capture the return value first (e.g.ret = shm_unlink(...); assert(ret == 0);, and ideally the same forftruncate()).
In MMU mode, the POSIX shared memory object persists after process exit because it is never unlinked. Its backing file descriptor is also left open when LKL shuts down. Unlink the object immediately after shm_open(), keeping the descriptor available for subsequent mappings. Add an optional shmem_cleanup host operation, called from free_mem() in MMU mode, to close shared_mem_fd and reset it to -1 on shutdown. Execute shm_unlink() and ftruncate() outside assert() so both calls are preserved when NDEBUG is defined. Closes: lkl#629 Signed-off-by: Cheng Lingfei <chenglingfei@foxmail.com>
Fixed. Thanks! Btw, the Windows CI build is failing because flex is missing from the MSYS2 environment. I'll send a separate PR to explicitly install flex and bison. |
In MMU mode, shmem_init() allocates POSIX shared memory via shm_open() to back LKL physical memory. Two issues currently exist:
The shared memory object is never unlinked, so it persists after the host process exits or crashes, potentially exhausting /dev/shm space during repeated testing or fuzzing.
The backing file descriptor is not closed when LKL shuts down. Reinitialization within the same host process overwrites shared_mem_fd without closing the previous descriptor, leaking file descriptors.
Fix these by:
Closes: #629