riscv-non-isa / riscv-iommu

RISC-V IOMMU Specification
https://jira.riscv.org/browse/RVG-55
Creative Commons Attribution 4.0 International
76 stars 15 forks source link

why need to add `masked_upper_bits != mask` #305

Closed baimengwei closed 2 months ago

baimengwei commented 2 months ago

https://github.com/riscv-non-isa/riscv-iommu/blob/main/iommu_ref_model/libiommu/src/iommu_two_stage_trans.c#L103

why need to add masked_upper_bits != mask ? If a iova is ffff_ffff_ffff_ffff,which exceed the sv39/sv48/sv57 translate mode size, Is this iova is legal ?

    if ( (masked_upper_bits != 0 && masked_upper_bits != mask && SXL == 0) ||
         (masked_upper_bits != 0 && SXL == 1) ) goto page_fault;

    i = LEVELS - 1;
    a = iosatp.PPN * PAGESIZE;

Thanks.

ved-rivos commented 2 months ago

why need to add masked_upper_bits != mask ?

Virtual addresses are always 64-bit wide or 32-bit wide. The range of valid 64-bit virtual addresses however depends on the virtual memory system mode. The rules to determine the validity of a virtual address are as follows :

If a iova is ffff_ffff_ffff_ffff,which exceed the sv39/sv48/sv57 translate mode size, Is this iova is legal ?

The address 0xFFFF_FFFF_FFFF_FFFF is all of these modes. The valid address ranges are as follows:

This effectively partitions the virtual memory space into two halves with a range of invalid addresses in the middle. This also ensures that all addresses that were valid in Sv39 are also valid in Sv48/Sv57, and all valid addresses of Sv48 are also valid in Sv57.

baimengwei commented 2 months ago

Thanks.