* [PATCH -tip 1/5] kprobes: Remove meaningless BUG_ON from disarming process
2018-08-21 9:37 [PATCH -tip 0/5] kprobes: Remove BUG_ON from kprobes Masami Hiramatsu
@ 2018-08-21 9:38 ` Masami Hiramatsu
2018-08-21 9:38 ` [PATCH -tip 2/5] kprobes: Remove meaningless BUG_ON from add_new_kprobe Masami Hiramatsu
` (3 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2018-08-21 9:38 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] 8+ messages in thread
* [PATCH -tip 2/5] kprobes: Remove meaningless BUG_ON from add_new_kprobe
2018-08-21 9:37 [PATCH -tip 0/5] kprobes: Remove BUG_ON from kprobes Masami Hiramatsu
2018-08-21 9:38 ` [PATCH -tip 1/5] kprobes: Remove meaningless BUG_ON from disarming process Masami Hiramatsu
@ 2018-08-21 9:38 ` Masami Hiramatsu
2018-08-21 9:39 ` [PATCH -tip 3/5] kprobes: Remove meaningless BUG_ON from reuse_unused_kprobe Masami Hiramatsu
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2018-08-21 9:38 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] 8+ messages in thread
* [PATCH -tip 3/5] kprobes: Remove meaningless BUG_ON from reuse_unused_kprobe
2018-08-21 9:37 [PATCH -tip 0/5] kprobes: Remove BUG_ON from kprobes Masami Hiramatsu
2018-08-21 9:38 ` [PATCH -tip 1/5] kprobes: Remove meaningless BUG_ON from disarming process Masami Hiramatsu
2018-08-21 9:38 ` [PATCH -tip 2/5] kprobes: Remove meaningless BUG_ON from add_new_kprobe Masami Hiramatsu
@ 2018-08-21 9:39 ` Masami Hiramatsu
2018-08-21 9:39 ` [PATCH -tip 4/5] kprobes: Return error if fail to reuse kprobe instead of BUG_ON Masami Hiramatsu
2018-08-21 9:39 ` [PATCH -tip 5/5] kprobes: Don't call BUG_ON if there is a kprobe in use on free list Masami Hiramatsu
4 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2018-08-21 9:39 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] 8+ messages in thread
* [PATCH -tip 4/5] kprobes: Return error if fail to reuse kprobe instead of BUG_ON
2018-08-21 9:37 [PATCH -tip 0/5] kprobes: Remove BUG_ON from kprobes Masami Hiramatsu
` (2 preceding siblings ...)
2018-08-21 9:39 ` [PATCH -tip 3/5] kprobes: Remove meaningless BUG_ON from reuse_unused_kprobe Masami Hiramatsu
@ 2018-08-21 9:39 ` Masami Hiramatsu
2018-08-21 9:39 ` [PATCH -tip 5/5] kprobes: Don't call BUG_ON if there is a kprobe in use on free list Masami Hiramatsu
4 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2018-08-21 9:39 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] 8+ messages in thread
* [PATCH -tip 5/5] kprobes: Don't call BUG_ON if there is a kprobe in use on free list
2018-08-21 9:37 [PATCH -tip 0/5] kprobes: Remove BUG_ON from kprobes Masami Hiramatsu
` (3 preceding siblings ...)
2018-08-21 9:39 ` [PATCH -tip 4/5] kprobes: Return error if fail to reuse kprobe instead of BUG_ON Masami Hiramatsu
@ 2018-08-21 9:39 ` Masami Hiramatsu
2018-09-10 12:23 ` Ingo Molnar
4 siblings, 1 reply; 8+ messages in thread
From: Masami Hiramatsu @ 2018-08-21 9:39 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>
---
kernel/kprobes.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 63c342e5e6c3..e3420364b415 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 (!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] 8+ messages in thread
* Re: [PATCH -tip 5/5] kprobes: Don't call BUG_ON if there is a kprobe in use on free list
2018-08-21 9:39 ` [PATCH -tip 5/5] kprobes: Don't call BUG_ON if there is a kprobe in use on free list Masami Hiramatsu
@ 2018-09-10 12:23 ` Ingo Molnar
2018-09-11 6:36 ` Masami Hiramatsu
0 siblings, 1 reply; 8+ messages in thread
From: Ingo Molnar @ 2018-09-10 12:23 UTC (permalink / raw)
To: Masami Hiramatsu
Cc: Ingo Molnar, Naveen N . Rao, Anil S Keshavamurthy,
David S . Miller, linux-kernel
* Masami Hiramatsu <mhiramat@kernel.org> wrote:
> 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>
> ---
> kernel/kprobes.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 63c342e5e6c3..e3420364b415 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 (!kprobe_unused(&op->kp)) {
> + /*
> + * This must not happen, but if there is a kprobe
> + * still in use, keep it on kprobes hash list.
> + */
> + continue;
If this is an 'impossible' code path then I think it would make sense to add a WARN_ON_ONCE()
here.
Thanks,
Ingo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH -tip 5/5] kprobes: Don't call BUG_ON if there is a kprobe in use on free list
2018-09-10 12:23 ` Ingo Molnar
@ 2018-09-11 6:36 ` Masami Hiramatsu
0 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2018-09-11 6:36 UTC (permalink / raw)
To: Ingo Molnar
Cc: Ingo Molnar, Naveen N . Rao, Anil S Keshavamurthy,
David S . Miller, linux-kernel
On Mon, 10 Sep 2018 14:23:56 +0200
Ingo Molnar <mingo@kernel.org> wrote:
>
> * Masami Hiramatsu <mhiramat@kernel.org> wrote:
>
> > 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>
> > ---
> > kernel/kprobes.c | 8 +++++++-
> > 1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> > index 63c342e5e6c3..e3420364b415 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 (!kprobe_unused(&op->kp)) {
> > + /*
> > + * This must not happen, but if there is a kprobe
> > + * still in use, keep it on kprobes hash list.
> > + */
> > + continue;
>
> If this is an 'impossible' code path then I think it would make sense to add a WARN_ON_ONCE()
> here.
I agree. This means something goes wrong. That is enough reason to warn user.
Thank you!
>
> Thanks,
>
> Ingo
--
Masami Hiramatsu <mhiramat@kernel.org>
^ permalink raw reply [flat|nested] 8+ messages in thread