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

[PMP tests] Does 'sfence-vma' needed after write pmpcfg register ? #609

Open
ansyser opened this issue Feb 6, 2025 · 2 comments
Open

Comments

@ansyser
Copy link

ansyser commented Feb 6, 2025

When working in M mode and MMU is not enabled, is it necessary to execute the sfence-vma instruction with rs1=x0 and rs2=x0 to refresh the TLB after writing the PMP control status registers? The RISC-V manual describes the operation after configuring PMP registers as follows: "If page-based virtual memory is not implemented, memory accesses check the PMP settings synchronously, so no sfence.vma is need". How should we understand the phrase 'page-based virtual memory' in this sentence? Does it only refer to MMU, or does it also include TLB?

Taking "pmp64-TOR-RWX.S" as an example:

    /* Assigning addresses to PMP address registers */
    	LA(x4, PMPADDRESS0)		// Value to be stored in pmpaddr0
	srl x4, x4, PMP_SHIFT		// Shift right by 2 times
	csrw 	pmpaddr0, x4		// Updated pmpaddr0
	sfence.vma x0, x0     // need to add?
	nop				// Added nop in case of trap
@allenjbaum
Copy link
Collaborator

allenjbaum commented Feb 6, 2025 via email

@ansyser
Copy link
Author

ansyser commented Feb 7, 2025

I found an issue in riscv-isa-manual, seems if our core support sv39/48,and working in m-mode, or in s-mode with satp.mode=bare, software needs to use an sfence.vma to sync PMP changes.

Irrespective of what satp.mode one operates in, if sv39 is supported, that equates to "page-based virtual memory is implemented". And hence software needs to use an sfence.vma to sync PMP changes.

To help this make sense, note that designs that implement page-based virtual memory will have TLBs and will typically cache translations for all modes of operations. And, as part of caching translations, the associated PMA and PMP information will also be cached.

So, for Bare mode, trivial 1-to-1 address translations, along with associated PMA and PMP info, will be cached. In essence, Bare mode is not a special case for all the address datapaths.

riscv/riscv-isa-manual#176

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

No branches or pull requests

2 participants