All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hw/nvme: fix mmio read
@ 2021-07-13  5:43 Klaus Jensen
       [not found] ` <CGME20210713093226epcas5p48dda40b1c0b3c76a9cced6b8889dde1d@epcas5p4.samsung.com>
  2021-07-13 10:07 ` Peter Maydell
  0 siblings, 2 replies; 7+ messages in thread
From: Klaus Jensen @ 2021-07-13  5:43 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, qemu-block, Klaus Jensen, Gollu Appalanaidu,
	Keith Busch, Klaus Jensen

From: Klaus Jensen <k.jensen@samsung.com>

The new PMR test unearthed a long-standing issue with MMIO reads on
big-endian hosts.

Fix by using the ldn_he_p helper instead of memcpy.

Cc: Gollu Appalanaidu <anaidu.gollu@samsung.com>
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/nvme/ctrl.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 2f0524e12a36..dd81c3b19c7e 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -5951,7 +5951,6 @@ static uint64_t nvme_mmio_read(void *opaque, hwaddr addr, unsigned size)
 {
     NvmeCtrl *n = (NvmeCtrl *)opaque;
     uint8_t *ptr = (uint8_t *)&n->bar;
-    uint64_t val = 0;
 
     trace_pci_nvme_mmio_read(addr, size);
 
@@ -5977,14 +5976,15 @@ static uint64_t nvme_mmio_read(void *opaque, hwaddr addr, unsigned size)
             (NVME_PMRCAP_PMRWBM(n->bar.pmrcap) & 0x02)) {
             memory_region_msync(&n->pmr.dev->mr, 0, n->pmr.dev->size);
         }
-        memcpy(&val, ptr + addr, size);
-    } else {
-        NVME_GUEST_ERR(pci_nvme_ub_mmiord_invalid_ofs,
-                       "MMIO read beyond last register,"
-                       " offset=0x%"PRIx64", returning 0", addr);
+
+        return ldn_he_p(ptr + addr, size);
     }
 
-    return val;
+    NVME_GUEST_ERR(pci_nvme_ub_mmiord_invalid_ofs,
+                   "MMIO read beyond last register,"
+                   " offset=0x%"PRIx64", returning 0", addr);
+
+    return 0;
 }
 
 static void nvme_process_db(NvmeCtrl *n, hwaddr addr, int val)
-- 
2.32.0



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

end of thread, other threads:[~2021-07-13 14:37 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-13  5:43 [PATCH] hw/nvme: fix mmio read Klaus Jensen
     [not found] ` <CGME20210713093226epcas5p48dda40b1c0b3c76a9cced6b8889dde1d@epcas5p4.samsung.com>
2021-07-13  9:28   ` Gollu Appalanaidu
2021-07-13 10:07 ` Peter Maydell
2021-07-13 10:19   ` Klaus Jensen
2021-07-13 10:31     ` Peter Maydell
2021-07-13 10:34       ` Klaus Jensen
2021-07-13 14:33         ` Klaus Jensen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.