qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] hw/riscv/riscv-iommu: Fix PPN field of Translation-reponse register
@ 2025-06-05 12:48 Nutty Liu
  2025-06-09  3:42 ` Alistair Francis
  0 siblings, 1 reply; 2+ messages in thread
From: Nutty Liu @ 2025-06-05 12:48 UTC (permalink / raw)
  To: Palmer Dabbelt, Alistair Francis, Weiwei Li,
	Daniel Henrique Barboza, Liu Zhiwei, qemu-riscv, qemu-devel
  Cc: Nutty Liu, Tomasz Jeznach

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] hw/riscv/riscv-iommu: Fix PPN field of Translation-reponse register
  2025-06-05 12:48 [PATCH v2] hw/riscv/riscv-iommu: Fix PPN field of Translation-reponse register Nutty Liu
@ 2025-06-09  3:42 ` Alistair Francis
  0 siblings, 0 replies; 2+ messages in thread
From: Alistair Francis @ 2025-06-09  3:42 UTC (permalink / raw)
  To: Nutty Liu
  Cc: Palmer Dabbelt, Alistair Francis, Weiwei Li,
	Daniel Henrique Barboza, Liu Zhiwei, qemu-riscv, qemu-devel,
	Tomasz Jeznach

On Thu, Jun 5, 2025 at 10:50 PM Nutty Liu <liujingqi@lanxincomputing.com> wrote:
>
> 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>

Thanks!

Applied to riscv-to-apply.next

Alistair

> ---
> 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
>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-09  3:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-05 12:48 [PATCH v2] hw/riscv/riscv-iommu: Fix PPN field of Translation-reponse register Nutty Liu
2025-06-09  3:42 ` Alistair Francis

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).