zero-day-labs / riscv-iommu

IOMMU IP compliant with the RISC-V IOMMU Specification v1.0
Apache License 2.0
73 stars 14 forks source link

Error with Right Leaf Page Table Entry #30

Open mhayat-10xe opened 3 months ago

mhayat-10xe commented 3 months ago

I wrote an assertion that states:

If there is a right leaf page table entry, then in the next cycle trans_valid must be high.

Below is the counter-example of the assertion failure, in the 12th cycle when we have a right leaf pte, dc.tc.pdtv == 0, and second stage is disabled then in the next cycle it must give trans_valid but it is giving trans_error in 12th cycle with cause_code == 15 which is wrong. image

mhayat-10xe commented 3 months ago

The bug arises from the condition specified in this line. Even if pdt_walk has not occurred previously, resulting in the pdtc cache not being updated before, pdtc_lu_contect.ta.sum still remains 0, incorrectly satisfying the condition.

To fix this issue, modify the line to (priv_lvl_i && iotlb_lu_1S_content.u && ((pdtc_lu_hit && !pdtc_lu_content.ta.sum) || iotlb_lu_1S_content.x))). This makes sure that it will only check the condition when there is a pdtc hit.

mhayat-10xe commented 2 months ago

@malejo97 can you please clarify the default value of sum when we have no process context?

malejo97 commented 1 month ago

Hi @mhayat-10xe,

The RISC-V IOMMU specification states that "_For requests without a processid the privilege mode must be User". Thus, requests with DC.tc.PDTV=0, or PV=0 and DC.tc.DPE=0, or with DC.fsc.pdtp.MODE = Bare (i.e., requests without Process Contexts) cannot have supervisor privilege mode. This is because the Process Context holds the ENS bit, which enables transactions requesting Supervisor privilege mode.

The real issue is that it was possible for an S-mode transaction to reach the if condition you refer without having an associated Process Context. I have included a check after updating the DDTC to guarantee that an S-mode transaction raises an error (Cause 260 - Transaction type disallowed) if it does not have an associated Process Context.