[PATCH] scsi: sd: infer lbpme from VPD B2 when READ CAPACITY 16 lacks LBPME

Hao Yao
2026-04-02T06:40:15Z

Some USB-NVMe bridge devices (e.g. Realtek RTL9210) correctly report
UNMAP support via VPD page B2 (LBPU=1) and block limits via VPD page
B0, but fail to set the LBPME (Logical Block Provisioning Management
Enabled) flag in the READ CAPACITY 16 response. This prevents the SCSI
disk driver from enabling discard/TRIM support.

Fix this by removing the early return in sd_read_block_provisioning()
when lbpme is not set, allowing the function to read VPD B2 regardless.
If VPD B2 indicates LBPU (UNMAP) support, set lbpme so that
sd_read_block_limits() and sd_discard_mode() can properly configure
discard.

Signed-off-by: Hao Yao <hao.yao@intel.com>
---
drivers/scsi/sd.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 628a1d0a74ba..ba653988dd13 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3466,9 +3466,6 @@ static void sd_read_block_provisioning(struct scsi_disk *sdkp)
{
struct scsi_vpd *vpd;

- if (sdkp->lbpme == 0)
- return;
-
rcu_read_lock();
vpd = rcu_dereference(sdkp->device->vpd_pgb2);

@@ -3481,6 +3478,20 @@ static void sd_read_block_provisioning(struct scsi_disk *sdkp)
sdkp->lbpu = (vpd->data[5] >> 7) & 1; /* UNMAP */
sdkp->lbpws = (vpd->data[5] >> 6) & 1; /* WRITE SAME(16) w/ UNMAP */
sdkp->lbpws10 = (vpd->data[5] >> 5) & 1; /* WRITE SAME(10) w/ UNMAP */
+
+ /*
+ * Some USB-NVMe bridge devices (e.g. Realtek RTL9210) report UNMAP
+ * support via VPD B2 (LBPU=1) but fail to set the LBPME flag in the
+ * READ CAPACITY 16 response. If VPD B2 indicates UNMAP support,
+ * enable lbpme so discard can be configured properly.
+ */
+ if (!sdkp->lbpme && sdkp->lbpu) {
+ if (sdkp->first_scan)
+ sd_printk(KERN_NOTICE, sdkp,
+ "LBPME not set in READ CAPACITY 16 but LBPU set in VPD B2; enabling discard\n");
+ sdkp->lbpme = 1;
+ }
+
rcu_read_unlock();
}

--
2.43.0