From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 746DA606A322 for ; Fri, 4 Dec 2026 06:57:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Xet6BzI1; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=F0mi49oz DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Date: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Cc:To:Subject: From:Message-ID:MIME-Version:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=OqG2r7XF7XcUbUL19MQ5hcoW3s/cyaSRfmHcOYOqw00=; b=Xet6BzI1xt/ZbegQKCcNPiwxL4 vC24zKoh3Cy10UW8txNZIXr8/zgU4Mmt+a7uHZneLaiZdEqXxZLFOrmYoRqq1e9DdgFhc3Bk2bgh4 ZafephWw4QZzYk4ablBMDppW5sv6X4XUGA2b9iKtn5hW6d9wBIxDfZudy7Dt6K4hecwokYZhafYAV i1hUB7dr61hXFy7t9O3FiqANAK5lLlt7KEwP+MQJgVUOzTN9QnG9wT/vIGZemHlYdY/hQwDeuXOIX FF87yw5sKtFr+i4FoqgJrjCAvxOcjKqGdEFU4nbORu87hFCB5uKxYlMtmUXUEp2crjX71raqeKVyU 7ruQmgeQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZNEO-0000000GrLC-2Dvg; Fri, 04 Dec 2026 06:57:20 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZNE9-0000000GrIj-0cly for linux-nvme@lists.infradead.org; Fri, 04 Dec 2026 06:57:05 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 86B85438D8; Fri, 4 Dec 2026 06:57:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 581851F000CE; Fri, 4 Dec 2026 06:57:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796367424; bh=OqG2r7XF7XcUbUL19MQ5hcoW3s/cyaSRfmHcOYOqw00=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=F0mi49ozjBE0TLASdewygxpYP9j/+OvP4B1hgbb/0XXTTOTzKOb3yU7xdoP6taX7s gPtSFR3TqNezJ9ufgWLK7ba6hYiz1ZjesAU8o6SEgq1kM1H7oIc3YAA7mzJZ/dagv3 7y4Lf0qQKAGvd43Gq3hPTVN5qM5k7Sl4coi3CwjVFlxWusUsl1nGQq0E4xKTuShBFH HV3d9MtPpv+zCDuMjhBnTMwEftbYgWDq9LpSt2hPTakUNbzkxd1bAb66dmmteVLGYi DE9WdMaWkDkok1aJyKmX0Z/eEVPtbyEH3jisfNoBOBtnC84+Lu+cXreXUiiRjo5O29 YC9/0TBglyeDQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] nvme: round physical block size down to a power of two To: "Li Youhong" Cc: linux-nvme@lists.infradead.org In-Reply-To: <20261204063559.1044548-1-dayou5941@163.com> References: <20261204063559.1044548-1-dayou5941@163.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 06:57:03 +0000 X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "Linux-nvme" X-Spam-Status: No, score=-11.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] nvme: rounddown_pow_of_two(0) UB on u32 overflow in nvme_update_disk_info() - [Medium] nvme: nvme_update_disk_info() rounds physical_block_size to non-divisor -- commit 206ca12cfb02e4dd20fd71b056be00d31099fd6f Author: Li Youhong nvme: round physical block size down to a power of two This commit rounds lim->physical_block_size down to the nearest power of two in nvme_update_disk_info() when the value derived from NPWG and the atomic write unit is not already a power of two. > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c > index f43582e5f6c4a..6b505971a02bd 100644 > --- a/drivers/nvme/host/core.c > +++ b/drivers/nvme/host/core.c > @@ -2137,6 +2137,14 @@ static bool nvme_update_disk_info(struct nvme_ns *= ns, struct nvme_id_ns *id, > */ > lim->logical_block_size =3D bs; > lim->physical_block_size =3D min(phys_bs, atomic_bs); > + /* > + * NPWG is only a preferred write granularity and need not yield a > + * power-of-two size (e.g. LBA=3D512, NPWG=3D2 -> 1536). The block layer > + * requires physical_block_size to be a power of two. > + */ > + if (!is_power_of_2(lim->physical_block_size)) > + lim->physical_block_size =3D > + rounddown_pow_of_two(lim->physical_block_size); [Severity: Medium] Can lim->physical_block_size be 0 here and invoke undefined behavior in rounddown_pow_of_two(0)? With CONFIG_TRANSPARENT_HUGEPAGE, blk_validate_block_size() accepts bs up to SZ_64K. If optperf is set and id->npwg is 0xffff, the u32 multiplication bs * (1 + le16_to_cpu(id->npwg)) overflows to 0. Because is_power_of_2(0) is false, this calls rounddown_pow_of_two(0) (1UL << (fls_long(0) - 1)), tripping CONFIG_UBSAN_SHIFT checks where blk_validate_limits() previously clamped 0 to lim->logical_block_size. Using check_mul_overflow() for phys_bs, as already done for discard_granularity in this function, and checking for non-zero before rounding would avoid the undefined shift. > lim->io_min =3D phys_bs; > lim->io_opt =3D io_opt; [Severity: Medium] Does rounddown_pow_of_two() guarantee that physical_block_size does not divide io_min whenever phys_bs is not a power of two? For any non-power-of-two phys_bs <=3D atomic_bs (such as 1536), rounding down yields a power of two p with p < phys_bs < 2 * p (1024), so io_min is never a multiple of physical_block_size. With NVMe multipath, nvme_update_ns_info() -> queue_limits_stack_bdev() -> blk_stack_limits() then overwrites io_min with physical_block_size, defeating NPWG advertisement, and sets BLK_FLAG_MISALIGNED so alignment_offset reports -1 on a healthy namespace. Even on single-path disks, blk_validate_limits() rounds lim->io_opt down to a multiple of lim->physical_block_size, truncating NOWS values that are multiples of NPWG (e.g. 1536 to 1024, below io_min). Using the largest power-of-two divisor of phys_bs capped by the atomic write limit (e.g. min(phys_bs & -phys_bs, rounddown_pow_of_two(atomic_bs))) would give a power-of-two physical_block_size that divides io_min without false misalignment. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204063559.1044= 548-1-dayou5941@163.com?part=3D1