From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=199.89.1.16 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795920057; b=YKsMxYrYXdH6OciPjOVDzs5idGIZyzmKvSJ0POW3Csl9NNohSv9iO/uZv+yS12CgI6kY ie1M7V3OpHEv99UTv7GxEAxJ++M/G0bUK+baqtU/MK+BX67vSULuGXCv9YLkjlONBf+5c 52++nWw8PD5uSoAa1HVQhIeKDq2n8OtoDbVKQ2Xf7BDkrkxgzE+iqqzIReGcntV3xTagi DUbDcYLVfr/TG9EgXwfsxsQGlEAQJ9vp6OGfAR0fTW8csdZI449DMwib81urP6niceQZW O9lo4V8JJ48ZuzfobKQqKSEbGclVUv8Xv+eGirNXUHbAIQ90tqwbk5rbNlFBLTcDvlQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795920057; h=DMARC-Filter:Received:DKIM-Signature:X-Virus-Scanned:Received: Received:Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc: References:Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=ZCrYtN5mEZLDBPQ9+4kUy/X8jw1qCzBrgTD5jB+Wi8k=; b=F3pkEoDbbe4B6MBlRlQ3oCoqUBcTtv9G4RzOFj4FKqKcSa7HGFvXMEZqO1XKu8Kn6Lew 523BPzK0ON1kX7Djq/9v5x1kcCph+n2bfFc1GixNTXyWHke5UDEicA5GUmjEUiu7r21hB FTRwNmyGCZtf6OYF2WxuzwQqOMM4U6FoBUD1N8id1XmDpbwDYIelUJRgGZapUzxzVzwvx sZwXnas2XXHuvU+6QWnFWpo0QvP1doDy0EMKNZS2Selhb4K7icyomGzGLgb6beZ+s4qPS SDC0KFxhYeJsb8dFFExSYfS2eYKBNidKc+7vrtQzHf3TqFt5is+pVEWgXN3V+68tleg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass header.d=acm.org header.i=@acm.org header.a=rsa-sha256 header.s=mr01 header.b=241NMmSh; arc=none smtp.remote-ip=199.89.1.16 Received: from 013.lax.mailroute.net (013.lax.mailroute.net [199.89.1.16]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91A7E606A31C; Sun, 29 Nov 2026 02:40:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 91A7E606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=acm.org header.i=@acm.org header.a=rsa-sha256 header.s=mr01 header.b=241NMmSh Received: from localhost (localhost [127.0.0.1]) by 013.lax.mailroute.net (Postfix) with ESMTP id 4jcWc80Hp6zlfvq7; Sun, 29 Nov 2026 02:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:content-type:content-type:in-reply-to :from:from:content-language:references:subject:subject :user-agent:mime-version:date:date:message-id:received:received; s=mr01; t=1795920052; x=1798512053; bh=ZCrYtN5mEZLDBPQ9+4kUy/X8 jw1qCzBrgTD5jB+Wi8k=; b=241NMmSh7wcONy4tMXawMYUB4ZiVLKJoc0CTS47i YCcLSW/5nTk9U2f8B5D6i1FPt7B+0cjDtK58MvoclSZ3jt623UbsnX9sqGjw3r7g yVOcOo5D770AWNXO/MVVVmMj1MkG/MffYJTRATj76rwsj4PQfvMt4YNyiB6pH+dD 4Auu/PTBnIItwdGBhV4FU3Dhb3CMvsONXcf1g6NEk9hTiKvdz7e0fve1dujOpRmH daEtT9wfeMB/Hvn73KrYAIx4BCaxEPjbL+pnY6lv3kPdcHS5aFK0wseZXmA1LrnN TNSdmwebLLU11iqN/pE1rNWHVAIDVz2k5ROUT+RQwDdZBw== X-Virus-Scanned: by MailRoute Received: from 013.lax.mailroute.net ([127.0.0.1]) by localhost (013.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id wMNzFXV_75eL; Sun, 29 Nov 2026 02:40:52 +0000 (UTC) Received: from [192.168.51.14] (c-24-6-239-25.hsd1.ca.comcast.net [24.6.239.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 013.lax.mailroute.net (Postfix) with ESMTPSA id 4jcWc35rFczlfvps; Sun, 29 Nov 2026 02:40:51 +0000 (UTC) Message-ID: Date: Sat, 28 Nov 2026 18:40:50 -0800 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 4/5] scsi: sd: Fix WRITE SAME(10) count truncation when the mode changes To: Chris Down , "Martin K. Petersen" , "James E.J. Bottomley" Cc: Christoph Hellwig , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com References: Content-Language: en-US From: Bart Van Assche In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/28/26 1:26 AM, Chris Down wrote: > @@ -603,8 +604,12 @@ provisioning_mode_store(struct device *dev, struct device_attribute *attr, > queue_limits_cancel_update(sdkp->disk->queue); > return -EINVAL; > } > + > + /* Queued discards are sized for the old mode. */ > + memflags = blk_mq_freeze_queue(sdkp->disk->queue); > sd_config_discard(sdkp, &lim, mode); > - err = queue_limits_commit_update_frozen(sdkp->disk->queue, &lim); > + err = queue_limits_commit_update(sdkp->disk->queue, &lim); > + blk_mq_unfreeze_queue(sdkp->disk->queue, memflags); > if (err) > return err; > return count; A few issues with this patch: 1. max_write_same_blocks_store() was missed. It still modifies sdp->no_write_same and sdkp->max_ws_blocks before queue_limits_start_update(), and calls sd_config_write_same() before queue_limits_commit_update_frozen() freezes the queue. 2. Both here and in sd_revalidate_disk(), sd_config_discard() and sd_config_write_same() mutate sdkp->provisioning_mode, sdkp->zeroing_mode, and sdkp->max_ws_blocks before queue_limits_commit_update() validates lim. If queue_limits_commit_update() returns an error, q->limits keeps the old (potentially larger) limits while sdkp has already switched to the new mode. > + /* > + * The WRITE SAME(10) modes can't address all of a disk with more than > + * 2^32 blocks, so don't show a bigger capacity until they are gone. > + */ > + sectors = logical_to_sectors(sdp, sdkp->capacity); > + grown = sectors > get_capacity(disk); > + if (!grown) > + set_capacity_and_notify(disk, sectors); > > - err = queue_limits_commit_update_frozen(sdkp->disk->queue, lim); > + /* > + * Queued requests are sized for the old modes, so only change the > + * modes once the queue is frozen. > + */ > + memflags = blk_mq_freeze_queue(sdkp->disk->queue); > + if (sdkp->media_present) > + sd_config_discard(sdkp, lim, sd_discard_mode(sdkp)); > + sd_config_write_same(sdkp, lim); > + err = queue_limits_commit_update(sdkp->disk->queue, lim); > + blk_mq_unfreeze_queue(sdkp->disk->queue, memflags); > + if (grown) > + set_capacity_and_notify(disk, sectors); > if (err) > goto out; 3. As sashiko-bot also pointed out, in the `grown` path: - `if (err) goto out;` is checked after `set_capacity_and_notify()`, so a failed limits commit still publishes the larger capacity and skips sd_zbc_revalidate_zones(). - queue_limits_commit_update() unlocks q->limits_lock, so `if (grown) set_capacity_and_notify(disk, sectors);` runs unlocked and can race with a concurrent sd_revalidate_disk() (from sd_rescan(), sd_open(), or cache_type_store()) that shrinks the disk back <= 2^32 and re-enables WRITE SAME(10) modes. 4. Updating capacity before freezing on shrink still does not prevent LBAs >= 2^32 from reaching sd_setup_write_same10_cmnd(): - In submit_bio_noacct(), bio_check_eod() runs before blk_throtl_bio() and before bio_queue_enter() in blk_mq_submit_bio(). Freezing the queue only drains bios already past bio_queue_enter(); a bio that already passed bio_check_eod() can enter the queue after unfreeze without re-checking EOD. - Existing partitions are not shrunk by set_capacity_and_notify(), and bio_check_eod() only checks the partition size, not disk->part0. Any discard or write zeroes to a partition extending past 2^32 blocks still wraps its LBA in sd_setup_write_same10_cmnd(). That's another strong reason to also enforce the LBA/count bounds in sd_setup_write_same10_cmnd(). Thanks, Bart.