public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi: sd: infer lbpme from VPD B2 when READ CAPACITY 16 lacks LBPME
@ 2026-04-02  6:39 Hao Yao
  2026-04-14  3:16 ` Martin K. Petersen
  0 siblings, 1 reply; 2+ messages in thread
From: Hao Yao @ 2026-04-02  6:39 UTC (permalink / raw)
  To: James.Bottomley, martin.petersen; +Cc: linux-scsi, linux-kernel, Hao Yao

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


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

end of thread, other threads:[~2026-04-14  3:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-02  6:39 [PATCH] scsi: sd: infer lbpme from VPD B2 when READ CAPACITY 16 lacks LBPME Hao Yao
2026-04-14  3:16 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox