Skip to contentSkip to conversation

nvme: fix CMB endianness confusion

PATCH Applied Paolo Bonzini 3 participants 3 messages Nov 22, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: fix CMB endianness confusion

The CMB is marked as DEVICE_LITTLE_ENDIAN, so the data must be read/written as if it was little-endian output (in the case of big endian, we get two swaps, one in the memory core and one in nvme.c).

---
 hw/block/nvme.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
hw/block/nvme.c +2 -5
index 5d92794ef7..8a12fba24f 100644
@@ -1175,16 +1175,13 @@ static void nvme_cmb_write(void *opaque, hwaddr addr, uint64_t data,
     unsigned size)
 {
     NvmeCtrl *n = (NvmeCtrl *)opaque;
-    memcpy(&n->cmbuf[addr], &data, size);
+    stn_le_p(&n->cmbuf[addr], size, data);
 }
 
 static uint64_t nvme_cmb_read(void *opaque, hwaddr addr, unsigned size)
 {
-    uint64_t val;
     NvmeCtrl *n = (NvmeCtrl *)opaque;
-
-    memcpy(&val, &n->cmbuf[addr], size);
-    return val;
+    return ldn_le_p(&n->cmbuf[addr], size);
 }
 
 static const MemoryRegionOps nvme_cmb_ops = {
Signature · 1 line
2.19.1
Tested-by on v1 1/1
#1 lore raw
Quoted 9 lines · Paolo Bonzini

The CMB is marked as DEVICE_LITTLE_ENDIAN, so the data must be read/written as if it was little-endian output (in the case of big endian, we get two swaps, one in the memory core and one in nvme.c).

---
 hw/block/nvme.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

This is sufficient to get the nvme-test to pass on sparc (big-endian host).

thanks
-- PMM

Applied
#2 lore raw
In reply to Paolo Bonzini

Am 22.11.2018 um 19:23 hat Paolo Bonzini geschrieben:

Quoted 6 lines

The CMB is marked as DEVICE_LITTLE_ENDIAN, so the data must be read/written as if it was little-endian output (in the case of big endian, we get two swaps, one in the memory core and one in nvme.c).

Thanks, applied to the block branch.

Kevin