From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3882A37D11B for ; Tue, 24 Feb 2026 14:33:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.95.11.211 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771943636; cv=none; b=XL/pI6CkP8ZslS8sMFtRuRjfyXWYNJKjpdXClxwa4NPdp+j1ZJ2ATTQfrMDPp9nlFTk9iFSizbF/X5Ktxov/NjtHMBN+qk/3r4ZPkaDgIlvRh+oF4z1Sx+NFUkE69+DLlweiXj6TnXpOUE+BzYXOFZJbAx9XgQ34vl9m1xHj9TY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771943636; c=relaxed/simple; bh=NLr+AfJBjThWsB514+ULR1czZy1lp4/Zrys3azfuvLk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PzTTybBit8Q5bj/jP2+9nRBfpXfqmU9hxO11o+k+kGnRNCnJ6i5n6oSokvFzQvcDhZi+C8fF3eZc8eXM47yQM3qTdOtc4owOXrYXvk3EZTpzQZyUS5lz/RG52x6lhkzqXuHBVRdH+d2M0DC/YYs5DfwSFk8KU4+9DZ3YN0YIBPA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lst.de; spf=pass smtp.mailfrom=lst.de; arc=none smtp.client-ip=213.95.11.211 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lst.de Received: by verein.lst.de (Postfix, from userid 2407) id 37C0368C7B; Tue, 24 Feb 2026 15:33:51 +0100 (CET) Date: Tue, 24 Feb 2026 15:33:50 +0100 From: Christoph Hellwig To: Caleb Sander Mateos Cc: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Chaitanya Kulkarni , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 5/7] nvme: set discard_granularity from NPDG/NPDA Message-ID: <20260224143350.GC11710@lst.de> References: <20260221033302.1451669-1-csander@purestorage.com> <20260221033302.1451669-6-csander@purestorage.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260221033302.1451669-6-csander@purestorage.com> User-Agent: Mutt/1.5.17 (2007-11-01) On Fri, Feb 20, 2026 at 08:33:00PM -0700, Caleb Sander Mateos wrote: > + if (ctrl->dmrsl && ctrl->dmrsl <= nvme_sect_to_lba(ns->head, UINT_MAX)) > + lim->max_hw_discard_sectors = > + nvme_lba_to_sect(ns->head, ctrl->dmrsl); > + else if (ctrl->oncs & NVME_CTRL_ONCS_DSM) > + lim->max_hw_discard_sectors = UINT_MAX; > + else > + lim->max_hw_discard_sectors = 0; > + > + if (optperf & 0x2 && nvm && nvm->npdgl) > + npdg = le32_to_cpu(nvm->npdgl); > + else if (optperf & 0x1) > + npdg = (u32)le16_to_cpu(id->npdg) + 1; > + if (optperf & 0x2 && nvm && nvm->npdal) > + npda = le32_to_cpu(nvm->npdal); > + else if (optperf) > + npda = (u32)le16_to_cpu(id->npda) + 1; This code looks like black magic. This is mostly a fault of the spec for using the weird matrix with unnamed values and the weird "0based" values. Please add a comment referencing the figure in the spec that this decodes. And maybe also a from0based helper mirroring to0based in nvmet.