From fce1b469e5a758bcad8bc46445f420f1a714ee30 Mon Sep 17 00:00:00 2001 From: Peter Xu Date: Fri, 2 Mar 2018 15:31:42 -0500 Subject: [PATCH] memory: tune last param of iommu_ops.translate() This patch converts the old "is_write" bool into IOMMUAccessFlags. The difference is that "is_write" can only express either read/write, but sometimes what we really want is "none" here (neither read nor write). Replay is an good example - during replay, we should not check any RW permission bits since thats not an actual IO at all. Backports commit bf55b7afce53718ef96f4e6616da62c0ccac37dd from qemu --- qemu/exec.c | 3 ++- qemu/include/exec/memory.h | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/qemu/exec.c b/qemu/exec.c index 4efbf08e..d5dfdd9c 100644 --- a/qemu/exec.c +++ b/qemu/exec.c @@ -415,7 +415,8 @@ static MemoryRegionSection address_space_do_translate(AddressSpace *as, break; } - iotlb = mr->iommu_ops->translate(mr, addr, is_write); + iotlb = mr->iommu_ops->translate(mr, addr, is_write ? + IOMMU_WO : IOMMU_RO); addr = ((iotlb.translated_addr & ~iotlb.addr_mask) | (addr & iotlb.addr_mask)); *plen = MIN(*plen, (addr | iotlb.addr_mask) - addr + 1); diff --git a/qemu/include/exec/memory.h b/qemu/include/exec/memory.h index 1bd54584..37e16c4c 100644 --- a/qemu/include/exec/memory.h +++ b/qemu/include/exec/memory.h @@ -143,8 +143,14 @@ struct MemoryRegionOps { typedef struct MemoryRegionIOMMUOps MemoryRegionIOMMUOps; struct MemoryRegionIOMMUOps { - /* Return a TLB entry that contains a given address. */ - IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr, bool is_write); + /* + * Return a TLB entry that contains a given address. Flag should + * be the access permission of this translation operation. We can + * set flag to IOMMU_NONE to mean that we don't need any + * read/write permission checks, like, when for region replay. + */ + IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr, + IOMMUAccessFlags flag); /* Returns minimum supported page size */ uint64_t (*get_min_page_size)(MemoryRegion *iommu); /* Called when the first notifier is set */