Skip to contentSkip to conversation

hw/riscv/riscv-iommu.c: check for misaligned IOHGATP_PPN

PATCH Applied Daniel Henrique Barboza 4 participants 5 messages Jul 2 – Jul 6 RISC-V

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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.

Fixes 69a9ae4836 ("hw/riscv/riscv-iommu: add ATS support")

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
index 974042d017..ad8e108a23 100644
@@ -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
Reviewed-by on v2 1/1
#2 lore raw
Quoted 5 lines · Daniel Henrique Barboza

We must check if IOHGATP_PPN is 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

Quoted 33 lines
---
 hw/riscv/riscv-iommu.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
hw/riscv/riscv-iommu.c +15 -0
index 974042d017..ad8e108a23 100644
@@ -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
Reviewed-by on v2 1/1
#3 lore raw
In reply to Daniel Henrique Barboza
Quoted 5 lines · Daniel Henrique Barboza

We must check if IOHGATP_PPN is 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

Thanks,
Nutty

Quoted 30 lines
---
  hw/riscv/riscv-iommu.c | 15 +++++++++++++++
  1 file changed, 15 insertions(+)
hw/riscv/riscv-iommu.c +15 -0
index 974042d017..ad8e108a23 100644
@@ -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) {
#4 lore raw
In reply to Daniel Henrique Barboza
Quoted 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.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]/

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 12 lines

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(+)

--
2.43.0