From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796387644; b=Hch8Ml9eFDW1Ix7OyE4H7tqJNsLDowuJkCCeJfuGUbzpyiLaNci1pO/lJD3HY++cj7ar FkuzwHsPdv4sY9Y25+KLpWcwooz6FRk7csfDPZaOq60VhhfQ0tkhBChpBA6mdMNQEyzxT KolDaXLF/pCGbYv69vGqhXahfh/yA8ydjjOvBhZushgKiz5iHu3+heGdKmRAz+dbd4wpo 2vGVCUHQAzYOZ++KkZi6nCmNcQbA8F4TsG79Q4XW5p7Ux7Hkb3EPPP8QqPSvVOtiGozFV k0TF/2HUGqfLLWA9WUmThbfPIafKgTJf++R/vcgmoVG2uNo+ptIrWQM+cyIXxRvythg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387644; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=YlTvotLmt7P272vnnhnR8kJsgxpnQ5i3P1Dmtam5sVk=; b=paJ5IjvIKkwPDhKYx3iJRfiPOjHTWP3fZgQjQq6I8DVXqzIhXbXoR7webpnsHJGKwYHg 16OxpHQ3eaBEAKKFz4oXtTIGr1wH5BWuLuPjI6hruviYU49xs5+67z/hRo6pa2kWPDkxu E6nN7zG/6gDDyL7HwjW5K8zft6kDdv5H3MkLdUA4QRQ9CvWECN0K8KYwIvosvYZrPRmpi kfEw1zeVG/3+zQsoU6O3wUHP9dRZdbq9Obp+gOXpAQz7Cgmgq/CBwgsskE35dTM41q1oA YSK2iD2/GaCCeO+13j6WbhoTw+ExOs25uU6qdfItYniMj65Czlhh5AEtJnGrtIzf4lA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=bvkMReqp; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DC0C606A32C; Fri, 4 Dec 2026 12:34:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=bvkMReqp Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E21C1F000C2; Fri, 4 Dec 2026 12:34:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387643; bh=YlTvotLmt7P272vnnhnR8kJsgxpnQ5i3P1Dmtam5sVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bvkMReqp5qMBvG3KM3qdSE4r4+v+0IrOvrrQww/0+gZ7WbYO/m0Bqf0iQdFToeXpc rrkxZepsdNg2NWM+YOzSARbGxwtEM+ojQ5qTnotBZUfOSv8igNMgjvYmMX+hqF/NRr ORf9iXvksZeTDRuUbPiwr/h5LGu1rPO+BFCsHln0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Damien Le Moal , Niklas Cassel , "Martin K. Petersen (Oracle)" , Sasha Levin Subject: [PATCH 6.1 0331/1059] scsi: scsi_debug: Advance the write pointer over the data written Date: Fri, 4 Dec 2026 18:57:42 +0900 Message-ID: <20261204100652.841273643@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Niklas Cassel [ Upstream commit cb2d2a7c80c62d1e5e476609706f29dd9584d0e0 ] resp_write_dt0() and resp_write_scat() advance the write pointer of a sequential write required zone by the transfer length of the command without looking at what do_device_access() returned, which is -1 when the data direction of the command does not match the operation, and a short byte count when the data-out buffer is smaller than the transfer length. An initiator can produce both with SG_IO. The zone then describes more data than is on the medium, and a write at the position where the data really ends is terminated with UNALIGNED WRITE COMMAND, so the zone has to be reset before it can be written to again. Advance the write pointer over the data that was written instead. As do_device_access() does not write a partial physical block to such a zone, that leaves the write pointer where a write can end. Assisted-by: LLM Reviewed-by: Damien Le Moal Fixes: f0d1cf9378bd ("scsi: scsi_debug: Add ZBC zone commands") Signed-off-by: Niklas Cassel Link: https://patch.msgid.link/20260929082456.857423-25-cassel@kernel.org Signed-off-by: Martin K. Petersen (Oracle) [ sashal: adjusted context for the older do_device_access() signature and locking helpers, and the prerequisite partial-physical-block clamp for zoned devices is not included. ] Signed-off-by: Sasha Levin --- drivers/scsi/scsi_debug.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -3720,9 +3720,9 @@ static int resp_write_dt0(struct scsi_cm ret = do_device_access(sip, scp, 0, lba, num, true); if (unlikely(scsi_debug_lbp())) map_region(sip, lba, num); - /* If ZBC zone then bump its write pointer */ - if (sdebug_dev_is_zoned(devip)) - zbc_inc_wp(devip, lba, num); + /* If ZBC zone then bump its write pointer over the data written */ + if (sdebug_dev_is_zoned(devip) && ret > 0) + zbc_inc_wp(devip, lba, ret >> ilog2(sdebug_sector_size)); sdeb_write_unlock(sip); if (unlikely(-1 == ret)) return DID_ERROR << 16; @@ -3882,9 +3882,10 @@ static int resp_write_scat(struct scsi_c ret = do_device_access(sip, scp, min_t(u64, sg_off, scsi_bufflen(scp)), lba, num, true); - /* If ZBC zone then bump its write pointer */ - if (sdebug_dev_is_zoned(devip)) - zbc_inc_wp(devip, lba, num); + /* If ZBC zone then bump its write pointer over the data written */ + if (sdebug_dev_is_zoned(devip) && ret > 0) + zbc_inc_wp(devip, lba, + ret >> ilog2(sdebug_sector_size)); if (unlikely(scsi_debug_lbp())) map_region(sip, lba, num); if (unlikely(-1 == ret)) {