Skip to content

Commit 3ea8fb5

Browse files
Jason Chienalistair23
authored andcommitted
hw/riscv/riscv-iommu: Fix process directory table walk
The PPN field in a non-leaf PDT entry is positioned differently from that in a leaf PDT entry. The original implementation incorrectly used the leaf entry's PPN mask to extract the PPN from a non-leaf entry, leading to an erroneous page table walk. This commit introduces new macros to properly define the fields for non-leaf PDT entries and corrects the page table walk. Signed-off-by: Jason Chien <[email protected]> Reviewed-by: Daniel Henrique Barboza <[email protected]> Message-ID: <[email protected]> Signed-off-by: Alistair Francis <[email protected]>
1 parent d2c5759 commit 3ea8fb5

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

hw/riscv/riscv-iommu-bits.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,16 @@ enum riscv_iommu_fq_causes {
415415
#define RISCV_IOMMU_DC_MSIPTP_MODE_OFF 0
416416
#define RISCV_IOMMU_DC_MSIPTP_MODE_FLAT 1
417417

418+
/* 2.2 Process Directory Table */
419+
#define RISCV_IOMMU_PDTE_VALID BIT_ULL(0)
420+
#define RISCV_IOMMU_PDTE_PPN RISCV_IOMMU_PPN_FIELD
421+
418422
/* Translation attributes fields */
419423
#define RISCV_IOMMU_PC_TA_V BIT_ULL(0)
420424
#define RISCV_IOMMU_PC_TA_RESERVED GENMASK_ULL(63, 32)
421425

422426
/* First stage context fields */
423-
#define RISCV_IOMMU_PC_FSC_PPN GENMASK_ULL(43, 0)
427+
#define RISCV_IOMMU_PC_FSC_PPN RISCV_IOMMU_ATP_PPN_FIELD
424428
#define RISCV_IOMMU_PC_FSC_RESERVED GENMASK_ULL(59, 44)
425429

426430
enum riscv_iommu_fq_ttypes {

hw/riscv/riscv-iommu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,10 +1042,10 @@ static int riscv_iommu_ctx_fetch(RISCVIOMMUState *s, RISCVIOMMUContext *ctx)
10421042
return RISCV_IOMMU_FQ_CAUSE_PDT_LOAD_FAULT;
10431043
}
10441044
le64_to_cpus(&de);
1045-
if (!(de & RISCV_IOMMU_PC_TA_V)) {
1045+
if (!(de & RISCV_IOMMU_PDTE_VALID)) {
10461046
return RISCV_IOMMU_FQ_CAUSE_PDT_INVALID;
10471047
}
1048-
addr = PPN_PHYS(get_field(de, RISCV_IOMMU_PC_FSC_PPN));
1048+
addr = PPN_PHYS(get_field(de, RISCV_IOMMU_PDTE_PPN));
10491049
}
10501050

10511051
riscv_iommu_hpm_incr_ctr(s, ctx, RISCV_IOMMU_HPMEVENT_PD_WALK);

0 commit comments

Comments
 (0)