Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency behavior between xiangshan and NEMU after setting PMP #4120

Open
4 tasks done
ha0lyu opened this issue Jan 2, 2025 · 2 comments
Open
4 tasks done

Inconsistency behavior between xiangshan and NEMU after setting PMP #4120

ha0lyu opened this issue Jan 2, 2025 · 2 comments
Labels
bug report Bugs to be confirmed

Comments

@ha0lyu
Copy link
Contributor

ha0lyu commented Jan 2, 2025

Before start

  • I have read the RISC-V ISA Manual and this is not a RISC-V ISA question. 我已经阅读过 RISC-V 指令集手册,这不是一个指令集本身的问题。
  • I have read the XiangShan Documents. 我已经阅读过香山文档。
  • I have searched the previous issues and did not find anything relevant. 我已经搜索过之前的 issue,并没有找到相关的。
  • I have reviewed the commit messages from the relevant commit history. 我已经浏览过相关的提交历史和提交信息。

Describe the bug

After setting PMP region, inconsistency behavior occurred.

image

image

Expected behavior

No consistence.

To Reproduce

_start:
li t0, 0x70020000
csrw pmpaddr0, t0
li t1, 0x88
csrw pmpcfg0, t1
li t1, 0x1
mret

Environment

  • XiangShan branch: master
  • XiangShan commit id: 51aa1b6
  • NEMU commit id: 1d750ea
  • SPIKE commit id:

Additional context

No response

@ha0lyu ha0lyu added the bug report Bugs to be confirmed label Jan 2, 2025
@cebarobot
Copy link
Member

cebarobot commented Jan 5, 2025

After modifying PMP configurations, SFENCE.VMA and HFENCE.GVMA instructions are required on XiangShan, as it implements page-based virtual memory.

There is a statement in RISC-V Privileged Architecture Manual / Machine-Level ISA / Physical Memory Protection / Physical Memory Protection and Paging:

... when the PMP settings are modified, M-mode software must synchronize the PMP settings with the virtual memory system and any PMP or address-translation caches. This is accomplished by executing an SFENCE.VMA instruction with rs1=x0 and rs2=x0, after the PMP CSRs are written. ...

If page-based virtual memory is not implemented, memory accesses check the PMP settings synchronously, so no SFENCE.VMA is needed.

There is supplementary explanation in changes log about "page-based virtual memory is not implemented":

PMP changes require an SFENCE.VMA on any hart that implements page-based virtual memory, even if VM is not currently enabled.

@Tang-Haojin
Copy link
Member

A complementary explanation: NEMU does not have detailed structures like ICache or TLB, so it is really hard to align NEMU with XS in such circumstances :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Bugs to be confirmed
Projects
None yet
Development

No branches or pull requests

3 participants