Commit Graph

40 Commits

Author SHA1 Message Date
ouyangxiangzhen 17c51c0667 userspace: Exclude nuttx/arch.h
This patch fixed userspace headers conflict. Architecture-related definition and API should not be exposed to users.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2024-11-01 16:59:37 +08:00
dongjiuzhu1 47478e543d fs/shm: support shm_open with flags O_TRUNC
testcase:
https://fossies.org/linux/posixtestsuite/conformance/interfaces/shm_open/25-1.c

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-10-31 18:47:51 -03:00
YAMAMOTO Takashi 761ee81956 move readv/writev to the kernel
currently, nuttx implements readv/writev on the top of read/write.
while it might work for the simplest cases, it's broken by design.
for example, it's impossible to make it work correctly for files
which need to preserve data boundaries without allocating a single
contiguous buffer. (udp socket, some character devices, etc)

this change is a start of the migration to a better design.
that is, implement read/write on the top of readv/writev.

to avoid a single huge change, following things will NOT be done in
this commit:

* fix actual bugs caused by the original readv-based-on-read design.
  (cf. https://github.com/apache/nuttx/pull/12674)

* adapt filesystems/drivers to actually benefit from the new interface.
  (except a few trivial examples)

* eventually retire the old interface.

* retire read/write syscalls. implement them in libc instead.

* pread/pwrite/preadv/pwritev (except the introduction of struct uio,
  which is a preparation to back these variations with the new
  interface.)
2024-10-30 17:07:54 +08:00
zhangshoukui 198dd93713 shmfs: return EINVAL if group null
Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2024-10-29 18:11:33 +08:00
zhangshoukui 646bf48ed2 shmfs: Assign a variable when object is not null
Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
2024-10-29 18:11:33 +08:00
Neo Xu 8a70377fc4 fs/shm: align memory size to cache line size
Make sure the share memory takes the full cache line.

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2024-10-27 10:38:58 +08:00
xuxingliang 9af5fc5d09 fs/shm: alloc aligned memory if CPU has cache
For kernel builds, shared memory is automatically aligned to page size.
For flat and protected builds, we align the memory size to the CPU cache
line size.

Failure to align memory properly could result in partial data read/write
by the CPU and peripherals, potentially causing data corruption during
cache flushes or invalidations.

Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-27 10:38:58 +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
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 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
dongjiuzhu1 43d0d95f81 fs/inode: using inode reference to indicate unlink and simply code
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-09 08:42:34 +08:00
hujun5 198630a809 sched: use this_task replace nxsched_self
reason:
We can reduce a function call to improve performance.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-09-05 09:33:50 -03:00
buxiasen 946ed96926 fs: add fs_heap, support shm/tmpfs/pseudofile with indepent heap
For some case, need large files from tmpfs or shmfs, will lead to high
pressure on memory fragments, add an optional fs_heap with independent
heap will benifit for memory fragments issue.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-08-25 22:12:37 +08:00
pengyinjie 77205b353f [fs][shmfs]:Avoid an integer overflow
[Desc]:We need to check the parameter passed to the kmm_zalloc(size_t) function.
If it exceeds the limit of size_t, we need to return an error directly to avoid further errors.

Signed-off-by: pengyinjie <pengyinjie@xiaomi.com>
2024-08-24 20:33:59 +08:00
guohao15 86e00896d3 fs:notify add support for inotify
support API: open close read write unlink mkdir rename fchstat rmdir symlink

Signed-off-by: guohao15 <guohao15@xiaomi.com>
2024-08-22 01:50:37 +08:00
Ville Juven f0846e1d2d fs/shmfs: Fix stat() system call for shmfs object
Set i_size for shmfs objects
2024-02-02 09:12:18 -08:00
Ville Juven 07ce2f717a shmfs/shmfs_alloc. Fix POSIX violation for shmfs_truncate
When shmfs_truncate is called, it uses shmfs_alloc_object to create the
physical backing for the shm file. However, the allocated physical
memory returned by mm_pgalloc is not cleared when CONFIG_BUILD_KERNEL is
set, which is a clear POSIX violation:

https://pubs.opengroup.org/onlinepubs/9699919799/functions/truncate.html

"If the file was previously shorter than length, its size is increased,
and the extended area appears as if it were zero-filled."

For FLAT and PROTECTED modes zalloc is used, so the violation affects
KERNEL mode only.
2024-02-02 09:09:55 -08:00
Ville Juven 43a26220be fs/shmfs: Fix CONFIG_FS_SHM -> CONFIG_FS_SHMFS
The macro was wrong
2024-01-31 08:51:52 -08:00
xuxin19 b1cc5b50b1 cmake:complete missing changes during cmake reforming for fs
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2023-09-08 21:20:16 +03:00
chao an b60f01a55b inode/i_private: remove all unnecessary cast for i_private
Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-29 08:58:07 +02:00
chao an 7aa45305b7 fs/inode: remove all unnecessary check for filep/inode
Since VFS layer already contains sanity checks, so remove unnecessary lower half checks

Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-29 09:47:11 +08:00
Ville Juven a37d094f31 fs/shmfs: Fix illegal usage of void* arithmetics
Fixes build error with -Werror:

shm/shmfs.c: In function 'shmfs_read':
shm/shmfs.c:122:33: error: pointer of type 'void *' used in arithmetic [-Werror=pointer-arith]
  122 |       memcpy(buffer, sho->paddr + startpos, nread);
      |                                 ^
shm/shmfs.c: In function 'shmfs_write':
shm/shmfs.c:166:25: error: pointer of type 'void *' used in arithmetic [-Werror=pointer-arith]
  166 |       memcpy(sho->paddr + startpos, buffer, nwritten);
      |                         ^
cc1: all warnings being treated as errors
2023-08-22 23:33:20 +08:00
fangxinyong 1adef07a79 fs/shmfs: implement read and write interface
To pass LTP posix case mmap/1-2.c

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-02 22:57:28 -07:00
fangxinyong ea52220509 fs/shmfs: fix inode leak issue
If the shm file is removed and a subsequent close, only release shm
object, but inode is leaked. Should decrease refcount to release inode
when unmapped, that matched with refcount increase when mapped.

Another fix that remove the shm file failed.
nsh> rm /var/shm/pts_mmap_1_2_5
nsh: rm: unlink failed: 6

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-02 22:57:28 -07:00
fangxinyong 43b0421b2a mm/map: limit the count of memory mapping for the task
No memory map count limit that will exhaust memory and cause
the system hang. Also that fix pass LTP posix case mmap/24-1.c

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-02 22:57:28 -07:00
yanghuatao e9d7210d02 sim/posix_test: fix shm_open() return file descriptor associated with FD_CLOEXEC
Make the pthread_setspecific pass the shm_open/11-1.c testcases. Function shm_open() should return a file descriptor for the shared memory object associated with FD_CLOEXEC. Reference to https://pubs.opengroup.org/onlinepubs/9699919799/functions/shm_open.html and https://github.com/lattera/glibc/blob/master/sysdeps/posix/shm_open.c#LL38C1-L38C1

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
2023-07-11 13:30:34 +08:00
chao an 6ee9ec7656 build: add initial cmake build system
1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)

------------------

How to test

From within nuttx/. Configure:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja

(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja

This uses ninja generator (install with sudo apt install ninja-build). To build:

$ cmake --build build

menuconfig:

$ cmake --build build -t menuconfig

--------------------------

2. cmake/build: reformat the cmake style by cmake-format

https://github.com/cheshirekow/cmake_format

$ pip install cmakelang

$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done

Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-08 13:50:48 +08:00
Xiang Xiao 17f173d555 fs/vfs: Zero file struct field with memset
to avoid set fields to zero one by one

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-08 17:56:07 +03:00
Xiang Xiao 51dc67ad5f fs: Add g_ prefix for all global file_operations instances
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-04-24 16:13:29 +02:00
Ville Juven 53d4b9ed54 mm/mm_map: Give the mm_map as parameter to the mm_map functions
This way the mappings can be modified for any vm area, not only the
process that is running.

Why? This allows mapping pages to kernel dynamically, this functionality
will be presented later.
2023-04-22 00:40:37 +08:00
Petro Karashchenko 2c972bd402 fs/shm: update pointer arithmetic logic
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-01-26 10:26:09 +08:00
Petro Karashchenko d35d8b4a12 fs/shm: use ERROR instead of -1
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-01-26 10:26:09 +08:00
Jukka Laitinen a0ebddaac1 fs/shm: Add initial implementation for posix shared memory
This implements the file system logic for posix shared memory:
shm_open, shm_unlink, mmap, munmap and close

For flat and protected builds the memory simply allocated from (user) heap

For kernel build the memory is allocated from page pool and mapped with MMU

This doesn't yet support protection flags or re-sizing already truncated shared
memory area.

Co-authored-by: Ville Juven <ville.juven@unikie.com>
Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2023-01-18 11:01:20 +08:00
Xiang Xiao 8a265e274d Kconfig: Remove EXPERIMENTAL for features which is been around a long time
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-19 11:39:22 -03:00
Xiang Xiao ea4a276eb0 shm: Rename FS_SHMPATH to FS_SHM_VFS_PATH
align with other similiar config which suffix with _VFS_PATH

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-02-05 23:58:01 +01:00
Alin Jerpelea f9fb182809 Author: Gregory Nutt: update licenses to Apache
Update files from Gregory Nutt to Apache 2.0 license.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-02-05 12:15:56 -03:00
Gregory Nutt 1ed9793751 fs/: Remove dangling space at the end of lines. 2017-06-28 13:17:55 -06:00
Gregory Nutt 342f5fe33d Fix references to the no-longer-existent misc/ directory in comments, README files, and documentation 2015-06-28 08:08:57 -06:00
Gregory Nutt ddbcba03d3 Oops... forgot to add a new directory in the last commit 2014-09-29 16:48:01 -06:00