Skip to contentSkip to conversation

hw/nvme: fix copy cmd for pi enabled namespaces

PATCH Applied Dmitry Tikhov 2 participants 2 messages Apr 21, 2022 – Apr 28, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 hw/nvme: fix copy cmd for pi enabled namespaces

Current implementation have problem in the read part of copy command. Because there is no metadata mangling before nvme_dif_check invocation, reftag error could be thrown for blocks of namespace that have not been previously written to.

---
v2:
* remove refactoring
* remove write part fix

---
 hw/nvme/ctrl.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/nvme/ctrl.c +4 -0
index 74540a03d5..08574c4dcb 100644
@@ -2787,6 +2787,10 @@ static void nvme_copy_in_completed_cb(void *opaque, int ret)
         size_t mlen = nvme_m2b(ns, nlb);
         uint8_t *mbounce = iocb->bounce + nvme_l2b(ns, nlb);
 
+        status = nvme_dif_mangle_mdata(ns, mbounce, mlen, slba);
+        if (status) {
+            goto invalid;
+        }
         status = nvme_dif_check(ns, iocb->bounce, len, mbounce, mlen, prinfor,
                                 slba, apptag, appmask, &reftag);
         if (status) {
Signature · 1 line
2.35.1
Applied
#1 lore raw
Quoted 32 lines · Dmitry Tikhov

Current implementation have problem in the read part of copy command. Because there is no metadata mangling before nvme_dif_check invocation, reftag error could be thrown for blocks of namespace that have not been previously written to.

---
v2:
* remove refactoring
* remove write part fix

---
 hw/nvme/ctrl.c | 4 ++++
 1 file changed, 4 insertions(+)
hw/nvme/ctrl.c +4 -0
index 74540a03d5..08574c4dcb 100644
@@ -2787,6 +2787,10 @@ static void nvme_copy_in_completed_cb(void *opaque, int ret)
         size_t mlen = nvme_m2b(ns, nlb);
         uint8_t *mbounce = iocb->bounce + nvme_l2b(ns, nlb);
 
+        status = nvme_dif_mangle_mdata(ns, mbounce, mlen, slba);
+        if (status) {
+            goto invalid;
+        }
         status = nvme_dif_check(ns, iocb->bounce, len, mbounce, mlen, prinfor,
                                 slba, apptag, appmask, &reftag);
         if (status) {
Signature · 1 line
2.35.1

Thanks Dmitry,

Applied to nvme-next.