riscv / riscv-isa-manual

RISC-V Instruction Set Manual
https://riscv.org/
Creative Commons Attribution 4.0 International
3.7k stars 645 forks source link

How to decide the memory attribute when PBMT=NC & PMA=IO ? #1723

Open rock-ifly opened 1 week ago

rock-ifly commented 1 week ago

The Svpbmt says that memAttr is both IO and NC for the purpose of FENCE, .aq and .rl

If the underlying physical memory attribute for a page is I/O, and the page has PBMT=NC, then accesses to that page obey RVWMO. However, accesses to such pages are considered to be both I/O and main memory accesses for the purposes of FENCE, .aq, and .rl.

How to understand the "both"?

the MMU only gives a definity memAttr for a specific PA, doesn't it ? If PA0 is defined as IO in PMA, and is override by PBMT=NC in a pte, then MMU output memAttr = NC according to Svpbmt spec. Then

  1. for a common ld/st intruction, ld xn, [PA0], what is the acutual memAttr with the PA0 in LSU interface to memory?
  2. for a FENCE/.aq/.rl instruction, what is the acutual memAttr with the PA0 in LSU interface to memory?
  3. any differences between 1 and 2 ?
gfavor commented 1 week ago

Yes, a leaf PTE defines the memory attributes for just (all) the PAs within that page.

The highlighted Svpbmt text is saying that all addresses within such a page (PMA=IO, PBMT=NC), are fenced by both IO fences and main memory fences (and similar for .aq/.rl fencing purposes). Whereas PMA=IO, by itself, would say that all addresses are only fenced by IO fences. And if PMA=main_mem and PBMT=NC together, then all addresses are only fenced by main memory fences.