Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit f60d24d

Browse files
committed
hw-breakpoints: Fix broken hw-breakpoint sample module
The hw-breakpoint sample module has been broken during the hw-breakpoint internals refactoring. Propagate the changes to it. Reported-by: "K. Prasad" <prasad@linux.vnet.ibm.com> Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
1 parent 9f6b3c2 commit f60d24d

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

kernel/hw_breakpoint.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ register_wide_hw_breakpoint(unsigned long addr,
454454
/* return the error if any */
455455
return ERR_PTR(err);
456456
}
457+
EXPORT_SYMBOL_GPL(register_wide_hw_breakpoint);
457458

458459
/**
459460
* unregister_wide_hw_breakpoint - unregister a wide breakpoint in the kernel
@@ -470,7 +471,7 @@ void unregister_wide_hw_breakpoint(struct perf_event **cpu_events)
470471
}
471472
free_percpu(cpu_events);
472473
}
473-
474+
EXPORT_SYMBOL_GPL(unregister_wide_hw_breakpoint);
474475

475476
static struct notifier_block hw_breakpoint_exceptions_nb = {
476477
.notifier_call = hw_breakpoint_exceptions_notify,

kernel/kallsyms.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ unsigned long kallsyms_lookup_name(const char *name)
181181
}
182182
return module_kallsyms_lookup_name(name);
183183
}
184+
EXPORT_SYMBOL_GPL(kallsyms_lookup_name);
184185

185186
int kallsyms_on_each_symbol(int (*fn)(void *, const char *, struct module *,
186187
unsigned long),

samples/hw_breakpoint/data_breakpoint.c

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,19 @@
2727
#include <linux/module.h> /* Needed by all modules */
2828
#include <linux/kernel.h> /* Needed for KERN_INFO */
2929
#include <linux/init.h> /* Needed for the macros */
30+
#include <linux/kallsyms.h>
3031

31-
#include <asm/hw_breakpoint.h>
32+
#include <linux/perf_event.h>
33+
#include <linux/hw_breakpoint.h>
3234

33-
struct hw_breakpoint sample_hbp;
35+
struct perf_event **sample_hbp;
3436

3537
static char ksym_name[KSYM_NAME_LEN] = "pid_max";
3638
module_param_string(ksym, ksym_name, KSYM_NAME_LEN, S_IRUGO);
3739
MODULE_PARM_DESC(ksym, "Kernel symbol to monitor; this module will report any"
3840
" write operations on the kernel symbol");
3941

40-
void sample_hbp_handler(struct hw_breakpoint *temp, struct pt_regs
41-
*temp_regs)
42+
static void sample_hbp_handler(struct perf_event *temp, void *data)
4243
{
4344
printk(KERN_INFO "%s value is changed\n", ksym_name);
4445
dump_stack();
@@ -48,30 +49,34 @@ void sample_hbp_handler(struct hw_breakpoint *temp, struct pt_regs
4849
static int __init hw_break_module_init(void)
4950
{
5051
int ret;
52+
unsigned long addr;
5153

52-
#ifdef CONFIG_X86
53-
sample_hbp.info.name = ksym_name;
54-
sample_hbp.info.type = HW_BREAKPOINT_WRITE;
55-
sample_hbp.info.len = HW_BREAKPOINT_LEN_4;
56-
#endif /* CONFIG_X86 */
54+
addr = kallsyms_lookup_name(ksym_name);
5755

58-
sample_hbp.triggered = (void *)sample_hbp_handler;
56+
sample_hbp = register_wide_hw_breakpoint(addr, HW_BREAKPOINT_LEN_4,
57+
HW_BREAKPOINT_W | HW_BREAKPOINT_R,
58+
sample_hbp_handler, true);
59+
if (IS_ERR(sample_hbp)) {
60+
ret = PTR_ERR(sample_hbp);
61+
goto fail;
62+
} else if (!sample_hbp) {
63+
ret = -EINVAL;
64+
goto fail;
65+
}
5966

60-
ret = register_kernel_hw_breakpoint(&sample_hbp);
61-
62-
if (ret < 0) {
63-
printk(KERN_INFO "Breakpoint registration failed\n");
64-
return ret;
65-
} else
66-
printk(KERN_INFO "HW Breakpoint for %s write installed\n",
67-
ksym_name);
67+
printk(KERN_INFO "HW Breakpoint for %s write installed\n", ksym_name);
6868

6969
return 0;
70+
71+
fail:
72+
printk(KERN_INFO "Breakpoint registration failed\n");
73+
74+
return ret;
7075
}
7176

7277
static void __exit hw_break_module_exit(void)
7378
{
74-
unregister_kernel_hw_breakpoint(&sample_hbp);
79+
unregister_wide_hw_breakpoint(sample_hbp);
7580
printk(KERN_INFO "HW Breakpoint for %s write uninstalled\n", ksym_name);
7681
}
7782

0 commit comments

Comments
 (0)