* [PATCH v2] nvme: fix PI insert on write
@ 2025-08-25 13:32 Christoph Hellwig
2025-08-25 14:01 ` Keith Busch
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Christoph Hellwig @ 2025-08-25 13:32 UTC (permalink / raw)
To: kbusch, sagi; +Cc: linux-nvme, martin.petersen, joshi.k
I recently ran into an issue where the PI generated using the block layer
integrity code differs from that from a kernel using the PRACT fallback
when the block layer integrity code is disabled, and I tracked this down
to us using PRACT incorrectly.
The NVM Command Set Specification (section 5.33 in 1.2, similar in older
versions) specifies the PRACT insert behavior as:
Inserted protection information consists of the computed CRC for the
protection information format (refer to section 5.3.1) in the Guard
field, the LBAT field value in the Application Tag field, the LBST
field value in the Storage Tag field, if defined, and the computed
reference tag in the Logical Block Reference Tag.
Where the computed reference tag is defined as following for type 1 and
type 2 using the text below that is duplicated in the respective bullet
points:
the value of the computed reference tag for the first logical block of
the command is the value contained in the Initial Logical Block
Reference Tag (ILBRT) or Expected Initial Logical Block Reference Tag
(EILBRT) field in the command, and the computed reference tag is
incremented for each subsequent logical block.
So we need to set ILBRT field, but we currently don't. Interestingly
this works fine on my older type 1 formatted SSD, but Qemu trips up on
this. We already set ILBRT for Write Same since commit aeb7bb061be5
("nvme: set the PRACT bit when using Write Zeroes with T10 PI").
To ease this, move the PI type check into nvme_set_ref_tag.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
Changes since v1:
- don't accidentally set the ILBRT field for type 3 PI
drivers/nvme/host/core.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 9707a0e8c431..fb36c5c9e55d 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -903,6 +903,15 @@ static void nvme_set_ref_tag(struct nvme_ns *ns, struct nvme_command *cmnd,
u32 upper, lower;
u64 ref48;
+ /* only type1 and type 2 PI formats have a reftag */
+ switch (ns->head->pi_type) {
+ case NVME_NS_DPS_PI_TYPE1:
+ case NVME_NS_DPS_PI_TYPE2:
+ break;
+ default:
+ return;
+ }
+
/* both rw and write zeroes share the same reftag format */
switch (ns->head->guard_type) {
case NVME_NVM_NS_16B_GUARD:
@@ -942,13 +951,7 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns,
if (nvme_ns_has_pi(ns->head)) {
cmnd->write_zeroes.control |= cpu_to_le16(NVME_RW_PRINFO_PRACT);
-
- switch (ns->head->pi_type) {
- case NVME_NS_DPS_PI_TYPE1:
- case NVME_NS_DPS_PI_TYPE2:
- nvme_set_ref_tag(ns, cmnd, req);
- break;
- }
+ nvme_set_ref_tag(ns, cmnd, req);
}
return BLK_STS_OK;
@@ -1039,6 +1042,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
if (WARN_ON_ONCE(!nvme_ns_has_pi(ns->head)))
return BLK_STS_NOTSUPP;
control |= NVME_RW_PRINFO_PRACT;
+ nvme_set_ref_tag(ns, cmnd, req);
}
if (bio_integrity_flagged(req->bio, BIP_CHECK_GUARD))
--
2.47.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2] nvme: fix PI insert on write
2025-08-25 13:32 [PATCH v2] nvme: fix PI insert on write Christoph Hellwig
@ 2025-08-25 14:01 ` Keith Busch
2025-08-25 14:09 ` Martin K. Petersen
2025-09-02 19:22 ` Keith Busch
2 siblings, 0 replies; 4+ messages in thread
From: Keith Busch @ 2025-08-25 14:01 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: sagi, linux-nvme, martin.petersen, joshi.k
On Mon, Aug 25, 2025 at 03:32:49PM +0200, Christoph Hellwig wrote:
>
> So we need to set ILBRT field, but we currently don't. Interestingly
> this works fine on my older type 1 formatted SSD, but Qemu trips up on
> this. We already set ILBRT for Write Same since commit aeb7bb061be5
> ("nvme: set the PRACT bit when using Write Zeroes with T10 PI").
>
> To ease this, move the PI type check into nvme_set_ref_tag.
Looks good
Reviewed-by: Keith Busch <kbusch@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2] nvme: fix PI insert on write
2025-08-25 13:32 [PATCH v2] nvme: fix PI insert on write Christoph Hellwig
2025-08-25 14:01 ` Keith Busch
@ 2025-08-25 14:09 ` Martin K. Petersen
2025-09-02 19:22 ` Keith Busch
2 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen @ 2025-08-25 14:09 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: kbusch, sagi, linux-nvme, martin.petersen, joshi.k
Christoph,
> I recently ran into an issue where the PI generated using the block
> layer integrity code differs from that from a kernel using the PRACT
> fallback when the block layer integrity code is disabled, and I
> tracked this down to us using PRACT incorrectly.
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] nvme: fix PI insert on write
2025-08-25 13:32 [PATCH v2] nvme: fix PI insert on write Christoph Hellwig
2025-08-25 14:01 ` Keith Busch
2025-08-25 14:09 ` Martin K. Petersen
@ 2025-09-02 19:22 ` Keith Busch
2 siblings, 0 replies; 4+ messages in thread
From: Keith Busch @ 2025-09-02 19:22 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: sagi, linux-nvme, martin.petersen, joshi.k
On Mon, Aug 25, 2025 at 03:32:49PM +0200, Christoph Hellwig wrote:
> I recently ran into an issue where the PI generated using the block layer
> integrity code differs from that from a kernel using the PRACT fallback
> when the block layer integrity code is disabled, and I tracked this down
> to us using PRACT incorrectly.
Thanks, applied to nvme-6.17.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-03 0:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-25 13:32 [PATCH v2] nvme: fix PI insert on write Christoph Hellwig
2025-08-25 14:01 ` Keith Busch
2025-08-25 14:09 ` Martin K. Petersen
2025-09-02 19:22 ` Keith Busch
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.