From: cp0613@linux.alibaba.com
To: opensbi@lists.infradead.org
Cc: anup@brainfault.org, samuel.holland@sifive.com,
guoren@kernel.org, Chen Pei <cp0613@linux.alibaba.com>
Subject: [PATCH v2 2/2] lib: sbi: Flush cache entries after writing PMP CSRs
Date: Thu, 26 Feb 2026 20:34:08 +0800 [thread overview]
Message-ID: <20260226123408.1597-3-cp0613@linux.alibaba.com> (raw)
In-Reply-To: <20260226123408.1597-1-cp0613@linux.alibaba.com>
From: Chen Pei <cp0613@linux.alibaba.com>
As the privileged specification states, after writing to the PMP CSRs,
a SFENCE.VMA or HFENCE.GVMA instruction should be executed with rs1=x0
and rs2=x0 to flush all address translation cache entries.
Considering the performance issues caused by flushing all address
translation cache entries, sbi_hart_pmp_fence_vma is used.
Signed-off-by: Chen Pei <cp0613@linux.alibaba.com>
---
lib/sbi/sbi_hart_pmp.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c
index 80407110..dc7f61fb 100644
--- a/lib/sbi/sbi_hart_pmp.c
+++ b/lib/sbi/sbi_hart_pmp.c
@@ -270,14 +270,21 @@ static int sbi_hart_smepmp_map_range(struct sbi_scratch *scratch,
pmp_flags, base, order);
pmp_set(SBI_SMEPMP_RESV_ENTRY, pmp_flags, base, order);
+ sbi_hart_pmp_fence_vma(addr, size);
+
return SBI_OK;
}
static int sbi_hart_smepmp_unmap_range(struct sbi_scratch *scratch,
unsigned long addr, unsigned long size)
{
+ int ret;
+
sbi_platform_pmp_disable(sbi_platform_ptr(scratch), SBI_SMEPMP_RESV_ENTRY);
- return pmp_disable(SBI_SMEPMP_RESV_ENTRY);
+ ret = pmp_disable(SBI_SMEPMP_RESV_ENTRY);
+ sbi_hart_pmp_fence_vma(addr, size);
+
+ return ret;
}
static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch)
@@ -333,6 +340,8 @@ static void sbi_hart_pmp_unconfigure(struct sbi_scratch *scratch)
sbi_platform_pmp_disable(sbi_platform_ptr(scratch), i);
pmp_disable(i);
}
+
+ sbi_hart_pmp_fence_all();
}
static struct sbi_hart_protection pmp_protection = {
--
2.50.1
--
opensbi mailing list
opensbi@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
next prev parent reply other threads:[~2026-02-26 12:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-26 12:34 [PATCH v2 0/2] lib: sbi: Flush cache entries after writing PMP CSRs cp0613
2026-02-26 12:34 ` [PATCH v2 1/2] lib: sbi: Introduce sbi_hart_pmp_fence_vma cp0613
2026-02-26 12:34 ` cp0613 [this message]
2026-02-27 1:19 ` [PATCH v2 2/2] lib: sbi: Flush cache entries after writing PMP CSRs Guo Ren
2026-02-27 1:21 ` Guo Ren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260226123408.1597-3-cp0613@linux.alibaba.com \
--to=cp0613@linux.alibaba.com \
--cc=anup@brainfault.org \
--cc=guoren@kernel.org \
--cc=opensbi@lists.infradead.org \
--cc=samuel.holland@sifive.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox