Skip to contentSkip to conversation

spapr_iommu: TCE permission bits fixes

PATCH Applied Greg Kurz 2 participants 5 messages Jun 16, 2015 – Jun 18, 2015

lore
Share & tools
lore

Greg Kurz

author
#0 lore raw

v2 cover spapr_iommu: TCE permission bits fixes

This series fixes some minor nits in the sPAPR IOMMU code. It supercedes my previous post:

"spapr_iommu: drop erroneous check in h_put_tce_indirect() and useless enum"

---

Greg Kurz (2):
spapr_iommu: drop erroneous check in h_put_tce_indirect()
spapr_iommu: translate sPAPRTCEAccess to IOMMUAccessFlags

 hw/ppc/spapr_iommu.c |   22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

--
Greg

author
#1 lore raw

PATCH v2 1/2 spapr_iommu: drop erroneous check in h_put_tce_indirect()

The tce_list variable is not a TCE but the address to a TCE: we shouldn't clear permission bits as we do now. And this is dead code anyway since we check tce_list is 4K aligned a few lines above.

This patch doesn't fix any bug, it is only code cleanup.

---
 hw/ppc/spapr_iommu.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/ppc/spapr_iommu.c +1 -3
index 8cd9dba9ac4d..ddd0ea5cd4dd 100644
@@ -267,9 +267,7 @@ static target_ulong h_put_tce_indirect(PowerPCCPU *cpu,
     ioba &= page_mask;
 
     for (i = 0; i < npages; ++i, ioba += page_size) {
-        target_ulong off = (tce_list & ~SPAPR_TCE_RW) +
-                                i * sizeof(target_ulong);
-        tce = ldq_be_phys(cs->as, off);
+        tce = ldq_be_phys(cs->as, tce_list + i * sizeof(target_ulong));
 
         ret = put_tce_emu(tcet, ioba, tce);
         if (ret) {
author
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] spapr_iommu: drop erroneous check in h_put_tce_indirect()

Quoted 4 lines · On Tue, 16 Jun 2015 18:26:47 +0200 Greg Kurz <[email protected]> wrote:

The tce_list variable is not a TCE but the address to a TCE: we shouldn't clear permission bits as we do now. And this is dead code anyway since we check tce_list is 4K aligned a few lines above.

Quoted 8 lines

This patch doesn't fix any bug, it is only code cleanup.

---
 hw/ppc/spapr_iommu.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Of course, I did forget the changelog...

v2:
- suggested by aik
- keep sPAPRTCEAccess, a translation helper is introduced in the next patch

Quoted 17 lines
hw/ppc/spapr_iommu.c +1 -3
index 8cd9dba9ac4d..ddd0ea5cd4dd 100644
@@ -267,9 +267,7 @@ static target_ulong h_put_tce_indirect(PowerPCCPU *cpu,
     ioba &= page_mask;
 
     for (i = 0; i < npages; ++i, ioba += page_size) {
-        target_ulong off = (tce_list & ~SPAPR_TCE_RW) +
-                                i * sizeof(target_ulong);
-        tce = ldq_be_phys(cs->as, off);
+        tce = ldq_be_phys(cs->as, tce_list + i * sizeof(target_ulong));
 
         ret = put_tce_emu(tcet, ioba, tce);
         if (ret) {
author
#3 lore raw

PATCH v2 2/2 spapr_iommu: translate sPAPRTCEAccess to IOMMUAccessFlags

In reply to Greg Kurz

The fact that these enums have matching values is pure coincidence. We actually need to translate from the PAPR definition to the QEMU one.

This patch doesn't fix any bug, it is only code cleanup.

---
 hw/ppc/spapr_iommu.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
hw/ppc/spapr_iommu.c +16 -2
index ddd0ea5cd4dd..9133912bb983 100644
@@ -60,6 +60,20 @@ sPAPRTCETable *spapr_tce_find_by_liobn(target_ulong liobn)
     return NULL;
 }
 
+static IOMMUAccessFlags spapr_tce_iommu_access_flags(uint64_t tce)
+{
+    switch (tce & SPAPR_TCE_RW) {
+    case SPAPR_TCE_FAULT:
+        return IOMMU_NONE;
+    case SPAPR_TCE_RO:
+        return IOMMU_RO;
+    case SPAPR_TCE_WO:
+        return IOMMU_WO;
+    default: /* SPAPR_TCE_RW */
+        return IOMMU_RW;
+    }
+}
+
 /* Called from RCU critical section */
 static IOMMUTLBEntry spapr_tce_translate_iommu(MemoryRegion *iommu, hwaddr addr,
                                                bool is_write)
@@ -82,7 +96,7 @@ static IOMMUTLBEntry spapr_tce_translate_iommu(MemoryRegion *iommu, hwaddr addr,
         ret.iova = addr & page_mask;
         ret.translated_addr = tce & page_mask;
         ret.addr_mask = ~page_mask;
-        ret.perm = tce & IOMMU_RW;
+        ret.perm = spapr_tce_iommu_access_flags(tce);
     }
     trace_spapr_iommu_xlate(tcet->liobn, addr, ret.iova, ret.perm,
                             ret.addr_mask);
@@ -233,7 +247,7 @@ static target_ulong put_tce_emu(sPAPRTCETable *tcet, target_ulong ioba,
     entry.iova = ioba & page_mask;
     entry.translated_addr = tce & page_mask;
     entry.addr_mask = ~page_mask;
-    entry.perm = tce & IOMMU_RW;
+    entry.perm = spapr_tce_iommu_access_flags(tce);
     memory_region_notify_iommu(&tcet->iommu, entry);
 
     return H_SUCCESS;
Applied
#4 lore raw
In reply to Greg Kurz
Quoted 5 lines · Greg Kurz

This series fixes some minor nits in the sPAPR IOMMU code. It supercedes my previous post:

"spapr_iommu: drop erroneous check in h_put_tce_indirect() and useless enum"

Thanks, applied to spapr-next.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson