From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.224.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795980324; b=GoNGAry1D84fHgZw3Lvc4TPVSnl7iIZU29XTkxGRI4SA5SZWMkS22o8hszXjVLZ7Rw+x s6fSxjM6eL6eouzQoCwXguwjFKMgk8D0P9jN6vjJ0GLJQmbPTYipQGJ4+h+dvxpDjrkc/ z/D0g6aG5ULuRlQaMOFEH3uWT8FodzjZbga3/Kol1Oj8aLL5cL6c2T+txnq72do0codum jBWeDC2AUOUpnaaeUsg1Ezi1BEmhd775W/kow7Tp5pCadreLDzSw9VqOo0NblcLVqUaQ1 YgmT27nx5NnemGYOdqMN7abEefh/m9KSkcvTOqDMrAoJDCcajOEBFSyikv+pD7I3Pog== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795980324; 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=UM2XTrE5B2jVZsswbStzijyk/0vu5a82DPBZIgJojG1iB145/4HBsgfeGiXkWnFL0RC6 vxu3l4lGpi98cEufdnB13sjaSxtgLc/YhtyhFbEZmcxoeMe0+B1KrOxnosCkWssUZ4Ld1 YWND9oMD1++8gmTEnh2Q9Ob1q877RHwqQMUW40WdEdRAXGW9FM81RxP3l0vkxIyTQ8N9+ LJ4RpTCEkqZEJnKlvfsMieTsIaNlURTFOdYKZo/E5mLynwrt++I0Ru4rCBXjVVRvOpkKf Ihy+RP5+b9B9ieFNmSi4WgJi5DuAwJRRKp6LWc3qw4/VdwmR8G/cDDZyhVIsRGNaHRg== 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.49 Received: from mail-yx1-f49.google.com (mail-yx1-f49.google.com [74.125.224.49]) (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 24356606A325 for ; Sun, 29 Nov 2026 19:25:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 24356606A325 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, unprotected) header.d=chrisdown.name header.i=@chrisdown.name header.a=rsa-sha256 header.s=google header.b=dAbUWs1I Received: by mail-yx1-f49.google.com with SMTP id 956f58d0204a3-67c58f18765so7369140d50.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=soVP9tBl/CV507RPSY5cHr4h6/345Yy0G6Av61+wUQs0AYHx58P/d+gATBa2Ba3bBO xDhKNqs7vNoiY3kTgChcI32LcD0dBnk/nuLNbRHO7Mt5kMwbripi0pXsKBPL3WEZ1uY6 WL4MMBeqErJm3myLL3fWjpnpz3guE3izGK/xTuswrPyMnUSkPaFb6Ue2wY8TLQWB0/JW Bv8gvtCqfLslQK1IwgD2oIZDEUnd1TZ/Z5Iy+fu0sj57UtfKo/zrocT8r+WPab5FMwsy WfODph2n7e3J+/uiJ13IpRjuPQYc9NKzvlms5Y1EUvn7HIg51DiROdNsh5irbjvARkaD pXqQ== X-Forwarded-Encrypted: i=1; AL+hErGMn3kHnHEFX5wUCBp1aqq9SBXdoC3p7i8FEs5dDj4XDzIJWKbpFt7by0UNAybP92zf4D4Frt+cLrprxfk=@vger.kernel.org X-Gm-Message-State: APuU4Z8NOZOUXraxmIFQ1186W05/9CZN+/xxsXm59y6/vpNmEtq5Jqvz h8SrgippoeUTqm0m8vOwMn1iy7XRgqrmB+owBTK7xuQUp6KJZmxzUltdlnBBANLIsIc= X-Gm-Gg: AZFdTZdXbC8lIMyMTM6gB4wD5LXSBNhDiXscqz7d0jBkSO0YuGrxwhaQDaaLse+OcPq /7meduIoY9zPdaZQJcgfLyA45b/uOxAWiGd3tkyAaBmE2BA9e+tbcvBemQ1q+CUc/uKZ5hh+fjF MIJx+2kTt4oTaU/6JmnKpGV9JQktFrbRxVFynTe1Xb9DXII2CNx2sArXFquXwkEqFBtvoMdhpA6 N2COR38ksMtyrZsOT5uBf5sxbuYSBbyk7pQTs4Xq4sIttCisFo9YmQQhJErPGxQAC8KJUQK6C6P IFfbtqjvLFxz6F52Pm+wzHvcsvXLBqN14nyt9ePWkJam7zmUxkNJ71I/cNVx5I1/cszYA9mAkpl kXT+mWvGpQaTP1RZxbzeuM831QXq6g7SQacXdsIQJaib9TD9y4WFMNisjedknqs7TkbAzD756sB 8rEXccemUpGlWwrQzJ7qJpLM5veWGGM9utnpUKDYHBf9bmfa1voBzHsXl4CE5gDaEvzGBTwAJyW qr6ew3Wa7PZ7rzkPsLBLHj9AYj2yc6dEMkwvokoK240zq0NuIb3+ITVh5WpZzyB+MN1Y8B4iqQR gVC3aio1eHtK0QoETbJptZqYbNX8xXlKdKr/IS0LtpNA7SVvvxxvjL5jN1mukh/8VaBxgwFSEtm i+WlGIcIHyOO16EqMA1/ZRvir0+HDKmzl+Joskh5ApobiNX6anpkYwpLG1WJyBH6szcTaPLlWWg 94D4K+AV6bPCyZccoi3MRAdADfqkGAOCSnnfU7ah2ZoGzAz1Frt3Uxcz1W34zdSAbTX0G+jZXJu tZ1fJFlXbzktOswU72XpX2+v5nqyWkz2Lx2OQWFWTHpUg== 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-kernel@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