Huffer342-WSH opened a new pull request, #16556:
URL: https://github.com/apache/nuttx/pull/16556

   ## Summary
   
   This commit fixes the issue where `map_region()` sets the page table 
incorrectly when provided with an unaligned `vaddr`.
   
   E.g.
   defconfig `rv-virt:knsh_paging` set 
   ```
   CONFIG_ARCH_PGPOOL_SIZE=4194304
   CONFIG_ARCH_PGPOOL_VBASE=0x80a00000
   ```
   and `l1 page size = 4M` for sv32
   > ```
   > #define RV_MMU_L1_PAGE_SIZE     (0x400000)   /* 4M */
   > ```
   Before this commit, the last half of the range `0x80c00000~0x80e00000` was 
not set in the L1 table entry.
   
   ## Impact
   
   rv-virt's kernel memory maping.
   
   ## Testing
   
   Tested on `rv-virt:knsh_paging`
   
   
case:https://github.com/Huffer342-WSH/nuttx-apps/commit/464492591f00015c0f325e82d58cfb2039ca936d
   
   before:
   ```
   NuttShell (NSH) NuttX-12.7.2-vela
   nsh> pagingtest
   [    3.278858] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020dcb6, MTVAL: c0001000
   [    3.279215] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020dcb6, MTVAL: c0002000
   [    3.279526] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020dcb6, MTVAL: c0003000
   [    3.279834] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020dcb6, MTVAL: c0004000
   [    3.280267] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020e604, MTVAL: c1000ffc
   [    3.280609] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020ec54, MTVAL: c0b0037c
   [    3.280869] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020eebe, MTVAL: c08ffffc
   [    3.281140] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020fc20, MTVAL: c0a00004
   [    3.281414] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020dbd8, MTVAL: c0900000
   [    3.282397] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000001e, MTVAL: c09ffffc
   
   ========== Memory Read/Write Test ==========
   
   Starting heap area on-demand paging test...
   Attempting to allocate 4194304 bytes of memory...
   [    3.284261] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c0000d4c, MTVAL: c0e0000c
   Memory allocation successful. Address: 0xc0a00008 - 0xc0e00008
   [0/924]0xc0a00008 write 0 read 0 rw success
   [    3.285230] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000008c, MTVAL: c0a01008
   [1/924]0xc0a01008 write 80 read 80 rw success
   [    3.285649] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000008c, MTVAL: c0a02008
   [2/924]0xc0a02008 write 160 read 160 rw success
   [    3.286070] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000008c, MTVAL: c0a03008
   [3/924]0xc0a03008 write 240 read 240 rw success
   [    3.286470] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000008c, MTVAL: c0a04008
   ...
   [    3.453192] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000008c, MTVAL: c0bcb008
   [459/924]0xc0bcb008 write 74 read 74 rw success
   [    3.453550] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000008c, MTVAL: c0bcc008
   [460/924]0xc0bcc008 write 154 read 154 rw success
   [    3.453911] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000008c, MTVAL: c0bcd008
   [461/924]0xc0bcd008 write 234 read 234 rw success
   [    3.454291] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000008c, MTVAL: c0bce008
   [    3.454525] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020dbd8, MTVAL: 80c00000
   [    3.454743] riscv_fillpage: PANIC!!! virtual address not mappable: 
80c00000
   [    3.455123] dump_assert_info: Current Version: NuttX  12.7.2-vela 
acc067e4f1 Jun 19 2025 21:04:33 risc-v
   [    3.455359] dump_assert_info: Assertion failed panic: at file: :0 task: 
pagingtest process: pagingtest 0xc000001c
   [    3.455647] up_dump_register: EPC: 1b243c0c
   [    3.455743] up_dump_register: A0: 80605570 A1: 00000000 A2: 806055c0 A3: 
80227974
   [    3.455908] up_dump_register: A4: 802266b4 A5: 80227a76 A6: 0a000000 A7: 
8027b954
   [    3.456073] up_dump_register: T0: 80227d58 T1: 00000001 T2: 00000010 T3: 
00000000
   [    3.456235] up_dump_register: T4: 80227a90 T5: 8060552c T6: 30303030
   [    3.456379] up_dump_register: S0: 8020dbd8 S1: 80605800 S2: 80227a90 S3: 
8060552c
   [    3.456543] up_dump_register: S4: 80227a90 S5: 8060552c S6: 18000000 S7: 
0000000f
   [    3.456706] up_dump_register: S8: 806055d8 S9: 80227974 S10: 8060552c 
S11: 8022711b
   [    3.456873] up_dump_register: SP: 8020dd86 FP: 8020dbd8 TP: 80605588 RA: 
00000075
   [    3.457089] dump_stacks: ERROR: Stack pointer is not within the stack
   [    3.457242] dump_stackinfo: IRQ Stack:
   [    3.457327] dump_stackinfo:   base: 0x80605000
   [    3.457423] dump_stackinfo:   size: 00002048
   
   ```
   
   after:
   ```
   NuttShell (NSH) NuttX-12.7.2-vela
   nsh> pagingtest
   [    7.334479] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020dca6, MTVAL: c0001000
   [    7.334892] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020dca6, MTVAL: c0002000
   [    7.335301] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020dca6, MTVAL: c0003000
   [    7.335687] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020dca6, MTVAL: c0004000
   [    7.336190] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020e5f4, MTVAL: c1000ffc
   [    7.336632] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020ec44, MTVAL: c0b0037c
   [    7.336958] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020eeae, MTVAL: c08ffffc
   [    7.337299] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020fc10, MTVAL: c0a00004
   [    7.337644] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: 8020dbc8, MTVAL: c0900000
   [    7.338801] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000001e, MTVAL: c09ffffc
   
   ========== Memory Read/Write Test ==========
   
   Starting heap area on-demand paging test...
   Attempting to allocate 4194304 bytes of memory...
   [    7.341066] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c0000d4c, MTVAL: c0e0000c
   Memory allocation successful. Address: 0xc0a00008 - 0xc0e00008
   [0/924]0xc0a00008 write 0 read 0 rw success
   [    7.342204] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000008c, MTVAL: c0a01008
   [1/924]0xc0a01008 write 80 read 80 rw success
   [    7.342722] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000008c, MTVAL: c0a02008
   [2/924]0xc0a02008 write 160 read 160 rw success
   [    7.343250] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000008c, MTVAL: c0a03008
   [3/924]0xc0a03008 write 240 read 240 rw success
   [    7.343756] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000008c, MTVAL: c0a04008
   ...
   [    7.754457] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000008c, MTVAL: c0d99008
   [921/924]0xc0d99008 write 137 read 137 rw success
   [    7.754898] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000008c, MTVAL: c0d9a008
   [922/924]0xc0d9a008 write 217 read 217 rw success
   [    7.755352] riscv_fillpage: EXCEPTION: Store/AMO page fault. MCAUSE: 
0000000f, EPC: c000008c, MTVAL: c0d9b008
   [923/924]0xc0d9b008 write 46 read 46 rw success
   
   ========== Test Completed ==========
   
   ```
   
   


-- 
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: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to