* [PATCH 1/2] hw/riscv: Don't insert DDT cache in Bare mode
2025-12-11 2:56 [PATCH 0/2] Don't insert DDT cache in Bare mode Jay Chang
@ 2025-12-11 2:56 ` Jay Chang
2025-12-11 2:56 ` [PATCH 2/2] hw/riscv: Refactor riscv_iommu_ctx_put() for Bare mode handling Jay Chang
1 sibling, 0 replies; 3+ messages in thread
From: Jay Chang @ 2025-12-11 2:56 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, Jay Chang, Frank Chang
In Bare mode the IOMMU does not perform DDT look-ups, therefore
caching DDT entries is unnecessary.
Signed-off-by: Jay Chang <jay.chang@sifive.com>
Reviewed-by: Frank Chang <frank.chang@sifive.com>
---
hw/riscv/riscv-iommu.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c
index 69852f4f13..79eee2e85e 100644
--- a/hw/riscv/riscv-iommu.c
+++ b/hw/riscv/riscv-iommu.c
@@ -1312,16 +1312,23 @@ static RISCVIOMMUContext *riscv_iommu_ctx(RISCVIOMMUState *s,
int fault = riscv_iommu_ctx_fetch(s, ctx);
if (!fault) {
- if (g_hash_table_size(ctx_cache) >= LIMIT_CACHE_CTX) {
+ if (mode != RISCV_IOMMU_DDTP_MODE_BARE) {
+ if (g_hash_table_size(ctx_cache) >= LIMIT_CACHE_CTX) {
+ g_hash_table_unref(ctx_cache);
+ ctx_cache = g_hash_table_new_full(riscv_iommu_ctx_hash,
+ riscv_iommu_ctx_equal,
+ g_free, NULL);
+ g_hash_table_ref(ctx_cache);
+ g_hash_table_unref(qatomic_xchg(&s->ctx_cache, ctx_cache));
+ }
+
+ g_hash_table_add(ctx_cache, ctx);
+ *ref = ctx_cache;
+ } else {
g_hash_table_unref(ctx_cache);
- ctx_cache = g_hash_table_new_full(riscv_iommu_ctx_hash,
- riscv_iommu_ctx_equal,
- g_free, NULL);
- g_hash_table_ref(ctx_cache);
- g_hash_table_unref(qatomic_xchg(&s->ctx_cache, ctx_cache));
+ /* Remember ctx so it can be freed */
+ *ref = ctx;
}
- g_hash_table_add(ctx_cache, ctx);
- *ref = ctx_cache;
return ctx;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH 2/2] hw/riscv: Refactor riscv_iommu_ctx_put() for Bare mode handling
2025-12-11 2:56 [PATCH 0/2] Don't insert DDT cache in Bare mode Jay Chang
2025-12-11 2:56 ` [PATCH 1/2] hw/riscv: " Jay Chang
@ 2025-12-11 2:56 ` Jay Chang
1 sibling, 0 replies; 3+ messages in thread
From: Jay Chang @ 2025-12-11 2:56 UTC (permalink / raw)
To: qemu-devel, qemu-riscv
Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li,
Daniel Henrique Barboza, Liu Zhiwei, Jay Chang, Frank Chang
Align SPEC: Bare mode contexts are not cached, so they require
direct memory deallocation via g_free instead of hash table cleanup.
Signed-off-by: Jay Chang <jay.chang@sifive.com>
Reviewed-by: Frank Chang <frank.chang@sifive.com>
---
hw/riscv/riscv-iommu.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c
index 79eee2e85e..fca5763858 100644
--- a/hw/riscv/riscv-iommu.c
+++ b/hw/riscv/riscv-iommu.c
@@ -1344,7 +1344,16 @@ static RISCVIOMMUContext *riscv_iommu_ctx(RISCVIOMMUState *s,
static void riscv_iommu_ctx_put(RISCVIOMMUState *s, void *ref)
{
- if (ref) {
+ unsigned mode = get_field(s->ddtp, RISCV_IOMMU_DDTP_MODE);
+
+ if (!ref) {
+ return;
+ }
+
+ /* ref is pointing to ctx in Bare mode. Bare mode ctx is not cached */
+ if (mode == RISCV_IOMMU_DDTP_MODE_BARE) {
+ g_free(ref);
+ } else {
g_hash_table_unref((GHashTable *)ref);
}
}
--
2.48.1
^ permalink raw reply related [flat|nested] 3+ messages in thread