Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1410508imm; Wed, 10 Oct 2018 14:13:13 -0700 (PDT) X-Google-Smtp-Source: ACcGV60FCoqadNoJSkwc9dQpYmJQO7AV2iCZ1MOCnQMbEEqEwObRdlmYzave9lX80H7Fy94LwUcq X-Received: by 2002:a62:ccd4:: with SMTP id j81-v6mr37164413pfk.76.1539205993748; Wed, 10 Oct 2018 14:13:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539205993; cv=none; d=google.com; s=arc-20160816; b=BZylNSRithuj83y+8dcbbqkATQUESWKRRbD+HIFQ5XXSZPHFwwq5nAAuA+DidXeE5T 8J0dXx8K4JiEbOTgeiXr2+7OXzB23lnxMWnrs8D690+HLQX1inD6SXxlxBB1ZB5EQeMY jZHIMv/GRNLbkzqBlb50terGOzlY6YPJqI40fjpoxSd3VN0nvJew3AOVJJLY5QQdO5yu FB/QR4Og0xjH8DXBPkyCWLUQSg1ZvTJ+KDrJ6E1/2iairGMDmuM9bqd3JMtQ+ov5gMtm T+qzgm6H89HzJvUzyy1CDIeyU3YVtMRlgTwm4XhAIC1ZtrettQQQNNuFgwwhspkboJGm 0AmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=d5MbBPN++KNI0kDtVt2t4fg35AeuAbIOLjvc/aKFoU8=; b=IpCwtbqRZxS+SdABf/uwE4xGdSEzWJlCh123GM/32e6SpewwNLsgUy1U+rIz6LNGWK CA/6XVPNpW693KfajDgO9QoSeavxcmAxCcGsZNADKyiIkNOc+MNidJOdwFtrXyATKCKe zLr1yO48N9w8eETzbDjzeVEqEiYwlaw3dzXli0sWUMksR6Zx4u/ZdVRd0kxyKF3J9j1V deySvXvI2jS2nj57cfNKNBf76VJCEVxllPwZkclSdcqjH0PjP9rSshwWjTgSg98UPzDi aA0Upg5ODgz1/S8i6+rCOZjUJGkPMTXiWVZFh121rhPTIVj1KQk9PlrKiyuyHa48oKG/ Uchg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w6-v6si25399059pgb.180.2018.10.10.14.12.58; Wed, 10 Oct 2018 14:13:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725967AbeJKEgZ (ORCPT + 99 others); Thu, 11 Oct 2018 00:36:25 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:41586 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725769AbeJKEgZ (ORCPT ); Thu, 11 Oct 2018 00:36:25 -0400 X-IronPort-AV: E=Sophos;i="5.54,365,1534802400"; d="scan'208";a="281719755" Received: from 89-157-201-244.rev.numericable.fr (HELO hadrien) ([89.157.201.244]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Oct 2018 23:12:26 +0200 Date: Wed, 10 Oct 2018 23:12:26 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Joel Fernandes cc: linux-kernel@vger.kernel.org, Gilles Muller , Nicolas Palix , Michal Marek , cocci@systeme.lip6.fr, Kees Cook Subject: Re: First coccinelle script, need some help. In-Reply-To: <20181010211125.GA128537@joelaf.mtv.corp.google.com> Message-ID: References: <20181010193854.GA93016@joelaf.mtv.corp.google.com> <20181010204517.GA109962@joelaf.mtv.corp.google.com> <20181010211125.GA128537@joelaf.mtv.corp.google.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 10 Oct 2018, Joel Fernandes wrote: > On Wed, Oct 10, 2018 at 10:51:28PM +0200, Julia Lawall wrote: > > > > > > On Wed, 10 Oct 2018, Joel Fernandes wrote: > > > > > On Wed, Oct 10, 2018 at 10:23:18PM +0200, Julia Lawall wrote: > > > > > > > > > > > > On Wed, 10 Oct 2018, Joel Fernandes wrote: > > > > > > > > > > > > > > Hi! > > > > > > > > > > I am trying to determine if a function argument is used across the whole > > > > > kernel for a certain kernel function. > > > > > > > > > > I mustered up enough courage to write my first coccinelle script after a few > > > > > late nights of reading up about it :) > > > > > > > > > > Here is .cocci script. I am trying to find if address is used at all in any > > > > > possible definitions of pte_alloc(): > > > > > > > > > > $ cat ~/pte_alloc.cocci > > > > > virtual report > > > > > > > > > > @pte_args depends on report@ > > > > > identifier E1, E2; > > > > > type T1, T2; > > > > > position p; > > > > > @@ > > > > > > > > > > pte_alloc@p(T1 E1, T2 E2) > > > > > { > > > > > ... > > > > > ( > > > > > ... > > > > > E2 > > > > > ... > > > > > ) > > > > > ... > > > > > } > > > > > > > > > > > > In report mode, by default, the pattern has to match on all paths. Also > > > > when you have ... before or after E2, there can be no occurrence of E2 in > > > > the code matched by the ... So your rule requires that on every possible > > > > execution path through the function, there is exactly one occurrence of > > > > E2. > > > > > > > > You can try the following instead: > > > > > > > > virtual report > > > > > > > > @pte_args depends on report exists@ > > > > identifier E1, E2; > > > > type T1, T2; > > > > position p; > > > > @@ > > > > > > > > pte_alloc@p(T1 E1, T2 E2) > > > > { > > > > ... when any > > > > E2 > > > > ... when any > > > > } > > > > > > Thanks for the quick reply. > > > If I just add 'depends on report exists' to the rule, then my original > > > example works fine now. I did not need to add the 'when any'. Do you mind > > > taking my original simple test.c example and modify it and let me know under > > > what situation would it not work? > > > > > > I even added address = 1 outside of the if block and it works fine, I see the > > > warning as I expect without 'when any' in pront of the "...". > > > > > > struct page *pte_alloc(struct mm_struct *mm, unsigned long address) > > > { > > > address = 1; > > > if (condition()) { > > > while (1) { > > > address++; > > > } > > > return NULL; > > > } > > > } > > > > This works, because there exists a path through the function that has only > > one use of address, ie the path where condition() is false. It should > > break if you put address = 2; just under address = 1, for example. > > > Ok, thanks. This fact really is a bit subtle I'd say but hopefully will not > be once I get past the learning curve. Interestingly, if I do the following > then that works too without needing 'exists': > > virtual report > > @pte_args depends on report@ > identifier E1, E2; > type T1, T2; > position p; > @@ > > pte_alloc@p(T1 E1, T2 E2) > { > <+... > E2 > ...+> > } > > @script:python depends on report@ > p << pte_args.p; > @@ > coccilib.report.print_report(p[0], "WARNING: found definition of pte_alloc with > address used in the body") Yes, that is another option. But it may be more expensive. julia