Skip to contentSkip to conversation

kprobes: drop the unnecessary unlikely()

PATCH In review [email protected] 2 participants 2 messages Jun 13, 2022 – Jun 15, 2022 kprobes

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kprobes: drop the unnecessary unlikely()

From: "binglei.wang" <[email protected]>

!ap is likely when checking re-registering existing kprobe.

	register_kprobe -> warn_kprobe_rereg -> __get_valid_kprobe

!ap is unlikely when checking whether the kprobe is valid on enable/disable ocassion.

	__disable_kprobe/enable_kprobe -> __get_valid_kprobe

Considering these two cases, choose to drop the unlikely() here.

---
 kernel/kprobes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/kprobes.c +1 -1
index f214f8c08..f4a829d98 100644
@@ -1504,7 +1504,7 @@ static struct kprobe *__get_valid_kprobe(struct kprobe *p)
 	lockdep_assert_held(&kprobe_mutex);
 
 	ap = get_kprobe(p->addr);
-	if (unlikely(!ap))
+	if (!ap)
 		return NULL;
 
 	if (p != ap) {
Signature · 1 line
2.27.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · On Mon, 13 Jun 2022 12:25:36 +0800 [email protected] wrote:

From: "binglei.wang" <[email protected]>

!ap is likely when checking re-registering existing kprobe.

	register_kprobe -> warn_kprobe_rereg -> __get_valid_kprobe
Quoted 7 lines

!ap is unlikely when checking whether the kprobe is valid on enable/disable ocassion.

	__disable_kprobe/enable_kprobe -> __get_valid_kprobe

Considering these two cases, choose to drop the unlikely() here.

This looks good to me.

Thank you!

Quoted 20 lines
---
 kernel/kprobes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/kprobes.c +1 -1
index f214f8c08..f4a829d98 100644
@@ -1504,7 +1504,7 @@ static struct kprobe *__get_valid_kprobe(struct kprobe *p)
 	lockdep_assert_held(&kprobe_mutex);
 
 	ap = get_kprobe(p->addr);
-	if (unlikely(!ap))
+	if (!ap)
 		return NULL;
 
 	if (p != ap) {
Signature · 1 line
2.27.0
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>