1 |
From a1ca3c314c8269850db5f1417ea2dfd9a254e10b Mon Sep 17 00:00:00 2001 |
2 |
From: Masami Hiramatsu <mhiramat@kernel.org> |
3 |
Date: Tue, 11 Sep 2018 19:20:40 +0900 |
4 |
Subject: [PATCH 059/145] kprobes: Return error if we fail to reuse kprobe |
5 |
instead of BUG_ON() |
6 |
|
7 |
[ Upstream commit 819319fc93461c07b9cdb3064f154bd8cfd48172 ] |
8 |
|
9 |
Make reuse_unused_kprobe() to return error code if |
10 |
it fails to reuse unused kprobe for optprobe instead |
11 |
of calling BUG_ON(). |
12 |
|
13 |
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org> |
14 |
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> |
15 |
Cc: David S . Miller <davem@davemloft.net> |
16 |
Cc: Linus Torvalds <torvalds@linux-foundation.org> |
17 |
Cc: Naveen N . Rao <naveen.n.rao@linux.vnet.ibm.com> |
18 |
Cc: Peter Zijlstra <peterz@infradead.org> |
19 |
Cc: Thomas Gleixner <tglx@linutronix.de> |
20 |
Link: http://lkml.kernel.org/r/153666124040.21306.14150398706331307654.stgit@devbox |
21 |
Signed-off-by: Ingo Molnar <mingo@kernel.org> |
22 |
Signed-off-by: Sasha Levin <sashal@kernel.org> |
23 |
--- |
24 |
kernel/kprobes.c | 27 ++++++++++++++++++++------- |
25 |
1 file changed, 20 insertions(+), 7 deletions(-) |
26 |
|
27 |
diff --git a/kernel/kprobes.c b/kernel/kprobes.c |
28 |
index ab257be4d924..4344381664cc 100644 |
29 |
--- a/kernel/kprobes.c |
30 |
+++ b/kernel/kprobes.c |
31 |
@@ -700,9 +700,10 @@ static void unoptimize_kprobe(struct kprobe *p, bool force) |
32 |
} |
33 |
|
34 |
/* Cancel unoptimizing for reusing */ |
35 |
-static void reuse_unused_kprobe(struct kprobe *ap) |
36 |
+static int reuse_unused_kprobe(struct kprobe *ap) |
37 |
{ |
38 |
struct optimized_kprobe *op; |
39 |
+ int ret; |
40 |
|
41 |
BUG_ON(!kprobe_unused(ap)); |
42 |
/* |
43 |
@@ -714,8 +715,12 @@ static void reuse_unused_kprobe(struct kprobe *ap) |
44 |
/* Enable the probe again */ |
45 |
ap->flags &= ~KPROBE_FLAG_DISABLED; |
46 |
/* Optimize it again (remove from op->list) */ |
47 |
- BUG_ON(!kprobe_optready(ap)); |
48 |
+ ret = kprobe_optready(ap); |
49 |
+ if (ret) |
50 |
+ return ret; |
51 |
+ |
52 |
optimize_kprobe(ap); |
53 |
+ return 0; |
54 |
} |
55 |
|
56 |
/* Remove optimized instructions */ |
57 |
@@ -940,11 +945,16 @@ static void __disarm_kprobe(struct kprobe *p, bool reopt) |
58 |
#define kprobe_disarmed(p) kprobe_disabled(p) |
59 |
#define wait_for_kprobe_optimizer() do {} while (0) |
60 |
|
61 |
-/* There should be no unused kprobes can be reused without optimization */ |
62 |
-static void reuse_unused_kprobe(struct kprobe *ap) |
63 |
+static int reuse_unused_kprobe(struct kprobe *ap) |
64 |
{ |
65 |
+ /* |
66 |
+ * If the optimized kprobe is NOT supported, the aggr kprobe is |
67 |
+ * released at the same time that the last aggregated kprobe is |
68 |
+ * unregistered. |
69 |
+ * Thus there should be no chance to reuse unused kprobe. |
70 |
+ */ |
71 |
printk(KERN_ERR "Error: There should be no unused kprobe here.\n"); |
72 |
- BUG_ON(kprobe_unused(ap)); |
73 |
+ return -EINVAL; |
74 |
} |
75 |
|
76 |
static void free_aggr_kprobe(struct kprobe *p) |
77 |
@@ -1318,9 +1328,12 @@ static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p) |
78 |
goto out; |
79 |
} |
80 |
init_aggr_kprobe(ap, orig_p); |
81 |
- } else if (kprobe_unused(ap)) |
82 |
+ } else if (kprobe_unused(ap)) { |
83 |
/* This probe is going to die. Rescue it */ |
84 |
- reuse_unused_kprobe(ap); |
85 |
+ ret = reuse_unused_kprobe(ap); |
86 |
+ if (ret) |
87 |
+ goto out; |
88 |
+ } |
89 |
|
90 |
if (kprobe_gone(ap)) { |
91 |
/* |
92 |
-- |
93 |
2.19.1 |
94 |
|