qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Nutty Liu" <liujingqi@lanxincomputing.com>
To: "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>,
	<qemu-riscv@nongnu.org>,  <qemu-devel@nongnu.org>
Cc: "Nutty Liu" <liujingqi@lanxincomputing.com>,
	 "Tomasz Jeznach" <tjeznach@rivosinc.com>
Subject: [PATCH v2] hw/riscv/riscv-iommu: Fix PPN field of Translation-reponse register
Date: Thu,  5 Jun 2025 20:48:48 +0800	[thread overview]
Message-ID: <20250605124848.1248-1-liujingqi@lanxincomputing.com> (raw)

The original implementation incorrectly performed a bitwise AND
operation between the PPN of iova and PPN Mask, leading to an
incorrect PPN field in Translation-reponse register.

The PPN of iova should be set entirely in the PPN field of
Translation-reponse register.

Also remove the code that was used to clear S field since this
field is already zero.

Signed-off-by: Nutty Liu <liujingqi@lanxincomputing.com>
Reviewed-by: Tomasz Jeznach <tjeznach@rivosinc.com>
---
V1 -> V2:
 - Commented by Alistair
 - Reviewed by Tomasz
 - Remove the extra code
---
 hw/riscv/riscv-iommu.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c
index a877e5da84..d8b1cb03a8 100644
--- a/hw/riscv/riscv-iommu.c
+++ b/hw/riscv/riscv-iommu.c
@@ -1935,11 +1935,7 @@ static void riscv_iommu_process_dbg(RISCVIOMMUState *s)
             iova = RISCV_IOMMU_TR_RESPONSE_FAULT | (((uint64_t) fault) << 10);
         } else {
             iova = iotlb.translated_addr & ~iotlb.addr_mask;
-            iova >>= TARGET_PAGE_BITS;
-            iova &= RISCV_IOMMU_TR_RESPONSE_PPN;
-
-            /* We do not support superpages (> 4kbs) for now */
-            iova &= ~RISCV_IOMMU_TR_RESPONSE_S;
+            iova = set_field(0, RISCV_IOMMU_TR_RESPONSE_PPN, PPN_DOWN(iova));
         }
         riscv_iommu_reg_set64(s, RISCV_IOMMU_REG_TR_RESPONSE, iova);
     }
-- 
2.49.0.windows.1


             reply	other threads:[~2025-06-05 12:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-05 12:48 Nutty Liu [this message]
2025-06-09  3:42 ` [PATCH v2] hw/riscv/riscv-iommu: Fix PPN field of Translation-reponse register 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=20250605124848.1248-1-liujingqi@lanxincomputing.com \
    --to=liujingqi@lanxincomputing.com \
    --cc=alistair.francis@wdc.com \
    --cc=dbarboza@ventanamicro.com \
    --cc=liwei1518@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=tjeznach@rivosinc.com \
    --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).