hw/riscv/riscv-iommu.c: check for misaligned IOHGATP_PPN
v2 cover hw/riscv/riscv-iommu.c: check for misaligned IOHGATP_PPN
Hi,
This new version fixes a blunder I made in v1 pointed by Chao and Nutty - I was using the PPN value, instead of the page table base address, to check for the 16kb alignment.
We no longer need to change qos-riscv-iommu.h because now we're doing the right thing.
Changes from v1:
- use PPN_PHYS(iohgatp_ppn), i.e. the page table base address, to
check for the 16kb alignment
- v1 link: https://lore.kernel.org/qemu-devel/[email protected]/
Daniel Henrique Barboza (1):
hw/riscv/riscv-iommu.c: check for misaligned IOHGATP_PPN
hw/riscv/riscv-iommu.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
Signature · 1 line
2.43.0
PATCH v2 1/1 hw/riscv/riscv-iommu.c: check for misaligned IOHGATP_PPN
We must check if IOHGATP_PPN is 16kb aligned for non-bare GATP modes.
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3550
--- hw/riscv/riscv-iommu.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
hw/riscv/riscv-iommu.c +15 -0
@@ -813,6 +813,21 @@ static bool riscv_iommu_validate_device_ctx(RISCVIOMMUState *s,return false; } +if (gatp !=RISCV_IOMMU_DC_IOHGATP_MODE_BARE ) { +uint64_t iohgatp_ppn =get_field (ctx->gatp, +RISCV_IOMMU_DC_IOHGATP_PPN ); + +/* +* One of the conditions for a misconfigured DDT entry +* according to the riscv-spec: "DC.iohgatp.MODE is not +* Bare and the root page table (address) determined by +* DC.iohgatp.PPN is not aligned to a 16-KiB boundary." +*/ +if (PPN_PHYS (iohgatp_ppn) & ((1ULL <<14 ) -1 )) { +return false; + } + } + fsc_mode =get_field (ctx->satp,RISCV_IOMMU_DC_FSC_MODE );if (ctx->tc &RISCV_IOMMU_DC_TC_PDTV ) {
Signature · 1 line
2.43.0
Quoted 5 lines · Daniel Henrique Barboza
We must check if
IOHGATP_PPNis 16kb aligned for non-bare GATP modes.Fixes 69a9ae4836 ("hw/riscv/riscv-iommu: add ATS support")Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3550
Signed-off-by Daniel Henrique Barboza <[email protected]>
Quoted 33 lines
--- hw/riscv/riscv-iommu.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)hw/riscv/riscv-iommu.c +15
-0@@ -813,6 +813,21 @@ static bool riscv_iommu_validate_device_ctx(RISCVIOMMUState *s,return false; } +if (gatp !=RISCV_IOMMU_DC_IOHGATP_MODE_BARE ) { +uint64_t iohgatp_ppn =get_field (ctx->gatp, +RISCV_IOMMU_DC_IOHGATP_PPN ); + +/* +* One of the conditions for a misconfigured DDT entry +* according to the riscv-spec: "DC.iohgatp.MODE is not +* Bare and the root page table (address) determined by +* DC.iohgatp.PPN is not aligned to a 16-KiB boundary." +*/ +if (PPN_PHYS (iohgatp_ppn) & ((1ULL <<14 ) -1 )) { +return false; + } + } + fsc_mode =get_field (ctx->satp,RISCV_IOMMU_DC_FSC_MODE );if (ctx->tc &RISCV_IOMMU_DC_TC_PDTV ) {Signature · 1 line
2.43.0
Quoted 5 lines · Daniel Henrique Barboza
We must check if
IOHGATP_PPNis 16kb aligned for non-bare GATP modes.Fixes 69a9ae4836 ("hw/riscv/riscv-iommu: add ATS support")Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/3550
Signed-off-by Daniel Henrique Barboza <[email protected]>
Thanks,
Nutty
Quoted 30 lines
--- hw/riscv/riscv-iommu.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)hw/riscv/riscv-iommu.c +15
-0@@ -813,6 +813,21 @@ static bool riscv_iommu_validate_device_ctx(RISCVIOMMUState *s,return false; } +if (gatp !=RISCV_IOMMU_DC_IOHGATP_MODE_BARE ) { +uint64_t iohgatp_ppn =get_field (ctx->gatp, +RISCV_IOMMU_DC_IOHGATP_PPN ); + +/* +* One of the conditions for a misconfigured DDT entry +* according to the riscv-spec: "DC.iohgatp.MODE is not +* Bare and the root page table (address) determined by +* DC.iohgatp.PPN is not aligned to a 16-KiB boundary." +*/ +if (PPN_PHYS (iohgatp_ppn) & ((1ULL <<14 ) -1 )) { +return false; + } + } + fsc_mode =get_field (ctx->satp,RISCV_IOMMU_DC_FSC_MODE );if (ctx->tc &RISCV_IOMMU_DC_TC_PDTV ) {
Alistair Francis
AppliedQuoted 7 lines · Daniel Henrique Barboza
Hi,
This new version fixes a blunder I made in v1 pointed by Chao and Nutty - I was using the PPN value, instead of the page table base address, to check for the 16kb alignment.
Quoted 7 lines
We no longer need to change
qos-riscv-iommu.hbecause now we're doing the right thing.Changes from v1:
- usePPN_PHYS(iohgatp_ppn), i.e. the page table base address, to
check for the 16kb alignment
- v1 link: https://lore.kernel.org/qemu-devel/[email protected]/
Thanks!
Applied to riscv-to-apply.next
Alistair
Quoted 12 lines
Daniel Henrique Barboza (1):
hw/riscv/riscv-iommu.c: check for misalignedIOHGATP_PPNhw/riscv/riscv-iommu.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)--
2.43.0