[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <tip-ea6a9d530c1779b9bd30944b803820c462f01eac@git.kernel.org>
Date: Mon, 12 Mar 2018 23:19:53 -0700
From: tip-bot for Jiri Olsa <tipbot@...or.com>
To: linux-tip-commits@...r.kernel.org
Cc: will.deacon@....com, chabbi.milind@...il.com, fweisbec@...il.com,
yao.jin@...ux.intel.com, jolsa@...nel.org, onestero@...hat.com,
tglx@...utronix.de, kan.liang@...el.com, namhyung@...nel.org,
dsahern@...il.com, mpe@...erman.id.au, hbathini@...ux.vnet.ibm.com,
jolsa@...hat.com, sukadev@...ux.vnet.ibm.com,
alexander.shishkin@...ux.intel.com, mingo@...nel.org,
torvalds@...ux-foundation.org, acme@...hat.com,
linux-kernel@...r.kernel.org, hpa@...or.com, peterz@...radead.org
Subject: [tip:perf/core] hw_breakpoint: Add modify_bp_slot() function
Commit-ID: ea6a9d530c1779b9bd30944b803820c462f01eac
Gitweb: https://git.kernel.org/tip/ea6a9d530c1779b9bd30944b803820c462f01eac
Author: Jiri Olsa <jolsa@...nel.org>
AuthorDate: Mon, 12 Mar 2018 14:45:43 +0100
Committer: Ingo Molnar <mingo@...nel.org>
CommitDate: Tue, 13 Mar 2018 06:56:07 +0100
hw_breakpoint: Add modify_bp_slot() function
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 <jolsa@...nel.org>
Cc: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@...hat.com>
Cc: David Ahern <dsahern@...il.com>
Cc: Frederic Weisbecker <fweisbec@...il.com>
Cc: Hari Bathini <hbathini@...ux.vnet.ibm.com>
Cc: Jin Yao <yao.jin@...ux.intel.com>
Cc: Jiri Olsa <jolsa@...hat.com>
Cc: Kan Liang <kan.liang@...el.com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Michael Ellerman <mpe@...erman.id.au>
Cc: Milind Chabbi <chabbi.milind@...il.com>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Oleg Nesterov <onestero@...hat.com>
Cc: Peter Zijlstra <peterz@...radead.org>
Cc: Sukadev Bhattiprolu <sukadev@...ux.vnet.ibm.com>
Cc: Thomas Gleixner <tglx@...utronix.de>
Cc: Will Deacon <will.deacon@....com>
Link: http://lkml.kernel.org/r/20180312134548.31532-4-jolsa@kernel.org
Signed-off-by: Ingo Molnar <mingo@...nel.org>
---
kernel/events/hw_breakpoint.c | 46 ++++++++++++++++++++++++++++++++++++-------
1 file changed, 39 insertions(+), 7 deletions(-)
diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c
index 9b31fbcc3305..776948beb4ac 100644
--- a/kernel/events/hw_breakpoint.c
+++ b/kernel/events/hw_breakpoint.c
@@ -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>
/*
@@ -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
@@ -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;
/*
@@ -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;
@@ -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);
Powered by blists - more mailing lists