diff mbox series

[v1,1/2] dma/xlnx-zdma: Fix descriptor loading (MEM) wrt endianness

Message ID 20200404122718.25111-2-edgar.iglesias@gmail.com (mailing list archive)
State New, archived
Headers show
Series dma/xlnx-zdma: Fix descriptor loading wrt host endianness | expand

Commit Message

Edgar E. Iglesias April 4, 2020, 12:27 p.m. UTC
From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>

Fix descriptor loading from memory wrt host endianness.

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
---
 hw/dma/xlnx-zdma.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Francisco Iglesias April 6, 2020, 10:01 a.m. UTC | #1
On [2020 Apr 04] Sat 14:27:17, Edgar E. Iglesias wrote:
> From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
> 
> Fix descriptor loading from memory wrt host endianness.
> 
> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>

Reviewed-by: Francisco Iglesias <frasse.iglesias@gmail.com>

> ---
>  hw/dma/xlnx-zdma.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/dma/xlnx-zdma.c b/hw/dma/xlnx-zdma.c
> index 1c45367f3c..5f4775f663 100644
> --- a/hw/dma/xlnx-zdma.c
> +++ b/hw/dma/xlnx-zdma.c
> @@ -299,19 +299,22 @@ static void zdma_put_regaddr64(XlnxZDMA *s, unsigned int basereg, uint64_t addr)
>      s->regs[basereg + 1] = addr >> 32;
>  }
>  
> -static bool zdma_load_descriptor(XlnxZDMA *s, uint64_t addr, void *buf)
> +static bool zdma_load_descriptor(XlnxZDMA *s, uint64_t addr,
> +                                 XlnxZDMADescr *descr)
>  {
>      /* ZDMA descriptors must be aligned to their own size.  */
>      if (addr % sizeof(XlnxZDMADescr)) {
>          qemu_log_mask(LOG_GUEST_ERROR,
>                        "zdma: unaligned descriptor at %" PRIx64,
>                        addr);
> -        memset(buf, 0x0, sizeof(XlnxZDMADescr));
> +        memset(descr, 0x0, sizeof(XlnxZDMADescr));
>          s->error = true;
>          return false;
>      }
>  
> -    address_space_read(s->dma_as, addr, s->attr, buf, sizeof(XlnxZDMADescr));
> +    descr->addr = address_space_ldq_le(s->dma_as, addr, s->attr, NULL);
> +    descr->size = address_space_ldl_le(s->dma_as, addr + 8, s->attr, NULL);
> +    descr->attr = address_space_ldl_le(s->dma_as, addr + 12, s->attr, NULL);
>      return true;
>  }
>  
> @@ -344,7 +347,7 @@ static void zdma_update_descr_addr(XlnxZDMA *s, bool type,
>      } else {
>          addr = zdma_get_regaddr64(s, basereg);
>          addr += sizeof(s->dsc_dst);
> -        address_space_read(s->dma_as, addr, s->attr, (void *) &next, 8);
> +        next = address_space_ldq_le(s->dma_as, addr, s->attr, NULL);
>      }
>  
>      zdma_put_regaddr64(s, basereg, next);
> -- 
> 2.20.1
>
Philippe Mathieu-Daudé April 7, 2020, 11:12 a.m. UTC | #2
On 4/4/20 2:27 PM, Edgar E. Iglesias wrote:
> From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
> 
> Fix descriptor loading from memory wrt host endianness.
> 
> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
> ---
>   hw/dma/xlnx-zdma.c | 11 +++++++----
>   1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/dma/xlnx-zdma.c b/hw/dma/xlnx-zdma.c
> index 1c45367f3c..5f4775f663 100644
> --- a/hw/dma/xlnx-zdma.c
> +++ b/hw/dma/xlnx-zdma.c
> @@ -299,19 +299,22 @@ static void zdma_put_regaddr64(XlnxZDMA *s, unsigned int basereg, uint64_t addr)
>       s->regs[basereg + 1] = addr >> 32;
>   }
>   
> -static bool zdma_load_descriptor(XlnxZDMA *s, uint64_t addr, void *buf)
> +static bool zdma_load_descriptor(XlnxZDMA *s, uint64_t addr,
> +                                 XlnxZDMADescr *descr)
>   {
>       /* ZDMA descriptors must be aligned to their own size.  */
>       if (addr % sizeof(XlnxZDMADescr)) {
>           qemu_log_mask(LOG_GUEST_ERROR,
>                         "zdma: unaligned descriptor at %" PRIx64,
>                         addr);
> -        memset(buf, 0x0, sizeof(XlnxZDMADescr));
> +        memset(descr, 0x0, sizeof(XlnxZDMADescr));
>           s->error = true;
>           return false;
>       }
>   
> -    address_space_read(s->dma_as, addr, s->attr, buf, sizeof(XlnxZDMADescr));
> +    descr->addr = address_space_ldq_le(s->dma_as, addr, s->attr, NULL);
> +    descr->size = address_space_ldl_le(s->dma_as, addr + 8, s->attr, NULL);
> +    descr->attr = address_space_ldl_le(s->dma_as, addr + 12, s->attr, NULL);

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

>       return true;
>   }
>   
> @@ -344,7 +347,7 @@ static void zdma_update_descr_addr(XlnxZDMA *s, bool type,
>       } else {
>           addr = zdma_get_regaddr64(s, basereg);
>           addr += sizeof(s->dsc_dst);
> -        address_space_read(s->dma_as, addr, s->attr, (void *) &next, 8);
> +        next = address_space_ldq_le(s->dma_as, addr, s->attr, NULL);
>       }
>   
>       zdma_put_regaddr64(s, basereg, next);
>
diff mbox series

Patch

diff --git a/hw/dma/xlnx-zdma.c b/hw/dma/xlnx-zdma.c
index 1c45367f3c..5f4775f663 100644
--- a/hw/dma/xlnx-zdma.c
+++ b/hw/dma/xlnx-zdma.c
@@ -299,19 +299,22 @@  static void zdma_put_regaddr64(XlnxZDMA *s, unsigned int basereg, uint64_t addr)
     s->regs[basereg + 1] = addr >> 32;
 }
 
-static bool zdma_load_descriptor(XlnxZDMA *s, uint64_t addr, void *buf)
+static bool zdma_load_descriptor(XlnxZDMA *s, uint64_t addr,
+                                 XlnxZDMADescr *descr)
 {
     /* ZDMA descriptors must be aligned to their own size.  */
     if (addr % sizeof(XlnxZDMADescr)) {
         qemu_log_mask(LOG_GUEST_ERROR,
                       "zdma: unaligned descriptor at %" PRIx64,
                       addr);
-        memset(buf, 0x0, sizeof(XlnxZDMADescr));
+        memset(descr, 0x0, sizeof(XlnxZDMADescr));
         s->error = true;
         return false;
     }
 
-    address_space_read(s->dma_as, addr, s->attr, buf, sizeof(XlnxZDMADescr));
+    descr->addr = address_space_ldq_le(s->dma_as, addr, s->attr, NULL);
+    descr->size = address_space_ldl_le(s->dma_as, addr + 8, s->attr, NULL);
+    descr->attr = address_space_ldl_le(s->dma_as, addr + 12, s->attr, NULL);
     return true;
 }
 
@@ -344,7 +347,7 @@  static void zdma_update_descr_addr(XlnxZDMA *s, bool type,
     } else {
         addr = zdma_get_regaddr64(s, basereg);
         addr += sizeof(s->dsc_dst);
-        address_space_read(s->dma_as, addr, s->attr, (void *) &next, 8);
+        next = address_space_ldq_le(s->dma_as, addr, s->attr, NULL);
     }
 
     zdma_put_regaddr64(s, basereg, next);