From: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
To: Steven Rostedt <rostedt@goodmis.org>,
Peter Zijlstra <peterz@infradead.org>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>,
Masami Hiramatsu <mhiramat@kernel.org>,
"David S . Miller" <davem@davemloft.net>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
Oleg Nesterov <oleg@redhat.com>,
Tzvetomir Stoyanov <tz.stoyanov@gmail.com>,
Naveen N Rao <naveen@kernel.org>,
Josh Poimboeuf <jpoimboe@kernel.org>,
Jason Baron <jbaron@akamai.com>, Ard Biesheuvel <ardb@kernel.org>,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: [PATCH 5/5] kprobes: Remove remaining gotos
Date: Mon, 9 Dec 2024 11:42:04 +0900 [thread overview]
Message-ID: <173371212474.480397.5684523564137819115.stgit@devnote2> (raw)
In-Reply-To: <173371205755.480397.7893311565254712194.stgit@devnote2>
From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Remove remaining gotos from kprobes.c to clean up the code.
This does not use cleanup macros, but changes code flow for avoiding
gotos.
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
---
kernel/kprobes.c | 63 +++++++++++++++++++++++++++---------------------------
1 file changed, 31 insertions(+), 32 deletions(-)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 34cbbb2206f4..030569210670 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1730,29 +1730,31 @@ static int __unregister_kprobe_top(struct kprobe *p)
if (IS_ERR(ap))
return PTR_ERR(ap);
- if (ap == p)
- /*
- * This probe is an independent(and non-optimized) kprobe
- * (not an aggrprobe). Remove from the hash list.
- */
- goto disarmed;
-
- /* Following process expects this probe is an aggrprobe */
- WARN_ON(!kprobe_aggrprobe(ap));
+ WARN_ON(ap != p && !kprobe_aggrprobe(ap));
- if (list_is_singular(&ap->list) && kprobe_disarmed(ap))
+ /*
+ * If the probe is an independent(and non-optimized) kprobe
+ * (not an aggrprobe), the last kprobe on the aggrprobe, or
+ * kprobe is already disarmed, just remove from the hash list.
+ */
+ if (ap == p ||
+ (list_is_singular(&ap->list) && kprobe_disarmed(ap))) {
/*
* !disarmed could be happen if the probe is under delayed
* unoptimizing.
*/
- goto disarmed;
- else {
- /* If disabling probe has special handlers, update aggrprobe */
- if (p->post_handler && !kprobe_gone(p)) {
- list_for_each_entry(list_p, &ap->list, list) {
- if ((list_p != p) && (list_p->post_handler))
- goto noclean;
- }
+ hlist_del_rcu(&ap->hlist);
+ return 0;
+ }
+
+ /* If disabling probe has special handlers, update aggrprobe */
+ if (p->post_handler && !kprobe_gone(p)) {
+ list_for_each_entry(list_p, &ap->list, list) {
+ if ((list_p != p) && (list_p->post_handler))
+ break;
+ }
+ /* No other probe has post_handler */
+ if (list_entry_is_head(list_p, &ap->list, list)) {
/*
* For the kprobe-on-ftrace case, we keep the
* post_handler setting to identify this aggrprobe
@@ -1761,24 +1763,21 @@ static int __unregister_kprobe_top(struct kprobe *p)
if (!kprobe_ftrace(ap))
ap->post_handler = NULL;
}
-noclean:
+ }
+
+ /*
+ * Remove from the aggrprobe: this path will do nothing in
+ * __unregister_kprobe_bottom().
+ */
+ list_del_rcu(&p->list);
+ if (!kprobe_disabled(ap) && !kprobes_all_disarmed)
/*
- * Remove from the aggrprobe: this path will do nothing in
- * __unregister_kprobe_bottom().
+ * Try to optimize this probe again, because post
+ * handler may have been changed.
*/
- list_del_rcu(&p->list);
- if (!kprobe_disabled(ap) && !kprobes_all_disarmed)
- /*
- * Try to optimize this probe again, because post
- * handler may have been changed.
- */
- optimize_kprobe(ap);
- }
+ optimize_kprobe(ap);
return 0;
-disarmed:
- hlist_del_rcu(&ap->hlist);
- return 0;
}
static void __unregister_kprobe_bottom(struct kprobe *p)
prev parent reply other threads:[~2024-12-09 2:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-09 2:40 [PATCH 0/5] kprobes: jump label: Cleanup with guard and __free Masami Hiramatsu (Google)
2024-12-09 2:41 ` [PATCH 1/5] jump_label: Define guard() for jump_label_lock Masami Hiramatsu (Google)
2024-12-09 2:41 ` [PATCH 2/5] kprobes: Use guard() for external locks Masami Hiramatsu (Google)
2024-12-09 11:04 ` Peter Zijlstra
2024-12-10 2:04 ` Masami Hiramatsu
2024-12-10 2:15 ` Masami Hiramatsu
2024-12-10 12:10 ` Peter Zijlstra
2024-12-10 14:12 ` Masami Hiramatsu
2024-12-10 23:17 ` Masami Hiramatsu
2024-12-09 2:41 ` [PATCH 3/5] kprobes: Use guard for rcu_read_lock Masami Hiramatsu (Google)
2024-12-09 2:41 ` [PATCH 4/5] kprobes: Remove unneeded goto Masami Hiramatsu (Google)
2024-12-09 2:42 ` Masami Hiramatsu (Google) [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=173371212474.480397.5684523564137819115.stgit@devnote2 \
--to=mhiramat@kernel.org \
--cc=anil.s.keshavamurthy@intel.com \
--cc=ardb@kernel.org \
--cc=davem@davemloft.net \
--cc=jbaron@akamai.com \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=naveen@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tz.stoyanov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).