tactcomplabs / rev

RISC-V SST CPU Component
Other
17 stars 21 forks source link

SST Segmentation Fault When Accessing Memory Across Pages with memHierarchy Backend #331

Open Artlands opened 2 days ago

Artlands commented 2 days ago

Describe the bug A segmentation fault occurs in SST when reading memory across pages using the memHierarchy backend due to incorrect logic in RevMem::ReadMem.

To Reproduce The issue is observed in the devel branch when the page size is changed to a smaller value, such as 4KB, during the execution of the test/syscalls/munmap test.

Additional context In the RevMem::ReadMem function, the code responsible for handling flag responses and clearing hazards (lines 770-783 in RevMem.cc) should be placed inside the else block when using the internal RevMem model.

Other comments/questions When using the memHierarchy backend, the cross-paging access is not relevant not only for memory read (as commented in line 771) but also for memory write. There is redundancy in calling ctrl->sendWRITERequest in RevMem::WriteMem, and the logic in these functions can be simplified. Additionally, the BaseMem address passed to ctrl->sendWRITERequest and ctrl->sendREADRequest is never used; only the virtual address is needed when sending memory requests to memHierarchy. Therefore, the memory controller interface could also be simplified.

leekillough commented 2 days ago

Can you please attach a test code?

Artlands commented 2 days ago

Can you please attach a test code?

The test code is /test/syscalls/munmap/munmap.c

After changing the pageSize to 4096 in RevMem.cc and reinstalling REV, run sst rev-model-options-config.py --model-options="--program=./syscalls/munmap/munmap.exe --enableMemH=1" in the test folder.

leekillough commented 2 days ago

If I run as you say, I get another error, an assertion failure:

RevCPU[cpu:ECALL_mmap:386000]: ECALL: mmap called
FATAL: RevCPU[cpu:FetchAndDecodeInst:169784000]: Error: Core 0 failed to decode instruction at PC=0x11278; Inst=0
leekillough commented 2 days ago

The assertion failure might be based on a page size assumption of the test. If I use the default page size, the test passes. There is no segfault anymore.