Skip to content

Commit 00b33cf

Browse files
birkelundChristoph Hellwig
authored andcommitted
nvme: fix write zeroes pi
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 <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 8e8aaf5 commit 00b33cf

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/nvme/host/core.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,10 +895,19 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns,
895895
cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req)));
896896
cmnd->write_zeroes.length =
897897
cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1);
898-
if (nvme_ns_has_pi(ns))
898+
899+
if (nvme_ns_has_pi(ns)) {
899900
cmnd->write_zeroes.control = cpu_to_le16(NVME_RW_PRINFO_PRACT);
900-
else
901-
cmnd->write_zeroes.control = 0;
901+
902+
switch (ns->pi_type) {
903+
case NVME_NS_DPS_PI_TYPE1:
904+
case NVME_NS_DPS_PI_TYPE2:
905+
cmnd->write_zeroes.reftag =
906+
cpu_to_le32(t10_pi_ref_tag(req));
907+
break;
908+
}
909+
}
910+
902911
return BLK_STS_OK;
903912
}
904913

0 commit comments

Comments
 (0)