linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] nvme: fix write zeroes pi
@ 2021-11-10  9:19 Klaus Jensen
  2021-11-11 13:30 ` Martin K. Petersen
  2021-11-19 17:10 ` Christoph Hellwig
  0 siblings, 2 replies; 3+ messages in thread
From: Klaus Jensen @ 2021-11-10  9:19 UTC (permalink / raw)
  To: linux-nvme
  Cc: Jens Axboe, Christoph Hellwig, linux-kernel, Keith Busch,
	Sagi Grimberg, Klaus Jensen

From: Klaus Jensen <k.jensen@samsung.com>

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>
---
v2: also set PRACT for type 3...

 drivers/nvme/host/core.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 3825b596ca16..41885ecc69fc 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -914,10 +914,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;
 }
 
-- 
2.33.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] nvme: fix write zeroes pi
  2021-11-10  9:19 [PATCH v2] nvme: fix write zeroes pi Klaus Jensen
@ 2021-11-11 13:30 ` Martin K. Petersen
  2021-11-19 17:10 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Martin K. Petersen @ 2021-11-11 13:30 UTC (permalink / raw)
  To: Klaus Jensen
  Cc: linux-nvme, Jens Axboe, Christoph Hellwig, linux-kernel,
	Keith Busch, Sagi Grimberg, Klaus Jensen


Klaus,

> 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).

Looks good to me.

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] nvme: fix write zeroes pi
  2021-11-10  9:19 [PATCH v2] nvme: fix write zeroes pi Klaus Jensen
  2021-11-11 13:30 ` Martin K. Petersen
@ 2021-11-19 17:10 ` Christoph Hellwig
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2021-11-19 17:10 UTC (permalink / raw)
  To: Klaus Jensen
  Cc: linux-nvme, Jens Axboe, Christoph Hellwig, linux-kernel,
	Keith Busch, Sagi Grimberg, Klaus Jensen

Thanks,

applied to nvme-5.16.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-19 17:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-10  9:19 [PATCH v2] nvme: fix write zeroes pi Klaus Jensen
2021-11-11 13:30 ` Martin K. Petersen
2021-11-19 17:10 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).