The current implementation reuses cached translations without checking whether their permissions satisfy the requested access.
Only reuse an IOATC entry when its permissions cover the current request. Otherwise, perform a page-table walk to check the requested access. Preserve the existing behavior for requests with IOMMU_NONE. This is also needed for hardware A/D updates, where mappings with a clear D bit must not cache write permission until the bit has been set. Signed-off-by: Tan Chi <[email protected]> --- hw/riscv/riscv-iommu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index 2dcc528599..6760699eb8 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -1781,7 +1781,9 @@ static int riscv_iommu_translate(RISCVIOMMUState *s, RISCVIOMMUContext *ctx, phys = iot->phys; } qemu_mutex_unlock(&s->iot_lock); - if (perm != IOMMU_NONE) { + if (perm != IOMMU_NONE && + (iotlb->perm == IOMMU_NONE || + (perm & iotlb->perm) == iotlb->perm)) { iotlb->translated_addr = PPN_PHYS(phys); iotlb->addr_mask = ~TARGET_PAGE_MASK; iotlb->perm = perm; -- 2.53.0
