Skip to content

Commit

Permalink
hw_breakpoint: Add modify_bp_slot() function
Browse files Browse the repository at this point in the history
Add the modify_bp_slot() function to keep slot numbers
correct when changing the breakpoint type.

Using existing __release_bp_slot()/__reserve_bp_slot()
call sequence to update the slot counts.

Signed-off-by: Jiri Olsa <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Hari Bathini <[email protected]>
Cc: Jin Yao <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Kan Liang <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Milind Chabbi <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Sukadev Bhattiprolu <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Will Deacon <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
olsajiri authored and Ingo Molnar committed Mar 13, 2018
1 parent 1ad9ff7 commit ea6a9d5
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions kernel/events/hw_breakpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <linux/list.h>
#include <linux/cpu.h>
#include <linux/smp.h>
#include <linux/bug.h>

#include <linux/hw_breakpoint.h>
/*
Expand Down Expand Up @@ -344,6 +345,38 @@ void release_bp_slot(struct perf_event *bp)
mutex_unlock(&nr_bp_mutex);
}

static int __modify_bp_slot(struct perf_event *bp, u64 old_type)
{
int err;

__release_bp_slot(bp, old_type);

err = __reserve_bp_slot(bp, bp->attr.bp_type);
if (err) {
/*
* Reserve the old_type slot back in case
* there's no space for the new type.
*
* This must succeed, because we just released
* the old_type slot in the __release_bp_slot
* call above. If not, something is broken.
*/
WARN_ON(__reserve_bp_slot(bp, old_type));
}

return err;
}

static int modify_bp_slot(struct perf_event *bp, u64 old_type)
{
int ret;

mutex_lock(&nr_bp_mutex);
ret = __modify_bp_slot(bp, old_type);
mutex_unlock(&nr_bp_mutex);
return ret;
}

/*
* Allow the kernel debugger to reserve breakpoint slots without
* taking a lock using the dbg_* variant of for the reserve and
Expand Down Expand Up @@ -435,6 +468,7 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att
u64 old_addr = bp->attr.bp_addr;
u64 old_len = bp->attr.bp_len;
int old_type = bp->attr.bp_type;
bool modify = attr->bp_type != old_type;
int err = 0;

/*
Expand All @@ -452,12 +486,9 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att
bp->attr.bp_type = attr->bp_type;
bp->attr.bp_len = attr->bp_len;

if (attr->disabled)
goto end;

err = validate_hw_breakpoint(bp);
if (!err)
perf_event_enable(bp);
if (!err && modify)
err = modify_bp_slot(bp, old_type);

if (err) {
bp->attr.bp_addr = old_addr;
Expand All @@ -469,9 +500,10 @@ int modify_user_hw_breakpoint(struct perf_event *bp, struct perf_event_attr *att
return err;
}

end:
bp->attr.disabled = attr->disabled;
if (!attr->disabled)
perf_event_enable(bp);

bp->attr.disabled = attr->disabled;
return 0;
}
EXPORT_SYMBOL_GPL(modify_user_hw_breakpoint);
Expand Down

0 comments on commit ea6a9d5

Please sign in to comment.