linux/drivers/nvme/host
Christoph Hellwig b146e0434f nvme: fix PI insert on write
[ Upstream commit 7ac3c2889b ]

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.

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2025-09-25 11:13:41 +02:00
..
apple.c block: add a rq_list type 2025-04-25 10:48:06 +02:00
auth.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
constants.c nvme: fix command limits status code 2025-06-19 15:32:18 +02:00
core.c nvme: fix PI insert on write 2025-09-25 11:13:41 +02:00
fabrics.c nvme-tcp: check for invalidated or revoked key 2024-08-22 13:25:07 -07:00
fabrics.h nvme-pci: do not directly handle subsys reset fallout 2024-06-26 07:02:22 -07:00
fault_inject.c fault-inject: improve build for CONFIG_FAULT_INJECTION=n 2024-09-01 20:43:33 -07:00
fc.c nvme-fc: rely on state transitions to handle connectivity loss 2025-03-22 12:54:28 -07:00
fc.h nvme-fc: Update header and host for common definitions for LS handling 2020-05-09 16:18:33 -06:00
hwmon.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
ioctl.c nvme: always punt polled uring_cmd end_io work to task_work 2025-06-27 11:11:38 +01:00
Kconfig nvme-tcp: select CONFIG_TLS from CONFIG_NVME_TCP_TLS 2025-05-09 09:50:46 +02:00
Makefile nvme: rework NVME_AUTH Kconfig selection 2023-10-12 08:04:49 -07:00
multipath.c nvme: multipath: fix return value of nvme_available_path 2025-05-02 07:59:23 +02:00
nvme.h nvme-pci: add support for sgl metadata 2025-03-13 13:02:01 +01:00
pci.c nvme-pci: skip nvme_write_sq_db on empty rqlist 2025-09-19 16:35:42 +02:00
pr.c nvme: fix command limits status code 2025-06-19 15:32:18 +02:00
rdma.c nvme-rdma: unquiesce admin_q before destroy it 2024-12-14 20:03:17 +01:00
sysfs.c nvme: make nvme_tls_attrs_group static 2025-02-17 10:04:59 +01:00
tcp.c nvme-tcp: log TLS handshake failures at error level 2025-08-20 18:30:19 +02:00
trace.c move asm/unaligned.h to linux/unaligned.h 2024-10-02 17:23:23 -04:00
trace.h nvme: fix async event trace event 2023-04-13 08:59:04 +02:00
zns.c block: Remove REQ_OP_ZONE_RESET_ALL emulation 2024-07-05 00:42:04 -06:00