On 3/2/25 6:12 AM, Jason Chien wrote:
> The bus number of a PCIe endpoint may change after PCIe re-enumeration,
> potentially causing the device ID stored in RISCVIOMMUSpace to become
> outdated. This can lead to an incorrect Device Directory Table walk.
>
> This commit ensures that the IOMMU dynamically retrieves the latest device
> IDs from the memory attributes of the requester devices, ensuring accuracy.
>
> Signed-off-by: Jason Chien <jason.chien@sifive.com>
> ---
Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
> hw/riscv/riscv-iommu.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c
> index d46beb2d64..b72ce8e6d0 100644
> --- a/hw/riscv/riscv-iommu.c
> +++ b/hw/riscv/riscv-iommu.c
> @@ -2644,7 +2644,13 @@ void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *iommu, PCIBus *bus,
> static int riscv_iommu_memory_region_index(IOMMUMemoryRegion *iommu_mr,
> MemTxAttrs attrs)
> {
> - return attrs.unspecified ? RISCV_IOMMU_NOPROCID : (int)attrs.pid;
> + RISCVIOMMUSpace *as = container_of(iommu_mr, RISCVIOMMUSpace, iova_mr);
> +
> + /* Requesters must attach its device ID. */
> + g_assert(attrs.unspecified == 0);
> +
> + as->devid = attrs.requester_id;
> + return attrs.pid;
> }
>
> static int riscv_iommu_memory_region_index_len(IOMMUMemoryRegion *iommu_mr)