From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=199.89.1.14 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795920120; b=y5sfkfaX1eXEQx+++iAOaE6blgxEVrV9uFxqlaqJ6uHva3emQ1r4srBXXbnXjpmdBYgY D1MvVAsSMFKK6DkTo720NmPPVcvd2CtHIu0bRzw7etdATjy7J7ug4/xhV+N/j/t2z963P HxUGBH+OH5kDHTfuS3raooLCPqlkO8Gt3Xktp3+pqD86PtKiMkhUmnckUOrUCS+mOCLsj Tnw8WjThrsVMmUN6J/NTx9P7oaLzFO5d/ZTWKVWpjA96n4/PRzWgW/oHbinExN/eDS3b+ Ntq1HnhsWXbdqpMgWV7XM+mN0aBakjBlzmbe6koh2eGWRPcZHbMKNo4psvKIFdnr0Bg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795920120; 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=lG5zcpNu68ql1qLUZv0tLGGsJC617pKGR6fz9X3dDqA=; b=cLGTfyuNhqrcHfCa+emR/scs7IR6HVanv7Dw/UbH8HTtFJZIKxZZEron69VxLNxvkLDj nRJ+tmRdfdwmwGSxqwRGNOQsTy57+Fzd0ppLFWYp7WY6gd/w35kQFGH1mCL8BJ4lGZZc6 e3jNKdDIsckEo16q0d+s6CTBfp1a1Bmt6FTLaVWVVNzazMAqjPMy0Fcm7adCebvKcdHJN gsLJQb2qgrfK6H4f0GEdGNv5cs4aN9VIagMnIf9wa1P9MT3iKYbVOOs0sK/cPcBeq3sZT rfbgQ/XtRpiF5fYYkgOq5hVFqkDEM3X6tkoNtDknk8+JV++R90devdXBB2U9Tn9gKMQ== 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="FU/R4tzf"; arc=none smtp.remote-ip=199.89.1.14 Received: from 011.lax.mailroute.net (011.lax.mailroute.net [199.89.1.14]) (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 C1813606A31C; Sun, 29 Nov 2026 02:41:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C1813606A31C 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=FU/R4tzf Received: from localhost (localhost [127.0.0.1]) by 011.lax.mailroute.net (Postfix) with ESMTP id 4jcWdM1xS8z1XM0p7; Sun, 29 Nov 2026 02:41:59 +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=1795920116; x=1798512117; bh=lG5zcpNu68ql1qLUZv0tLGGs JC617pKGR6fz9X3dDqA=; b=FU/R4tzf7CXA/BVn47GF2T2XfNpIzH9u/iSFf8L/ tAMjUV06BI65QMvvjSQu1oFKH1aLlND1g/9Jg+jdjT9oOF7oxgCGfA2D2fFY00Pb PtkRWzrD7V0gf7mxvgpIzsSdkfrunT36vW56XnGv/EIdWWmW32k3vzz8eLgff+3s 7+QursUlcbUB5sa23mEtZEfS5LQdwqTEYbd602XaPNsB93EEMmVEI2UHi0GIclsC aY4IGDslMvN+Ii8hH1XLJk8Sp4VCpMl7PvPk7jPOH4M9nCZHPk3znynOEyFJ6iOj RzpPb3b1YEb6M+7aAJPsKoSyuqafHjNAMzvUNGZM4nCoXQ== X-Virus-Scanned: by MailRoute Received: from 011.lax.mailroute.net ([127.0.0.1]) by localhost (011.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id jc0_Kuy_kVfn; Sun, 29 Nov 2026 02:41:56 +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 011.lax.mailroute.net (Postfix) with ESMTPSA id 4jcWdH3nHrz1XM6J6; Sun, 29 Nov 2026 02:41:55 +0000 (UTC) Message-ID: <73aefcc3-319d-42a0-afae-7b88ac6594dc@acm.org> Date: Sat, 28 Nov 2026 18:41:54 -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 5/5] scsi: sd: Fix unsplit discards when the granularity exceeds the limit 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: <6e833f169d0c31a3a7da7581c68d4aee5d348ca1.1795842371.git.chris@chrisdown.name> Content-Language: en-US From: Bart Van Assche In-Reply-To: <6e833f169d0c31a3a7da7581c68d4aee5d348ca1.1795842371.git.chris@chrisdown.name> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 11/28/26 1:26 AM, Chris Down wrote: > @@ -206,6 +206,17 @@ static void sd_config_discard(struct scsi_disk *sdkp, struct queue_limits *lim, > > lim->max_hw_discard_sectors = max_blocks * > (logical_block_size >> SECTOR_SHIFT); > + > + /* > + * The block layer doesn't split a discard if the limit is below the > + * granularity, so we'd get discards of any size. > + */ > + if (lim->max_hw_discard_sectors && > + lim->max_hw_discard_sectors < > + lim->discard_granularity >> SECTOR_SHIFT) { > + sdkp->provisioning_mode = SD_LBP_DISABLE; > + lim->max_hw_discard_sectors = 0; > + } > } My concerns about the above changes are as follows: 1. This only checks lim->max_hw_discard_sectors, whereas blk_validate_limits() sets: lim->max_discard_sectors = min(lim->max_hw_discard_sectors, lim->max_user_discard_sectors); and __bio_split_discard() splits against lim->max_discard_sectors. There are still multiple ways to hit `max_discard_sectors < granularity` (or 0) with sdkp->provisioning_mode still set to SD_LBP_WS10 / SD_LBP_ZERO: - If userspace previously lowered discard_max_bytes and a revalidate later raises unmap_granularity above max_user_discard_sectors (but still <= max_hw_discard_sectors), Patch 5 doesn't trigger, max_discard_sectors remains non-zero, and __bio_split_discard() returns every discard unsplit. - SCSI VPD 0xb0 unmap_granularity does not have to be a power of 2, while queue_max_discard_sectors_store() checks alignment with `max_discard_bytes & (discard_granularity - 1)`. For example, with discard_granularity = 0x5000 (40 sectors), writing 0x2000 (16 sectors) passes `0x2000 & 0x4fff == 0`, leaving 0 < max_discard_sectors < granularity and unsplit discards. - Writing 0 to discard_max_bytes while a large discard is in flight or being split leaves sdkp->provisioning_mode unchanged while __bio_split_discard() returns the remaining bio unsplit. Since this is a block-layer invariant (already worked around in mmc and drbd as well), shouldn't blk_validate_limits() and/or __bio_split_discard() handle it centrally? 2. In provisioning_mode_store(), if the user explicitly writes "writesame_10" or "writesame_zero" and this check overrides sdkp->provisioning_mode to SD_LBP_DISABLE, the sysfs store still returns success (`count`) instead of -EINVAL (inconsistent with patch 3). 3. Pre-existing, but right above this hunk, `sdkp->unmap_granularity * logical_block_size` is computed in 32-bit unsigned int from a raw u32 VPD field. A large unmap_granularity (e.g. >= 0x800000 for 512-byte blocks) overflows and wraps lim->discard_granularity to a small value, defeating this check. Thanks, Bart.