-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Revert "fs/inode: add pre-allocated task files to avoid allocator access #14416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ess"
This reverts commit 086834aae1722af2797fd5d4d0f79226ac11c2e9.
The refs in the filelist cannot protect the handles in the prefiles
The prefiles and its associated group are allocated together, and when
the group leaves, they are released together.
During a reboot process, the sync operation may encounter a "used after free"
issue.
issue stack:
(filep=filep@entry=0x3c482770) at ../../../fs/vfs/fs_close.c:80
../../../fs/vfs/fs_close.c:118
../../../fs/inode/fs_files.c:476
/home/cibuild/Public/jenkinsversion/2148/nuttx/include/nuttx/fs/fs.h:870
at ../../../fs/inode/fs_files.c:223
<task_fssync(tcb_s*, void*)>, arg=0x0) at
../../../sched/sched/sched_foreach.c:73
data=<optimized out>) at ../../../fs/fs_initialize.c:48
../../../sched/misc/reboot_notifier.c:87
../../../boards/boardctl.c:415
argv=0x3d3e07e8) at ../../../../apps/nshlib/nsh_syscmds.c:465
argc=argc@entry=2, argv=0x3d3e07e8, argv@entry=0x3d3e0820)
at ../../../../apps/nshlib/nsh_command.c:1247
argv=0x3d3e0820, argc=2, vtbl=0x3c5d2aa8) at
../../../../apps/nshlib/nsh_parse.c:847
cmdline=cmdline@entry=0x3d3df93a "reboot") at
../../../../apps/nshlib/nsh_parse.c:2757
"reboot") at ../../../../apps/nshlib/nsh_parse.c:2844
argc=argc@entry=3, argv=0x3d3df920) at
../../../../apps/nshlib/nsh_session.c:146
char**)>, isctty=isctty@entry=0) at
../../../../apps/nshlib/nsh_system.c:47
out>) at ../../../../apps/nshlib/nsh_system.c:80
entrypt=<optimized out>) at
../../../libs/libc/sched/task_startup.c:70
And the original prefile improvement was only 3 microseconds, which is
very minimal, so reverting it is the best approach.
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
|
[Experimental Bot, please feedback here] The PR summary does not fully meet NuttX requirements. Here's a breakdown and suggestions for improvement: Strengths:
Areas for Improvement:
Revised Summary (Example): This PR reverts commit 086834aae1722af2797fd5d4d0f79226ac11c2e9, which introduced pre-allocated task files to improve performance. However, this change caused a "used after free" issue during reboot due to the way pre-allocated files and their associated groups are released. This revert removes the pre-allocation mechanism, reverting to the original file handling logic. This ensures that file handles are released correctly during shutdown, preventing the "used after free" error. Revised Testing (Example): Build Host(s): Linux (Ubuntu 20.04), x86_64, GCC 9.4.0 Testing logs before change: Testing logs after change: |
I think, the main argument for the reverted commit (d297482) is functional safety requirements, not time consumption. |
#11850 was merged earlier |
anchao
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not merge this PR, thanks
@anchao This is an issue related to filelist references, not file references. Can this functionality be made configurable with a default setting to turn it off? Or are there any other good solutions to this problem? |
We will ensure that the application code does not exceed CONFIG_NFILE_DESCRIPTORS_PER_BLOCK, so file_extend() is useless.
No, static reservation is a better solution. As long as the nuttx task is created, it needs 3 handles for standard input 、output、 error(0,1,2),So pre-reserve for the file list is a certain event and cannot be skipped, so why not make it static reservation? |
If that's the case, tasks using a static file list shouldn't exit, now using such a static file list for tasks that need to exit doesn't make sense. However, given the current requirement to enforce the use of such static lists, it would be best if there were options available. |
The static file list could be exited and closed, but the reserved static buffer should not be freed. is it be possible to calculate whether the current filep is in the static file list to decide whether to release the file list? |
is the "functional safety requirements" documented somewhere? |
|
i don't understand how ISO26262 is related here.
it seems to have an obvious downside.
that is, when the workload on the system is not static as yours. also, the associated code/structural complexity (which might caused the crash @Donny9 was observing, i dunno) can be considered as another downside.
while i agree about the kernel threads, this stuff is not limited to kernel threads, is it? (well, actually i personally tend to think kernel threads should not use file descriptors at all. |
I think you should read this part of the code further. PR #11850 just replace dynamic allocation to static definition. It does not waste any memory.
This flaw should be solved in a more elegant fix instead of revert. |
it makes "struct filelist" larger, which consumes memory. |
But task_create will also request the same memory, I just moved it to tcb->group by static. |
@yamt why do you think that functional safety doesn't matter much for NuttX? I think this is a big deal for this project. BTW. dynamic files allocation is a relatively new feature (Apache era) which was also not fully discussed during its introduction and at that time introduced a difficult-to-detect bug (#6012) |
i just asked what "functional safety requirements" is because i had no idea what it is. |
if all tasks have a few open files, maybe. |
|
As the convention, we could hold the revert for several days if someone could provide a fix, otherwise the revert has to been merged. |
is this what people talking about here? |
OK, that make sense :) Functional safety opens up the possibility for NuttX to be used in many other industries |
yes, ISO 26262 is an automotive-specific standard, more general standard is IEC 61508 |
ok. thank you for explanation. |
Summary
Revert "fs/inode: add pre-allocated task files to avoid allocator access
This reverts commit 086834aae1722af2797fd5d4d0f79226ac11c2e9.
The refs in the filelist cannot protect the handles in the prefiles The prefiles and its associated group are allocated together, and when the group leaves, they are released together.
During a reboot process, the sync operation may encounter a "used after free" issue.
issue stack:
../../../sched/sched/sched_foreach.c:73
data=) at ../../../fs/fs_initialize.c:48
../../../sched/misc/reboot_notifier.c:87
../../../boards/boardctl.c:415
argv=0x3d3e07e8) at ../../../../apps/nshlib/nsh_syscmds.c:465
argc=argc@entry=2, argv=0x3d3e07e8, argv@entry=0x3d3e0820)
at ../../../../apps/nshlib/nsh_command.c:1247
argv=0x3d3e0820, argc=2, vtbl=0x3c5d2aa8) at
../../../../apps/nshlib/nsh_parse.c:847
cmdline=cmdline@entry=0x3d3df93a "reboot") at
../../../../apps/nshlib/nsh_parse.c:2757
"reboot") at ../../../../apps/nshlib/nsh_parse.c:2844
argc=argc@entry=3, argv=0x3d3df920) at
../../../../apps/nshlib/nsh_session.c:146
char**)>, isctty=isctty@entry=0) at
../../../../apps/nshlib/nsh_system.c:47
out>) at ../../../../apps/nshlib/nsh_system.c:80
entrypt=) at
../../../libs/libc/sched/task_startup.c:70
And the original prefile improvement was only 3 microseconds, which is very minimal, so reverting it is the best approach.
Impact
Bug fix
Testing
local test