riscv-sfence-hfence

梳理riscv中sfence和hfence。

sfence

sfence.vma

RS1(vaddr) RS2(asid) Description
==x0 ==x0 删除 “vm(virtualization mode)=0” 的TLB entries
==x0 =! x0 删除 “vm=0” 且 “asid匹配(和rs2比较)” 且 “g==0” 的TLB entries
=! x0 ==x0 删除 “vm=0” 且 “addr匹配 (需结合level判断)” 的TLB entries
=! x0 =! x0 删除 “vm=0” 且 “asid匹配(和rs2比较)” 且 “g==0” 且 “addr匹配 (需结合level判断)” 的TLB entries

hfence

hfence.vvma

RS1(vaddr) RS2(asid) Description
==x0 ==x0 删除 “vm=1” 且 “VMID匹配(和hgatp.vmid比较)” 的TLB entries
==x0 =! x0 删除 “vm=1” 且 “VMID匹配(和hgatp.vmid比较)” 且 “asid匹配(和rs2比较)” 且 “g==0” 的TLB entries
=! x0 ==x0 删除 “vm=1” 且 “VMID匹配(和hgatp.vmid比较)” 且 “addr匹配 (需结合level判断)” 的TLB entries
=! x0 =! x0 删除 “vm=1” 且 “VMID匹配(和hgatp.vmid比较)” 且 “asid匹配(和rs2比较)” 且 “g==0” 且 “addr匹配 (需结合level判断)” 的TLB entries

hfence.gvma

RS1(vaddr) RS2(asid) Description
==x0 ==x0 删除 “vm=1” 的TLB entries
==x0 =! x0 删除 “vm=1” 且 “VMID匹配(和rs2比较)” 的TLB entries
=! x0 ==x0 删除 “vm=1” 且 “guest physical addr匹配 (需结合level判断)” 的TLB entries
=! x0 =! x0 删除 “vm=1” 且 “VMID匹配(和rs2比较)” 且 “guest physical addr匹配 (需结合level判断)” 的TLB entries

Special Scenario

在Guest下(也就是VS模式下),执行sfence.vma,应该要转化成hfence.vvma。

在Guest下(也就是VS模式下),写satp,应该要转化成写vsatp。