]> www.infradead.org Git - users/willy/linux.git/commitdiff
nvme: fix write zeroes pi
authorKlaus Jensen <k.jensen@samsung.com>
Wed, 10 Nov 2021 09:19:06 +0000 (10:19 +0100)
committerChristoph Hellwig <hch@lst.de>
Tue, 23 Nov 2021 16:22:41 +0000 (17:22 +0100)
Write Zeroes sets PRACT when block integrity is enabled (as it should),
but neglects to also set the reftag which is expected by reads. This
causes protection errors on reads.

Fix this by setting the reftag for type 1 and 2 (for type 3, reads will
not check the reftag).

Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/host/core.c

index 50a98f56da88ce7491719d6f36f51a3b7f7eb358..4c63564adeaa6a4c25727893a89b935710966162 100644 (file)
@@ -895,10 +895,19 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns,
                cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req)));
        cmnd->write_zeroes.length =
                cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1);
-       if (nvme_ns_has_pi(ns))
+
+       if (nvme_ns_has_pi(ns)) {
                cmnd->write_zeroes.control = cpu_to_le16(NVME_RW_PRINFO_PRACT);
-       else
-               cmnd->write_zeroes.control = 0;
+
+               switch (ns->pi_type) {
+               case NVME_NS_DPS_PI_TYPE1:
+               case NVME_NS_DPS_PI_TYPE2:
+                       cmnd->write_zeroes.reftag =
+                               cpu_to_le32(t10_pi_ref_tag(req));
+                       break;
+               }
+       }
+
        return BLK_STS_OK;
 }