Skip to contentSkip to conversation

spapr_iommu: fix erroneous sanity check in h_put_tce_indirect()

PATCH In review Greg Kurz 2 participants 4 messages Jun 15, 2015 – Jun 16, 2015

lore
Share & tools
lore

Greg Kurz

author
#0 lore raw

PATCH 1/1 spapr_iommu: fix erroneous sanity check in h_put_tce_indirect()

According to PAPR+ 3.2.2.2, the TCE is implemented as follows:
bits 0-51: real page number
bits 52-61: reserved for future use
bits 62-63: page protection (read-only, write-only, read-write)

Possible values for the protection bits are necessarly non-zero and thus H_PUT_TCE_INDIRECT currently always fails and returns H_PARAMETER.

The code explicitly clears the protection bits when computing the TCE offset, a few lines below (tce_list & ~SPAPR_TCE_RW)... The sanity check is obviously wrong for these bits.

Moreover, I could find no indication in PAPR+ that using the other reserved bits should error out with H_PARAMETER.

This patch simply drops the offending check.

---
 hw/ppc/spapr_iommu.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_iommu.c +1 -1
index 8cd9dba9ac4d..37a1110c9d87 100644
@@ -258,7 +258,7 @@ static target_ulong h_put_tce_indirect(PowerPCCPU *cpu,
         return H_PARAMETER;
     }
 
-    if ((npages > 512) || (tce_list & SPAPR_TCE_PAGE_MASK)) {
+    if (npages > 512) {
         return H_PARAMETER;
     }
 
#1 lore raw
Quoted 4 lines · Greg Kurz

According to PAPR+ 3.2.2.2, the TCE is implemented as follows:
bits 0-51: real page number
bits 52-61: reserved for future use
bits 62-63: page protection (read-only, write-only, read-write)

tce_list is not a TCE, it is "The logical address of a page of (4 K long on a 4 K boundary) of TCE contents to be stored in the TCE table (contains logical address of storage page to be mapped)" so we rather want to remove (tce_list & ~SPAPR_TCE_RW) below.

Quoted 32 lines

Possible values for the protection bits are necessarly non-zero and thus H_PUT_TCE_INDIRECT currently always fails and returns H_PARAMETER.

The code explicitly clears the protection bits when computing the TCE offset, a few lines below (tce_list & ~SPAPR_TCE_RW)... The sanity check is obviously wrong for these bits.

Moreover, I could find no indication in PAPR+ that using the other reserved bits should error out with H_PARAMETER.

This patch simply drops the offending check.

---
  hw/ppc/spapr_iommu.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_iommu.c +1 -1
index 8cd9dba9ac4d..37a1110c9d87 100644
@@ -258,7 +258,7 @@ static target_ulong h_put_tce_indirect(PowerPCCPU *cpu,
          return H_PARAMETER;
      }
 
-    if ((npages > 512) || (tce_list & SPAPR_TCE_PAGE_MASK)) {
+    if (npages > 512) {
          return H_PARAMETER;
      }
 
Signature · 1 line
Alexey
author
#2 lore raw
Quoted 8 lines · On Tue, 16 Jun 2015 18:53:51 +1000 Alexey Kardashevskiy <[email protected]> wrote:
Quoted 4 lines · Greg Kurz

According to PAPR+ 3.2.2.2, the TCE is implemented as follows:
bits 0-51: real page number
bits 52-61: reserved for future use
bits 62-63: page protection (read-only, write-only, read-write)

Quoted 5 lines

tce_list is not a TCE, it is "The logical address of a page of (4 K long on a 4 K boundary) of TCE contents to be stored in the TCE table (contains logical address of storage page to be mapped)" so we rather want to remove (tce_list & ~SPAPR_TCE_RW) below.

Oops my bad for the confustion... :-\

Then it looks like SPAPR_TCE_RW can be dropped as well since put_tce_emu() uses IOMMU_RW instead.

Quoted 35 lines
Quoted 33 lines

Possible values for the protection bits are necessarly non-zero and thus H_PUT_TCE_INDIRECT currently always fails and returns H_PARAMETER.

The code explicitly clears the protection bits when computing the TCE offset, a few lines below (tce_list & ~SPAPR_TCE_RW)... The sanity check is obviously wrong for these bits.

Moreover, I could find no indication in PAPR+ that using the other reserved bits should error out with H_PARAMETER.

This patch simply drops the offending check.

---
  hw/ppc/spapr_iommu.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_iommu.c +1 -1
index 8cd9dba9ac4d..37a1110c9d87 100644
@@ -258,7 +258,7 @@ static target_ulong h_put_tce_indirect(PowerPCCPU *cpu,
          return H_PARAMETER;
      }
 
-    if ((npages > 512) || (tce_list & SPAPR_TCE_PAGE_MASK)) {
+    if (npages > 512) {
          return H_PARAMETER;
      }
 
#3 lore raw
Quoted 17 lines · Greg Kurz
Quoted 8 lines · On Tue, 16 Jun 2015 18:53:51 +1000 Alexey Kardashevskiy <[email protected]> wrote:
Quoted 4 lines · Greg Kurz

According to PAPR+ 3.2.2.2, the TCE is implemented as follows:
bits 0-51: real page number
bits 52-61: reserved for future use
bits 62-63: page protection (read-only, write-only, read-write)

Quoted 5 lines

tce_list is not a TCE, it is "The logical address of a page of (4 K long on a 4 K boundary) of TCE contents to be stored in the TCE table (contains logical address of storage page to be mapped)" so we rather want to remove (tce_list & ~SPAPR_TCE_RW) below.

Quoted 4 lines

Oops my bad for the confustion... :-\

Then it looks like SPAPR_TCE_RW can be dropped as well since put_tce_emu() uses IOMMU_RW instead.

Well, spapr_tce_translate_iommu() should actually translate SPAPR_TCE_xxx (PAPR defined flags) to IOMMU_xxx (QEMU IOMMUTLBEntry permission bits), not just rely on the fact that they match.

Quoted 37 lines
Quoted 36 lines
Quoted 34 lines

Possible values for the protection bits are necessarly non-zero and thus H_PUT_TCE_INDIRECT currently always fails and returns H_PARAMETER.

The code explicitly clears the protection bits when computing the TCE offset, a few lines below (tce_list & ~SPAPR_TCE_RW)... The sanity check is obviously wrong for these bits.

Moreover, I could find no indication in PAPR+ that using the other reserved bits should error out with H_PARAMETER.

This patch simply drops the offending check.

---
   hw/ppc/spapr_iommu.c |    2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/spapr_iommu.c +1 -1
index 8cd9dba9ac4d..37a1110c9d87 100644
@@ -258,7 +258,7 @@ static target_ulong h_put_tce_indirect(PowerPCCPU *cpu,
           return H_PARAMETER;
       }
 
-    if ((npages > 512) || (tce_list & SPAPR_TCE_PAGE_MASK)) {
+    if (npages > 512) {
           return H_PARAMETER;
       }
 
Signature · 1 line
Alexey