Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp85737rdb; Wed, 29 Nov 2023 21:39:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IExBE1Du63N2gohg3ZBdgDBOBlUmiuswwksiua/xvx7G7oe6WqVjQXMjEKaBSv2PM+b+yFl X-Received: by 2002:a05:6a20:158e:b0:18b:cdd5:10c1 with SMTP id h14-20020a056a20158e00b0018bcdd510c1mr30972323pzj.26.1701322755787; Wed, 29 Nov 2023 21:39:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701322755; cv=none; d=google.com; s=arc-20160816; b=z2bymMuMumspqJHoeojxOAFjQPopYIDQGgBfxhznkZXzLpWQ/kUhxQoxrA+9e/aDOy J6nyigSUjZZdXrB0o4nG6gaGs577D1tnEum9nf3F/5jhq2qWpJjyX2ta9bvHguHsBN9A WX37SkoWh6XEY81s5RoZnCxYoyTHuUYvZBrOyX9P0iQW3LJ1Elr4KBK34JgjV+p9hFKz 7Epei9xSCwNETojSJXWvfw89TvMm8qp4x464FSGCbruJM9KdAC5PLxTVUuBjXz9yL/xU BDmHk6UiQAVe/vwXGYu4HphmnIzGtgUdfayXfZQp9Jdg6ruBMJtXBFAgf5PXMH9JtAYo Syig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type:user-agent :in-reply-to:mime-version:message-id:subject:cc:to:from:date :dkim-signature:dkim-filter; bh=AwXYEEVHcvV3S/ajD9i4L0qerh5l4o65/EouB/56Wy4=; fh=fb/ewYt++C2l/vHXl5gHJA9HV3n01+XxJZvNUZgBSJU=; b=q/8dcnLGy+3SGRTf2xx1/9MljI88o+764vO3q1r29LB/cTPn3OatFmob3xeE4wA6HE +ZyN6fxQRBtpHtbOz1bZTwSm3wDmQd64cM995n6GlYNM/QmbnxjspX+kQivponBLxoDy a8XQ6fdhZSx4Bg74CuAixr0QBBCZmXT5ICyQkINY/OQieMvAF9uNTVQwVX/MBZ+gSZrn Y2B+zVWLW9w4FyIx7L+pkNL441y4g70aSxYuiADbooQPGX334NbElTbdQc+pNGWMlhyT EkMoZUPYf8wNVGI5p1o2bM3Dk6Atla4DkbXWL0g3Hsn9iIr54uJxBqY5XFYnTs8yA8Ro BJ7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=JXGDMjmM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id k18-20020a056a00135200b0069100706960si519091pfu.116.2023.11.29.21.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 21:39:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=JXGDMjmM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 23BDA803A676; Wed, 29 Nov 2023 21:39:13 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344521AbjK3Fi4 (ORCPT + 99 others); Thu, 30 Nov 2023 00:38:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbjK3Fiz (ORCPT ); Thu, 30 Nov 2023 00:38:55 -0500 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9436193 for ; Wed, 29 Nov 2023 21:39:00 -0800 (PST) Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20231130053858epoutp03d661793524a284caf462e9d6debbddaf~cUARN2uDP1507115071epoutp03g for ; Thu, 30 Nov 2023 05:38:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20231130053858epoutp03d661793524a284caf462e9d6debbddaf~cUARN2uDP1507115071epoutp03g DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1701322738; bh=AwXYEEVHcvV3S/ajD9i4L0qerh5l4o65/EouB/56Wy4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=JXGDMjmM6HLaJDssXGG6PbDSf6QJsNTKokHdFo79bNRKfoxymanzUQrf04rc4HiWi +Iv9wDuk7Tgmg+WxAnhbzwckXd2TjvFwX6TPT68JfEM+rgGqeziAyw28OkM8Vb+8W9 qfbJLb8jRi8zfBNDc5G3qOiCQNeab2p488+4yOcU= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas5p4.samsung.com (KnoxPortal) with ESMTP id 20231130053858epcas5p4a3511e2de128a5435a08d08da6a140d1~cUAQ0hbeh3076230762epcas5p4u; Thu, 30 Nov 2023 05:38:58 +0000 (GMT) Received: from epsmges5p1new.samsung.com (unknown [182.195.38.175]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4SglNw70F2z4x9Q5; Thu, 30 Nov 2023 05:38:56 +0000 (GMT) Received: from epcas5p2.samsung.com ( [182.195.41.40]) by epsmges5p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 02.9C.09634.0FF18656; Thu, 30 Nov 2023 14:38:56 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20231129105501epcas5p415ce4aaa65bd771d074cedaa77ef2c02~cEq75Vat11053110531epcas5p4y; Wed, 29 Nov 2023 10:55:01 +0000 (GMT) Received: from epsmgmcp1.samsung.com (unknown [182.195.42.82]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231129105501epsmtrp27a248fc8c69c60745aa90591add6566b~cEq73L9KV1131511315epsmtrp2E; Wed, 29 Nov 2023 10:55:01 +0000 (GMT) X-AuditID: b6c32a49-159fd700000025a2-6d-65681ff0d19a Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgmcp1.samsung.com (Symantec Messaging Gateway) with SMTP id C5.73.18939.58817656; Wed, 29 Nov 2023 19:55:01 +0900 (KST) Received: from green245 (unknown [107.99.41.245]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231129105459epsmtip216ec737777cda4beaed8df1cf5b31a84~cEq5so4rk2956529565epsmtip22; Wed, 29 Nov 2023 10:54:59 +0000 (GMT) Date: Wed, 29 Nov 2023 16:18:37 +0530 From: Nitesh Shetty To: Dan Carpenter Cc: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , James Smart , Chaitanya Kulkarni , error27@gmail.com, gost.dev@samsung.com, nitheshshetty@gmail.com, linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] nvme: Update type from size_t to u16 for opts->queue_size Message-ID: <20231129104837.arls2gn3wttiqiff@green245> MIME-Version: 1.0 In-Reply-To: <0cd6862e-8037-40b3-9fde-b7f10d66e31c@suswa.mountain> User-Agent: NeoMutt/20171215 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrNJsWRmVeSWpSXmKPExsWy7bCmhu4H+YxUg5ZWM4vVd/vZLD7Ma2W3 eLTMz+LmgZ1MFitXH2Wy2L3wI5PFpEPXGC2eXp3FZHF51xw2i/nLnrJb7HjSyGix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0zXK3Pb1fgy5YrY5pbN+Dvfev9JXQ1mnXvq16NSikKIo51c6cy/G7stkilCzm6bEUpyRaKjF XFScCAAFdA1DHgMAAA== X-CMS-MailID: 20231129105501epcas5p415ce4aaa65bd771d074cedaa77ef2c02 X-Msg-Generator: CA Content-Type: multipart/mixed; boundary="----enUWWt6WoF-Ggb2-rjyEux7skZ5dSWJ5iC_e377tM680ja-K=_1a776_" X-Sendblock-Type: REQ_APPROVE CMS-TYPE: 105P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20231128123622epcas5p4940679fbbafdf0da802deea3e531f850 References: <20231128122958.2235-1-nj.shetty@samsung.com> <0cd6862e-8037-40b3-9fde-b7f10d66e31c@suswa.mountain> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 29 Nov 2023 21:39:13 -0800 (PST) ------enUWWt6WoF-Ggb2-rjyEux7skZ5dSWJ5iC_e377tM680ja-K=_1a776_ Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Disposition: inline On 29/11/23 12:26PM, Dan Carpenter wrote: >On Tue, Nov 28, 2023 at 05:59:56PM +0530, Nitesh Shetty wrote: >> This fixes the smatch warning, "nvme_loop_create_ctrl() warn: >> 'opts->queue_size - 1' 18446744073709551615 can't fit into 65535 >> 'ctrl->ctrl.sqsize'" >> We don't need size_t for queue_size, u16 should serve the purpose, >> as max size is limited to NVMF_DEF_QUEUE_SIZE(1024). >> >> Signed-off-by: Nitesh Shetty > >Huh... I'm sorry I wasn't necessarily aware that I had published this >Smatch warning. I feel like it has a high rate of false positives. > >Generally with Smatch warnings, I'm not going to try silence every >false positive. And I had one complaint recently that I was too focused >on silencing false positives instead of discovering new bugs... > >The other thing about static analysis is that static checker developers >want 0% false positives and kernel developers want 100% false positives. >I'm a kernel developer so in code that I have looked at the rate of >false positives is very close to 100%. Only new code has valid >warnings. > >Here is what this code looks like: > >drivers/nvme/target/loop.c > 573 if (opts->queue_size > ctrl->ctrl.maxcmd) { > 574 /* warn if maxcmd is lower than queue_size */ > 575 dev_warn(ctrl->ctrl.device, > 576 "queue_size %zu > ctrl maxcmd %u, clamping down\n", > 577 opts->queue_size, ctrl->ctrl.maxcmd); > 578 opts->queue_size = ctrl->ctrl.maxcmd; > 579 } > 580 ctrl->ctrl.sqsize = opts->queue_size - 1; > >Smatch thinks that opts->queue_size is a value that comes from the user >in the 16-47 range. But the bug is that Smatch thinks that >ctrl->ctrl.maxcmd is zero. 16 is greater than zero so we do the >opts->queue_size = ctrl->ctrl.maxcmd; assignment. Then zero minus one >is ULONG_MAX so that's a very high number. > >Smatch is just wrong in this case. Let me try figure out what went >wrong. The ctrl->ctrl.maxcmd = 0 comes from: > > ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); > >It's supposed to get set to unknown in nvme_loop_configure_admin_queue(). >The database has the correct data. > >$ smdb.py return_states nvme_loop_configure_admin_queue | grep maxcmd >drivers/nvme/target/loop.c | nvme_loop_configure_admin_queue | 229 | 0| PARAM_SET | 0 | $->ctrl.maxcmd | 0-u16max | >drivers/nvme/target/loop.c | nvme_loop_configure_admin_queue | 231 | s32min-(-1),1-s32max| PARAM_ADD | 0 | $->ctrl.maxcmd | 0-u16max | > >But the issue is that Smatch thinks that nvme_loop_configure_admin_queue() >always fails with -12. The reason for that is because Smatch thinks >that ctrl->ctrl.ops is NULL but the function can only succeed when it's >non-NULL. > >The ctrl->ops assignment happens in nvme_init_ctrl() and it should have >been easy to track. I am not sure what went wrong there. I'll take a >look at that and fix it. Thank you for this insight. I ran smatch on complete kernel using smatch's test_kernel.sh I was unaware of this smbd.py option. I will explore this. Meanwhile I feel this patch is still relevant, as it aligns opts queue_size with size of ctrl queue_size. Regards, Nitesh Shetty ------enUWWt6WoF-Ggb2-rjyEux7skZ5dSWJ5iC_e377tM680ja-K=_1a776_ Content-Type: text/plain; charset="utf-8" ------enUWWt6WoF-Ggb2-rjyEux7skZ5dSWJ5iC_e377tM680ja-K=_1a776_--