Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1874419pxb; Sat, 2 Apr 2022 06:44:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhj0G6t48Mw6V0prLD4t9xUvpvc9zRRBm6wmgpNE3iBjdWzsQ8IXfY5id6L+avYJA3F1rV X-Received: by 2002:a63:770c:0:b0:386:361f:ecce with SMTP id s12-20020a63770c000000b00386361feccemr18943042pgc.202.1648907077032; Sat, 02 Apr 2022 06:44:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648907077; cv=none; d=google.com; s=arc-20160816; b=T5k8n9WyyCFKAvwN9xLO/RP9sITe675cxNRDujmKDAZyDdu7Nwd/TBmhUktgk+muWc BNYXCIatphGyzzMJyWEqAlOB1lYwWuS2vwWfMlJwDGcSUH6q5Cu4LZBYXBcLsVoGtIng UX8XZlDTkwvVk6IcwEO1jWovXH9+mmHMYpaTGXkDGL6sJNrrkVB/Bhxw7G+GuUFbB7hq 8UX8hxhKON3f+2Vq6d2RZwL/hd158SB1ZYVP3uanyYStK1EUft08wniCe5n/SXeAW2gT QTxpFWwSwqwelC2U6O9+dJgTwQFo7D7STHfSURE5NafHiuqkSC+2RqYm8UJNt0c0H7BE x9Ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=topTsn3BbDfEubVD1cikcVfyc0RXu7k2rZg0bc7HcHo=; b=PTAm//pZgY9SVFGobjk3zEfUkGcg/aPLJdYy46BgjdjhgFfKCLwFhIa77oF1SXZa2C gIjndWVn2LIOJ64ZH7fKVliAyp4QS9+d2STvlyd1y1bMWHEb056IFA/d1S7yo4PNcrix E93XevMOPC8wS0UB1LDydBODwOo2dO+F/597b4HQOvnioD3+JCjYcEwCER2WPcKqDh6z Rmhi6b3beDSimK9ssCiNwB3V7FYihcIcw6z7qBx/3hYdVndOS8Jt7X6/lxwbgKuzvWGM jVnWX4qWZ/mRiuhewav6rOMI6j0r0AHsY+AOIamnrikA1SH6LmS7XiGdhhfW+6KG0lNj Uy9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=kvy8iUb1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o22-20020a637e56000000b003862e2ae4f3si4928926pgn.352.2022.04.02.06.44.22; Sat, 02 Apr 2022 06:44:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=kvy8iUb1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239512AbiDAAVO (ORCPT + 99 others); Thu, 31 Mar 2022 20:21:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243400AbiDAAVC (ORCPT ); Thu, 31 Mar 2022 20:21:02 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4FA5336E2F for ; Thu, 31 Mar 2022 17:19:12 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id l7-20020a05600c1d0700b0038c99618859so2587324wms.2 for ; Thu, 31 Mar 2022 17:19:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=topTsn3BbDfEubVD1cikcVfyc0RXu7k2rZg0bc7HcHo=; b=kvy8iUb1fFHIuiK+XjgqcekL+X6UMxEzYpsrUiZ8Stm1VLlUJIAam6VAhMQAdmAbk6 bsSEg1aUauNnoglAjYIxKaP44MwOs+4OT4XmY7G2oqXPdj84UhOfYQ5Y08GbxveQbkvz 4A6Jy7qjdcj50NkLOrU34POwuYAJMBy0IPJa6ro2Gy1LkwjtLESG305tN64Rn9BcXZM1 amKusHf8M9dHjLnKptYtkvVO3FjH0xMZxBOuCDyPsHJK+2wK/wHwWIPCBVXdEMCTyWXt ysi8ByznGhqNnsBdZySNf279wyWen3egCdQgHfElynmekbwZNfLEP9ZqBYZXFpS4AmDy xuTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=topTsn3BbDfEubVD1cikcVfyc0RXu7k2rZg0bc7HcHo=; b=e1bD7ZlVTRjMEDfYWdBuy9JPxnx/y0J9Mjd7TjGo6wKqKBLIBsGDOAJ6oZl9yesR+B DkHikcE1PzGtk/NC96sIg66lMxHti0GdhR4d9fwa2EqvI7qbT+flrtaOeDnT4xW3xa6w 5tmqj9azjb9l8R5dA4kiScr/6QkbhsQOfBUZ9HUSnxlOt3rPL3nZioEDDc8PFYwm3HAr uGFxVa2HuTFuG0DSAtLhDQiYytAB4WawUc1bb8gWAgwj61D99o5EVX7p4dqsGRL0CE7H wl2YRSv2XXP4mmnOMdbGjRvwrXuy/lXHkWmZQQcEFxPpX5GXQKhU6jo3OEnKmtUxEBZs 23qw== X-Gm-Message-State: AOAM532mXnM+0EGRVLK+LqN/MkZgJylpyYcrX8GiEj3d4QeSuUVMB15g 3f0ZcuMi7FgelpqM95sBSgbI4xCVNtxq6ncCXRAINQ== X-Received: by 2002:a05:600c:6004:b0:38c:6c00:4316 with SMTP id az4-20020a05600c600400b0038c6c004316mr6700826wmb.6.1648772350645; Thu, 31 Mar 2022 17:19:10 -0700 (PDT) MIME-Version: 1.0 References: <11f4750c6d4c175994dfd36d1ff385f68f61bd02.1648593132.git.marcelo.schmitt1@gmail.com> In-Reply-To: From: David Gow Date: Fri, 1 Apr 2022 08:18:59 +0800 Message-ID: Subject: Re: [PATCH v2 2/2] Documentation: dev-tools: Enhance static analysis section with discussion To: Marcelo Schmitt Cc: Jonathan Corbet , Mauro Carvalho Chehab , Daniel Latypov , "open list:DOCUMENTATION" , linux-sparse@vger.kernel.org, cocci@inria.fr, smatch@vger.kernel.org, Linux Kernel Mailing List , Shuah Khan , Dan Carpenter , julia.lawall@inria.fr Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 31, 2022 at 3:30 AM Marcelo Schmitt wrote: > > On 03/30, David Gow wrote: > > On Wed, Mar 30, 2022 at 7:23 AM Marcelo Schmitt > > wrote: > > > > > > Enhance the static analysis tools section with a discussion on when to > > > use each of them. > > > > > > This was mainly taken from Dan Carpenter and Julia Lawall's comments on > > > the previous documentation patch for static analysis tools. > > > > > > Lore: https://lore.kernel.org/linux-doc/20220329090911.GX3293@kadam/T/#mb97770c8e938095aadc3ee08f4ac7fe32ae386e6 > > > > > > Signed-off-by: Marcelo Schmitt > > > Cc: Dan Carpenter > > > Cc: Julia Lawall > > > --- > > > > Thanks: this sort of "when to use which tool" information is really > > what the testing guide page needs. > > > > I'm not familiar enough with these tools that I can really review the > > details properly, but nothing stands out as obviously wrong to me. > > I've made a few comments below regardless, but feel free to ignore > > them if they're not quite right. > > > > Acked-by: David Gow > > > > Cheers, > > -- David > > > > > Documentation/dev-tools/testing-overview.rst | 33 ++++++++++++++++++++ > > > 1 file changed, 33 insertions(+) > > > > > > diff --git a/Documentation/dev-tools/testing-overview.rst b/Documentation/dev-tools/testing-overview.rst > > > index b5e02dd3fd94..91e479045d3a 100644 > > > --- a/Documentation/dev-tools/testing-overview.rst > > > +++ b/Documentation/dev-tools/testing-overview.rst > > > @@ -146,3 +146,36 @@ Documentation/dev-tools/coccinelle.rst documentation page for details. > > > > > > Beware, though, that static analysis tools suffer from **false positives**. > > > Errors and warns need to be evaluated carefully before attempting to fix them. > > > + > > > +When to use Sparse and Smatch > > > +----------------------------- > > > + > > > +Sparse is useful for type checking, detecting places that use ``__user`` > > > +pointers improperly, or finding endianness bugs. Sparse runs much faster than > > > +Smatch. > > > > Given that the __user pointer and endianness stuff is found as a > > result of Sparse's type checking support, would rewording this as > > "Sparse does type checking, such as [detecting places...]" or similar > > be more clear? > > Myabe. I tried changing it a little while adding a bit of information from > https://lwn.net/Articles/689907/ > > "Sparse does type checking, such as verifying that annotated variables do not > cause endianness bugs, detecting places that use ``__user`` pointers improperly, > and analyzing the compatibility of symbol initializers." > > Does it sound better? > Yeah: that sounds much better to me. Thanks! > > > > > + > > > +Smatch does flow analysis and, if allowed to build the function database, it > > > +also does cross function analysis. Smatch tries to answer questions like where > > > +is this buffer allocated? How big is it? Can this index be controlled by the > > > +user? Is this variable larger than that variable? > > > + > > > +It's generally easier to write checks in Smatch than it is to write checks in > > > +Sparse. Nevertheless, there are some overlaps between Sparse and Smatch checks > > > +because there is no reason for re-implementing Sparse's check in Smatch. > > > > This last sentence isn't totally clear to me. Should this "because" be "so"? > > Smatch uses (is shipped with) a modified Sparse implementation which it uses as > a C parser. Apparently, Sparse does some checkings while parsing the code for > Smatch so that's why we have some overlapping between the checks made when we > run Smatch and the ones made when we run Sparse alone. > > I didn't dig into the code, but I guess further modifying Sparse to prevent it > from doing some types of cheks wouldn't add much to Smatch. That last saying > should've reflected this fact, but it seems to cause confusion without a proper > context. Reading the sentence back again, I think we could just drop the last > part: > > "Nevertheless, there are some overlaps between Sparse and Smatch checks." > Yeah, I do think that makes more sense. I don't think the fact that some of the checks overlap causes any problems at all, to be honest, so you _could_ get rid of the whole sentence without losing too much, but I'm also happy with it as it is in v3. > > > > > + > > > +Strong points of Smatch and Coccinelle > > > +-------------------------------------- > > > + > > > +Coccinelle is probably the easiest for writing checks. It works before the > > > +pre-compiler so it's easier to check for bugs in macros using Coccinelle. > > > +Coccinelle also writes patches fixes for you which no other tool does. > > > + > > > +With Coccinelle you can do a mass conversion from > > > > (Maybe start this with "For example," just to make it clear that this > > paragraph is mostly following on from how useful it is that Coccinelle > > produces fixes, not just warnings.) > > Will do > > > > > > +``kmalloc(x * size, GFP_KERNEL)`` to ``kmalloc_array(x, size, GFP_KERNEL)``, and > > > +that's really useful. If you just created a Smatch warning and try to push the > > > +work of converting on to the maintainers they would be annoyed. You'd have to > > > +argue about each warning if can really overflow or not. > > > + > > > +Coccinelle does no analysis of variable values, which is the strong point of > > > +Smatch. On the other hand, Coccinelle allows you to do simple things in a simple > > > +way. > > > -- > > > 2.35.1 > > >