Commit Graph

2241 Commits

Author SHA1 Message Date
Xiang Xiao 7c839d7a09 rptun: Remove include/nuttx/rptun/openamp.h
and use include/nuttx/rpmsg/rpmsg.h instead

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-10-07 00:44:28 +08:00
chenrun1 8f9857bf8c fs_lock:Check the nwaiter when deleting a bucket
Summary:
  Fixed the problem of releasing the bucket prematurely in multi-threaded flock scenarios.

A thread setlk
B thread setlk_wait
A thread releases lock but fails to determine if nwaiter causes the bucket to be released prematurely
post B thread causes crash due to heap use after free

https://github.com/apache/nuttx/issues/13821

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-10-05 21:09:46 +08:00
Michal Lenc f778660aca smartfs: return -ENOTTY if ioctl command is not found
The upper layer expects -ENOTTY is returned if ioctl command is not
found in file system specific implementation.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2024-10-05 20:52:31 +08:00
zhanghongyu bd83d2aca5 fs_lock: fix cmake build error
nuttx/fs/vfs/fs_lock.c:39:10: fatal error: sched/sched.h: No such file or directory
   39 | #include "sched/sched.h"
      |          ^~~~~~~~~~~~~~~

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-10-05 13:43:02 +08:00
zhengyu9 70a91289dd fs: fdcheck can't assert
while running fdcheck_test_common there should be assertion failed

Signed-off-by: zhengyu9 <zhengyu9@xiaomi.com>
2024-10-03 14:22:55 +08:00
dongjiuzhu1 b2e69b86ad fs/inode: remove unnecessary return value for inode_addrefs
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-10-02 01:56:46 +08:00
dongjiuzhu1 09a9611ae9 fs/inode: using rwsem lock as inode_lock to avoid deadlock
Example:
When executing "df -h" on Core A to view mount information, this
process will traverse inode nodes, thereby holding the inode_lock.
Since the inode type of the mount point may be rpmsgfs, it will fetch statfs
information from another Core B.

Meanwhile, rcS on Core B needs to obtain file information from Core A,
which will be achieved by fetching stat information through rpmsgfs.
When this message arrives at Core A, a deadlock can occur between Core A's
rptun ap and nsh task.

However, both of these places involve read operations only, thus a reader-writer lock
can be utilized to prevent such a deadlock.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-10-02 01:56:46 +08:00
dongjiuzhu1 f9283c4e70 fs/vfs: fix compile break when enable PSEUDOFS_FILE
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-10-01 20:39:05 +08:00
xuxingliang 7044b10c88 task: use get_task_name where possible
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-01 20:38:06 +08:00
anjiahao ee07a269af fs/ioctl:add FIOC_XIPBASE to get file xip address
in tmpfs/romfs, we can get file real xip address to execute program

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-30 18:25:46 +08:00
buxiasen 2746aa0643 fs: fix dup not compatible with fdcheck & fdsan
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-09-30 16:53:51 +08:00
dongjiuzhu1 5b889b9270 fs/dup: remove template filep to optimize dup operation
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-30 16:53:51 +08:00
chenrun1 96206cbf9d fs/xxfs:Replace kmm with fs heap
Summary:
  1.Add configuration to allocate memory from the specified section
  2.Replace all memory operations (kmm_) in the vfs with
    fs_heap_. When FS_HEAPSIZE > 0, memory is requested for the file system by specifying a configured heap location. By default (i.e. FS_HEAPSIZE=0) fs_heap_ is equivalent to kmm_

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-09-30 16:30:56 +08:00
chenrun1 e0df067d3c accept4:move function from net to fs
Summary:
  Implementation in accept4 is special, the requested newsock is saved as filep->priv. This will cause sock_file_close to use fs_heap_free filep->priv during close. When fs_heap is configured, the released memory will not be on fs_heap, causing a crash.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-09-30 16:30:56 +08:00
dongjiuzhu1 4df9a3cb42 fs/mount: move mountpoint inode create after bind
This can avoid the issue of invalid inode access when bind is not yet
completed.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-30 10:30:16 +08:00
dongjiuzhu1 29e7b00c4e fs/epoll: add error log when epoll wait return failed
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-28 10:44:59 +08:00
dongjiuzhu1 580bdda624 fs/poll: ouput error log about poll failed
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-28 10:44:59 +08:00
dulibo1 3c866e8cfd procfs:fix cat dir cause crash
ap> cat pm
=================================================================
==30235==ERROR: AddressSanitizer: heap-buffer-overflow on address 0xf436edd9 at pc 0x03338a48 bp 0x9d1b6ca8 sp 0x9d1b6c98
READ of size 1 at 0xf436edd9 thread T0
    #0 0x3338a47 in strncmp string/lib_strncmp.c:42
    #1 0x371af87 in pm_get_file_index power/pm/pm_procfs.c:174
    #2 0x371b066 in pm_open power/pm/pm_procfs.c:207
    #3 0x3640d20 in procfs_open procfs/fs_procfs.c:419
    #4 0x359bce2 in file_vopen vfs/fs_open.c:240
    #5 0x359c431 in nx_vopen vfs/fs_open.c:312
    #6 0x359cb53 in open vfs/fs_open.c:465
    #7 0x33bccc9 in nsh_catfile /apps/nshlib/nsh_fsutils.c:140
    #8 0x33b28cc in cmd_cat /apps/nshlib/nsh_fscmds.c:556
    #9 0x33a434f in nsh_command /apps/nshlib/nsh_command.c:1164
    #10 0x3381b8f in nsh_execute /apps/nshlib/nsh_parse.c:845
    #11 0x338dc17 in nsh_parse_command /apps/nshlib/nsh_parse.c:2744
    #12 0x338e273 in nsh_parse /apps/nshlib/nsh_parse.c:2828
    #13 0x3390b47 in nsh_session /apps/nshlib/nsh_session.c:245
    #14 0x337e90a in nsh_consolemain /apps/nshlib/nsh_consolemain.c:75
    #15 0x337e7f7 in nsh_main /apps/system/nsh/nsh_main.c:74
    #16 0x332b6e6 in nxtask_startup sched/task_startup.c:70
    #17 0x323ec3f in nxtask_start task/task_start.c:134
    #18 0x33636ea in pre_start sim/sim_initialstate.c:52

ap> cat net
=================================================================
==30303==ERROR: AddressSanitizer: heap-buffer-overflow on address 0xf4479a5a at pc 0x03338a48 bp 0x9d2b6ce8 sp 0x9d2b6cd8
READ of size 1 at 0xf4479a5a thread T0
    #0 0x3338a47 in strncmp string/lib_strncmp.c:42
    #1 0x5395d62 in netprocfs_open procfs/net_procfs.c:215
    #2 0x3640d20 in procfs_open procfs/fs_procfs.c:419
    #3 0x359bce2 in file_vopen vfs/fs_open.c:240
    #4 0x359c431 in nx_vopen vfs/fs_open.c:312
    #5 0x359cb53 in open vfs/fs_open.c:465
    #6 0x33bccc9 in nsh_catfile /apps/nshlib/nsh_fsutils.c:140
    #7 0x33b28cc in cmd_cat /apps/nshlib/nsh_fscmds.c:556
    #8 0x33a434f in nsh_command /apps/nshlib/nsh_command.c:1164
    #9 0x3381b8f in nsh_execute /apps/nshlib/nsh_parse.c:845
    #10 0x338dc17 in nsh_parse_command /apps/nshlib/nsh_parse.c:2744
    #11 0x338e273 in nsh_parse /apps/nshlib/nsh_parse.c:2828
    #12 0x3390b47 in nsh_session /apps/nshlib/nsh_session.c:245
    #13 0x337e90a in nsh_consolemain /apps/nshlib/nsh_consolemain.c:75
    #14 0x337e7f7 in nsh_main /apps/system/nsh/nsh_main.c:74
    #15 0x332b6e6 in nxtask_startup sched/task_startup.c:70
    #16 0x323ec3f in nxtask_start task/task_start.c:134
    #17 0x33636ea in pre_start sim/sim_initialstate.c:52

Signed-off-by: dulibo1 <dulibo1@xiaomi.com>
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-09-27 23:19:57 +08:00
Michal Lenc 8639b1ca66 smartfs: add support for FIOC_FILEPATH ioctl
The FIOC_FILEPATH ioctl call is required if smartfs is to be used
together with inotify monitoring system. This implements the
call support to smartfs file system. The path to the file has to
be stored in smartfs_ofile_s structure during file open (and is freed
during close) as smartfs currently is not able to obtain the path
knowing only the file node. The full path is concatenated with the file
name and creates the full path needed for inotify to detect whether
the file is on the watchlist.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
2024-09-27 10:28:37 +08:00
guoshichao 203944b724 fs_fcntl: fix the ret value not check error
add ret value check on file_seek function to compat with misra rule

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-09-27 00:20:53 +08:00
chenrun1 e86be98d14 fs_rammap:Check last fileseek restore fpos
Summary:
  When restoring rammap fpos, we check the return value to avoid potential problems caused by no error return if the restore fails.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-09-26 16:15:17 +08:00
zhangshoukui d68fab125e FS_RAMMAP depends on FS_REFCOUNT and remove useless macro
Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2024-09-23 18:22:35 +08:00
zhangshoukui 7e97691452 Should call fs_putfilep put fs reference when call files_fget complete
Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2024-09-23 18:22:35 +08:00
dongjiuzhu1 a2845faee3 fs/chmod/fchmod/lchmod: only set permissions by mode_t and ignore other bits
test case:

int main(void)
{
  struct stat buf;
  int ret;

  stat("test1.t", &buf);
  printf("test1.t st.mode:%x\n", buf.st_mode);
  stat("test.t", &buf);
  printf("test.t st.mode:%x\n", buf.st_mode);
  ret = chmod("test1.t", buf.st_mode);
  if (ret == 0)
    {
      stat("test1.t", &buf);
      printf("test1.t st.mode:%x\n", buf.st_mode);
    }

  return 0;
}

>>
test1.t st.mode:81b4
test.t st.mode:81fd
test1.t st.mode:81fd

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-23 14:57:37 +08:00
chenrun1 03f215b374 nuttx/atomic.h:fix Fixed the pragma of ATOMIC_VAR_INIT in clang
Error: vfs/fs_epoll.c:126:3: error: macro 'ATOMIC_VAR_INIT' has been marked as deprecated [-Werror,-Wdeprecated-pragma]
  ATOMIC_VAR_INIT(1),     /* i_crefs */
  ^
/Applications/Xcode_15.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/stdatomic.h:54:41: note: macro marked 'deprecated' here
                                        ^
1 error generated.
make[1]: *** [fs_epoll.o] Error 1
Error: socket/socket.c:78:3: error: macro 'ATOMIC_VAR_INIT' has been marked as deprecated [-Werror,-Wdeprecated-pragma]
  ATOMIC_VAR_INIT(1),     /* i_crefs */

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-09-23 14:07:03 +08:00
chenrun1 4cec713dbf fs_inode:Change the type of i_crefs to atomic_int
Summary:
  1.Modified the i_crefs from int16_t to atomic_int
  2.Modified the i_crefs add, delete, read, and initialize interfaces to atomic operations
The purpose of this change is to avoid deadlock in cross-core scenarios, where A Core blocks B Core’s request for a write operation to A Core when A Core requests a read operation to B Core.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-09-23 14:07:03 +08:00
wangjianyu3 b30f866f80 Thermal: Add procfs file nodes
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2024-09-23 08:57:29 +08:00
guoshichao f01a2c70fd greenhills: fix the enumerated type mixed using warning
CC:  obstack/lib_obstack_printf.c "mmap/fs_rammap.c", line 126: warning #188-D: enumerated type mixed with
          another type
    enum mm_map_type_e type = (uintptr_t)entry->priv.p & 3;
                              ^

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-09-19 14:08:07 +08:00
Shoukui Zhang 5d3d123272 BCH: Add readonly configuration for BCH devices
Signed-off-by: Shoukui Zhang <zhangshoukui@xiaomi.com>
2024-09-19 03:53:20 +08:00
ligd 90dcd5edd3 critmonitor: add caller support
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-19 03:16:14 +08:00
yinshengkai e28b311b78 Make each function of SCHED_CRITMONITOR independent
There will be a large performance loss after SCHED_CRITMONITOR is enabled.
By isolating thread running time-related functions, CPU load can be run with less overhead.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-09-19 03:16:14 +08:00
anjiahao 5952bc7392 fs_dup2:fix inode->i_crefs counting error
file_ioctl failed, but close success, inode need release

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-19 02:55:13 +08:00
zhangshoukui 3fb6b4c9ec fix mmap compile error.
mmap/fs_rammap.c:81:39: error: expected ‘)’ before ‘PRIdOFF’
   81 |       ferr("ERRORL Seek to position %"PRIdOFF" failed\n", fpos);
      |                                       ^~~~~~~
mmap/fs_rammap.c:81:12: warning: spurious trailing ‘%’ in format [-Wformat=]
   81 |       ferr("ERRORL Seek to position %"PRIdOFF" failed\n", fpos);
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
mmap/fs_rammap.c:81:37: note: format string is defined here
   81 |       ferr("ERRORL Seek to position %"PRIdOFF" failed\n", fpos);
      |                                     ^
In file included from mmap/fs_rammap.c:30:
mmap/fs_rammap.c:98:51: error: expected ‘)’ before ‘PRIdOFF’
   98 |               ferr("ERROR: Write failed: offset=%"PRIdOFF" nwrite=%zd\n",
      |                                                   ^~~~~~~
mmap/fs_rammap.c:98:20: warning: spurious trailing ‘%’ in format [-Wformat=]
   98 |               ferr("ERROR: Write failed: offset=%"PRIdOFF" nwrite=%zd\n",
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mmap/fs_rammap.c:98:49: note: format string is defined here
   98 |               ferr("ERROR: Write failed: offset=%"PRIdOFF" nwrite=%zd\n",

Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2024-09-19 01:43:50 +08:00
chenrun1 250353240c rammap:Adjust the lower two bits to represent type
Summary:
  In rammap:
   1.0 - User
   2.1 - Kernel
   3.2 - XIP
  Therefore we need to use 2 bits to represent the type

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-09-19 01:43:50 +08:00
chenrun1 c9148fbb0a fs_msync:Fix crash caused under the anonymous mapping
Summary:
 Limitations of using fs putfile

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-09-19 01:43:50 +08:00
chenrun1 d04205aa3d fs/mmap/msync:support msync.
Summary:
  1.Added msync callback in struct mm_map_entry_s
  2.Added msync API in fs_msync.c
  3.Added static msync_rammap for rammap.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-09-19 01:43:50 +08:00
wanggang26 484600bd75 mmap: add xip mmap type support
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-09-19 01:43:50 +08:00
chao an 3cce16dd0c fs/dump: correct SCHED_DUMP_ON_EXIT to DUMP_ON_EXIT
1. correct SCHED_DUMP_ON_EXIT to DUMP_ON_EXIT
2. dump file list only if DUMP_ON_EXIT enabled

Signed-off-by: chao an <anchao@lixiang.com>
2024-09-18 23:48:31 +08:00
zhangshoukui baa716a85d fs: Dump the list of files when the file description runs out
Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2024-09-18 13:48:45 +08:00
Shoukui Zhang 175fcb799e add sched note for littlefs/romfs/rpmsgfs
Signed-off-by: Shoukui Zhang <zhangshoukui@xiaomi.com>
2024-09-17 15:21:54 -03:00
simbit18 583f025422 Fix Kconfig style
Remove spaces from Kconfig files
Add TABs
Replace help => ---help---
2024-09-17 22:16:41 +08:00
YAMAMOTO Takashi a78622d7bf file_read: fix a bogus cast 2024-09-17 20:10:31 +08:00
zhangshoukui 13dd7bbfb3 Add reference count configuration
Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2024-09-17 12:01:53 +08:00
zhangshoukui 0b084308ba Fix Multiple close fd when SMP enable
task1:
The refs is 0 but the inode has not been released
task2:
Executing files_duplist, get filep with refs is zero, but the inode has not yet released.

[    0.530600] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: backtrace:
[    0.530800] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x4045172>] backtrace_unwind+0x241/0x244
[    0.531200] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x4009150>] sched_backtrace+0x27/0x4c
[    0.531500] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x402f0fa>] sched_dumpstack+0x3d/0xa0
[    0.531700] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x4002c90>] _assert+0x1e3/0x564
[    0.532000] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x40221f6>] __assert+0x19/0x24
[    0.532200] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x41fe376>] tcp_stop_monitor+0x61/0x6c
[    0.532500] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x41fe19e>] tcp_close+0xad/0xdc
[    0.532700] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x41ecc18>] inet_close+0x7b/0x8c
[    0.533000] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x41ec374>] psock_close+0x27/0x70
[    0.533300] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x420b68e>] sock_file_close+0x15/0x3c
[    0.533500] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x4206704>] file_close+0x1f/0x80
[    0.533800] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x4205278>] files_duplist+0x39f/0x45c
[    0.534100] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x4000e3c>] group_setuptaskfiles+0x57/0xc0
[    0.534300] [CPU1] [ 6] [ ALERT] [ap] sched_dumpstack: [ 6] [<0x400bc6c>] nxtask_init+0x5b/0x13c

Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2024-09-17 12:01:53 +08:00
Xiang Xiao 744da99250 Fix vfs/fs_fstatfs.c:60:21: warning: variable 'inode' set but not used
60 |   FAR struct inode *inode;
      |                     ^~~~~

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-09-17 12:01:53 +08:00
Shoukui Zhang 43223124ec vfs/file: add reference counting to prevent accidental close during reading writing...
Signed-off-by: Shoukui Zhang <zhangshoukui@xiaomi.com>
2024-09-17 12:01:53 +08:00
wanggang26 89e5ceb51e vfs:fix a type mismatch issue and a typo
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-09-16 11:24:56 -03:00
dongjiuzhu1 d2591380ae Revert "fs/mount and fs/romfs: Add support to mount a ROMFS volume using an MTD driver interface using the standard mount() operation."
This reverts commit 5708a1ac73.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-16 12:27:40 +08:00
dongjiuzhu1 ace2683492 fs/mount: add ftl proxy to mount block filesystem on mtd device
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-16 12:27:40 +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