From: Alistair Francis <alistair23@gmail.com>
To: frank.chang@sifive.com
Cc: qemu-devel@nongnu.org, Palmer Dabbelt <palmer@dabbelt.com>,
Alistair Francis <alistair.francis@wdc.com>,
Weiwei Li <liwei1518@gmail.com>,
Daniel Henrique Barboza <dbarboza@ventanamicro.com>,
Liu Zhiwei <zhiwei_liu@linux.alibaba.com>,
"open list:RISC-V TCG CPUs" <qemu-riscv@nongnu.org>
Subject: Re: [PATCH] hw/riscv: riscv-iommu: Don't look up DDT cache in Off and Bare modes
Date: Wed, 12 Nov 2025 11:10:58 +1000 [thread overview]
Message-ID: <CAKmqyKOap9CuuQWpm6ABiCWQ1_-1b-27m7bLWqRvuv0LkaToNg@mail.gmail.com> (raw)
In-Reply-To: <20251028085032.2053569-1-frank.chang@sifive.com>
On Tue, Oct 28, 2025 at 6:54 PM <frank.chang@sifive.com> wrote:
>
> From: Frank Chang <frank.chang@sifive.com>
>
> According to the RISC-V IOMMU specification:
>
> * When ddtp.iommu_mode is set to Off, there is no DDT look-up, and an "All
> inbound transactions disallowed" fault (cause = 256) is reported for any
> inbound transaction.
>
> * When ddtp.iommu_mode is set to Bare, there is no DDT look-up, and the
> translated address is the same as the IOVA, unless the transaction type
> is disallowed (cause = 260).
>
> In the current implementation, the DDT cache is incorrectly looked up
> even when ddtp.iommu_mode is set to Off or Bare. This may result in
> unintended cache hits.
>
> Therefore, the DDT cache must not be looked up when ddtp.iommu_mode is
> set to Off or Bare. For other modes, software is required to issue cache
> invalidation commands before any inbound transactions.
>
> Signed-off-by: Frank Chang <frank.chang@sifive.com>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> hw/riscv/riscv-iommu.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c
> index b33c7fe3259..95db811f125 100644
> --- a/hw/riscv/riscv-iommu.c
> +++ b/hw/riscv/riscv-iommu.c
> @@ -1290,13 +1290,18 @@ static RISCVIOMMUContext *riscv_iommu_ctx(RISCVIOMMUState *s,
> .devid = devid,
> .process_id = process_id,
> };
> + unsigned mode = get_field(s->ddtp, RISCV_IOMMU_DDTP_MODE);
>
> ctx_cache = g_hash_table_ref(s->ctx_cache);
> - ctx = g_hash_table_lookup(ctx_cache, &key);
>
> - if (ctx && (ctx->tc & RISCV_IOMMU_DC_TC_V)) {
> - *ref = ctx_cache;
> - return ctx;
> + if (mode != RISCV_IOMMU_DDTP_MODE_OFF &&
> + mode != RISCV_IOMMU_DDTP_MODE_BARE) {
> + ctx = g_hash_table_lookup(ctx_cache, &key);
> +
> + if (ctx && (ctx->tc & RISCV_IOMMU_DC_TC_V)) {
> + *ref = ctx_cache;
> + return ctx;
> + }
> }
>
> ctx = g_new0(RISCVIOMMUContext, 1);
> --
> 2.43.0
>
>
next prev parent reply other threads:[~2025-11-12 1:11 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-28 8:50 [PATCH] hw/riscv: riscv-iommu: Don't look up DDT cache in Off and Bare modes frank.chang
2025-10-28 9:09 ` Jim Shu
2025-10-30 14:23 ` Daniel Henrique Barboza
2025-11-12 1:10 ` Alistair Francis [this message]
2025-11-12 1:27 ` Alistair Francis
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=CAKmqyKOap9CuuQWpm6ABiCWQ1_-1b-27m7bLWqRvuv0LkaToNg@mail.gmail.com \
--to=alistair23@gmail.com \
--cc=alistair.francis@wdc.com \
--cc=dbarboza@ventanamicro.com \
--cc=frank.chang@sifive.com \
--cc=liwei1518@gmail.com \
--cc=palmer@dabbelt.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=zhiwei_liu@linux.alibaba.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;
as well as URLs for NNTP newsgroup(s).