<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Thu, Feb 26, 2026 at 8:34 PM <<a href="mailto:cp0613@linux.alibaba.com">cp0613@linux.alibaba.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From: Chen Pei <<a href="mailto:cp0613@linux.alibaba.com" target="_blank">cp0613@linux.alibaba.com</a>><br>
<br>
As the privileged specification states, after writing to the PMP CSRs,<br>
a SFENCE.VMA or HFENCE.GVMA instruction should be executed with rs1=x0<br>
and rs2=x0 to flush all address translation cache entries.<br>
<br>
Considering the performance issues caused by flushing all address<br>
translation cache entries, sbi_hart_pmp_fence_vma is used.<br></blockquote><div>It's not aligned with the spec description; PMP is about PA, but SFENCE. VMA is about the VA. So we don't know whether the other VAs has mapped to the PA that the pmp is related to.<br><br>That's why spec needs "rs1=x0 and rs2=x0 to flush all address translation cache entries."<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Signed-off-by: Chen Pei <<a href="mailto:cp0613@linux.alibaba.com" target="_blank">cp0613@linux.alibaba.com</a>><br>
---<br>
lib/sbi/sbi_hart_pmp.c | 11 ++++++++++-<br>
1 file changed, 10 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c<br>
index 80407110..dc7f61fb 100644<br>
--- a/lib/sbi/sbi_hart_pmp.c<br>
+++ b/lib/sbi/sbi_hart_pmp.c<br>
@@ -270,14 +270,21 @@ static int sbi_hart_smepmp_map_range(struct sbi_scratch *scratch,<br>
pmp_flags, base, order);<br>
pmp_set(SBI_SMEPMP_RESV_ENTRY, pmp_flags, base, order);<br>
<br>
+ sbi_hart_pmp_fence_vma(addr, size);<br>
+<br>
return SBI_OK;<br>
}<br>
<br>
static int sbi_hart_smepmp_unmap_range(struct sbi_scratch *scratch,<br>
unsigned long addr, unsigned long size)<br>
{<br>
+ int ret;<br>
+<br>
sbi_platform_pmp_disable(sbi_platform_ptr(scratch), SBI_SMEPMP_RESV_ENTRY);<br>
- return pmp_disable(SBI_SMEPMP_RESV_ENTRY);<br>
+ ret = pmp_disable(SBI_SMEPMP_RESV_ENTRY);<br>
+ sbi_hart_pmp_fence_vma(addr, size);<br>
+<br>
+ return ret;<br>
}<br>
<br>
static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch)<br>
@@ -333,6 +340,8 @@ static void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch)<br>
sbi_platform_pmp_disable(sbi_platform_ptr(scratch), i);<br>
pmp_disable(i);<br>
}<br>
+<br>
+ sbi_hart_pmp_fence_all();<br>
}<br>
<br>
static struct sbi_hart_protection pmp_protection = {<br>
-- <br>
2.50.1<br>
<br>
</blockquote></div><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr">Best Regards<br> Guo Ren<br></div></div></div>