Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp8579639rwp; Wed, 19 Jul 2023 11:58:08 -0700 (PDT) X-Google-Smtp-Source: APBJJlEFtLFxUVImZlpOQ6X3Wp7rsQkz20oYbv7B1q1NyFKokwG7FmFUbV3FgHbN9fLR7WU0eZZw X-Received: by 2002:a17:902:7201:b0:1b3:d4ae:7e21 with SMTP id ba1-20020a170902720100b001b3d4ae7e21mr15397386plb.63.1689793088599; Wed, 19 Jul 2023 11:58:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689793088; cv=none; d=google.com; s=arc-20160816; b=OTyhqDsSGGonnn7+PO2S3r+38RKucuS/15nsBdFo71/KQsa+/5hpUx1/5GhPTDBXZk Pz6FSgIsk4R0m0OW+h6DE02XwsJw3E6zsDKgJbSqFzZJCrH+vjlB8lDqPdoiiaYbzSUZ l7K6E713ofxR48Miu4bf50rPgUkiijLe6wRRdolnP9o6HD7FWVv8xRp27GOwHi5CROoh Ibh86R5AX+lFfLsLNw66k8Wdr2x+3ZW5veG7SigVXDqrK3WP+baGVxe1Kahu/y8uxNv5 D/V4/wUtmbFF3AXytikzYgfENBPvvzo+tZvMcB+a4Wrb8sutxVV7y023fIDSG+4Gw34F 8zQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=w+DbDW4SH7bsE6fWp3BaG3tGvPLz08lnC+WZ+wC8dks=; fh=0cNiEokRMCP9wes26NLgPbqDCI4XIRE+lf/PFicWBYA=; b=RcOxdyTb1cD7lIohX5Lca1rQy3k2hgcyLdgJbDSo4KojhV7IHzo25bzxovFXSU6Xul 4zfWm1Liid8LIlwXFdrhiJ4Wkwxb8MPyxe/9096UCctupvQu9fAZppXqhyIVDNJmsg8q U6uesxuOlUhAVwAPLn63N+WfwgSgi+5bFxL6iPDDk781RRSFZchOuhBmBYMBa2jISTxP jcBktRi0Sr0jK7WsLqv7bGbdt9gOG8PQTkqPqt7PVuEvdyRNwmEwVC98hyDn9C+fTrfu Tymf9AsOXwV9S/JF//oz8d6ixnNnCJGUKq8F2zKpEGjQCYGEVIbSssijoL8FC6znJr1D wusw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iMpmumbM; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ki4-20020a170903068400b001b8946f3f95si3737336plb.312.2023.07.19.11.57.56; Wed, 19 Jul 2023 11:58:08 -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=@kernel.org header.s=k20201202 header.b=iMpmumbM; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229529AbjGSS15 (ORCPT + 99 others); Wed, 19 Jul 2023 14:27:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230358AbjGSS14 (ORCPT ); Wed, 19 Jul 2023 14:27:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B65E10FC; Wed, 19 Jul 2023 11:27:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 940D7616FD; Wed, 19 Jul 2023 18:27:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDBDEC433C8; Wed, 19 Jul 2023 18:27:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689791273; bh=abnVgmoykOrPBnFbts3x0YYarmtT6yCNCnDn9/9ZvQM=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=iMpmumbM2AgUGjTSrP0pLzS5YwuVEFC7WmOPLk2Um7JpzC8pqn6yHsIX/V2PEkMJE JHl7Y/mKrivqULXRMemYhDVZNrHrAnrFH5rqYSETChScbbur6bkUf5QxocDHKTL6SD vtiN5bFSOGAgPs5l951xs/qFe0q6OGweOXy5rIikXX2nsDrR508JqlZ0NShIP1ja1m g+Og93DmD6YKsiW9/e6epsXV9UPFGoMEhWV2vYpCogzAV9C4bTs6meFN3LYg2YgX0s zSS9bw+iIpZXK6L8o1DWi4IUqzfHjQPE8/eZmD46VI5A4xt5OiEb+EuA9CnCyZsGMd WLPbEK7fdYQYA== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 9B04DCE092F; Wed, 19 Jul 2023 11:27:52 -0700 (PDT) Date: Wed, 19 Jul 2023 11:27:52 -0700 From: "Paul E. McKenney" To: Joel Fernandes Cc: Joe Perches , rcu@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, rostedt@goodmis.org, Andy Whitcroft , Dwaipayan Ray , Lukas Bulwahn , Alexei Starovoitov , Daniel Borkmann , John Fastabend , bpf@vger.kernel.org Subject: Re: [PATCH rcu 5/5] checkpatch: Complain about unexpected uses of RCU Tasks Trace Message-ID: <351d0261-210a-44a3-ade6-59289f407db2@paulmck-laptop> Reply-To: paulmck@kernel.org References: <20230717180454.1097714-5-paulmck@kernel.org> <04e74fd214a01bee0fb5ac690730cb386536cced.camel@perches.com> <8477fd32-38a5-4d66-8deb-a61b0e290df5@paulmck-laptop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham 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 Wed, Jul 19, 2023 at 07:51:58AM -0400, Joel Fernandes wrote: > > > On 7/17/23 19:34, Paul E. McKenney wrote: > > On Mon, Jul 17, 2023 at 03:34:14PM -0700, Joe Perches wrote: > > > On Mon, 2023-07-17 at 11:04 -0700, Paul E. McKenney wrote: > > > > RCU Tasks Trace is quite specialized, having been created specifically > > > > for sleepable BPF programs. Because it allows general blocking within > > > > readers, any new use of RCU Tasks Trace must take current use cases into > > > > account. Therefore, update checkpatch.pl to complain about use of any of > > > > the RCU Tasks Trace API members outside of BPF and outside of RCU itself. > > > > > > > > Cc: Andy Whitcroft (maintainer:CHECKPATCH) > > > > Cc: Joe Perches (maintainer:CHECKPATCH) > > > > Cc: Dwaipayan Ray (reviewer:CHECKPATCH) > > > > Cc: Lukas Bulwahn > > > > Cc: Alexei Starovoitov > > > > Cc: Daniel Borkmann > > > > Cc: John Fastabend > > > > Cc: > > > > Signed-off-by: Paul E. McKenney > > > > --- > > > > scripts/checkpatch.pl | 18 ++++++++++++++++++ > > > > 1 file changed, 18 insertions(+) > > > > > > > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > > > [] > > > > @@ -7457,6 +7457,24 @@ sub process { > > > > } > > > > } > > > > +# Complain about RCU Tasks Trace used outside of BPF (and of course, RCU). > > > > + if ($line =~ /\brcu_read_lock_trace\s*\(/ || > > > > + $line =~ /\brcu_read_lock_trace_held\s*\(/ || > > > > + $line =~ /\brcu_read_unlock_trace\s*\(/ || > > > > + $line =~ /\bcall_rcu_tasks_trace\s*\(/ || > > > > + $line =~ /\bsynchronize_rcu_tasks_trace\s*\(/ || > > > > + $line =~ /\brcu_barrier_tasks_trace\s*\(/ || > > > > + $line =~ /\brcu_request_urgent_qs_task\s*\(/) { > > > > + if ($realfile !~ m@^kernel/bpf@ && > > > > + $realfile !~ m@^include/linux/bpf@ && > > > > + $realfile !~ m@^net/bpf@ && > > > > + $realfile !~ m@^kernel/rcu@ && > > > > + $realfile !~ m@^include/linux/rcu@) { > > > > > > Functions and paths like these tend to be accreted. > > > > > > Please use a variable or 2 like: > > > > > > our $rcu_trace_funcs = qr{(?x: > > > rcu_read_lock_trace | > > > rcu_read_lock_trace_held | > > > rcu_read_unlock_trace | > > > call_rcu_tasks_trace | > > > synchronize_rcu_tasks_trace | > > > rcu_barrier_tasks_trace | > > > rcu_request_urgent_qs_task > > > )}; > > > our $rcu_trace_paths = qr{(?x: > > > kernel/bfp/ | > > > include/linux/bpf | > > > net/bpf/ | > > > kernel/rcu/ | > > > include/linux/rcu > > > )}; > > > > Like this? > > > > # Complain about RCU Tasks Trace used outside of BPF (and of course, RCU). > > our $rcu_trace_funcs = qr{(?x: > > rcu_read_lock_trace | > > rcu_read_lock_trace_held | > > rcu_read_unlock_trace | > > call_rcu_tasks_trace | > > synchronize_rcu_tasks_trace | > > rcu_barrier_tasks_trace | > > rcu_request_urgent_qs_task > > )}; > > our $rcu_trace_paths = qr{(?x: > > kernel/bfp/ | > > include/linux/bpf | > > net/bpf/ | > > kernel/rcu/ | > > include/linux/rcu > > )}; > > if ($line =~ /$rcu_trace_funcs/) { > > if ($realfile !~ m@^$rcu_trace_paths@) { > > WARN("RCU_TASKS_TRACE", > > "use of RCU tasks trace is incorrect outside BPF or core RCU code\n" . $herecurr); > > } > > } > > > > No, that is definitely wrong. It has lost track of the list of pathnames, > > thus complaining about uses of those functions in files where their use > > is permitted. > > > > But this seems to work: > > > > # Complain about RCU Tasks Trace used outside of BPF (and of course, RCU). > > our $rcu_trace_funcs = qr{(?x: > > rcu_read_lock_trace | > > rcu_read_lock_trace_held | > > rcu_read_unlock_trace | > > call_rcu_tasks_trace | > > synchronize_rcu_tasks_trace | > > rcu_barrier_tasks_trace | > > rcu_request_urgent_qs_task > > )}; > > if ($line =~ /\b$rcu_trace_funcs\s*\(/) { > > if ($realfile !~ m@^kernel/bpf@ && > > $realfile !~ m@^include/linux/bpf@ && > > $realfile !~ m@^net/bpf@ && > > $realfile !~ m@^kernel/rcu@ && > > $realfile !~ m@^include/linux/rcu@) { > > WARN("RCU_TASKS_TRACE", > > "use of RCU tasks trace is incorrect outside BPF or core RCU code\n" . $herecurr); > > } > > } > > > > Maybe the "^" needs to be distributed into $rcu_trace_paths? > > > > # Complain about RCU Tasks Trace used outside of BPF (and of course, RCU). > > our $rcu_trace_funcs = qr{(?x: > > rcu_read_lock_trace | > > rcu_read_lock_trace_held | > > rcu_read_unlock_trace | > > call_rcu_tasks_trace | > > synchronize_rcu_tasks_trace | > > rcu_barrier_tasks_trace | > > rcu_request_urgent_qs_task > > )}; > > our $rcu_trace_paths = qr{(?x: > > ^kernel/bfp/ | > > ^include/linux/bpf | > > ^net/bpf/ | > > ^kernel/rcu/ | > > ^include/linux/rcu > > )}; > > if ($line =~ /\b$rcu_trace_funcs\s*\(/) { > > if ($realfile !~ m@$rcu_trace_paths@) { > > WARN("RCU_TASKS_TRACE", > > "use of RCU tasks trace is incorrect outside BPF or core RCU code\n" . $herecurr); > > } > > } > > > > But no joy here, either. Which is no surprise, given that perl is > > happy to distribute the "\b" and the "\s*\(" across the elements of > > $rcu_trace_funcs. I tried a number of other variations, including > > inverting the "if" condition "(!(... =~ ...))", inverting the "if" > > condition via an empty "then" clause, replacing the "m@" with "/", > > replacing the "|" in the "qr{}" with "&", and a few others. > > > > Again, listing the pathnames explicitly in the second "if" condition > > works just fine. > > > > Not a perl expert but I wonder if the following are any options at all: > > 1. Instead of having a complex list of strings in a regex variable, it might > be easier to hold the strings as a perl array, and then iterate over that > array checking each element of the array on every iteration, against the > line. > > 2. Roll the "\b" and/or "^" in into the regex variable itself than trying > make them play with the variable later. > > 3. Use parentheses around the variable? Not sure if that will work but I > wonder if it has something to do with operator precedence. > > 4. Instead of a list of paths, maybe it is better to look for "rcu" or "bpf" > in the regex itself? That way new paths don't require script updates (at the > expense though of false-positives (highly unlikely, IMHO)). Given perl's tendency to have corner cases in its corner cases, I am guessing that the "^" character combined with the "/" character is causing trouble here. Especially given that I don't see any use of such a pattern anywhere in checkpatch.pl except directly in a "~" expression, and there are a lot of those. So I will keep it as is unless I hear otherwise from Joe Perches. Thanx, Paul