Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

samples/hw_breakpoint: drop use of kallsyms_lookup_name()

The 'data_breakpoint' test code is the only modular user of
kallsyms_lookup_name(), which was exported as part of fixing the test in
f60d24d2ad04 ("hw-breakpoints: Fix broken hw-breakpoint sample module").

In preparation for un-exporting this symbol, switch the test over to using
__symbol_get(), which can be used to place breakpoints on exported
symbols.

Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Reviewed-by: Quentin Perret <qperret@google.com>
Cc: K.Prasad <prasad@linux.vnet.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Frederic Weisbecker <frederic@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Miroslav Benes <mbenes@suse.cz>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Joe Lawrence <joe.lawrence@redhat.com>
Link: http://lkml.kernel.org/r/20200221114404.14641-3-will@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Will Deacon and committed by
Linus Torvalds
d8a84d33 4800314e

+7 -2
+7 -2
samples/hw_breakpoint/data_breakpoint.c
··· 23 23 24 24 struct perf_event * __percpu *sample_hbp; 25 25 26 - static char ksym_name[KSYM_NAME_LEN] = "pid_max"; 26 + static char ksym_name[KSYM_NAME_LEN] = "jiffies"; 27 27 module_param_string(ksym, ksym_name, KSYM_NAME_LEN, S_IRUGO); 28 28 MODULE_PARM_DESC(ksym, "Kernel symbol to monitor; this module will report any" 29 29 " write operations on the kernel symbol"); ··· 41 41 { 42 42 int ret; 43 43 struct perf_event_attr attr; 44 + void *addr = __symbol_get(ksym_name); 45 + 46 + if (!addr) 47 + return -ENXIO; 44 48 45 49 hw_breakpoint_init(&attr); 46 - attr.bp_addr = kallsyms_lookup_name(ksym_name); 50 + attr.bp_addr = (unsigned long)addr; 47 51 attr.bp_len = HW_BREAKPOINT_LEN_4; 48 52 attr.bp_type = HW_BREAKPOINT_W; 49 53 ··· 70 66 static void __exit hw_break_module_exit(void) 71 67 { 72 68 unregister_wide_hw_breakpoint(sample_hbp); 69 + symbol_put(ksym_name); 73 70 printk(KERN_INFO "HW Breakpoint for %s write uninstalled\n", ksym_name); 74 71 } 75 72