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 1/2] lib: sbi: Introduce sbi_hart_pmp_fence_vma
Date: Thu, 26 Feb 2026 20:34:07 +0800 [thread overview]
Message-ID: <20260226123408.1597-2-cp0613@linux.alibaba.com> (raw)
In-Reply-To: <20260226123408.1597-1-cp0613@linux.alibaba.com>
From: Chen Pei <cp0613@linux.alibaba.com>
The original sbi_hart_pmp_fence implementation actually flushes all address
translation cache entries. The sbi_hart_pmp_fence_vma is introduced to flush
only the entries corresponding to a given address and size.
Signed-off-by: Chen Pei <cp0613@linux.alibaba.com>
---
include/sbi/sbi_hart_pmp.h | 3 ++-
lib/sbi/sbi_hart_pmp.c | 30 +++++++++++++++++++++++++++---
platform/generic/eswin/eic770x.c | 2 +-
3 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/include/sbi/sbi_hart_pmp.h b/include/sbi/sbi_hart_pmp.h
index a7765d17..5d359764 100644
--- a/include/sbi/sbi_hart_pmp.h
+++ b/include/sbi/sbi_hart_pmp.h
@@ -15,7 +15,8 @@ unsigned int sbi_hart_pmp_count(struct sbi_scratch *scratch);
unsigned int sbi_hart_pmp_log2gran(struct sbi_scratch *scratch);
unsigned int sbi_hart_pmp_addrbits(struct sbi_scratch *scratch);
bool sbi_hart_smepmp_is_fw_region(unsigned int pmp_idx);
-void sbi_hart_pmp_fence(void);
+void sbi_hart_pmp_fence_all(void);
+void sbi_hart_pmp_fence_vma(unsigned long start, unsigned long size);
int sbi_hart_pmp_init(struct sbi_scratch *scratch);
#endif
diff --git a/lib/sbi/sbi_hart_pmp.c b/lib/sbi/sbi_hart_pmp.c
index 02a3b3c4..80407110 100644
--- a/lib/sbi/sbi_hart_pmp.c
+++ b/lib/sbi/sbi_hart_pmp.c
@@ -62,7 +62,7 @@ bool sbi_hart_smepmp_is_fw_region(unsigned int pmp_idx)
return bitmap_test(fw_smepmp_ids, pmp_idx) ? true : false;
}
-void sbi_hart_pmp_fence(void)
+void sbi_hart_pmp_fence_all(void)
{
/*
* As per section 3.7.2 of privileged specification v1.12,
@@ -86,6 +86,30 @@ void sbi_hart_pmp_fence(void)
}
}
+void sbi_hart_pmp_fence_vma(unsigned long start, unsigned long size)
+{
+ if ((start == 0 && size == 0) || (size == SBI_TLB_FLUSH_ALL)) {
+ sbi_hart_pmp_fence_all();
+ } else {
+ /* Flush TLB entries for the specified address range */
+ if (misa_extension('S')) {
+ unsigned long i;
+ for (i = 0; i < size; i += PAGE_SIZE) {
+ __asm__ __volatile__("sfence.vma %0"
+ :
+ : "r"(start + i)
+ : "memory");
+ }
+
+ if (misa_extension('H')) {
+ for (i = 0; i < size; i += PAGE_SIZE) {
+ __sbi_hfence_gvma_gpa((start + i) >> 2);
+ }
+ }
+ }
+ }
+}
+
static void sbi_hart_smepmp_set(struct sbi_scratch *scratch,
struct sbi_domain *dom,
struct sbi_domain_memregion *reg,
@@ -213,7 +237,7 @@ static int sbi_hart_smepmp_configure(struct sbi_scratch *scratch)
* Keep the RLB bit so that dynamic mappings can be done.
*/
- sbi_hart_pmp_fence();
+ sbi_hart_pmp_fence_all();
return 0;
}
@@ -293,7 +317,7 @@ static int sbi_hart_oldpmp_configure(struct sbi_scratch *scratch)
for(; pmp_idx < pmp_count; pmp_idx++)
pmp_disable(pmp_idx);
- sbi_hart_pmp_fence();
+ sbi_hart_pmp_fence_all();
return 0;
}
diff --git a/platform/generic/eswin/eic770x.c b/platform/generic/eswin/eic770x.c
index 7330df9f..d5564d35 100644
--- a/platform/generic/eswin/eic770x.c
+++ b/platform/generic/eswin/eic770x.c
@@ -347,7 +347,7 @@ static int eswin_eic7700_pmp_configure(struct sbi_scratch *scratch)
while (pmp_idx < pmp_max)
pmp_disable(pmp_idx++);
- sbi_hart_pmp_fence();
+ sbi_hart_pmp_fence_all();
return 0;
no_more_pmp:
sbi_printf("%s: insufficient PMP entries\n", __func__);
--
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 ` cp0613 [this message]
2026-02-26 12:34 ` [PATCH v2 2/2] " cp0613
2026-02-27 1:19 ` 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-2-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