hw/riscv/riscv-iommu: fix MSI_PTE_M_BASIC address
PATCH 1/1 hw/riscv/riscv-iommu: fix MSI_PTE_M_BASIC address
We're not considering the page offset when retrieving the MSI address. riscv-iommu spec 1.0 says:
"1. Let A be the GPA
(...)
13. If msipte.M == 3 the PTE is in basic translate mode and the translation process is as follows:
(...)
b. Compute the translated address as msipte.PPN << 12 | A[11:0]."
I.e. we need to bit_ior the GPA page offset in the translated address.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3560
--- hw/riscv/riscv-iommu-bits.h | 1 + hw/riscv/riscv-iommu.c | 1 + 2 files changed, 2 insertions(+)
hw/riscv/riscv-iommu-bits.h +1 -0
@@ -471,4 +471,5 @@ struct riscv_iommu_msi_pte {#define RISCV_IOMMU_MSI_MRIF_NPPN RISCV_IOMMU_PPN_FIELD#define RISCV_IOMMU_MSI_MRIF_NID_MSB BIT_ULL(60) +#define RISCV_IOMMU_MSI_BASIC_PAGE_OFFSET GENMASK_ULL(11, 0)#endif /* _RISCV_IOMMU_BITS_H_ */
hw/riscv/riscv-iommu.c +1 -0
@@ -658,6 +658,7 @@ static MemTxResult riscv_iommu_msi_write(RISCVIOMMUState *s,case RISCV_IOMMU_MSI_PTE_M_BASIC :/* MSI Pass-through mode */ addr =PPN_PHYS (get_field (pte[0 ],RISCV_IOMMU_MSI_PTE_PPN )); + addr |= (gpa &RISCV_IOMMU_MSI_BASIC_PAGE_OFFSET ); trace_riscv_iommu_msi(s->parent_obj.id, PCI_BUS_NUM(ctx->devid), PCI_SLOT(ctx->devid), PCI_FUNC(ctx->devid),
Signature · 1 line
2.43.0
Quoted 12 lines · Daniel Henrique Barboza
We're not considering the page offset when retrieving the MSI address. riscv-iommu spec 1.0 says:
"1. Let A be the GPA
(...)
13. If msipte.M == 3 the PTE is in basic translate mode and the translation process is as follows:
(...)
b. Compute the translated address as msipte.PPN << 12 | A[11:0]."
Quoted 5 lines
I.e. we need to
bit_iorthe GPA page offset in the translated address.Fixes 0c54acb8243d ("hw/riscv: add RISC-V IOMMU base emulation")Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3560
Signed-off-by Daniel Henrique Barboza <[email protected]>
Thanks,
Nutty
Quoted 27 lines
--- hw/riscv/riscv-iommu-bits.h | 1 + hw/riscv/riscv-iommu.c | 1 + 2 files changed, 2 insertions(+)hw/riscv/riscv-iommu-bits.h +1
-0@@ -471,4 +471,5 @@ struct riscv_iommu_msi_pte {#define RISCV_IOMMU_MSI_MRIF_NPPN RISCV_IOMMU_PPN_FIELD#define RISCV_IOMMU_MSI_MRIF_NID_MSB BIT_ULL(60) +#define RISCV_IOMMU_MSI_BASIC_PAGE_OFFSET GENMASK_ULL(11, 0)#endif /* _RISCV_IOMMU_BITS_H_ */ hw/riscv/riscv-iommu.c +1
-0@@ -658,6 +658,7 @@ static MemTxResult riscv_iommu_msi_write(RISCVIOMMUState *s,case RISCV_IOMMU_MSI_PTE_M_BASIC :/* MSI Pass-through mode */ addr =PPN_PHYS (get_field (pte[0 ],RISCV_IOMMU_MSI_PTE_PPN )); + addr |= (gpa &RISCV_IOMMU_MSI_BASIC_PAGE_OFFSET ); trace_riscv_iommu_msi(s->parent_obj.id, PCI_BUS_NUM(ctx->devid), PCI_SLOT(ctx->devid), PCI_FUNC(ctx->devid),