Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Niklas Cassel <cassel@kernel.org>
To: Damien Le Moal <dlemoal@kernel.org>
Cc: "James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
	"Martin K. Petersen" <mkp@kernel.org>,
	linux-scsi@vger.kernel.org, John Garry <john.garry@linux.dev>
Subject: Re: [PATCH v3 2/6] scsi: scsi_debug: Do not write a partial physical block
Date: Thu, 17 Sep 2026 15:47:28 +0200	[thread overview]
Message-ID: <aqvvcEUo1u_6BqJS@ryzen> (raw)
In-Reply-To: <72659c27-3742-4760-8a5f-46d65ccf4012@kernel.org>

On Thu, Sep 17, 2026 at 08:11:39PM +0700, Damien Le Moal wrote:
> > @@ -4290,6 +4290,19 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp,
> >  
> >  	fsp = sip->storep;
> >  
> > +	/*
> > +	 * A data-out buffer that does not hold all of the data that the
> > +	 * command asks for is written up to the last whole physical block
> > +	 * that it does hold, so that a partial physical block is never
> > +	 * written. The bytes that are left over are reported as a residual.
> > +	 */
> > +	if (do_write) {
> > +		u32 avail = (sdb->length - sg_skip) / sdebug_sector_size;
> > +
> > +		if (avail < num)
> > +			num = round_down(avail, 1U << sdebug_physblk_exp);
> 
> Nope, that is not correct. physical sector unaligned writes are OK with regular
> disks. They are not for ZBC, but we should check that in
> check_zbc_access_params() I think.

Patch [4/6] scsi: scsi_debug: Enforce physical block alignment of zonedwrites

does add a check for SWR zones, and for SWR zone only, which errors out if
the write is not aligned to the physical block size.

However, in the case of a short data-out buffer, the request is valid, so I
don't think that check_zbc_access_params() is the right place for the above
check.

But you are right that the check in do_device_access() should be gated on
SWR zones as well...


Something like this:

@@ -4263,6 +4273,8 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp,
        u64 block;
        enum dma_data_direction dir;
        struct scsi_data_buffer *sdb = &scp->sdb;
+       struct scsi_device *sdp = scp->device;
+       struct sdebug_dev_info *devip = (struct sdebug_dev_info *)sdp->hostdata;
        u8 *fsp;
        int i, total = 0;
 
@@ -4290,6 +4302,23 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp,
 
        fsp = sip->storep;
 
+       /*
+        * For SWR zones, a data-out buffer that does not hold all of the data
+        * that the command asks for is written up to the last whole physical
+        * block that it does hold, so that a partial physical block is never
+        * written. The bytes that are left over are reported as a residual.
+        */
+       if (do_write && sdebug_dev_is_zoned(devip)) {
+               struct sdeb_zone_state *zsp = zbc_zone(devip, lba);
+
+               if (zsp->z_type == ZBC_ZTYPE_SWR) {
+                       u32 avail = (sdb->length - sg_skip) / sdebug_sector_size;
+
+                       if (avail < num)
+                               num = round_down(avail, 1U << sdebug_physblk_exp);
+               }
+       }
+
        block = do_div(lba, sdebug_store_sectors);
 
        /* Only allow 1x atomic write or multiple non-atomic writes at any given time */



Kind regards,
Niklas

  reply	other threads:[~2026-09-17 13:47 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17 12:54 [PATCH v3 0/6] scsi: scsi_debug: fix zoned write validation Niklas Cassel
2026-09-17 12:54 ` [PATCH v3 1/6] scsi: scsi_debug: Report the residual of a write Niklas Cassel
2026-09-17 13:04   ` sashiko-bot
2026-09-17 13:06   ` Damien Le Moal
2026-09-17 12:54 ` [PATCH v3 2/6] scsi: scsi_debug: Do not write a partial physical block Niklas Cassel
2026-09-17 13:11   ` Damien Le Moal
2026-09-17 13:47     ` Niklas Cassel [this message]
2026-09-17 12:54 ` [PATCH v3 3/6] scsi: scsi_debug: Advance the write pointer over the data written Niklas Cassel
2026-09-17 13:13   ` Damien Le Moal
2026-09-17 12:54 ` [PATCH v3 4/6] scsi: scsi_debug: Enforce physical block alignment of zoned writes Niklas Cassel
2026-09-17 13:09   ` sashiko-bot
2026-09-17 12:54 ` [PATCH v3 5/6] scsi: scsi_debug: Map the region written by WRITE ATOMIC (16) Niklas Cassel
2026-09-17 13:12   ` sashiko-bot
2026-09-17 14:01     ` Niklas Cassel
2026-09-17 13:14   ` Damien Le Moal
2026-09-17 12:54 ` [PATCH v3 6/6] scsi: scsi_debug: Validate zone access for " Niklas Cassel
2026-09-17 13:15   ` Damien Le Moal
2026-09-17 13:05 ` [PATCH v3 0/6] scsi: scsi_debug: fix zoned write validation Damien Le Moal

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=aqvvcEUo1u_6BqJS@ryzen \
    --to=cassel@kernel.org \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=dlemoal@kernel.org \
    --cc=john.garry@linux.dev \
    --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