Skip to contentSkip to conversation

hw/riscv/riscv-iommu: Fix PPN field of Translation-reponse register

PATCH Nutty Liu 1 participant 1 message Jun 5, 2025 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): CAH2o1u7L=O+AOtbpkb09EanpmdhKX20Xx+EoFBJOStv3kVxKwg@mail.gmail.com

Nutty Liu

author
#2 lore raw
Quoted 13 lines · Tomasz Jeznach
Quoted 12 lines · Nutty Liu

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.

---
  hw/riscv/riscv-iommu.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
Quoted 14 lines

hw/riscv/riscv-iommu.c static void riscv_iommu_process_dbg(RISCVIOMMUState *s) · line 1939

Quoted 12 lines
hw/riscv/riscv-iommu.c +1 -2
index a877e5da84..f529a6a3d7 100644
@@ -1935,8 +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;
+            iova = set_field(0, RISCV_IOMMU_TR_RESPONSE_PPN, PPN_DOWN(iova));
 

Thanks for catching this. Yes, there is an issue here. Also, the line below, clearing _S bit, is no longer needed.

Thanks for your review.
Indeed. I will also remove the line below.

Quoted 8 lines
Quoted 4 lines
hw/riscv/riscv-iommu.c +0 -1
              /* We do not support superpages (> 4kbs) for now */
              iova &= ~RISCV_IOMMU_TR_RESPONSE_S;
--

2.49.0.windows.1

Best,
- Tomasz

Thanks,
Nutty