Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4723191imw; Tue, 19 Jul 2022 11:58:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sOBe4l8FX6TOjmwbV8bVbMCXzOk5mgJk1hwzIOgBP8bUnWe3qoHx1aVz+PSo09pDlKP2jt X-Received: by 2002:a65:6a04:0:b0:411:b3d3:a840 with SMTP id m4-20020a656a04000000b00411b3d3a840mr31040192pgu.99.1658257121104; Tue, 19 Jul 2022 11:58:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658257121; cv=none; d=google.com; s=arc-20160816; b=DxAnD4F/m8IpJDAvTloUT5fx8E7A+J/CBR2YV1LBJDq2ax37pJlvMvZB7o65jbedlb khczLXtwRitN4nSeEgfLhYynpFIdc2Hlqnq2az7wviTeHLDUuX2a6pCCFzutzYnM4Bad xAK0kSfxU1madEGaGnmb8FG/arsRPXC1vYAnBgckuZQr6W31BoGY8t8dzxbMLa1SvdBi w0/DIMT3O00F0FfDf6S/VvJc9cJcNoI4GymiKGvdKCgFbJwvoGdXnD1SVGiUnDZJYA4w Uv+CDYvhFR2Ew/JKVFz+ofFyrEBNtSKMx/JVkaEZndUjuvl60YpBBqijpdDvuG9agDaG sUrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=A8KXOgGB7p4bcgpiqT9BsYMv+26bHN1uF4h4Keq1Up8=; b=GDEP0SqTG4yxRUAp9CnLGAhPfynB1p0dOAA7xfZLUChp6hMazk1jZlC5v3G6rk3AOY iG/ZyTUTtpjjLqQ1aLBDb2CjujC2U8lVH7r59/pydfC1+JufUd2BFV64AbFkTpGqmPHc 0hQ6NF6N7G1lK/t/cgfvVvTt/suv5v7KgejZRC7nDB6Im302xyCpFGCIm3pPvsCR3flH /pDUPxIpdtcdcG/nyu6ent19/5ZrWqav4q9Jh1jlnHO77abJs5nhflSFsqEVHu0diOYY 8ZBf8FRo2rsHFT3VP4iehkRcZ6y5mkKkCHB2BdHkACJWUyacmUTX/XH0E/RL39NjiLM9 tX5w== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j3-20020a056a00174300b0051b904d9c7csi20711486pfc.251.2022.07.19.11.58.24; Tue, 19 Jul 2022 11:58:41 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238356AbiGSScQ (ORCPT + 99 others); Tue, 19 Jul 2022 14:32:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233242AbiGSScP (ORCPT ); Tue, 19 Jul 2022 14:32:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AE7657214; Tue, 19 Jul 2022 11:32:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C564561787; Tue, 19 Jul 2022 18:32:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D16C0C341C6; Tue, 19 Jul 2022 18:32:11 +0000 (UTC) Date: Tue, 19 Jul 2022 14:32:10 -0400 From: Steven Rostedt To: Song Liu Cc: Petr Mladek , kernel test robot , Song Liu , bpf , lkml , "live-patching@vger.kernel.org" , "kbuild-all@lists.01.org" , Daniel Borkmann , Kernel Team , "jolsa@kernel.org" Subject: Re: [PATCH v4 bpf-next 2/4] ftrace: allow IPMODIFY and DIRECT ops on the same function Message-ID: <20220719143210.08f9922b@gandalf.local.home> In-Reply-To: <9DAB0710-7D60-46AC-8A2F-ED4B8A1A4BC0@fb.com> References: <20220718055449.3960512-3-song@kernel.org> <202207181552.VuKfz9zg-lkp@intel.com> <9DAB0710-7D60-46AC-8A2F-ED4B8A1A4BC0@fb.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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 Mon, 18 Jul 2022 16:59:51 +0000 Song Liu wrote: > >> vim +/direct_mutex_locked +8197 kernel/trace/ftrace.c > >> > >> 8182 > >> 8183 /** > >> 8184 * register_ftrace_function - register a function for profiling > >> 8185 * @ops: ops structure that holds the function for profiling. > >> 8186 * > >> 8187 * Register a function to be called by all functions in the > >> 8188 * kernel. > >> 8189 * > >> 8190 * Note: @ops->func and all the functions it calls must be labeled > >> 8191 * with "notrace", otherwise it will go into a > >> 8192 * recursive loop. > >> 8193 */ > >> 8194 int register_ftrace_function(struct ftrace_ops *ops) > >> 8195 __releases(&direct_mutex) > >> 8196 { > >>> 8197 bool direct_mutex_locked = false; > >> 8198 int ret; > >> 8199 > >> 8200 ftrace_ops_init(ops); > >> 8201 > >> 8202 ret = prepare_direct_functions_for_ipmodify(ops); > >> 8203 if (ret < 0) > >> 8204 return ret; > >> 8205 else if (ret == 1) > >> 8206 direct_mutex_locked = true; > > > > Honestly, this is another horrible trick. Would it be possible to > > call prepare_direct_functions_for_ipmodify() with direct_mutex > > already taken? Agreed. I'm not sure why I didn't notice this in the other versions. Probably was looking too much at the other logic. :-/ > > > > I mean something like: > > > > mutex_lock(&direct_mutex); > > > > ret = prepare_direct_functions_for_ipmodify(ops); > > if (ret) > > goto out: > > > > mutex_lock(&ftrace_lock); > > ret = ftrace_startup(ops, 0); > > mutex_unlock(&ftrace_lock); > > > > out: > > mutex_unlock(&direct_mutex); > > return ret; > > Yeah, we can actually do something like this. We can also move the > ops->flags & FTRACE_OPS_FL_IPMODIFY check to > register_ftrace_function(), so we only lock direct_mutex when when > it is necessary. No need. Just take the direct_mutex, and perhaps add a: lockdep_assert_held(&direct_mutex); in the prepare_direct_functions_for_ipmodify(). This is far from a fast path to do any tricks in trying to optimize it. -- Steve