Skip to contentSkip to conversation

nvme: fix copy direction in DMA reads going to CMB

PATCH Applied Klaus Birkelund Jensen 4 participants 5 messages May 18, 2019 – May 20, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme: fix copy direction in DMA reads going to CMB

nvme_dma_read_prp erronously used qemu_iovec_*to*_buf instead of qemu_iovec_*from*_buf when the request involved the controller memory buffer.

---
 hw/block/nvme.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/nvme.c +1 -1
index 7caf92532a09..63a5b58849fb 100644
@@ -238,7 +238,7 @@ static uint16_t nvme_dma_read_prp(NvmeCtrl *n, uint8_t *ptr, uint32_t len,
         }
         qemu_sglist_destroy(&qsg);
     } else {
-        if (unlikely(qemu_iovec_to_buf(&iov, 0, ptr, len) != len)) {
+        if (unlikely(qemu_iovec_from_buf(&iov, 0, ptr, len) != len)) {
             trace_nvme_err_invalid_dma();
             status = NVME_INVALID_FIELD | NVME_DNR;
         }
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Klaus Birkelund Jensen

nvme_dma_read_prp erronously used qemu_iovec_*to*_buf instead of qemu_iovec_*from*_buf when the request involved the controller memory buffer.

---
  hw/block/nvme.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/nvme.c +0 -0
index 7caf92532a09..63a5b58849fb 100644

hw/block/nvme.c static uint16_t nvme_dma_read_prp(NvmeCtrl *n, uint8_t *ptr, uint32_t len, · line 244

Quoted 8 lines
hw/block/nvme.c +1 -1
@@ -238,7 +238,7 @@ static uint16_t nvme_dma_read_prp(NvmeCtrl *n, uint8_t *ptr, uint32_t len,
          }
          qemu_sglist_destroy(&qsg);
      } else {
-        if (unlikely(qemu_iovec_to_buf(&iov, 0, ptr, len) != len)) {
+        if (unlikely(qemu_iovec_from_buf(&iov, 0, ptr, len) != len)) {
              trace_nvme_err_invalid_dma();
              status = NVME_INVALID_FIELD | NVME_DNR;
          }
#3 lore raw
In reply to Klaus Birkelund Jensen
Quoted 5 lines · Klaus Birkelund Jensen

nvme_dma_read_prp erronously used qemu_iovec_*to*_buf instead of qemu_iovec_*from*_buf when the request involved the controller memory buffer.

I was wondering how this mistake got by for so long, and it looks like the only paths here require an admin command with dev->host transfer to CMB. That's just not done in any host implementation I'm aware of since it'd make it more difficult to use for no particular gain AFAICS, so I'd be curious to hear if you have a legit implementation doing this.

Anyway, thanks for the fix.

#4 lore raw
Quoted 5 lines · Keith Busch
Quoted 4 lines · Klaus Birkelund Jensen

nvme_dma_read_prp erronously used qemu_iovec_*to*_buf instead of qemu_iovec_*from*_buf when the request involved the controller memory buffer.

Quoted 8 lines
Quoted 1 line

I was wondering how this mistake got by for so long, and it looks like the only paths here require an admin command with dev->host transfer to CMB. That's just not done in any host implementation I'm aware of since it'd make it more difficult to use for no particular gain AFAICS, so I'd be curious to hear if you have a legit implementation doing this.

I'm just trying to get the device to be as compliant as possible, but I don't know why you'd have any reason to do a, say Get Feature, to the CMB.