From nobody Mon Nov 25 09:32:14 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6684B188737; Mon, 28 Oct 2024 07:12:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730099539; cv=none; b=k9Avq3K6pQ2T1yoJxdML9d9UvVv0U9jLfpxpia3IAIFq/dMXpvZPjDBXkaqh3oPD8dQsgmtfdjlxUuzjbO5c0tGuweLgVbKwrrVEJOrc7ah+bmW5muBK6p7vFKNmTy24dsuVFF2VfGqqjofEvhbs0zfsfxPrQEFYBOzE5nCzKic= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730099539; c=relaxed/simple; bh=KsohIQAJFRxFyrJE+8Xs1vbrzneRIvJPl7fp30prFUk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=VhX0SaGhg9LJ41DaPpSEus2uE+x/+7Af4PH4uxh5inMMf5gHPo+QfV+PZPR9WkvGK10n32m/5r3wa2uAHDsFKQ+qWuYjTkoJJFjz2cOaq0UyFxZnnwmiXzScau7ffL3gQyCRkz2CdDdrSq4vDXnoWZBTIbiFJyCm04TXuc81DYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23475C4CEC7; Mon, 28 Oct 2024 07:12:19 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t5Jw3-000000053D3-3oGh; Mon, 28 Oct 2024 03:13:07 -0400 Message-ID: <20241028071307.770550792@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 28 Oct 2024 03:12:29 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Peter Zijlstra Subject: [PATCH 1/5] fgraph: Use guard(mutex)(&ftrace_lock) for unregister_ftrace_graph() References: <20241028071228.575900713@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The ftrace_lock is held throughout unregister_ftrace_graph(), use a guard to simplify the error paths. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/fgraph.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 001abf376c0c..0bf78517b5d4 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -1381,17 +1381,17 @@ void unregister_ftrace_graph(struct fgraph_ops *gop= s) { int command =3D 0; =20 - mutex_lock(&ftrace_lock); + guard(mutex)(&ftrace_lock); =20 if (unlikely(!ftrace_graph_active)) - goto out; + return; =20 if (unlikely(gops->idx < 0 || gops->idx >=3D FGRAPH_ARRAY_SIZE || fgraph_array[gops->idx] !=3D gops)) - goto out; + return; =20 if (fgraph_lru_release_index(gops->idx) < 0) - goto out; + return; =20 fgraph_array[gops->idx] =3D &fgraph_stub; =20 @@ -1413,7 +1413,5 @@ void unregister_ftrace_graph(struct fgraph_ops *gops) unregister_pm_notifier(&ftrace_suspend_notifier); unregister_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL); } - out: gops->saved_func =3D NULL; - mutex_unlock(&ftrace_lock); } --=20 2.45.2 From nobody Mon Nov 25 09:32:14 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BB32191493; Mon, 28 Oct 2024 07:12:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730099539; cv=none; b=jDIH41p8Rn8BBWt9s94ncSsytZRmGIf6reSQ+1Bmd5t6Iz7wnvuvGLz/twR1O7IFt/K9cA19YDBv+M7QbEkhCi/UTflZGn6QOGr2DC4XFZPCh689DEDm+Lj3DKWTqO62Zd8SwWoDnw6sxxs8XxT590hCdknlBx3VqBexmuks2jk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730099539; c=relaxed/simple; bh=CrpZfsQvl+o/WpkUnkpWR88txNPc6znh+Atzuyb7wlw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=icU7R4tSwt0s7wNmmv8SB55jkFSKwkvYSLt+kXMWNgxWP/aGWNTCz0i7MvwFMVOSpIPAoIqrxM5hgLv6MLINSYi5if16sUWdEhfKyDrWYh92Yiy3ogxVuKpw6gZe0vt8rHBp2HZWHpFxPqcvchdtqeACgXgtQkHi8FdJzOFzOSw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37328C4CEE3; Mon, 28 Oct 2024 07:12:19 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t5Jw4-000000053DY-0HWJ; Mon, 28 Oct 2024 03:13:08 -0400 Message-ID: <20241028071307.927146604@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 28 Oct 2024 03:12:30 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Peter Zijlstra Subject: [PATCH 2/5] ftrace: Use guard for match_records() References: <20241028071228.575900713@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The ftrace_lock is held for most of match_records() until the end of the function. Use guard to make error paths simpler. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index e9fd4fb2769e..44adc34643c9 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -4829,15 +4829,13 @@ match_records(struct ftrace_hash *hash, char *func,= int len, char *mod) mod_g.len =3D strlen(mod_g.search); } =20 - mutex_lock(&ftrace_lock); + guard(mutex)(&ftrace_lock); =20 if (unlikely(ftrace_disabled)) - goto out_unlock; + return 0; =20 - if (func_g.type =3D=3D MATCH_INDEX) { - found =3D add_rec_by_index(hash, &func_g, clear_filter); - goto out_unlock; - } + if (func_g.type =3D=3D MATCH_INDEX) + return add_rec_by_index(hash, &func_g, clear_filter); =20 do_for_each_ftrace_rec(pg, rec) { =20 @@ -4846,16 +4844,12 @@ match_records(struct ftrace_hash *hash, char *func,= int len, char *mod) =20 if (ftrace_match_record(rec, &func_g, mod_match, exclude_mod)) { ret =3D enter_record(hash, rec, clear_filter); - if (ret < 0) { - found =3D ret; - goto out_unlock; - } + if (ret < 0) + return ret; found =3D 1; } cond_resched(); } while_for_each_ftrace_rec(); - out_unlock: - mutex_unlock(&ftrace_lock); =20 return found; } --=20 2.45.2 From nobody Mon Nov 25 09:32:14 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8BAE4191473; Mon, 28 Oct 2024 07:12:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730099539; cv=none; b=N8+XRH4sD+7Q9bEU0KmwjwrV36psc85mHtB+p0gFAOf0KRfwGF29sib6BEsaiBQcS3Hh4hy2wVIXrMi7KdqKUPrcLly1CeD3LKlc15Glzm4GMIUAyV7UT7+8ehkkluTi+oBfiMAAQdlv4/8F6iAtTFVtAVM/FYZjoz29mWz7oEY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730099539; c=relaxed/simple; bh=9vBWJH11IbK66QgWVk9H9Vqyr8xXbIoeCjdz00lvw7I=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=RbuvSxBfZWswrDtTlIHmpuWKIF60XLR33b+eJXbPkEBS/zbLRu7fDOUf1bU3A4IMrne8YUCRzH3OVi3pbFF/Fvt/BziabhoteewW+9BGGHkUwh/5qho1N3BasY9UoqLX/fkpBmv2uNz1RJIINOzlfkg0hEYquLBdBUXH3WMQFPU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B3A9C4CEEB; Mon, 28 Oct 2024 07:12:19 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t5Jw4-000000053E2-0xwV; Mon, 28 Oct 2024 03:13:08 -0400 Message-ID: <20241028071308.088458856@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 28 Oct 2024 03:12:31 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Peter Zijlstra Subject: [PATCH 3/5] ftrace: Use guard to lock ftrace_lock in cache_mod() References: <20241028071228.575900713@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The ftrace_lock is held throughout cache_mod(), use guard to simplify the error paths. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 44adc34643c9..64997416415e 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -4947,14 +4947,14 @@ static int cache_mod(struct trace_array *tr, { struct ftrace_mod_load *ftrace_mod, *n; struct list_head *head =3D enable ? &tr->mod_trace : &tr->mod_notrace; - int ret; =20 - mutex_lock(&ftrace_lock); + guard(mutex)(&ftrace_lock); =20 /* We do not cache inverse filters */ if (func[0] =3D=3D '!') { + int ret =3D -EINVAL; + func++; - ret =3D -EINVAL; =20 /* Look to remove this hash */ list_for_each_entry_safe(ftrace_mod, n, head, list) { @@ -4970,20 +4970,15 @@ static int cache_mod(struct trace_array *tr, continue; } } - goto out; + return ret; } =20 - ret =3D -EINVAL; /* We only care about modules that have not been loaded yet */ if (module_exists(module)) - goto out; + return -EINVAL; =20 /* Save this string off, and execute it when the module is loaded */ - ret =3D ftrace_add_mod(tr, func, module, enable); - out: - mutex_unlock(&ftrace_lock); - - return ret; + return ftrace_add_mod(tr, func, module, enable); } =20 static int --=20 2.45.2 From nobody Mon Nov 25 09:32:14 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFB0A1917FA; Mon, 28 Oct 2024 07:12:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730099539; cv=none; b=A2cRM8vj79OYa9HllePPZy/Rc1PXVgwHiFkly9jEVa1dxCLB/jf52sygnDj6qIyOBImjJ6wuJgWCwS/AQf6VRG8bd5crL7Db9+3IxwglYUOWamXpao3lnCdJijxn+BmW3bW/REhv5T6EOJtH3GF2dOxWuSH2dqB+duokO7iUgPs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730099539; c=relaxed/simple; bh=lCXGtBtcvfnsJggzf5kZ3rR7Y+fds+4jXs55q+WtBm4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=JQnA9WREADszwA/xU7kq9J3Mayoyk5dggunBMdPGjDSdghb76IORBLsJLOfGPyKf3S/jjatmy9Pe8Y+4nLkhescAxkDF+QpdORHU524E8xgDZBtGC9di3hI42LUiL3c91wQJgHmi5kBj4zGscXE8FUfObqkGSoi4WJWh0KfKUDE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80458C4CEC3; Mon, 28 Oct 2024 07:12:19 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t5Jw4-000000053EW-1bzP; Mon, 28 Oct 2024 03:13:08 -0400 Message-ID: <20241028071308.250787901@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 28 Oct 2024 03:12:32 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Peter Zijlstra Subject: [PATCH 4/5] ftrace: Use guard to take the ftrace_lock in release_probe() References: <20241028071228.575900713@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The ftrace_lock is held throughout the entire release_probe() function. Use guard to simplify any exit paths. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 64997416415e..c0fabd7da5b2 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -5288,7 +5288,7 @@ static void release_probe(struct ftrace_func_probe *p= robe) { struct ftrace_probe_ops *probe_ops; =20 - mutex_lock(&ftrace_lock); + guard(mutex)(&ftrace_lock); =20 WARN_ON(probe->ref <=3D 0); =20 @@ -5306,7 +5306,6 @@ static void release_probe(struct ftrace_func_probe *p= robe) list_del(&probe->list); kfree(probe); } - mutex_unlock(&ftrace_lock); } =20 static void acquire_probe_locked(struct ftrace_func_probe *probe) --=20 2.45.2 From nobody Mon Nov 25 09:32:14 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E3703191F7F; Mon, 28 Oct 2024 07:12:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730099539; cv=none; b=tBiyVIn9AZIu0QbLM9ELwSMpKnYvr1gv0hNZ2w6WXm++XSyFLo+k4M1nivXnobxbrH+9iEqvLxueQOlJ7x9cCoifyALjOiLuqok/lZjOGhobfE8nyhEAMiS5EHIQ428S9gLkQCt7YKf7i6G5wu5E+qKDimJ4fn3UEpj5mLUys9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730099539; c=relaxed/simple; bh=OZ76P+x20FJGM1mhnK21A4nkaPxTbLlBClKvkWtTMVg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=V1WIPk1PFtt5NdfLWt9gcpqyEIFM9/mQiNtYHfNeG45SjcqaWainGrCrRldx9G/1ZKGghRNkXx/QQ20oljL1RME8QH0OSd29Nc6Plk2bvpVrd+Fl2iy8W3i1uD3p02mgv2vyfTUc5dZt9M4LTP7AqkEKi79h2YLsc7GaBoL/FuQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6A53C4CEC7; Mon, 28 Oct 2024 07:12:19 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t5Jw4-000000053F0-2HvF; Mon, 28 Oct 2024 03:13:08 -0400 Message-ID: <20241028071308.406073025@goodmis.org> User-Agent: quilt/0.68 Date: Mon, 28 Oct 2024 03:12:33 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Peter Zijlstra Subject: [PATCH 5/5] ftrace: Use guard to take ftrace_lock in ftrace_graph_set_hash() References: <20241028071228.575900713@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt The ftrace_lock is taken for most of the ftrace_graph_set_hash() function throughout the end. Use guard to take the ftrace_lock to simplify the exit paths. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ftrace.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index c0fabd7da5b2..b4ef469f4fd2 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -6816,12 +6816,10 @@ ftrace_graph_set_hash(struct ftrace_hash *hash, cha= r *buffer) =20 func_g.len =3D strlen(func_g.search); =20 - mutex_lock(&ftrace_lock); + guard(mutex)(&ftrace_lock); =20 - if (unlikely(ftrace_disabled)) { - mutex_unlock(&ftrace_lock); + if (unlikely(ftrace_disabled)) return -ENODEV; - } =20 do_for_each_ftrace_rec(pg, rec) { =20 @@ -6837,7 +6835,7 @@ ftrace_graph_set_hash(struct ftrace_hash *hash, char = *buffer) if (entry) continue; if (add_hash_entry(hash, rec->ip) =3D=3D NULL) - goto out; + return 0; } else { if (entry) { free_hash_entry(hash, entry); @@ -6846,13 +6844,8 @@ ftrace_graph_set_hash(struct ftrace_hash *hash, char= *buffer) } } } while_for_each_ftrace_rec(); -out: - mutex_unlock(&ftrace_lock); =20 - if (fail) - return -EINVAL; - - return 0; + return fail ? -EINVAL : 0; } =20 static ssize_t --=20 2.45.2