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=1796384971; b=fMrEiotGbTaxoiZn9qZhCwf6XkxAUSKuQZrQWJC6VxkNgpD69qAzhJwUfkgxbaqsInvz XhZSESZh1bPQ9+YlDa13GgurwAxzO/vbSuowlQMDkhGGJHa/32/Ua4ebhD4gXJI7HbvG1 6eejqoPNJynPSPnQ8JT0H0Z0uvya7xEXHozla1/qtyQ5zgSqy0fnfb0IusPmMe2PltgJb wlIhPrwVfpEQddgkYkiDSk5ccYSKI+WOCKI+dp7ewLCQ3N6mUDfh0RIvABLBZRQmVb9qu kUdue2B58vSyIIfDuSOPdMBnDqJ+AhxZj6Wot1ioMMO7cw/2ueaUWnnb6Je3QCR/Qzw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384971; 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=AXHCKh23L6XNEP5rTT+Lx9QMP8WE8OoAXHq4XaxmBAY=; b=PN11Ra60FZt/B8+4edelY8xxUTAE+Y4NzIjWmbLpOuQu10txXAU8EwnECPZgBjar+y0r BrQQ3Nd8fXpWcEV340tz6Y+O0BO9Fr2oCoV2UleYk+8W6fvh56Mzs4vELs2uEZAJli6jF bUv36da3E5jLXM48mm2pLaTpHQVCov+6QGIapKvmt3eiMqP9NNQduPNIfBzlkfSBjg/u8 xPTqNn1HOAqSqxAbYTUAmPALeguRirt7LbyeVfJu9e4KG091fo78Z5STk8dRro/Vni5Oz I5kbxw+jePGfB2NG7V9R8wkp0q2bCOCYEpm4Rwk+loMnBe4aDwgA8+SJ+VHlPAPPxFw== 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=TRCjHfxj; 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 6F387606A322; Fri, 4 Dec 2026 11:49:31 +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=TRCjHfxj Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F7531F0092C; Fri, 4 Dec 2026 11:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384971; bh=AXHCKh23L6XNEP5rTT+Lx9QMP8WE8OoAXHq4XaxmBAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TRCjHfxjNeoO5Q9CjCtcAQgYJy4KCL2ztI44tD3R8fvwC8KFp2AGER70Gza7txvft Mar6Bk7oS9BvFPL6yZ6MKrip7pScEDbhFMOAaCibzCo0Se7LDbzyGBYPSJo5DS76aL SjC56qqn9Ijwyx8qHOkgD1XH2BdydluH3Npys4vc= 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 0365/1167] scsi: scsi_debug: Do not write a partial physical block to a zoned device Date: Fri, 4 Dec 2026 18:56:32 +0900 Message-ID: <20261204100711.491582905@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 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 0a7dff23a4e90..3be6f38d473d1 100644 --- a/drivers/scsi/scsi_debug.c +++ b/drivers/scsi/scsi_debug.c @@ -3020,6 +3020,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) { @@ -3035,6 +3037,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