Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1390613imm; Wed, 10 Oct 2018 13:52:08 -0700 (PDT) X-Google-Smtp-Source: ACcGV63fR9qMBfYi1jTys4U0kfBnI7Sxnb8GlcHqTBHaSfsVLTfQwu2e//rPjpqdmucLUAt8OjaQ X-Received: by 2002:a17:902:e201:: with SMTP id ce1-v6mr27640613plb.47.1539204727971; Wed, 10 Oct 2018 13:52:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539204727; cv=none; d=google.com; s=arc-20160816; b=F2R5Rtb6WBiLazTwgpNOY3v7Av25NNUNCP38Z6nsrDGe4VyrBozf74gSdVfAQydQcv Rqji8U0yDCT+V06n6Jc5BX002zJBEVmBxNuX7jA8XhwEJsUG4eCn/OajW5Jk7DcQpcru f7OQzVyGEjv6+GiKKM+lSPEC29amvT/R07r86sBpSkEMfR0t9aaY4m9bhgNkSXVNCj52 w85etHddaJftA1eJgy5H2R3ZunWAASrUDaDhr05gapGebmgTQZd+ygxENKq7MG3std/A AdrVc7wnsEnZbXePY85S2cSfTjjRKS6dheVhGYijkNZMGEXDbp0AN291QQGz2U/N+mHO M6Yg== 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=Ewq+Oewa4Kvh1tByJP/XEWPJdLesSv3KT54Rp9wzyIo=; b=IrsWM0sKglMXTrILaxuCHN9N+hLlh9f2opJljkvYCcrWw2fOTmgjDexAlk9vHNWVLt XA+usbcdDFVc0cBKb8ZRgyrOMAYQ73Pk17/i5MY0kV/BFh/xT0r37CHgw8+TgeXLrJuh eB/gPGnHzgafqi4GjDD9cHawjiUeLlZu8rqL+S5xPsC+ERH3NDkZkGiMc/ApXVAbmwxc PL/hSfdZKL/t1qn5QjANjzdSlUBvpsfRb8d07bN0aWIBwTA3iwcdM5gbyymUrcFPQjpN lerrIA3Y6K8uBu2UkSuaToVXOvwy4s/gHLvaGZn+hGf/HaMoBsiBBPBzqM0HZTJAQgd2 9iaA== 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 t7-v6si24528297ply.150.2018.10.10.13.51.52; Wed, 10 Oct 2018 13:52:07 -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 S1725908AbeJKEPY (ORCPT + 99 others); Thu, 11 Oct 2018 00:15:24 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:6151 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725822AbeJKEPX (ORCPT ); Thu, 11 Oct 2018 00:15:23 -0400 X-IronPort-AV: E=Sophos;i="5.54,365,1534802400"; d="scan'208";a="281719066" 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 22:51:28 +0200 Date: Wed, 10 Oct 2018 22:51:28 +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: <20181010204517.GA109962@joelaf.mtv.corp.google.com> Message-ID: References: <20181010193854.GA93016@joelaf.mtv.corp.google.com> <20181010204517.GA109962@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: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. julia