Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp5102184pxb; Thu, 14 Oct 2021 19:29:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydVYuERzOjCEZDR+Qj2BJW1HD814KvgKNTXUsv9RwFewXKLK7g+/R7Rm2M+ppVFAk6ayTS X-Received: by 2002:a05:6402:90c:: with SMTP id g12mr14198583edz.198.1634264971939; Thu, 14 Oct 2021 19:29:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634264971; cv=none; d=google.com; s=arc-20160816; b=Hp5wZJkPFBkCBN+7ZjcD23XS1ut2YniHGZcR3wG6lX7CypMebN6dhbQ4chVzVtnB1l bHN321D3HSKEUyN5HXTmTBC8lO9HP4RkkqkVfkI35iSr2JmHRaElEkMlLCQP5TvTrv3w 1wC2XGSYtru24ob+D544KKVBQxlPvMXXn0SDrl5vQ6Ts8pvl239DJTk3+JaQNSv+XW/V MvuuvumM2wLWwyfQDM4RQ+F6dWvLDRtnguubl/EJ9S2bzGeICBdM0bXQ/UTKh4yrakb5 l+CAwm3S6EmwrkdYGz9J4VbtIr8euua+rDsVrTjZb41+XKTQj9j4Fg4UAWbpvX3csgZn +wOg== 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=6TQlWaQ/2j2CVIneXWGVZFPa2r986YPjVBroYAuCCQ4=; b=xpJupDkaEMnbq0nfgkWqEGqK16mODdbkC1aot/YMj5iF6Hk+DnWG4hNYl9y0B+yc24 KYTWDG2PJdAJrVhSr5vcx/y1a1uKiJpUhSAXH4QbCz70ilZYYCAf5xyQc+jj+13cWc+I MtToh45qZTGDLXdWqAN3mBhwE+MX4HD/pORJaidCChHh+lJJL2hlKmzKjKUD8k1Cx3jG ji64o6M391nxMUicMahPey1os8ecthR6LDEhlni5nrtpgTsiDiGRCCOGAizgqrbxjaJ1 7yb8KB3lmQQtOaYhGKRC9FR9343/hzwoNAWuNyyxenvnWzHnRmSCxKhHKST/K8Gh7GG5 r8fQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r21si5770946edb.376.2021.10.14.19.28.54; Thu, 14 Oct 2021 19:29:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231408AbhJNUaa (ORCPT + 99 others); Thu, 14 Oct 2021 16:30:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:40134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232172AbhJNUa1 (ORCPT ); Thu, 14 Oct 2021 16:30:27 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 43775603E5; Thu, 14 Oct 2021 20:28:21 +0000 (UTC) Date: Thu, 14 Oct 2021 16:28:19 -0400 From: Steven Rostedt To: Jiri Olsa Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Subject: Re: [PATCH 7/8] ftrace: Add multi direct modify interface Message-ID: <20211014162819.5c85618b@gandalf.local.home> In-Reply-To: <20211008091336.33616-8-jolsa@kernel.org> References: <20211008091336.33616-1-jolsa@kernel.org> <20211008091336.33616-8-jolsa@kernel.org> 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 8 Oct 2021 11:13:35 +0200 Jiri Olsa wrote: > + /* > + * Shutdown the ops, change 'direct' pointer for each > + * ops entry in direct_functions hash and startup the > + * ops back again. > + * > + * Note there is no callback called for @ops object after > + * this ftrace_shutdown call until ftrace_startup is called > + * later on. > + */ > + err = ftrace_shutdown(ops, 0); > + if (err) > + goto out_unlock; I believe I said before that we can do this by adding a stub ops that match all the functions with the direct ops being modified. This will cause the loop function to be called, which will call the direct function helper, which will then call the direct function that is found. That is, there is no "pause" in calling the direct callers. Either the old direct is called, or the new one. When the function returns, all are calling the new one. That is, instead of: [ Changing direct call from my_direct_1 to my_direct_2 ] : call my_direct_1 |||||||||||||||||||| vvvvvvvvvvvvvvvvvvvv : nop |||||||||||||||||||| vvvvvvvvvvvvvvvvvvvv : call my_direct_2 We have it do: : call my_direct_1 |||||||||||||||||||| vvvvvvvvvvvvvvvvvvvv : call ftrace_caller : [..] call ftrace_ops_list_func ftrace_ops_list_func() { ops->func() -> direct_helper -> set rax to my_direct_1 or my_direct_2 } call rax (to either my_direct_1 or my_direct_2 |||||||||||||||||||| vvvvvvvvvvvvvvvvvvvv : call my_direct_2 I did this on top of this patch: Signed-off-by: Steven Rostedt (VMware) --- kernel/trace/ftrace.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 30120342176e..7ad1e8ae5855 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -5561,8 +5561,12 @@ EXPORT_SYMBOL_GPL(unregister_ftrace_direct_multi); */ int modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr) { - struct ftrace_hash *hash = ops->func_hash->filter_hash; + struct ftrace_hash *hash; struct ftrace_func_entry *entry, *iter; + static struct ftrace_ops tmp_ops = { + .func = ftrace_stub, + .flags = FTRACE_OPS_FL_STUB, + }; int i, size; int err; @@ -5572,21 +5576,22 @@ int modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr) return -EINVAL; mutex_lock(&direct_mutex); - mutex_lock(&ftrace_lock); + + /* Enable the tmp_ops to have the same functions as the direct ops */ + ftrace_ops_init(&tmp_ops); + tmp_ops.func_hash = ops->func_hash; + + err = register_ftrace_function(&tmp_ops); + if (err) + goto out_direct; /* - * Shutdown the ops, change 'direct' pointer for each - * ops entry in direct_functions hash and startup the - * ops back again. - * - * Note there is no callback called for @ops object after - * this ftrace_shutdown call until ftrace_startup is called - * later on. + * Now the ftrace_ops_list_func() is called to do the direct callers. + * We can safely change the direct functions attached to each entry. */ - err = ftrace_shutdown(ops, 0); - if (err) - goto out_unlock; + mutex_lock(&ftrace_lock); + hash = ops->func_hash->filter_hash; size = 1 << hash->size_bits; for (i = 0; i < size; i++) { hlist_for_each_entry(iter, &hash->buckets[i], hlist) { @@ -5597,10 +5602,12 @@ int modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr) } } - err = ftrace_startup(ops, 0); + /* Removing the tmp_ops will add the updated direct callers to the functions */ + unregister_ftrace_function(&tmp_ops); out_unlock: mutex_unlock(&ftrace_lock); + out_direct: mutex_unlock(&direct_mutex); return err; } -- 2.31.1