qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 0/2] spapr_iommu: TCE permission bits fixes
@ 2015-06-16 16:26 Greg Kurz
  2015-06-16 16:26 ` [Qemu-devel] [PATCH v2 1/2] spapr_iommu: drop erroneous check in h_put_tce_indirect() Greg Kurz
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Greg Kurz @ 2015-06-16 16:26 UTC (permalink / raw)
  To: David Gibson; +Cc: Alexey Kardashevskiy, qemu-ppc, qemu-devel

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH v2 1/2] spapr_iommu: drop erroneous check in h_put_tce_indirect()
  2015-06-16 16:26 [Qemu-devel] [PATCH v2 0/2] spapr_iommu: TCE permission bits fixes Greg Kurz
@ 2015-06-16 16:26 ` Greg Kurz
  2015-06-16 16:38   ` Greg Kurz
  2015-06-16 16:26 ` [Qemu-devel] [PATCH v2 2/2] spapr_iommu: translate sPAPRTCEAccess to IOMMUAccessFlags Greg Kurz
  2015-06-18  6:23 ` [Qemu-devel] [PATCH v2 0/2] spapr_iommu: TCE permission bits fixes David Gibson
  2 siblings, 1 reply; 5+ messages in thread
From: Greg Kurz @ 2015-06-16 16:26 UTC (permalink / raw)
  To: David Gibson; +Cc: Alexey Kardashevskiy, qemu-ppc, qemu-devel

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.

Suggested-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
---
 hw/ppc/spapr_iommu.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
index 8cd9dba9ac4d..ddd0ea5cd4dd 100644
--- a/hw/ppc/spapr_iommu.c
+++ b/hw/ppc/spapr_iommu.c
@@ -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) {

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH v2 2/2] spapr_iommu: translate sPAPRTCEAccess to IOMMUAccessFlags
  2015-06-16 16:26 [Qemu-devel] [PATCH v2 0/2] spapr_iommu: TCE permission bits fixes Greg Kurz
  2015-06-16 16:26 ` [Qemu-devel] [PATCH v2 1/2] spapr_iommu: drop erroneous check in h_put_tce_indirect() Greg Kurz
@ 2015-06-16 16:26 ` Greg Kurz
  2015-06-18  6:23 ` [Qemu-devel] [PATCH v2 0/2] spapr_iommu: TCE permission bits fixes David Gibson
  2 siblings, 0 replies; 5+ messages in thread
From: Greg Kurz @ 2015-06-16 16:26 UTC (permalink / raw)
  To: David Gibson; +Cc: Alexey Kardashevskiy, qemu-ppc, qemu-devel

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.

Suggested-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
---
 hw/ppc/spapr_iommu.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
index ddd0ea5cd4dd..9133912bb983 100644
--- a/hw/ppc/spapr_iommu.c
+++ b/hw/ppc/spapr_iommu.c
@@ -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;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v2 1/2] spapr_iommu: drop erroneous check in h_put_tce_indirect()
  2015-06-16 16:26 ` [Qemu-devel] [PATCH v2 1/2] spapr_iommu: drop erroneous check in h_put_tce_indirect() Greg Kurz
@ 2015-06-16 16:38   ` Greg Kurz
  0 siblings, 0 replies; 5+ messages in thread
From: Greg Kurz @ 2015-06-16 16:38 UTC (permalink / raw)
  To: David Gibson; +Cc: Alexey Kardashevskiy, qemu-ppc, qemu-devel

On Tue, 16 Jun 2015 18:26:47 +0200
Greg Kurz <gkurz@linux.vnet.ibm.com> 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.
> 
> This patch doesn't fix any bug, it is only code cleanup.
> 
> Suggested-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
> ---
>  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

> diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
> index 8cd9dba9ac4d..ddd0ea5cd4dd 100644
> --- a/hw/ppc/spapr_iommu.c
> +++ b/hw/ppc/spapr_iommu.c
> @@ -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) {
> 
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/2] spapr_iommu: TCE permission bits fixes
  2015-06-16 16:26 [Qemu-devel] [PATCH v2 0/2] spapr_iommu: TCE permission bits fixes Greg Kurz
  2015-06-16 16:26 ` [Qemu-devel] [PATCH v2 1/2] spapr_iommu: drop erroneous check in h_put_tce_indirect() Greg Kurz
  2015-06-16 16:26 ` [Qemu-devel] [PATCH v2 2/2] spapr_iommu: translate sPAPRTCEAccess to IOMMUAccessFlags Greg Kurz
@ 2015-06-18  6:23 ` David Gibson
  2 siblings, 0 replies; 5+ messages in thread
From: David Gibson @ 2015-06-18  6:23 UTC (permalink / raw)
  To: Greg Kurz; +Cc: Alexey Kardashevskiy, qemu-ppc, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 474 bytes --]

On Tue, Jun 16, 2015 at 06:26:39PM +0200, Greg Kurz wrote:
> 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.

-- 
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

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-18  6:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-16 16:26 [Qemu-devel] [PATCH v2 0/2] spapr_iommu: TCE permission bits fixes Greg Kurz
2015-06-16 16:26 ` [Qemu-devel] [PATCH v2 1/2] spapr_iommu: drop erroneous check in h_put_tce_indirect() Greg Kurz
2015-06-16 16:38   ` Greg Kurz
2015-06-16 16:26 ` [Qemu-devel] [PATCH v2 2/2] spapr_iommu: translate sPAPRTCEAccess to IOMMUAccessFlags Greg Kurz
2015-06-18  6:23 ` [Qemu-devel] [PATCH v2 0/2] spapr_iommu: TCE permission bits fixes David Gibson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).