Skip to contentSkip to conversation

hw/arm/smmuv3: Pass the real perm to returned IOMMUTLBEntry in smmuv3_translate()

PATCH Superseded chenxiang via 2 participants 3 messages Apr 7, 2022 – Apr 16, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/arm/smmuv3: Pass the real perm to returned IOMMUTLBEntry in smmuv3_translate()

From: Xiang Chen <[email protected]>

In function memory_region_iommu_replay(), it decides to notify() or not according to the perm of returned IOMMUTLBEntry. But for smmuv3, the returned perm is always IOMMU_NONE even if the translation success. Pass the real perm to returned IOMMUTLBEntry to avoid the issue.

---
 hw/arm/smmuv3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/smmuv3.c +1 -1
index 674623aabe..707eb430c2 100644
@@ -760,7 +760,7 @@ epilogue:
     qemu_mutex_unlock(&s->mutex);
     switch (status) {
     case SMMU_TRANS_SUCCESS:
-        entry.perm = flag;
+        entry.perm = cached_entry->entry.perm;
         entry.translated_addr = cached_entry->entry.translated_addr +
                                     (addr & cached_entry->entry.addr_mask);
         entry.addr_mask = cached_entry->entry.addr_mask;
Signature · 1 line
2.33.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Chenxiang,

Quoted 5 lines · chenxiang via

From: Xiang Chen <[email protected]>

In function memory_region_iommu_replay(), it decides to notify() or not according to the perm of returned IOMMUTLBEntry. But for smmuv3, the returned perm is always IOMMU_NONE even if the translation success.

I think you should precise in the commit message that memory_region_iommu_replay() always calls the IOMMU MR translate() callback with flag=IOMMU_NONE and thus, currently, translate() returns an IOMMUTLBEntry with perm set to IOMMU_NONE if the translation succeeds, whereas it is expected to return the actual permission set in the table entry.

Quoted 12 lines

Pass the real perm to returned IOMMUTLBEntry to avoid the issue.

---
 hw/arm/smmuv3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/smmuv3.c +0 -0
index 674623aabe..707eb430c2 100644

hw/arm/smmuv3.c epilogue: · line 763

Quoted 5 lines
hw/arm/smmuv3.c +1 -1
@@ -760,7 +760,7 @@ epilogue:
     qemu_mutex_unlock(&s->mutex);
     switch (status) {
     case SMMU_TRANS_SUCCESS:
-        entry.perm = flag;
+        entry.perm = cached_entry->entry.perm;

With that clarification

the translate() doc in ./include/exec/memory.h states
"
If IOMMU_NONE is passed then the IOMMU must do the
     * full page table walk and report the permissions in the returned
     * IOMMUTLBEntry. (Note that this implies that an IOMMU may not
     * return different mappings for reads and writes.)
"

Thanks

Eric

Quoted 3 lines
hw/arm/smmuv3.c +0 -0
         entry.translated_addr = cached_entry->entry.translated_addr +
                                     (addr & cached_entry->entry.addr_mask);
         entry.addr_mask = cached_entry->entry.addr_mask;
#2 lore raw

Hi Eric,

Quoted 8 lines · Eric Auger

Hi Chenxiang,

Quoted 5 lines · chenxiang via

From: Xiang Chen <[email protected]>

In function memory_region_iommu_replay(), it decides to notify() or not according to the perm of returned IOMMUTLBEntry. But for smmuv3, the returned perm is always IOMMU_NONE even if the translation success.

Quoted 6 lines

I think you should precise in the commit message that memory_region_iommu_replay() always calls the IOMMU MR translate() callback with flag=IOMMU_NONE and thus, currently, translate() returns an IOMMUTLBEntry with perm set to IOMMU_NONE if the translation succeeds, whereas it is expected to return the actual permission set in the table entry.

Thank you for your comments.
I will change the commit message in next version.

Quoted 20 lines
Quoted 14 lines

Pass the real perm to returned IOMMUTLBEntry to avoid the issue.

---
  hw/arm/smmuv3.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/arm/smmuv3.c +0 -0
index 674623aabe..707eb430c2 100644

hw/arm/smmuv3.c epilogue: · line 763

Quoted 5 lines
hw/arm/smmuv3.c +1 -1
@@ -760,7 +760,7 @@ epilogue:
      qemu_mutex_unlock(&s->mutex);
      switch (status) {
      case SMMU_TRANS_SUCCESS:
-        entry.perm = flag;
+        entry.perm = cached_entry->entry.perm;

With that clarification

Quoted 1 line

Ok, thanks

Quoted 18 lines

the translate() doc in ./include/exec/memory.h states
"
If IOMMU_NONE is passed then the IOMMU must do the
* full page table walk and report the permissions in the returned
* IOMMUTLBEntry. (Note that this implies that an IOMMU may not
* return different mappings for reads and writes.)
"

Thanks

Eric

hw/arm/smmuv3.c epilogue: · line 766

Quoted 3 lines
hw/arm/smmuv3.c +0 -0
          entry.translated_addr = cached_entry->entry.translated_addr +
                                      (addr & cached_entry->entry.addr_mask);
          entry.addr_mask = cached_entry->entry.addr_mask;

.