Don't insert DDT cache in Bare mode
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
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 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
@@ -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; }
Signature · 1 line
2.48.1
Re: [PATCH 1/2] hw/riscv: Don't insert DDT cache in Bare mode
Quoted 6 lines · Jay Chang
In Bare mode the IOMMU does not perform DDT look-ups, therefore caching DDT entries is unnecessary.
Signed-off-by Jay Chang <[email protected]>Reviewed-by Frank Chang <[email protected]>---
Quoted 39 lines
hw/riscv/riscv-iommu.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)hw/riscv/riscv-iommu.c +15
-8@@ -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; }
Re: [PATCH 1/2] hw/riscv: Don't insert DDT cache in Bare mode
In reply to Jay ChangQuoted 6 lines · Jay Chang
In Bare mode the IOMMU does not perform DDT look-ups, therefore caching DDT entries is unnecessary.
Signed-off-by Jay Chang <[email protected]>Reviewed-by Frank Chang <[email protected]>---
Thanks,
Nutty
Quoted 39 lines
hw/riscv/riscv-iommu.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)hw/riscv/riscv-iommu.c +15
-8@@ -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; }
PATCH 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
@@ -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); } }
Signature · 1 line
2.48.1
Re: [PATCH 2/2] hw/riscv: Refactor riscv_iommu_ctx_put() for Bare mode handling
Quoted 6 lines · Jay Chang
Align SPEC: Bare mode contexts are not cached, so they require direct memory deallocation via
g_freeinstead of hash table cleanup.Signed-off-by Jay Chang <[email protected]>Reviewed-by Frank Chang <[email protected]>---
Quoted 25 lines
hw/riscv/riscv-iommu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/riscv/riscv-iommu.c +10
-1@@ -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); } }
Re: [PATCH 2/2] hw/riscv: Refactor riscv_iommu_ctx_put() for Bare mode handling
In reply to Jay ChangQuoted 6 lines · Jay Chang
Align SPEC: Bare mode contexts are not cached, so they require direct memory deallocation via
g_freeinstead of hash table cleanup.Signed-off-by Jay Chang <[email protected]>Reviewed-by Frank Chang <[email protected]>---
Thanks,
Nutty
Quoted 25 lines
hw/riscv/riscv-iommu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)hw/riscv/riscv-iommu.c +10
-1@@ -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); } }
Hi,
Gentle ping on this patch.
Thanks,
Jay Chang
Quoted 17 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 leaksJay Chang (2):
hw/riscv: Don't insert DDT cache in Bare mode hw/riscv: Refactorriscv_iommu_ctx_put()for Bare mode handlinghw/riscv/riscv-iommu.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)--
2.48.1
Quoted 4 lines · Jay Chang
Hi,
Gentle ping on this patch.
Can you please resend the series, I lost this the first time around
Alistair
Quoted 22 lines
Thanks,
Jay ChangQuoted 17 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 leaksJay Chang (2):
hw/riscv: Don't insert DDT cache in Bare mode hw/riscv: Refactorriscv_iommu_ctx_put()for Bare mode handlinghw/riscv/riscv-iommu.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)--
2.48.1