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=1796387641; b=uMoJ+uwbU8YyJQLbqe/SxfAUy4i1GCJs1mqjfRrshO2iTCTAczHTljUAHTne856mEjm9 ActJg4Qu0uqcy/iSyNcBmGKl5QOOpXVjK8FM3UbGRrfTzvb4cBTt2j7aebi97Vv4HmVC/ Z9zB6Hl6UKNuTs26VjKjxUefclwnrUYZDkZGKD1Bx7iMSSVXCmtX/PRkbw+otiWtoDmVl vAyJ9jUBY+i1UQa4hoYnZb8RiHl0KHhmm9u/OLGakPri2Ne1tBKbM1Gp8jltGjDjwFyWm 7N7C5VRYSkzzGVzMW98LVS6MMSXmtJTfk0Hg7DVs1/1nt11dUDUmu2kQBymX0S3wbyA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387641; 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=OMa2tUOOR2cRBFVk3KTlHvyndDngzGner3pJmSA4RJw=; b=ReZQEObiH8jgF+RuWP/lWfkmWk/By27B1UXmV6alEszE9r1j3VrkaVRjeDl8+l+LM3ib P8KhT58obvMa4e05aPg87tf8rZb/UgpNLGtoLF6lgx605O6Or1ccRefacMA++3YKqTSgR lPU+PH8u7B5RmvCHjDZSjhsPVOmjM6/mr+8JXpcVsS8FVmWep/rciVrke7087LyMhP5ne KsGRydNuwVOTNCr0jr5jYQUw45l9VHcVT0Qm5ZRlwesEfsrTK79YBSbbFgW509/MVCKYv gx/jrNyk4LBG/HQHxS6uogldFt6A6uOuj9eSeRkkD0MB490wPs5K8H7u6EC6CxahRZw== 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=10K8XAPx; 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 C949D606A330; Fri, 4 Dec 2026 12:34:01 +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=10K8XAPx Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1D891F00931; Fri, 4 Dec 2026 12:34:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387641; bh=OMa2tUOOR2cRBFVk3KTlHvyndDngzGner3pJmSA4RJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=10K8XAPxU4MLzvQ3wvvNvND72Rx1ZhRXiB6tB30LL04JWKtgie9j14KTaFzf+CrMM XC7Yok2jlzBpMtzCweNQ1nROIpH18i2sWX/XYWlSghxaRRjESQXrcPo8hKXciyzehU 6UcJyejQXoLVkxuBfTQRSh4rVa8rHj0soUdRiy9o= 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 0330/1059] scsi: scsi_debug: Do not write a partial physical block to a zoned device Date: Fri, 4 Dec 2026 18:57:41 +0900 Message-ID: <20261204100652.813997132@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: patches@lists.linux.dev 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 b8fad9f02485f179e35bc4677386b6608d8cefb0 ] do_device_access() copies one logical block at a time and stops at the first short copy, so a data-out buffer smaller than the transfer length of the command can leave part of a physical block written. An initiator can arrange that with SG_IO. That is acceptable everywhere but a sequential write required zone, where ZBC-3 r06 (T10/BSR INCITS 579), 4.5.3.3.2, requires a write to end on a physical block boundary. For such a zone, stop at the last whole physical block that the buffer holds. The bytes left over are not written, and are reported to the initiator as part of the residual. Assisted-by: LLM Reviewed-by: Damien Le Moal Signed-off-by: Niklas Cassel Link: https://patch.msgid.link/20260929082456.857423-24-cassel@kernel.org Signed-off-by: Martin K. Petersen (Oracle) Signed-off-by: Sasha Levin --- drivers/scsi/scsi_debug.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c index da43ed8f9b9ad..8ec8c151f4936 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -3032,6 +3032,8 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp, u64 block, rest = 0; 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; if (do_write) { @@ -3047,6 +3049,25 @@ static int do_device_access(struct sdeb_store_info *sip, struct scsi_cmnd *scp, return -1; fsp = sip->storep; + /* + * A write to a sequential write required zone has to end on a physical + * block boundary, so if the data-out buffer does not hold all of the + * data that the command asks for, write up to the last whole physical + * block that it does hold. What is left over is reported as part of + * the 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) + >> ilog2(sdebug_sector_size); + + if (avail < num) + num = round_down(avail, 1U << sdebug_physblk_exp); + } + } + block = do_div(lba, sdebug_store_sectors); if (block + num > sdebug_store_sectors) rest = block + num - sdebug_store_sectors; -- 2.53.0