casaroli opened a new pull request, #20951:
URL: https://github.com/apache/nuttx/pull/20951

   ## Summary
   
   In the kernel build, a shm object (`shm_open()`) is a list of single pages 
from the page pool. `shmfs_read()` and `shmfs_write()` copied the data at the 
first page plus the file position (`(char *)sho->paddr + pos`). After the first 
page this is correct only if the pages of the object are contiguous, and it 
uses the physical address as the kernel address.
   
   The new `shmfs_copy()` copies page by page through the kernel address of 
each page (`up_addrenv_page_vaddr()`). In the flat and protected builds the 
object is one block of memory, and the copy is the `memcpy()` as before.
   
   ## Impact
   
   Kernel builds with `CONFIG_FS_SHMFS`: `read()` and `write()` after the first 
page of a shm object use the pages of that object. Flat and protected builds do 
not change. `mmap()` of a shm object does not change.
   
   In the kernel build, `CONFIG_FS_SHMFS` selects `CONFIG_ARCH_VMA_MAPPING`. 
The architectures that build shmfs there (arm64, armv7-a, risc-v) have 
`up_addrenv_page_vaddr()`; `shmfs_alloc_object()` already uses 
`up_addrenv_page_wipe()` from the same file.
   
   ## Testing
   
   Test program `shmrw.c`. Step 1 reads a new object (zeros). Step 2 makes 
object `a` (one page, not mapped) and object `b` (one page, 0xb1 through 
`mmap()`), frees `a`, then makes object `x` (two pages, the second page 0x5a 
through `mmap()`). The first page of `x` is the page of `a`, so the two pages 
of `x` are not contiguous. `read()` of `x` at 4096 must give 0x5a, and 
`write()` of 0x77 at 4096 must show in the mapping of `x` and not in `b`.
   
   `qemu-armv7a:knsh` (kernel build, QEMU 11, Arm GNU 13.2) with 
`CONFIG_ARCH_VMA_MAPPING` and `CONFIG_FS_SHMFS`:
   
   | | master | this PR |
   |---|---|---|
   | step 1 | PASS | PASS |
   | step 2 `read()` of `x` at 4096 | FAIL: 16 bytes of 0xb1 (the data of 
object `b`) | PASS: 0x5a |
   | step 2 `write()` of `x` at 4096 | FAIL: `x[4096]` stays 0x5a, `b[0]` 
becomes 0x77 | PASS: `x[4096]` = 0x77, `b[0]` = 0xb1 |
   | `ostest` | `Exiting with status 0` | `Exiting with status 0` |
   
   `qemu-armv8a:knsh` (kernel) and `qemu-armv8a:nsh` (flat), each with 
`CONFIG_FS_SHMFS`: `ostest` exits with status 0 (QEMU with HVF). 
`rv-virt:knsh64` (kernel, with a mapping area) and `rv-virt:pnsh64` 
(protected), each with `CONFIG_FS_SHMFS`, build.
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
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