mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Chris Down <chris@chrisdown.name>
To: "Martin K. Petersen" <mkp@kernel.org>,
	"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>
Cc: Christoph Hellwig <hch@lst.de>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-team@meta.com
Subject: [PATCH v2 1/5] scsi: sd: Fix stale max_hw_wzeroes_unmap_sectors after a mode change
Date: Sat, 28 Nov 2026 01:26:31 -0800	[thread overview]
Message-ID: <e8d703511f446b850bbdbc0e26ca5e53e6672b4c.1795842371.git.chris@chrisdown.name> (raw)
In-Reply-To: <cover.1795842371.git.chris@chrisdown.name>

sd_config_write_same() sets max_hw_wzeroes_unmap_sectors when the
zeroing mode requires unmap. However, it does not clear it later. If
the mode changes to one that doesn't unmap, the old value stays, and
the queue still reports that write zeroes will unmap.

blk_validate_limits() also wants max_hw_wzeroes_unmap_sectors to be
either zero or equal to max_write_zeroes_sectors. This means that if
the write zeroes limit changes as well, the whole update is rejected
and none of the new limits are applied.

This can already be triggered from sysfs. On a disk that was in one of
the unmap modes, writing "write" to zeroing_mode and then 0 to
max_write_same_blocks makes that store fail with -EINVAL. From that
point forward, so does the limits update in each revalidate. The next
patch makes the zeroing mode depend on the capacity as well, and then
resizing a disk can trigger it too.

So, let's clear the limit when the mode doesn't unmap.

Fixes: 6dffe079fe36 ("scsi: sd: set max_hw_wzeroes_unmap_sectors if device supports SD_ZERO_*_UNMAP")
Cc: <stable@vger.kernel.org>
Signed-off-by: Chris Down <chris@chrisdown.name>
---
 drivers/scsi/sd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index dc45df819c42..c7018a5de847 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1249,6 +1249,8 @@ out:
 	    sdkp->zeroing_mode == SD_ZERO_WS10_UNMAP)
 		lim->max_hw_wzeroes_unmap_sectors =
 				lim->max_write_zeroes_sectors;
+	else
+		lim->max_hw_wzeroes_unmap_sectors = 0;
 }
 
 static blk_status_t sd_setup_flush_cmnd(struct scsi_cmnd *cmd)
-- 
2.56.1


  reply	other threads:[~2026-11-28  9:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28  9:26 [PATCH v2 0/5] scsi: sd: Fix WRITE SAME(10) data corruption Chris Down
2026-11-28  9:26 ` Chris Down [this message]
2026-11-28  9:26 ` [PATCH v2 2/5] scsi: sd: Fix data corruption in WRITE SAME(10) write zeroes Chris Down
2026-11-28  9:26 ` [PATCH v2 3/5] scsi: sd: Fix data corruption in WRITE SAME(10) discards Chris Down
2026-11-28  9:26 ` [PATCH v2 4/5] scsi: sd: Fix WRITE SAME(10) count truncation when the mode changes Chris Down
2026-11-28  9:26 ` [PATCH v2 5/5] scsi: sd: Fix unsplit discards when the granularity exceeds the limit Chris Down

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=e8d703511f446b850bbdbc0e26ca5e53e6672b4c.1795842371.git.chris@chrisdown.name \
    --to=chris@chrisdown.name \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=hch@lst.de \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=mkp@kernel.org \
    /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

all inboxes | Powered by JetHome®