From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795980325; b=2OQG9iWV3sUybF7jIeJnA43qNy29ZpzAZFpnj8TY+3nhx9i6qBtgF3y/n0ue9v+BRWtV je27DpOw+mTh9e0kPkwr9ZTNLhl5oGaW3IKYtVCVk2q3lFNc/ob1uPPe/UnQnnA6KsQE5 bS2QjumoH0UEclFrpjeImfGpSMHrZmLcM1JQr+ZsHyosZ+yixzzlxdDsP1N/udafQUrdE y0O/IzmLTzqeQjAur1k4sKTjNcVAn9pFbVkx0P+RUaGvGNvQXgBxgEA0/fvMVZw9cOCM0 khv3FbAVSbb1OVleVJ12lGsN3kylOjOb56yCmC/Pwhk5NlljDfgSqIHwdq4RS1F7QOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795980325; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:Message-ID:From:Subject:To:Cc:MIME-Version:Content-Type: Content-Disposition:User-Agent; bh=biiiVRE6psh29x5puEuPkw1Vyqz3K11tE/bwxrpFlpc=; b=sXfuQs8iq047pRy3XXDH3pbWMP060sFraRndS4I9YaUa2JIzGZVL9/7TLNPVagPCJ2UT eHHL3/MQIMFf6VoP+oKh9qQNrZXhpO13yosFqxtPQI7hIpf/F2xH+ecEqI42NjwQm+9RY NNK/zJkpOEmE3S8WLIY6GQntktjoOHPLSDGRCe7CwAKnt/dugTV+BBftIN/yyNJMukoxc YdyZXERobTV960/gF0V9E/lEHLZCeWeuxlLyLfWZ/XCnFn1CDpLBwzjTs3lXftDesrddX ZYN5YqgCmHuJ0CYbSMJ9G5FKAIoEcQDNazI+KMY8e352WIgcw+aIHae7Xi2VMQft5GQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=chrisdown.name; spf=pass smtp.mailfrom=chrisdown.name; dkim=pass header.d=chrisdown.name header.i=@chrisdown.name header.a=rsa-sha256 header.s=google header.b=dAbUWs1I; arc=none smtp.remote-ip=74.125.224.48 Received: from mail-yx1-f48.google.com (mail-yx1-f48.google.com [74.125.224.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31A0B606A327 for ; Sun, 29 Nov 2026 19:25:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 31A0B606A327 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chrisdown.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chrisdown.name header.i=@chrisdown.name header.a=rsa-sha256 header.s=google header.b=dAbUWs1I Received: by mail-yx1-f48.google.com with SMTP id 956f58d0204a3-67c58f18765so7369141d50.1 for ; Sun, 29 Nov 2026 11:25:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chrisdown.name; s=google; t=1795980323; x=1796585123; darn=vger.kernel.org; h=user-agent:content-disposition:content-type:mime-version:cc:to :subject:from:message-id:date:from:to:cc:subject:date:message-id :reply-to:content-type; bh=biiiVRE6psh29x5puEuPkw1Vyqz3K11tE/bwxrpFlpc=; b=dAbUWs1Ivn66zv63Qk/LkkWHIx7xMtkct+aRYF+pgkKq+weyufaZfWxc+kIp+ryBM3 /XJC0SQJ41AkEN2R+o9m1iy0gDEC6guneOFBzKvsfXOZHu7mCUZwumW6S0cO4WcaN/6U TvUpQKM6I7KQOeWROLn/+u3ECfLjVQwO3YmKA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795980323; x=1796585123; h=user-agent:content-disposition:content-type:mime-version:cc:to :subject:from:message-id:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=biiiVRE6psh29x5puEuPkw1Vyqz3K11tE/bwxrpFlpc=; b=hukrnHiGXVvAMJdFRf3V5Qqx3px1EOZTcrCgBVzmXFeoMQeX19akBn2LVuVyOZt2+e zk5ctvKGiRpnk7k0YJGFn2hJk03xrSt3GlVVAfAANc2fg/CVv8nHKOowm2V8O4v6cVBB Dr5gH80prJuIFFAzQ6fwN6wOf8Wr33bHHpoJy71doOL0haAu3UJsItZ4eLGjOrnXho+7 DmtR29+LVPzSjfN91M+HnB2kNCmkfnz/2/QoEb9S6JNcOFLg1v6z08l40ih3jnTs5WZ9 /FyUDXI524r/gnrL0mav0d5BxiKjb/C/cMLbTu+HiBii09XfjLlYxBER/GnuV3N6fvDF FTHg== X-Forwarded-Encrypted: i=1; AL+hErHR/jGk/UglIr1clS4ey0MbHkcp9r/el1GIe8/Kw/4hlsrCpGW+v/F6luLCehXu0g/fcz6MskP3vf44@vger.kernel.org X-Gm-Message-State: APuU4Z8EjN+/Td7mydwrG+A5GpFo0WHa/LdvulvW3bvGnhV+zl5zqmT4 tW7c7CAyMkQnoQymk5AjyhVgJwWDOdOxQ4stbc2YEh+qw58/e3oSuWiUHHRfvFFtvOx5alDKNt5 9YbjzgQUv/9JgOnxSmw== X-Gm-Gg: AZFdTZeVKOpi5hpHWHzh3Xs0GqpJzpee3uNJoGfAnx/C2cOoFxvjh7quF23cChmc4i1 7hAM1VWaxfjvtdu+LeOBSYeH/fjQiJqP0WEUIiwhlIEuZtYtG0g5oOkctTsSAbiSEj2iD3s5Zf3 VhrBNPyFuopyImSXT7prFWYz5myG9nxUVtmkLxq+ESu7Cip5DsmSuKjmZ9/FhT1NNPIZKNIWxNZ MnfqCiUWhRoF00dSyc0+4bI6HNdDQtM30G0+B5QGwjGpDn6+uhpHysnMO2n4XUl6nhDVw1slELG Efwifwyt5/tG+ramGuEPdSgCSoIaEWRJ+3esAYK+iKBo84C71IXhkI2JxgSVAFVf+WOC3y/1V5+ RJte2wNeJUZLe6DFQSwW6dr+EsfAwswQg0oNsbgKio7M5Nky3nLB2h/8dRV5/IaK6KhuoIEDCyu VEvaksXTqqYjYOvs3UJRaNGV+rpokUHKwtlI1/aXtUv9bl9bMboO5khfyoDc5Ms/yvW3p3Y9wmw rZ48oBldTDtmk91Zk4rATU5KnvHJdeobYPr0wZI+4FyveDyXhZ09jVuSjdersU2z5xsZADUSbVp 7p7X7ja7dyw/h6n+mj29VO5CjEGBytJ/zjhgFNI2DWZrgLaVO4K+kLlNdiIa6ouxHci1L6NlSOL zUvrxFEH2TyI7jpit9KVzrNpWGX9iTaM9E7tvFMCPAC9smRBohcvfH61QjIreQ9KVgvFeT8wD2h jYcf996vfWvVGaWzUYyUcc6tfADRd2YmVDEyFJHnH/9fJW/hartUUK0fR1F++3eUzcAQNvPefFV o0zOsXEZhKu5o2hBwncSKxiALw+B+8D3CNJ4IW/fAwZwg== X-Received: by 2002:a05:690e:c8:b0:67c:23f2:4262 with SMTP id 956f58d0204a3-67df44bcccemr6693565d50.82.1795980323116; Sun, 29 Nov 2026 11:25:23 -0800 (PST) Received: from [172.20.0.2] (c-73-207-185-9.hsd1.ga.comcast.net. [73.207.185.9]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-67e7c416511sm2272433d50.6.2026.11.29.11.25.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Nov 2026 11:25:22 -0800 (PST) Date: Sun, 29 Nov 2026 11:25:21 -0800 Message-ID: From: Chris Down Subject: [PATCH v3 0/5] scsi: sd: Fix WRITE SAME(10) data corruption To: "Martin K. Petersen" , "James E.J. Bottomley" Cc: Christoph Hellwig , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, sashiko-bot@kernel.org, Bart Van Assche X-Mailing-List: linux-scsi@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/2.4.3 (cc9e3943) (2026-10-09) With scsi_debug and 512-byte logical blocks, a 1 MiB discard at 2 TiB succeeds, but it's the first MiB of the disk that gets discarded. This happens because the starting LBA wraps to zero, because it doesn't fit in WRITE SAME(10). Write zeroes can also run out of bits for the block count. With a 0x20000-block WRITE SAME limit, a 64 MiB hole punch sends a count of zero and leaves the whole range as it was. scsi_debug doesn't unmap anything when the count is zero, but in SBC it is intended to imply that every block from the LBA to the end of the disk should be unmapped unless the device sets WSNZ. Let's only use the WRITE SAME(10) modes when a 32-bit LBA can address the whole disk, and keep the queue limits and the modes in step so that requests fit in the count. A request that still doesn't fit is failed instead of being truncated. v3: - Update the unmap write zeroes limit in zeroing_mode_store(), and check and change the mode there under the limits lock with the queue frozen (Bart) - Change max_write_same_blocks with the queue frozen as well (Bart) - Set a grown capacity under the limits lock, so that a revalidate running at the same time can't leave the disk bigger than its modes can address (Sashiko, Bart) - Fail requests that don't fit in WRITE SAME(10) in sd_setup_write_same10_cmnd(), for the ones that the modes and the limits can't stop (Bart) - Drop the patch that disabled discard when the granularity is above the discard limit. That belongs in the block layer, and the new check stops the truncation in the meantime (Bart) - Check the gendisk capacity as well in sd_can_use_ws10(), since sdkp->capacity is zero while a removable disk has no medium (Bart) - Use U32_MAX in sd_can_use_ws10(), and fix the comment about the capacity in provisioning_mode_store() (Bart) v2: - Don't select or accept the WRITE SAME(10) modes when a 32-bit LBA can't address the whole disk, instead of checking each request (Christoph) - Clear max_hw_wzeroes_unmap_sectors when the zeroing mode doesn't unmap, since the zeroing mode can now change on a resize - Change the modes with the queue frozen, so that queued requests are not sent in a mode they were not sized for - Disable discard when the granularity is above the discard limit, since the block layer doesn't split discards in that case v2: https://lore.kernel.org/r/cover.1795842371.git.chris@chrisdown.name v1: https://lore.kernel.org/r/cover.1794069087.git.chris@chrisdown.name Chris Down (5): scsi: sd: Fix stale max_hw_wzeroes_unmap_sectors after a mode change scsi: sd: Fix data corruption in WRITE SAME(10) write zeroes scsi: sd: Fix data corruption in WRITE SAME(10) discards scsi: sd: Fix WRITE SAME(10) count truncation when the mode changes scsi: sd: Fix truncation of WRITE SAME(10) requests that don't fit drivers/scsi/sd.c | 124 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 106 insertions(+), 18 deletions(-) base-commit: efd68f17acca65f581b9f2fa9ba50c8643ab544d -- 2.56.1