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

Configure Feed

Select the types of activity you want to include in your feed.

kprobes: treewide: Cleanup the error messages for kprobes

This clean up the error/notification messages in kprobes related code.
Basically this defines 'pr_fmt()' macros for each files and update
the messages which describes

- what happened,
- what is the kernel going to do or not do,
- is the kernel fine,
- what can the user do about it.

Also, if the message is not needed (e.g. the function returns unique
error code, or other error message is already shown.) remove it,
and replace the message with WARN_*() macros if suitable.

Link: https://lkml.kernel.org/r/163163036568.489837.14085396178727185469.stgit@devnote2

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

authored by

Masami Hiramatsu and committed by
Steven Rostedt (VMware)
9c89bb8e 4402deae

+41 -40
+3 -1
arch/arm/probes/kprobes/core.c
··· 11 11 * Copyright (C) 2007 Marvell Ltd. 12 12 */ 13 13 14 + #define pr_fmt(fmt) "kprobes: " fmt 15 + 14 16 #include <linux/kernel.h> 15 17 #include <linux/kprobes.h> 16 18 #include <linux/module.h> ··· 280 278 break; 281 279 case KPROBE_REENTER: 282 280 /* A nested probe was hit in FIQ, it is a BUG */ 283 - pr_warn("Unrecoverable kprobe detected.\n"); 281 + pr_warn("Failed to recover from reentered kprobes.\n"); 284 282 dump_kprobe(p); 285 283 fallthrough; 286 284 default:
+4 -1
arch/arm64/kernel/probes/kprobes.c
··· 7 7 * Copyright (C) 2013 Linaro Limited. 8 8 * Author: Sandeepa Prabhu <sandeepa.prabhu@linaro.org> 9 9 */ 10 + 11 + #define pr_fmt(fmt) "kprobes: " fmt 12 + 10 13 #include <linux/extable.h> 11 14 #include <linux/kasan.h> 12 15 #include <linux/kernel.h> ··· 221 218 break; 222 219 case KPROBE_HIT_SS: 223 220 case KPROBE_REENTER: 224 - pr_warn("Unrecoverable kprobe detected.\n"); 221 + pr_warn("Failed to recover from reentered kprobes.\n"); 225 222 dump_kprobe(p); 226 223 BUG(); 227 224 break;
+5 -5
arch/csky/kernel/probes/kprobes.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0+ 2 2 3 + #define pr_fmt(fmt) "kprobes: " fmt 4 + 3 5 #include <linux/kprobes.h> 4 6 #include <linux/extable.h> 5 7 #include <linux/slab.h> ··· 79 77 { 80 78 unsigned long probe_addr = (unsigned long)p->addr; 81 79 82 - if (probe_addr & 0x1) { 83 - pr_warn("Address not aligned.\n"); 84 - return -EINVAL; 85 - } 80 + if (probe_addr & 0x1) 81 + return -EILSEQ; 86 82 87 83 /* copy instruction */ 88 84 p->opcode = le32_to_cpu(*p->addr); ··· 225 225 break; 226 226 case KPROBE_HIT_SS: 227 227 case KPROBE_REENTER: 228 - pr_warn("Unrecoverable kprobe detected.\n"); 228 + pr_warn("Failed to recover from reentered kprobes.\n"); 229 229 dump_kprobe(p); 230 230 BUG(); 231 231 break;
+5 -6
arch/mips/kernel/kprobes.c
··· 11 11 * Copyright (C) IBM Corporation, 2002, 2004 12 12 */ 13 13 14 + #define pr_fmt(fmt) "kprobes: " fmt 15 + 14 16 #include <linux/kprobes.h> 15 17 #include <linux/preempt.h> 16 18 #include <linux/uaccess.h> ··· 82 80 insn = p->addr[0]; 83 81 84 82 if (insn_has_ll_or_sc(insn)) { 85 - pr_notice("Kprobes for ll and sc instructions are not" 86 - "supported\n"); 83 + pr_notice("Kprobes for ll and sc instructions are not supported\n"); 87 84 ret = -EINVAL; 88 85 goto out; 89 86 } ··· 220 219 return 0; 221 220 222 221 unaligned: 223 - pr_notice("%s: unaligned epc - sending SIGBUS.\n", current->comm); 222 + pr_notice("Failed to emulate branch instruction because of unaligned epc - sending SIGBUS to %s.\n", current->comm); 224 223 force_sig(SIGBUS); 225 224 return -EFAULT; 226 225 ··· 239 238 regs->cp0_epc = (unsigned long)p->addr; 240 239 else if (insn_has_delayslot(p->opcode)) { 241 240 ret = evaluate_branch_instruction(p, regs, kcb); 242 - if (ret < 0) { 243 - pr_notice("Kprobes: Error in evaluating branch\n"); 241 + if (ret < 0) 244 242 return; 245 - } 246 243 } 247 244 regs->cp0_epc = (unsigned long)&p->ainsn.insn[0]; 248 245 }
+5 -6
arch/riscv/kernel/probes/kprobes.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0+ 2 2 3 + #define pr_fmt(fmt) "kprobes: " fmt 4 + 3 5 #include <linux/kprobes.h> 4 6 #include <linux/extable.h> 5 7 #include <linux/slab.h> ··· 52 50 { 53 51 unsigned long probe_addr = (unsigned long)p->addr; 54 52 55 - if (probe_addr & 0x1) { 56 - pr_warn("Address not aligned.\n"); 57 - 58 - return -EINVAL; 59 - } 53 + if (probe_addr & 0x1) 54 + return -EILSEQ; 60 55 61 56 /* copy instruction */ 62 57 p->opcode = *p->addr; ··· 190 191 break; 191 192 case KPROBE_HIT_SS: 192 193 case KPROBE_REENTER: 193 - pr_warn("Unrecoverable kprobe detected.\n"); 194 + pr_warn("Failed to recover from reentered kprobes.\n"); 194 195 dump_kprobe(p); 195 196 BUG(); 196 197 break;
+3 -1
arch/s390/kernel/kprobes.c
··· 7 7 * s390 port, used ppc64 as template. Mike Grundy <grundym@us.ibm.com> 8 8 */ 9 9 10 + #define pr_fmt(fmt) "kprobes: " fmt 11 + 10 12 #include <linux/moduleloader.h> 11 13 #include <linux/kprobes.h> 12 14 #include <linux/ptrace.h> ··· 261 259 * is a BUG. The code path resides in the .kprobes.text 262 260 * section and is executed with interrupts disabled. 263 261 */ 264 - pr_err("Invalid kprobe detected.\n"); 262 + pr_err("Failed to recover from reentered kprobes.\n"); 265 263 dump_kprobe(p); 266 264 BUG(); 267 265 }
+16 -20
kernel/kprobes.c
··· 18 18 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi 19 19 * <prasanna@in.ibm.com> added function-return probes. 20 20 */ 21 + 22 + #define pr_fmt(fmt) "kprobes: " fmt 23 + 21 24 #include <linux/kprobes.h> 22 25 #include <linux/hash.h> 23 26 #include <linux/init.h> ··· 895 892 optimize_kprobe(p); 896 893 } 897 894 cpus_read_unlock(); 898 - printk(KERN_INFO "Kprobes globally optimized\n"); 895 + pr_info("kprobe jump-optimization is enabled. All kprobes are optimized if possible.\n"); 899 896 out: 900 897 mutex_unlock(&kprobe_mutex); 901 898 } ··· 928 925 929 926 /* Wait for unoptimizing completion */ 930 927 wait_for_kprobe_optimizer(); 931 - printk(KERN_INFO "Kprobes globally unoptimized\n"); 928 + pr_info("kprobe jump-optimization is disabled. All kprobes are based on software breakpoint.\n"); 932 929 } 933 930 934 931 static DEFINE_MUTEX(kprobe_sysctl_mutex); ··· 1006 1003 * unregistered. 1007 1004 * Thus there should be no chance to reuse unused kprobe. 1008 1005 */ 1009 - printk(KERN_ERR "Error: There should be no unused kprobe here.\n"); 1006 + WARN_ON_ONCE(1); 1010 1007 return -EINVAL; 1011 1008 } 1012 1009 ··· 1043 1040 int ret = 0; 1044 1041 1045 1042 ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 0, 0); 1046 - if (ret) { 1047 - pr_debug("Failed to arm kprobe-ftrace at %pS (%d)\n", 1048 - p->addr, ret); 1043 + if (WARN_ONCE(ret < 0, "Failed to arm kprobe-ftrace at %pS (error %d)\n", p->addr, ret)) 1049 1044 return ret; 1050 - } 1051 1045 1052 1046 if (*cnt == 0) { 1053 1047 ret = register_ftrace_function(ops); 1054 - if (ret) { 1055 - pr_debug("Failed to init kprobe-ftrace (%d)\n", ret); 1048 + if (WARN(ret < 0, "Failed to register kprobe-ftrace (error %d)\n", ret)) 1056 1049 goto err_ftrace; 1057 - } 1058 1050 } 1059 1051 1060 1052 (*cnt)++; ··· 1081 1083 1082 1084 if (*cnt == 1) { 1083 1085 ret = unregister_ftrace_function(ops); 1084 - if (WARN(ret < 0, "Failed to unregister kprobe-ftrace (%d)\n", ret)) 1086 + if (WARN(ret < 0, "Failed to unregister kprobe-ftrace (error %d)\n", ret)) 1085 1087 return ret; 1086 1088 } 1087 1089 1088 1090 (*cnt)--; 1089 1091 1090 1092 ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 1, 0); 1091 - WARN_ONCE(ret < 0, "Failed to disarm kprobe-ftrace at %pS (%d)\n", 1093 + WARN_ONCE(ret < 0, "Failed to disarm kprobe-ftrace at %pS (error %d)\n", 1092 1094 p->addr, ret); 1093 1095 return ret; 1094 1096 } ··· 1878 1880 1879 1881 node = node->next; 1880 1882 } 1881 - pr_err("Oops! Kretprobe fails to find correct return address.\n"); 1883 + pr_err("kretprobe: Return address not found, not execute handler. Maybe there is a bug in the kernel.\n"); 1882 1884 BUG_ON(1); 1883 1885 1884 1886 found: ··· 2207 2209 /* Caller must NOT call this in usual path. This is only for critical case */ 2208 2210 void dump_kprobe(struct kprobe *kp) 2209 2211 { 2210 - pr_err("Dumping kprobe:\n"); 2211 - pr_err("Name: %s\nOffset: %x\nAddress: %pS\n", 2212 + pr_err("Dump kprobe:\n.symbol_name = %s, .offset = %x, .addr = %pS\n", 2212 2213 kp->symbol_name, kp->offset, kp->addr); 2213 2214 } 2214 2215 NOKPROBE_SYMBOL(dump_kprobe); ··· 2470 2473 err = populate_kprobe_blacklist(__start_kprobe_blacklist, 2471 2474 __stop_kprobe_blacklist); 2472 2475 if (err) { 2473 - pr_err("kprobes: failed to populate blacklist: %d\n", err); 2474 - pr_err("Please take care of using kprobes.\n"); 2476 + pr_err("Failed to populate blacklist (error %d), kprobes not restricted, be careful using them!\n", err); 2475 2477 } 2476 2478 2477 2479 if (kretprobe_blacklist_size) { ··· 2479 2483 kretprobe_blacklist[i].addr = 2480 2484 kprobe_lookup_name(kretprobe_blacklist[i].name, 0); 2481 2485 if (!kretprobe_blacklist[i].addr) 2482 - printk("kretprobe: lookup failed: %s\n", 2486 + pr_err("Failed to lookup symbol '%s' for kretprobe blacklist. Maybe the target function is removed or renamed.\n", 2483 2487 kretprobe_blacklist[i].name); 2484 2488 } 2485 2489 } ··· 2683 2687 } 2684 2688 2685 2689 if (errors) 2686 - pr_warn("Kprobes globally enabled, but failed to arm %d out of %d probes\n", 2690 + pr_warn("Kprobes globally enabled, but failed to enable %d out of %d probes. Please check which kprobes are kept disabled via debugfs.\n", 2687 2691 errors, total); 2688 2692 else 2689 2693 pr_info("Kprobes globally enabled\n"); ··· 2726 2730 } 2727 2731 2728 2732 if (errors) 2729 - pr_warn("Kprobes globally disabled, but failed to disarm %d out of %d probes\n", 2733 + pr_warn("Kprobes globally disabled, but failed to disable %d out of %d probes. Please check which kprobes are kept enabled via debugfs.\n", 2730 2734 errors, total); 2731 2735 else 2732 2736 pr_info("Kprobes globally disabled\n");