[PATCH] scsi: target: Keep Block Limits VPD page 64 bytes without atomic writes
From: Lukas Herbolt
Date: Fri Dec 04 2026 - 09:17:46 EST
Commit 710ad826e300 ("scsi: target: Report atomic values in INQUIRY")
changed the Block Limits VPD page (0xb0) length reported by LIO from
0x3c (64 bytes including the 4-byte header) to 40 (44 bytes total) when
thin provisioning is enabled and the backend does not support atomic
writes, which is always the case for fileio.
The SCSI disk driver only reads the thin provisioning fields of the
Block Limits VPD page when the page is at least 64 bytes long (see
sd_read_block_limits() in drivers/scsi/sd.c; this requirement dates
back to the original "buffer[3] == 0x3c" check added in 2011). With a
44-byte page the MAXIMUM UNMAP LBA COUNT, MAXIMUM UNMAP BLOCK
DESCRIPTOR COUNT, OPTIMAL UNMAP GRANULARITY and MAXIMUM WRITE SAME
LENGTH fields are ignored by the initiator and sdkp->max_ws_blocks and
sdkp->max_unmap_blocks remain zero.
As a result, for LIO fileio LUNs (and iblock LUNs whose backing device
does not support atomic writes) the SCSI disk driver falls back to
SD_MAX_WS16_BLOCKS and advertises a discard limit of 4 GiB - 512 bytes
instead of the max_write_same_len-based limit of the target, so WRITE
SAME based discards larger than max_write_same_len fail with
TCM_INVALID_CDB_FIELD:
WRITE_SAME sectors: 4097 exceeds max_write_same_len: 4096
Discards are also silently disabled for LUNs that only advertise
emulate_tpu, because sd_discard_mode() requires max_unmap_blocks to be
non-zero to select UNMAP mode.
Restore the pre-710ad826e300 behavior and keep declaring a 60-byte
(64 bytes total) page when thin provisioning is enabled, with the
atomic write fields left zero-filled. The buffer is allocated with
kzalloc() in spc_emulate_inquiry(), so no explicit zeroing is needed.
Fixes: 710ad826e300 ("scsi: target: Report atomic values in INQUIRY")
Signed-off-by: Lukas Herbolt <lherbolt@xxxxxxxxxx>
---
drivers/target/target_core_spc.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c
index f20bc6ea019b..87ae50eed7bc 100644
--- a/drivers/target/target_core_spc.c
+++ b/drivers/target/target_core_spc.c
@@ -597,7 +597,15 @@ spc_emulate_evpd_b0(struct se_cmd *cmd, unsigned char *buf)
*/
put_unaligned_be64(dev->dev_attrib.max_write_same_len, &buf[36]);
- put_unaligned_be16(40, &buf[2]);
+ /*
+ * The thin provisioning fields end at byte 43, but the SCSI disk
+ * driver only reads them if the page is at least 64 bytes long
+ * (see sd_read_block_limits()). Keep declaring the full page
+ * length including the (zeroed) atomic write fields when atomic
+ * writes are not supported, as was done before atomic write
+ * support was added.
+ */
+ put_unaligned_be16(60, &buf[2]);
try_atomic:
/*
--
2.56.0