linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -tip v2 0/5] kprobes: Remove BUG_ON from kprobes
@ 2018-09-11 10:18 Masami Hiramatsu
  2018-09-11 10:19 ` [PATCH -tip v2 1/5] kprobes: Remove meaningless BUG_ON from disarming process Masami Hiramatsu
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Masami Hiramatsu @ 2018-09-11 10:18 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Naveen N . Rao, Anil S Keshavamurthy, David S . Miller,
	Masami Hiramatsu, linux-kernel

Hi,

Here are v2 patches to remove BUG_ON from kprobes.

Since BUG_ON() kills the machine, it must not be used
for debugging or assertion. These patches remove
meaningless BUG_ON or replace it with return errors.

In this version, I updated 5/5 to use WARN_ON_ONCE()
for unusual case, according to Ingo's comment.

Thank you,

---

Masami Hiramatsu (5):
      kprobes: Remove meaningless BUG_ON from disarming process
      kprobes: Remove meaningless BUG_ON from add_new_kprobe
      kprobes: Remove meaningless BUG_ON from reuse_unused_kprobe
      kprobes: Return error if fail to reuse kprobe instead of BUG_ON
      kprobes: Don't call BUG_ON if there is a kprobe in use on free list


 kernel/kprobes.c |   39 +++++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 12 deletions(-)

--
Masami Hiramatsu (Linaro) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH -tip v2 1/5] kprobes: Remove meaningless BUG_ON from disarming process
  2018-09-11 10:18 [PATCH -tip v2 0/5] kprobes: Remove BUG_ON from kprobes Masami Hiramatsu
@ 2018-09-11 10:19 ` Masami Hiramatsu
  2018-09-12  6:51   ` [tip:perf/core] kprobes: Remove pointless BUG_ON() " tip-bot for Masami Hiramatsu
  2018-09-11 10:19 ` [PATCH -tip v2 2/5] kprobes: Remove meaningless BUG_ON from add_new_kprobe Masami Hiramatsu
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Masami Hiramatsu @ 2018-09-11 10:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Naveen N . Rao, Anil S Keshavamurthy, David S . Miller,
	Masami Hiramatsu, linux-kernel

All aggr_probe at this line are already disarmed by
disable_kprobe() or checked by kprobe_disarmed().
So this BUG_ON() does meaningless check. Remove it.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/kprobes.c |    1 -
 1 file changed, 1 deletion(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index ab257be4d924..d1edd8d5641e 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1704,7 +1704,6 @@ static int __unregister_kprobe_top(struct kprobe *p)
 	return 0;
 
 disarmed:
-	BUG_ON(!kprobe_disarmed(ap));
 	hlist_del_rcu(&ap->hlist);
 	return 0;
 }


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH -tip v2 2/5] kprobes: Remove meaningless BUG_ON from add_new_kprobe
  2018-09-11 10:18 [PATCH -tip v2 0/5] kprobes: Remove BUG_ON from kprobes Masami Hiramatsu
  2018-09-11 10:19 ` [PATCH -tip v2 1/5] kprobes: Remove meaningless BUG_ON from disarming process Masami Hiramatsu
@ 2018-09-11 10:19 ` Masami Hiramatsu
  2018-09-12  6:52   ` [tip:perf/core] kprobes: Remove pointless BUG_ON() from add_new_kprobe() tip-bot for Masami Hiramatsu
  2018-09-11 10:20 ` [PATCH -tip v2 3/5] kprobes: Remove meaningless BUG_ON from reuse_unused_kprobe Masami Hiramatsu
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Masami Hiramatsu @ 2018-09-11 10:19 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Naveen N . Rao, Anil S Keshavamurthy, David S . Miller,
	Masami Hiramatsu, linux-kernel

Before calling add_new_kprobe(), aggr_probe's GONE
flag and kprobe GONE flag are cleared. We don't need
to worry about that flag at this point.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/kprobes.c |    2 --
 1 file changed, 2 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index d1edd8d5641e..231569e1e2c8 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1259,8 +1259,6 @@ NOKPROBE_SYMBOL(cleanup_rp_inst);
 /* Add the new probe to ap->list */
 static int add_new_kprobe(struct kprobe *ap, struct kprobe *p)
 {
-	BUG_ON(kprobe_gone(ap) || kprobe_gone(p));
-
 	if (p->post_handler)
 		unoptimize_kprobe(ap, true);	/* Fall back to normal kprobe */
 


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH -tip v2 3/5] kprobes: Remove meaningless BUG_ON from reuse_unused_kprobe
  2018-09-11 10:18 [PATCH -tip v2 0/5] kprobes: Remove BUG_ON from kprobes Masami Hiramatsu
  2018-09-11 10:19 ` [PATCH -tip v2 1/5] kprobes: Remove meaningless BUG_ON from disarming process Masami Hiramatsu
  2018-09-11 10:19 ` [PATCH -tip v2 2/5] kprobes: Remove meaningless BUG_ON from add_new_kprobe Masami Hiramatsu
@ 2018-09-11 10:20 ` Masami Hiramatsu
  2018-09-12  6:52   ` [tip:perf/core] kprobes: Remove pointless BUG_ON() from reuse_unused_kprobe() tip-bot for Masami Hiramatsu
  2018-09-11 10:20 ` [PATCH -tip v2 4/5] kprobes: Return error if fail to reuse kprobe instead of BUG_ON Masami Hiramatsu
  2018-09-11 10:21 ` [PATCH -tip v2 5/5] kprobes: Don't call BUG_ON if there is a kprobe in use on free list Masami Hiramatsu
  4 siblings, 1 reply; 11+ messages in thread
From: Masami Hiramatsu @ 2018-09-11 10:20 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Naveen N . Rao, Anil S Keshavamurthy, David S . Miller,
	Masami Hiramatsu, linux-kernel

Since reuse_unused_kprobe is called when the given kprobe
is unused, checking it inside again with BUG_ON is
meaningless. Remove it.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/kprobes.c |    1 -
 1 file changed, 1 deletion(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 231569e1e2c8..277a6cbe83db 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -704,7 +704,6 @@ static void reuse_unused_kprobe(struct kprobe *ap)
 {
 	struct optimized_kprobe *op;
 
-	BUG_ON(!kprobe_unused(ap));
 	/*
 	 * Unused kprobe MUST be on the way of delayed unoptimizing (means
 	 * there is still a relative jump) and disabled.


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH -tip v2 4/5] kprobes: Return error if fail to reuse kprobe instead of BUG_ON
  2018-09-11 10:18 [PATCH -tip v2 0/5] kprobes: Remove BUG_ON from kprobes Masami Hiramatsu
                   ` (2 preceding siblings ...)
  2018-09-11 10:20 ` [PATCH -tip v2 3/5] kprobes: Remove meaningless BUG_ON from reuse_unused_kprobe Masami Hiramatsu
@ 2018-09-11 10:20 ` Masami Hiramatsu
  2018-09-12  6:53   ` [tip:perf/core] kprobes: Return error if we fail to reuse kprobe instead of BUG_ON() tip-bot for Masami Hiramatsu
  2018-09-11 10:21 ` [PATCH -tip v2 5/5] kprobes: Don't call BUG_ON if there is a kprobe in use on free list Masami Hiramatsu
  4 siblings, 1 reply; 11+ messages in thread
From: Masami Hiramatsu @ 2018-09-11 10:20 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Naveen N . Rao, Anil S Keshavamurthy, David S . Miller,
	Masami Hiramatsu, linux-kernel

Make reuse_unused_kprobe() to return error code if
it fails to reuse unused kprobe for optprobe instead
of calling BUG_ON().

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 kernel/kprobes.c |   27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 277a6cbe83db..63c342e5e6c3 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -700,9 +700,10 @@ static void unoptimize_kprobe(struct kprobe *p, bool force)
 }
 
 /* Cancel unoptimizing for reusing */
-static void reuse_unused_kprobe(struct kprobe *ap)
+static int reuse_unused_kprobe(struct kprobe *ap)
 {
 	struct optimized_kprobe *op;
+	int ret;
 
 	/*
 	 * Unused kprobe MUST be on the way of delayed unoptimizing (means
@@ -713,8 +714,12 @@ static void reuse_unused_kprobe(struct kprobe *ap)
 	/* Enable the probe again */
 	ap->flags &= ~KPROBE_FLAG_DISABLED;
 	/* Optimize it again (remove from op->list) */
-	BUG_ON(!kprobe_optready(ap));
+	ret = kprobe_optready(ap);
+	if (ret)
+		return ret;
+
 	optimize_kprobe(ap);
+	return 0;
 }
 
 /* Remove optimized instructions */
@@ -939,11 +944,16 @@ static void __disarm_kprobe(struct kprobe *p, bool reopt)
 #define kprobe_disarmed(p)			kprobe_disabled(p)
 #define wait_for_kprobe_optimizer()		do {} while (0)
 
-/* There should be no unused kprobes can be reused without optimization */
-static void reuse_unused_kprobe(struct kprobe *ap)
+static int reuse_unused_kprobe(struct kprobe *ap)
 {
+	/*
+	 * If the optimized kprobe is NOT supported, the aggr kprobe is
+	 * released at the same time that the last aggregated kprobe is
+	 * unregistered.
+	 * Thus there should be no chance to reuse unused kprobe.
+	 */
 	printk(KERN_ERR "Error: There should be no unused kprobe here.\n");
-	BUG_ON(kprobe_unused(ap));
+	return -EINVAL;
 }
 
 static void free_aggr_kprobe(struct kprobe *p)
@@ -1315,9 +1325,12 @@ static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p)
 			goto out;
 		}
 		init_aggr_kprobe(ap, orig_p);
-	} else if (kprobe_unused(ap))
+	} else if (kprobe_unused(ap)) {
 		/* This probe is going to die. Rescue it */
-		reuse_unused_kprobe(ap);
+		ret = reuse_unused_kprobe(ap);
+		if (ret)
+			goto out;
+	}
 
 	if (kprobe_gone(ap)) {
 		/*


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH -tip v2 5/5] kprobes: Don't call BUG_ON if there is a kprobe in use on free list
  2018-09-11 10:18 [PATCH -tip v2 0/5] kprobes: Remove BUG_ON from kprobes Masami Hiramatsu
                   ` (3 preceding siblings ...)
  2018-09-11 10:20 ` [PATCH -tip v2 4/5] kprobes: Return error if fail to reuse kprobe instead of BUG_ON Masami Hiramatsu
@ 2018-09-11 10:21 ` Masami Hiramatsu
  2018-09-12  6:54   ` [tip:perf/core] kprobes: Don't call BUG_ON() " tip-bot for Masami Hiramatsu
  4 siblings, 1 reply; 11+ messages in thread
From: Masami Hiramatsu @ 2018-09-11 10:21 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Naveen N . Rao, Anil S Keshavamurthy, David S . Miller,
	Masami Hiramatsu, linux-kernel

Instead of calling BUG_ON, if we find a kprobe in use on free kprobe
list, just remove it from the list and keep it on kprobe hash list
as same as other in-use kprobes.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
---
 Changes in v2:
  - Use WARN_ON_ONCE() for unusual case.
---
 kernel/kprobes.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 63c342e5e6c3..90e98e233647 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -546,8 +546,14 @@ static void do_free_cleaned_kprobes(void)
 	struct optimized_kprobe *op, *tmp;
 
 	list_for_each_entry_safe(op, tmp, &freeing_list, list) {
-		BUG_ON(!kprobe_unused(&op->kp));
 		list_del_init(&op->list);
+		if (WARN_ON_ONCE(!kprobe_unused(&op->kp))) {
+			/*
+			 * This must not happen, but if there is a kprobe
+			 * still in use, keep it on kprobes hash list.
+			 */
+			continue;
+		}
 		free_aggr_kprobe(&op->kp);
 	}
 }


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tip:perf/core] kprobes: Remove pointless BUG_ON() from disarming process
  2018-09-11 10:19 ` [PATCH -tip v2 1/5] kprobes: Remove meaningless BUG_ON from disarming process Masami Hiramatsu
@ 2018-09-12  6:51   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2018-09-12  6:51 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, torvalds, davem, naveen.n.rao, mhiramat, tglx,
	anil.s.keshavamurthy, linux-kernel, mingo, peterz

Commit-ID:  d0555fc78fdba5646a460e83bd2d8249c539bb89
Gitweb:     https://git.kernel.org/tip/d0555fc78fdba5646a460e83bd2d8249c539bb89
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Tue, 11 Sep 2018 19:19:14 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 12 Sep 2018 08:01:15 +0200

kprobes: Remove pointless BUG_ON() from disarming process

All aggr_probes at this line are already disarmed by
disable_kprobe() or checked by kprobe_disarmed().

So this BUG_ON() is pointless, remove it.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: David S . Miller <davem@davemloft.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Naveen N . Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/153666115463.21306.8799008438116029806.stgit@devbox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/kprobes.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index ab257be4d924..d1edd8d5641e 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1704,7 +1704,6 @@ noclean:
 	return 0;
 
 disarmed:
-	BUG_ON(!kprobe_disarmed(ap));
 	hlist_del_rcu(&ap->hlist);
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tip:perf/core] kprobes: Remove pointless BUG_ON() from add_new_kprobe()
  2018-09-11 10:19 ` [PATCH -tip v2 2/5] kprobes: Remove meaningless BUG_ON from add_new_kprobe Masami Hiramatsu
@ 2018-09-12  6:52   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2018-09-12  6:52 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: davem, anil.s.keshavamurthy, torvalds, hpa, mingo, mhiramat,
	naveen.n.rao, tglx, linux-kernel, peterz

Commit-ID:  c72e6742f62d7bb82a77a41ca53940cb8f73e60f
Gitweb:     https://git.kernel.org/tip/c72e6742f62d7bb82a77a41ca53940cb8f73e60f
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Tue, 11 Sep 2018 19:19:43 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 12 Sep 2018 08:01:15 +0200

kprobes: Remove pointless BUG_ON() from add_new_kprobe()

Before calling add_new_kprobe(), aggr_probe's GONE
flag and kprobe GONE flag are cleared. We don't need
to worry about that flag at this point.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: David S . Miller <davem@davemloft.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Naveen N . Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/153666118298.21306.4915366706875652652.stgit@devbox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/kprobes.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index d1edd8d5641e..231569e1e2c8 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -1259,8 +1259,6 @@ NOKPROBE_SYMBOL(cleanup_rp_inst);
 /* Add the new probe to ap->list */
 static int add_new_kprobe(struct kprobe *ap, struct kprobe *p)
 {
-	BUG_ON(kprobe_gone(ap) || kprobe_gone(p));
-
 	if (p->post_handler)
 		unoptimize_kprobe(ap, true);	/* Fall back to normal kprobe */
 

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tip:perf/core] kprobes: Remove pointless BUG_ON() from reuse_unused_kprobe()
  2018-09-11 10:20 ` [PATCH -tip v2 3/5] kprobes: Remove meaningless BUG_ON from reuse_unused_kprobe Masami Hiramatsu
@ 2018-09-12  6:52   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2018-09-12  6:52 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: torvalds, linux-kernel, hpa, mhiramat, mingo, davem,
	naveen.n.rao, tglx, anil.s.keshavamurthy, peterz

Commit-ID:  a6d18e65dff2b73ceeb187c598b48898e36ad7b1
Gitweb:     https://git.kernel.org/tip/a6d18e65dff2b73ceeb187c598b48898e36ad7b1
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Tue, 11 Sep 2018 19:20:11 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 12 Sep 2018 08:01:16 +0200

kprobes: Remove pointless BUG_ON() from reuse_unused_kprobe()

Since reuse_unused_kprobe() is called when the given kprobe
is unused, checking it inside again with BUG_ON() is
pointless. Remove it.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: David S . Miller <davem@davemloft.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Naveen N . Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/153666121154.21306.17540752948574483565.stgit@devbox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/kprobes.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 231569e1e2c8..277a6cbe83db 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -704,7 +704,6 @@ static void reuse_unused_kprobe(struct kprobe *ap)
 {
 	struct optimized_kprobe *op;
 
-	BUG_ON(!kprobe_unused(ap));
 	/*
 	 * Unused kprobe MUST be on the way of delayed unoptimizing (means
 	 * there is still a relative jump) and disabled.

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tip:perf/core] kprobes: Return error if we fail to reuse kprobe instead of BUG_ON()
  2018-09-11 10:20 ` [PATCH -tip v2 4/5] kprobes: Return error if fail to reuse kprobe instead of BUG_ON Masami Hiramatsu
@ 2018-09-12  6:53   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2018-09-12  6:53 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: davem, linux-kernel, anil.s.keshavamurthy, hpa, naveen.n.rao,
	mhiramat, torvalds, mingo, tglx, peterz

Commit-ID:  819319fc93461c07b9cdb3064f154bd8cfd48172
Gitweb:     https://git.kernel.org/tip/819319fc93461c07b9cdb3064f154bd8cfd48172
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Tue, 11 Sep 2018 19:20:40 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 12 Sep 2018 08:01:16 +0200

kprobes: Return error if we fail to reuse kprobe instead of BUG_ON()

Make reuse_unused_kprobe() to return error code if
it fails to reuse unused kprobe for optprobe instead
of calling BUG_ON().

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: David S . Miller <davem@davemloft.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Naveen N . Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/153666124040.21306.14150398706331307654.stgit@devbox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/kprobes.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 277a6cbe83db..63c342e5e6c3 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -700,9 +700,10 @@ static void unoptimize_kprobe(struct kprobe *p, bool force)
 }
 
 /* Cancel unoptimizing for reusing */
-static void reuse_unused_kprobe(struct kprobe *ap)
+static int reuse_unused_kprobe(struct kprobe *ap)
 {
 	struct optimized_kprobe *op;
+	int ret;
 
 	/*
 	 * Unused kprobe MUST be on the way of delayed unoptimizing (means
@@ -713,8 +714,12 @@ static void reuse_unused_kprobe(struct kprobe *ap)
 	/* Enable the probe again */
 	ap->flags &= ~KPROBE_FLAG_DISABLED;
 	/* Optimize it again (remove from op->list) */
-	BUG_ON(!kprobe_optready(ap));
+	ret = kprobe_optready(ap);
+	if (ret)
+		return ret;
+
 	optimize_kprobe(ap);
+	return 0;
 }
 
 /* Remove optimized instructions */
@@ -939,11 +944,16 @@ static void __disarm_kprobe(struct kprobe *p, bool reopt)
 #define kprobe_disarmed(p)			kprobe_disabled(p)
 #define wait_for_kprobe_optimizer()		do {} while (0)
 
-/* There should be no unused kprobes can be reused without optimization */
-static void reuse_unused_kprobe(struct kprobe *ap)
+static int reuse_unused_kprobe(struct kprobe *ap)
 {
+	/*
+	 * If the optimized kprobe is NOT supported, the aggr kprobe is
+	 * released at the same time that the last aggregated kprobe is
+	 * unregistered.
+	 * Thus there should be no chance to reuse unused kprobe.
+	 */
 	printk(KERN_ERR "Error: There should be no unused kprobe here.\n");
-	BUG_ON(kprobe_unused(ap));
+	return -EINVAL;
 }
 
 static void free_aggr_kprobe(struct kprobe *p)
@@ -1315,9 +1325,12 @@ static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p)
 			goto out;
 		}
 		init_aggr_kprobe(ap, orig_p);
-	} else if (kprobe_unused(ap))
+	} else if (kprobe_unused(ap)) {
 		/* This probe is going to die. Rescue it */
-		reuse_unused_kprobe(ap);
+		ret = reuse_unused_kprobe(ap);
+		if (ret)
+			goto out;
+	}
 
 	if (kprobe_gone(ap)) {
 		/*

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [tip:perf/core] kprobes: Don't call BUG_ON() if there is a kprobe in use on free list
  2018-09-11 10:21 ` [PATCH -tip v2 5/5] kprobes: Don't call BUG_ON if there is a kprobe in use on free list Masami Hiramatsu
@ 2018-09-12  6:54   ` tip-bot for Masami Hiramatsu
  0 siblings, 0 replies; 11+ messages in thread
From: tip-bot for Masami Hiramatsu @ 2018-09-12  6:54 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: davem, hpa, torvalds, peterz, linux-kernel, naveen.n.rao,
	anil.s.keshavamurthy, mingo, mhiramat, tglx

Commit-ID:  cbdd96f5586151e48317d90a403941ec23f12660
Gitweb:     https://git.kernel.org/tip/cbdd96f5586151e48317d90a403941ec23f12660
Author:     Masami Hiramatsu <mhiramat@kernel.org>
AuthorDate: Tue, 11 Sep 2018 19:21:09 +0900
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Wed, 12 Sep 2018 08:01:16 +0200

kprobes: Don't call BUG_ON() if there is a kprobe in use on free list

Instead of calling BUG_ON(), if we find a kprobe in use on free kprobe
list, just remove it from the list and keep it on kprobe hash list
as same as other in-use kprobes.

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: David S . Miller <davem@davemloft.net>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Naveen N . Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/153666126882.21306.10738207224288507996.stgit@devbox
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 kernel/kprobes.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 63c342e5e6c3..90e98e233647 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -546,8 +546,14 @@ static void do_free_cleaned_kprobes(void)
 	struct optimized_kprobe *op, *tmp;
 
 	list_for_each_entry_safe(op, tmp, &freeing_list, list) {
-		BUG_ON(!kprobe_unused(&op->kp));
 		list_del_init(&op->list);
+		if (WARN_ON_ONCE(!kprobe_unused(&op->kp))) {
+			/*
+			 * This must not happen, but if there is a kprobe
+			 * still in use, keep it on kprobes hash list.
+			 */
+			continue;
+		}
 		free_aggr_kprobe(&op->kp);
 	}
 }

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2018-09-12  6:57 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-11 10:18 [PATCH -tip v2 0/5] kprobes: Remove BUG_ON from kprobes Masami Hiramatsu
2018-09-11 10:19 ` [PATCH -tip v2 1/5] kprobes: Remove meaningless BUG_ON from disarming process Masami Hiramatsu
2018-09-12  6:51   ` [tip:perf/core] kprobes: Remove pointless BUG_ON() " tip-bot for Masami Hiramatsu
2018-09-11 10:19 ` [PATCH -tip v2 2/5] kprobes: Remove meaningless BUG_ON from add_new_kprobe Masami Hiramatsu
2018-09-12  6:52   ` [tip:perf/core] kprobes: Remove pointless BUG_ON() from add_new_kprobe() tip-bot for Masami Hiramatsu
2018-09-11 10:20 ` [PATCH -tip v2 3/5] kprobes: Remove meaningless BUG_ON from reuse_unused_kprobe Masami Hiramatsu
2018-09-12  6:52   ` [tip:perf/core] kprobes: Remove pointless BUG_ON() from reuse_unused_kprobe() tip-bot for Masami Hiramatsu
2018-09-11 10:20 ` [PATCH -tip v2 4/5] kprobes: Return error if fail to reuse kprobe instead of BUG_ON Masami Hiramatsu
2018-09-12  6:53   ` [tip:perf/core] kprobes: Return error if we fail to reuse kprobe instead of BUG_ON() tip-bot for Masami Hiramatsu
2018-09-11 10:21 ` [PATCH -tip v2 5/5] kprobes: Don't call BUG_ON if there is a kprobe in use on free list Masami Hiramatsu
2018-09-12  6:54   ` [tip:perf/core] kprobes: Don't call BUG_ON() " tip-bot for Masami Hiramatsu

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).