Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1409531imm; Wed, 10 Oct 2018 14:12:14 -0700 (PDT) X-Google-Smtp-Source: ACcGV61A/b3V1/WZYcyN62KdtdKdt4gUyxcg+nUCoU9JHg4AWR9B/45ehy3Oxtxl2g36kPzMb2G6 X-Received: by 2002:a17:902:b182:: with SMTP id s2-v6mr34404388plr.84.1539205934944; Wed, 10 Oct 2018 14:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539205934; cv=none; d=google.com; s=arc-20160816; b=hTPp//qffw5/n7OkbahzgB0eN2SpxteoXrBnZs3sMPlvq7tdezKKRrUMKaXNGxJ3jj TdqPvIvCa4feVSywSE9ZPNDJ0Q/Q9f7ZecnZxtcqaYNUlMNbS35gn0tCckXQGyO0XzxN 0JgCg0QlBxJlEFy/ize2Ul6+qtHL6DZMsnwAld4lsacI4X5uJumldvgHcHkWbcqFb4/5 FfCFiX5gPh5T4JTc4b7lS0i65r7Jza064nqIIIPtEmToZ8xYZRk76O+eqAFOvLG9koed BAmL1DhuFIuYqi5Qh3QazCECZUJKlKqxwF8C5ubRt/ZclC7QXvqHDAsjuBILVYaUggNz IfVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=PDuqIALn1i+X2vOVw+K7nCtjRp1s1GJq7dtezCzIKno=; b=uleqefVRThZTdH08K0wZmlPXfELCTGn0lI+Njpob+GlBu7PHAtAUAHnC8SrCjpW2pE hFRzN1y68jUPcuZMxLfADNgR7ykmkjPUXT6ofjGTyoSd5Iq+Px0xmezT5i/992fl8ZTt wWLAGkEIvhlJ+Fua/UrmfBjXs0j14tLdbUBmDG29+wfil1UcBVaB1ylUsaGDffMZCTiI pXK4fcFGwi+L4TM2kC86QqcCy4cw1PywZtF1gnFTYmJbD5OufcLM42oBkF3WbIbaNd+0 sfZVS7GzmAveSKGULsQp59sGzK4xMYK4htHh5/yLrCRLPOmMaHScZ50ioQaukNqcXNGM Q61w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=Gqz7mivE; 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 p16-v6si23038410pgb.404.2018.10.10.14.11.58; Wed, 10 Oct 2018 14:12:14 -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; dkim=pass header.i=@joelfernandes.org header.s=google header.b=Gqz7mivE; 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 S1726008AbeJKEfZ (ORCPT + 99 others); Thu, 11 Oct 2018 00:35:25 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:38437 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725769AbeJKEfZ (ORCPT ); Thu, 11 Oct 2018 00:35:25 -0400 Received: by mail-pl1-f195.google.com with SMTP id q19-v6so23917pll.5 for ; Wed, 10 Oct 2018 14:11:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=PDuqIALn1i+X2vOVw+K7nCtjRp1s1GJq7dtezCzIKno=; b=Gqz7mivETC0VPDC2/7p0ZP4H56lCH28iu9ljJp9l4kbfmRkYnBpepyWoFnSzuXuoF7 1UFk7IgMPWX9dgphZS3lAvoPGmq0LTcoKiCu0ULEMnGzyzinjTUHmdKtgZ4asrzq1V1Y iJfhhew9o/8y0DpvaR6Rh8qxXZsc6M7IRtdZE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=PDuqIALn1i+X2vOVw+K7nCtjRp1s1GJq7dtezCzIKno=; b=myu5aEUK7iDH+toHLr4g2gf851OMH/NNCtM6512KiA1Ya6yog2hfVrdQO1YwpXExk9 OXw7nYCRWwzaE2tJg+sTVX69HhIxY7C/tmyXmKJmgf2uI+yxuYMwCw1BknQkdr35lxyv pwYLKuWBqpNabPiO/Z6JOfoAwsRrfAqndUielTuTjAu5Ioz0PBuVdyV0Byrq0d/ECCFS iYv0V7NvWD9OH+pL2MaRPSnS9cyVDJKNJ4mMb7Dxn3ZXroiHQwFGGvRHYB2z/DdRhgIp 4wHlHLcpWs/oC9OdyoLlCdUDEAPteyzoiaBy4FUPi0cW/gmL0GcT/ura1Uymns5OBDEy GwjQ== X-Gm-Message-State: ABuFfohXOp1ij+79iyJRozRsV1AFVKtI7ihqhlpyAz7xqU6TBpniTE3h +TGdBM3z3SY1cDS1hnKYz5guOw== X-Received: by 2002:a17:902:b08e:: with SMTP id p14-v6mr34787431plr.241.1539205887364; Wed, 10 Oct 2018 14:11:27 -0700 (PDT) Received: from localhost ([2620:0:1000:1601:3aef:314f:b9ea:889f]) by smtp.gmail.com with ESMTPSA id u62-v6sm34355648pfu.69.2018.10.10.14.11.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Oct 2018 14:11:26 -0700 (PDT) Date: Wed, 10 Oct 2018 14:11:25 -0700 From: Joel Fernandes To: Julia Lawall 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. Message-ID: <20181010211125.GA128537@joelaf.mtv.corp.google.com> References: <20181010193854.GA93016@joelaf.mtv.corp.google.com> <20181010204517.GA109962@joelaf.mtv.corp.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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") thanks, - Joel