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
On 12/11/2025 10:56 AM, Jay Chang wrote:
> 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>
> ---
Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>
Thanks,
Nutty
> 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;
> }
>
On 12/10/25 11:56 PM, Jay Chang wrote:
> 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>
> ---
Reviewed-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.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;
> }
>
© 2016 - 2026 Red Hat, Inc.