Skip to content
This repository has been archived by the owner on Aug 27, 2022. It is now read-only.

Commit

Permalink
kprobes: Return error if we fail to reuse kprobe instead of BUG_ON()
Browse files Browse the repository at this point in the history
[ Upstream commit 819319fc93461c07b9cdb3064f154bd8cfd48172 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
mhiramat authored and gregkh committed Nov 13, 2018
1 parent 313c940 commit 82b0f70
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

BUG_ON(!kprobe_unused(ap));
/*
Expand All @@ -714,8 +715,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 */
Expand Down Expand Up @@ -940,11 +945,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)
Expand Down Expand Up @@ -1318,9 +1328,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)) {
/*
Expand Down

0 comments on commit 82b0f70

Please sign in to comment.