From nobody Mon Nov 25 05:19:19 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 2A7971CF5E9 for ; Wed, 30 Oct 2024 05:36:11 +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=1730266572; cv=none; b=bd6DCmJrPnQ6WhmnbadgX/7QPQOi4oo+rjHVDJkJSrDd7Y0/wgHCxfe9WduQscM7ZK8oy5zfDEdIBRgGE4OH4qGyNY6xOBoKNJ1yUazEM3dGP/pk+dWCalycn9hv1haSPOW9njStgo4gQ+E66D6dM6vmqdSXxMY3xW8eKhuAxp4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730266572; c=relaxed/simple; bh=RZcE8kYwVBL5aI5YvzmADyiAuU5C/gpT3PizaPFFQNc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=LknfrF5M/bLRJvnQ6iNo7LamFRX7FHnv0Yo4UCei/HVBJ7PFFPJ6nartHqcFyMtihG15HzXG4G+daoEADYNZTDJw8fEjCcHG1ckPf3B1WD/twRs3nPgZ6W1unNw8yp1Ptp8EEYckzIKnRkMIfbI/qQZS50DH1RPpcE0+Pi//P5o= 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 B0672C4CEE9; Wed, 30 Oct 2024 05:36:11 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t61OC-00000005BCe-3Bw4; Wed, 30 Oct 2024 01:37:04 -0400 Message-ID: <20241030053704.621655585@goodmis.org> User-Agent: quilt/0.68 Date: Wed, 30 Oct 2024 01:36:51 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Ryan Roberts Subject: [for-next][PATCH 1/7] fgraph: Separate size of ret_stack from PAGE_SIZE References: <20241030053650.956861738@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 ret_stack (shadow stack used by function graph infrastructure) is currently defined as PAGE_SIZE. But some architectures which have 64K PAGE_SIZE, this is way overkill. Also there's an effort to allow the PAGE_SIZE to be defined at boot up. Hard code it for now to 4096. In the future, this size may change and even be dependent on specific architectures. Link: https://lore.kernel.org/all/e5067bb8-0fcd-4739-9bca-0e872037d5a1@arm.= com/ Cc: Mark Rutland Cc: Mathieu Desnoyers Link: https://lore.kernel.org/20241019152951.053f9646@rorschach.local.home Suggested-by: Ryan Roberts Reviewed-by: Ryan Roberts Acked-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) --- kernel/trace/fgraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 13fcc25d15a0..4ce87982966a 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -153,7 +153,7 @@ enum { * SHADOW_STACK_OFFSET: The size in long words of the shadow stack * SHADOW_STACK_MAX_OFFSET: The max offset of the stack for a new frame to= be added */ -#define SHADOW_STACK_SIZE (PAGE_SIZE) +#define SHADOW_STACK_SIZE (4096) #define SHADOW_STACK_OFFSET (SHADOW_STACK_SIZE / sizeof(long)) /* Leave on a buffer at the end */ #define SHADOW_STACK_MAX_OFFSET \ --=20 2.45.2 From nobody Mon Nov 25 05:19:19 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 D33371CF289 for ; Wed, 30 Oct 2024 05:36:11 +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=1730266571; cv=none; b=Tj1zMjm0BLm/427S7GCironuexLtGAG7LI3VaY0BVCw7MNSjt8iOMrsi0BBJvLJmqXY/HguUIS+mYYRYFTWRe/NZXPG02B3mU9228vw7M2YadUktx+RWCKPZTNHE9ib3+Shz9VwArwInniANlxdG04FFMOp9MtExH1EvP5Jn2H4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730266571; c=relaxed/simple; bh=XNUK0TECBAjRZzXRzwjfDmT9lMeI7Lr7DwwAmU30QsM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=hE+lTc7OFzcI0VwvDWYbecuOIiUHkOOMijG2vCFTDoPt4OplX+Tsl9j+hB0ua+Oo1s9pjQGh3ZNa2pRt53vo0xY21+KPZ0/F4xnJRBPviB2iyG22lBl1Cd9GrDzo/7FW0NpjOO2mAHkGTKnr+7s7kSfD90VBYgJ89Kt60BRlZvg= 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 8A8AAC4CEE4; Wed, 30 Oct 2024 05:36:11 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t61OC-00000005BD8-3qGF; Wed, 30 Oct 2024 01:37:04 -0400 Message-ID: <20241030053704.781457290@goodmis.org> User-Agent: quilt/0.68 Date: Wed, 30 Oct 2024 01:36:52 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Ryan Roberts Subject: [for-next][PATCH 2/7] fgraph: Give ret_stack its own kmem cache References: <20241030053650.956861738@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 ret_stack (shadow stack used by function graph infrastructure) is created for every task on the system when function graph is enabled. Give it its own kmem_cache. This will make it easier to see how much memory is being used specifically for function graph shadow stacks. In the future, this size may change and may not be a power of two. Having its own cache can also keep it from fragmenting memory. Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Ryan Roberts Link: https://lore.kernel.org/20241026063210.7d4910a7@rorschach.local.home Acked-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) --- kernel/trace/fgraph.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/kernel/trace/fgraph.c b/kernel/trace/fgraph.c index 4ce87982966a..001abf376c0c 100644 --- a/kernel/trace/fgraph.c +++ b/kernel/trace/fgraph.c @@ -172,6 +172,8 @@ enum { DEFINE_STATIC_KEY_FALSE(kill_ftrace_graph); int ftrace_graph_active; =20 +static struct kmem_cache *fgraph_stack_cachep; + static struct fgraph_ops *fgraph_array[FGRAPH_ARRAY_SIZE]; static unsigned long fgraph_array_bitmask; =20 @@ -1022,8 +1024,11 @@ static int alloc_retstack_tasklist(unsigned long **r= et_stack_list) int start =3D 0, end =3D FTRACE_RETSTACK_ALLOC_SIZE; struct task_struct *g, *t; =20 + if (WARN_ON_ONCE(!fgraph_stack_cachep)) + return -ENOMEM; + for (i =3D 0; i < FTRACE_RETSTACK_ALLOC_SIZE; i++) { - ret_stack_list[i] =3D kmalloc(SHADOW_STACK_SIZE, GFP_KERNEL); + ret_stack_list[i] =3D kmem_cache_alloc(fgraph_stack_cachep, GFP_KERNEL); if (!ret_stack_list[i]) { start =3D 0; end =3D i; @@ -1054,7 +1059,7 @@ static int alloc_retstack_tasklist(unsigned long **re= t_stack_list) rcu_read_unlock(); free: for (i =3D start; i < end; i++) - kfree(ret_stack_list[i]); + kmem_cache_free(fgraph_stack_cachep, ret_stack_list[i]); return ret; } =20 @@ -1117,9 +1122,12 @@ void ftrace_graph_init_idle_task(struct task_struct = *t, int cpu) if (ftrace_graph_active) { unsigned long *ret_stack; =20 + if (WARN_ON_ONCE(!fgraph_stack_cachep)) + return; + ret_stack =3D per_cpu(idle_ret_stack, cpu); if (!ret_stack) { - ret_stack =3D kmalloc(SHADOW_STACK_SIZE, GFP_KERNEL); + ret_stack =3D kmem_cache_alloc(fgraph_stack_cachep, GFP_KERNEL); if (!ret_stack) return; per_cpu(idle_ret_stack, cpu) =3D ret_stack; @@ -1139,7 +1147,10 @@ void ftrace_graph_init_task(struct task_struct *t) if (ftrace_graph_active) { unsigned long *ret_stack; =20 - ret_stack =3D kmalloc(SHADOW_STACK_SIZE, GFP_KERNEL); + if (WARN_ON_ONCE(!fgraph_stack_cachep)) + return; + + ret_stack =3D kmem_cache_alloc(fgraph_stack_cachep, GFP_KERNEL); if (!ret_stack) return; graph_init_task(t, ret_stack); @@ -1154,7 +1165,11 @@ void ftrace_graph_exit_task(struct task_struct *t) /* NULL must become visible to IRQs before we free it: */ barrier(); =20 - kfree(ret_stack); + if (ret_stack) { + if (WARN_ON_ONCE(!fgraph_stack_cachep)) + return; + kmem_cache_free(fgraph_stack_cachep, ret_stack); + } } =20 #ifdef CONFIG_DYNAMIC_FTRACE @@ -1294,6 +1309,14 @@ int register_ftrace_graph(struct fgraph_ops *gops) =20 guard(mutex)(&ftrace_lock); =20 + if (!fgraph_stack_cachep) { + fgraph_stack_cachep =3D kmem_cache_create("fgraph_stack", + SHADOW_STACK_SIZE, + SHADOW_STACK_SIZE, 0, NULL); + if (!fgraph_stack_cachep) + return -ENOMEM; + } + if (!fgraph_initialized) { ret =3D cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "fgraph:online", fgraph_cpu_init, NULL); --=20 2.45.2 From nobody Mon Nov 25 05:19:19 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 2A7ED1CF5EC for ; Wed, 30 Oct 2024 05:36:11 +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=1730266572; cv=none; b=jegcVQZz8ehJQPMjV30y1dYEV2WtlyN7xzRHsSPD4G0NswdmW5uu2JHYqOMMmck8cUNELRhLKlp3rHu3eULXakruMFOiUEazE5ninQe2CsVOvDLvGY2WErnWCZGV18pthD1Vn6E28UnBTcH/mfc0grxMbxMRj9xssV9UgNBquvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730266572; c=relaxed/simple; bh=4JFa/lks/etTOtrtpJZCxlzJzGohLAQHk7UPWvizd+E=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=QVU9JizQ4JcwX89t61M73lRh6+c9gkUjFTuAV/sy/tEF9RXoIZe2XUqmSo/X9U0imw8Cvkca6ZOCp0PbbuoWNi4jKZK6zcqSP60NgD1ejBRvlwz7dRFqVH69kpQXDMsnmuflrH4yiYEwCY0j78Xzg4/MRH/Zeu6QIu+msuWHwkw= 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 B6E1FC4CEEB; Wed, 30 Oct 2024 05:36:11 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t61OD-00000005BDe-0KBa; Wed, 30 Oct 2024 01:37:05 -0400 Message-ID: <20241030053704.935817830@goodmis.org> User-Agent: quilt/0.68 Date: Wed, 30 Oct 2024 01:36:53 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Peter Zijlstra Subject: [for-next][PATCH 3/7] fgraph: Use guard(mutex)(&ftrace_lock) for unregister_ftrace_graph() References: <20241030053650.956861738@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. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Thomas Gleixner Cc: Peter Zijlstra Link: https://lore.kernel.org/20241028071307.770550792@goodmis.org 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 05:19:19 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 2A8501CF5EF for ; Wed, 30 Oct 2024 05:36:11 +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=1730266572; cv=none; b=ORe+flSLlKx/ygDjdP9q2u+TJfi/QqgcSwGeME0YnACt76O407nPdYJ2ScXOPMLSmQw7hdgfPRCgxSShGXzzhMYCHMoMmKt7VdPEVlIwyMDwAZE+RPXfANmBFgkikPQMBJz8lW8DWGNv3zvsoWGOEPjJm23ZsYXmDzP1kgjb8UI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730266572; c=relaxed/simple; bh=OuLL3exypl11ULrKaSrCWv5HuV9Jk6r3IsdHk1JgQz8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=rvjvqeqT1g7Eiaj1LU5veEjpcVzhvDa6NKBGc7RMRs3tCdscrNwxkSa4Nh8tjYuvxv05fFToIAJZtGeGLLBb65caPof9ehxlBtXAWveSo3dYt9ipj0Cx6HWr7HdZYgazWY9TjWYCo0e+rR3Vx7xlWB1Wezik5OV4oOcm5rKJr1g= 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 DDFF2C4CEEE; Wed, 30 Oct 2024 05:36:11 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t61OD-00000005BE8-10oi; Wed, 30 Oct 2024 01:37:05 -0400 Message-ID: <20241030053705.099732744@goodmis.org> User-Agent: quilt/0.68 Date: Wed, 30 Oct 2024 01:36:54 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Peter Zijlstra Subject: [for-next][PATCH 4/7] ftrace: Use guard for match_records() References: <20241030053650.956861738@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. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Thomas Gleixner Cc: Peter Zijlstra Link: https://lore.kernel.org/20241028071307.927146604@goodmis.org 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 05:19:19 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 362B21CF5F2 for ; Wed, 30 Oct 2024 05:36:12 +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=1730266572; cv=none; b=XNz3aX9ybAcbJj3Pabtzi2M5EdO10lUi9n8g2/n4DplQxMvp8lM2y1Ub4c9DkUzfTXMLS5LH27D3NFLXKpdUVDTx9w6zesAf6FDQ609gMgCLagHpYEGHi3Zp70xVLyrpy6RUAGPhPouAK1HDIPUe+oC58lx4SXpCW+YKFGFfXXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730266572; c=relaxed/simple; bh=vABfQU5WgsXJEBcJ/VpC+SkLw/4ZGNvqd7pkyDXSqTk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=BokkZrBYpAgLqKEa0ROI7ik0OSiup5Fm+bMzNgaYf21nghc/NE/yrXSU8cCqOXygpYm7eycPCNOPyyJb9zUBBiHw1utixsuvAtkPtcZDNbS6oW6fYf1+WgyMh/JuoohQAJLbcApblTgoR3FRP4uJrPctzlPJJanYTcCb4LODDis= 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 0B86DC4CEE6; Wed, 30 Oct 2024 05:36:12 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t61OD-00000005BEc-1gQg; Wed, 30 Oct 2024 01:37:05 -0400 Message-ID: <20241030053705.261500336@goodmis.org> User-Agent: quilt/0.68 Date: Wed, 30 Oct 2024 01:36:55 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Peter Zijlstra Subject: [for-next][PATCH 5/7] ftrace: Use guard to lock ftrace_lock in cache_mod() References: <20241030053650.956861738@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. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Thomas Gleixner Cc: Peter Zijlstra Link: https://lore.kernel.org/20241028071308.088458856@goodmis.org 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 05:19:19 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 9EE081CFEBF for ; Wed, 30 Oct 2024 05:36:12 +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=1730266572; cv=none; b=VsvdHmXLykdGmaxGHjj0uRCQ9S1Eui0AnF1KHUT3uPdPD6mm5j2OtTqzuNc1jJJ/vk3qZXC7bir7Ru9klG7v4GCLhuLlgG1Er1lkWDZDyMBP+T1+SEz3o7jUBa+LIHIvQL5FbglXz65X7IwAd1zzzat+8gV8yVpaFzAkMRxN45A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730266572; c=relaxed/simple; bh=C/P4YFKOxfIINPnLJNGwaI787j2YgQiojpvwktaVW/Y=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Y/U7dCGW5MYB3lCnbHCHeLHeEYtM1kchI3T7s+1QeU6K4qJndaY23dMQ024WiNJH/N/aQuYyylC9vzFOzQ8+uiwY/04IsG/7ivUoJUW416mLqltNENWX+Tb5w4jj7lf+5MhPumReMSiAsFc4DIBtL6Ky2CYbyQnuz0ZAeItXLSs= 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 473D2C4CEE9; Wed, 30 Oct 2024 05:36:12 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t61OD-00000005BF6-2LUc; Wed, 30 Oct 2024 01:37:05 -0400 Message-ID: <20241030053705.422226102@goodmis.org> User-Agent: quilt/0.68 Date: Wed, 30 Oct 2024 01:36:56 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Peter Zijlstra Subject: [for-next][PATCH 6/7] ftrace: Use guard to take the ftrace_lock in release_probe() References: <20241030053650.956861738@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. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Thomas Gleixner Cc: Peter Zijlstra Link: https://lore.kernel.org/20241028071308.250787901@goodmis.org 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 05:19:19 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 711151CF7C3 for ; Wed, 30 Oct 2024 05:36:12 +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=1730266572; cv=none; b=eea9ift1sFNfe90sAQrliiX1AGBjtGu4pB8yGlqi1llzdSHsZQPlP19L99ZQP38jRYgWFBvyV/fy/Q9KNn2jdtFrifB6zFgHtI8Oai8K5uEDO1WeNSmUegMzik7hHtl/A/ammNmXf+CVlnWpJI24DitxI/j3l4J6ZJcUx4eW+Tg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730266572; c=relaxed/simple; bh=QuMj2j7J2Ycw9ms4XdQMDgXZ6XGNcGjJq/4L8I63wTo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=nhObgNm+xVLvDfqnvuW5gWMC59o5Rf6diHyvtlWvh/wSGq+yspPJD9xAI04bPws53uWaUEz5CvKbJlWRKe8UrsOYfGIfRMF8PSGoTWtzXd0aNgeRGvCm0hcqY0+z9nMp+9uAK4cvKz5w+msWBqyWfBtdzPi5bNAYeE8c4X1mCHw= 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 54C8FC4CEED; Wed, 30 Oct 2024 05:36:12 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.98) (envelope-from ) id 1t61OD-00000005BFa-30L7; Wed, 30 Oct 2024 01:37:05 -0400 Message-ID: <20241030053705.580984615@goodmis.org> User-Agent: quilt/0.68 Date: Wed, 30 Oct 2024 01:36:57 -0400 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Thomas Gleixner , Peter Zijlstra Subject: [for-next][PATCH 7/7] ftrace: Use guard to take ftrace_lock in ftrace_graph_set_hash() References: <20241030053650.956861738@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. Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Thomas Gleixner Cc: Peter Zijlstra Link: https://lore.kernel.org/20241028071308.406073025@goodmis.org 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