Don't insert DDT cache in Bare mode
v2 cover Don't insert DDT cache in Bare mode
When IOMMU is in Bare mode, DDT (Device Directory Table) lookup is not performed. This series fixes two issues:
1. Avoid inserting unnecessary DDT cache entries in Bare mode
2. Properly free Bare mode contexts to prevent memory leaks
Change V2
Rebase riscv-to-apply.next
Jay Chang (2):
hw/riscv: Don't insert DDT cache in Bare mode hw/riscv: Refactor riscv_iommu_ctx_put() for Bare mode handling
hw/riscv/riscv-iommu.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
Signature · 1 line
2.48.1
PATCH v2 1/2 hw/riscv: Don't insert DDT cache in Bare mode
In Bare mode the IOMMU does not perform DDT look-ups, therefore caching DDT entries is unnecessary.
--- hw/riscv/riscv-iommu.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
hw/riscv/riscv-iommu.c +15 -8
@@ -1358,16 +1358,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; }
Signature · 1 line
2.48.1
PATCH v2 2/2 hw/riscv: Refactor riscv_iommu_ctx_put() for Bare mode handling
In reply to Jay ChangAlign SPEC: Bare mode contexts are not cached, so they require direct memory deallocation via g_free instead of hash table cleanup.
--- hw/riscv/riscv-iommu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
hw/riscv/riscv-iommu.c +10 -1
@@ -1390,7 +1390,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); } }
Signature · 1 line
2.48.1
Alistair Francis
AppliedQuoted 7 lines · Jay Chang
When IOMMU is in Bare mode, DDT (Device Directory Table) lookup is not performed. This series fixes two issues:
1. Avoid inserting unnecessary DDT cache entries in Bare mode
2. Properly free Bare mode contexts to prevent memory leaks
Quoted 6 lines
Change V2
Rebase riscv-to-apply.nextJay Chang (2):
hw/riscv: Don't insert DDT cache in Bare mode hw/riscv: Refactorriscv_iommu_ctx_put()for Bare mode handling
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 8 lines
hw/riscv/riscv-iommu.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)--
2.48.1