public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Hao Yao <hao.yao@intel.com>
To: James.Bottomley@HansenPartnership.com, martin.petersen@oracle.com
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	Hao Yao <hao.yao@intel.com>
Subject: [PATCH] scsi: sd: infer lbpme from VPD B2 when READ CAPACITY 16 lacks LBPME
Date: Thu,  2 Apr 2026 14:39:51 +0800	[thread overview]
Message-ID: <20260402063959.4005814-1-hao.yao@intel.com> (raw)

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


                 reply	other threads:[~2026-04-02  6:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260402063959.4005814-1-hao.yao@intel.com \
    --to=hao.yao@intel.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox