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=1796384974; b=Kuj0mSm+f5gHof6qV5qPzG08a82K7c8xmHMA9LCWzf5jfqZfhwrpmYIDshNw47LeYLu7 TxaKLEPNPyLQ+20fa0sq0P0fr9OGDwJ8NextakiZQDsHtiSwl2AWCs2I6ITJsKVex4Xyd 0LNUuIJeEjiwxuPETEltErHW0oKH40c0IRNe08Pxus8fBf+AmqIs21VNOqINLP67e1SaA Qp/37ZXo+816Kn+b3On3h0avYGXc1aWr8acbxsokQvjOQTHIx+G3J6hxer2CigOyAv9tI Rfzk57f/+MPFOePeYKOozuS2+MiAwDi9RJZQUDu8c0iGlVmUANv8RYYQhnpGLwz6KAg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384974; 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=hImfhRx9Fd+gyokj6DB76OC3zNSn9E5PnbsQJpt7Dzs=; b=IMfI6mz06JM8jgObjdoqe6OI+4S52PeCDRConlr3QDPdSVJvvY79uh7SjkUVXpXZGOYc myWzZo3kEG8zv8a6/EGY/cEs/geBAgkiHR+JlvZ5YM/dL/dewIm2PyAZBzxg6E7opPxNz kIhrdaGw7drOPZCc5Y3uQvivxBkyQSdf8XdE4hZQFs5kmuwekoQmC8UAvDvowuQvaO1j6 EMHoITQ8O1pJZ3TYnPYnDw4ICIw92TdESqaWoZkEASTCmE0Oyi2vN3qphZFR36wej9w4V pJgdrXCxvw1ChS7xv45XvNP8RUyqnTkBAnI4Ul/EriRXZA2EtJthf1LS68cB7vGKS+Q== 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=iF4HTMAZ; 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 38A4D606A68D; Fri, 4 Dec 2026 11:49:34 +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=iF4HTMAZ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 730EF1F00934; Fri, 4 Dec 2026 11:49:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384973; bh=hImfhRx9Fd+gyokj6DB76OC3zNSn9E5PnbsQJpt7Dzs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=iF4HTMAZ1pjTWj4NeaBZGU/kp72LMyfBhAoh34wJPHZPNWYFtjLzQUG1D//TUqEgP gq4Wjbblt4trtT8NXFF1Ws6IdWLO4aRmEklCw+7xl5jzbDMQ4TiRKEDjpg9j6aOzlP ZNiAU5SBY19KXZTWKvXIFsYR+Jv81X2qpkuqYIIc= 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.6 0366/1167] scsi: scsi_debug: Advance the write pointer over the data written Date: Fri, 4 Dec 2026 18:56:33 +0900 Message-ID: <20261204100711.517701305@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@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.6-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: Context lines adapted to the older tree (scsi_debug_lbp(), sdeb_write_unlock(sip), and no group/atomic arguments in do_device_access()); the changed lines match upstream. ] 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 @@ -3708,9 +3708,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; @@ -3870,9 +3870,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)) {