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: Fix coding style issues

Fix coding style issues reported by checkpatch.pl and update
comments to quote variable names and add "()" to function
name.
One TODO comment in __disarm_kprobe() is removed because
it has been done by following commit.

Link: https://lkml.kernel.org/r/163163037468.489837.4282347782492003960.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)
223a76b2 9c89bb8e

+145 -131
+23 -17
include/linux/kprobes.h
··· 3 3 #define _LINUX_KPROBES_H 4 4 /* 5 5 * Kernel Probes (KProbes) 6 - * include/linux/kprobes.h 7 6 * 8 7 * Copyright (C) IBM Corporation, 2002, 2004 9 8 * ··· 38 39 #define KPROBE_REENTER 0x00000004 39 40 #define KPROBE_HIT_SSDONE 0x00000008 40 41 41 - #else /* CONFIG_KPROBES */ 42 + #else /* !CONFIG_KPROBES */ 42 43 #include <asm-generic/kprobes.h> 43 44 typedef int kprobe_opcode_t; 44 45 struct arch_specific_insn { ··· 227 228 return READ_ONCE(ri->rph->rp); 228 229 } 229 230 230 - #else /* CONFIG_KRETPROBES */ 231 + #else /* !CONFIG_KRETPROBES */ 231 232 static inline void arch_prepare_kretprobe(struct kretprobe *rp, 232 233 struct pt_regs *regs) 233 234 { ··· 238 239 } 239 240 #endif /* CONFIG_KRETPROBES */ 240 241 242 + /* Markers of '_kprobe_blacklist' section */ 243 + extern unsigned long __start_kprobe_blacklist[]; 244 + extern unsigned long __stop_kprobe_blacklist[]; 245 + 241 246 extern struct kretprobe_blackpoint kretprobe_blacklist[]; 242 247 243 248 #ifdef CONFIG_KPROBES_SANITY_TEST 244 249 extern int init_test_probes(void); 245 - #else 250 + #else /* !CONFIG_KPROBES_SANITY_TEST */ 246 251 static inline int init_test_probes(void) 247 252 { 248 253 return 0; ··· 306 303 #define KPROBE_OPTINSN_PAGE_SYM "kprobe_optinsn_page" 307 304 int kprobe_cache_get_kallsym(struct kprobe_insn_cache *c, unsigned int *symnum, 308 305 unsigned long *value, char *type, char *sym); 309 - #else /* __ARCH_WANT_KPROBES_INSN_SLOT */ 306 + #else /* !__ARCH_WANT_KPROBES_INSN_SLOT */ 310 307 #define DEFINE_INSN_CACHE_OPS(__name) \ 311 308 static inline bool is_kprobe_##__name##_slot(unsigned long addr) \ 312 309 { \ ··· 348 345 extern int proc_kprobes_optimization_handler(struct ctl_table *table, 349 346 int write, void *buffer, 350 347 size_t *length, loff_t *ppos); 351 - #endif 348 + #endif /* CONFIG_SYSCTL */ 352 349 extern void wait_for_kprobe_optimizer(void); 353 - #else 350 + #else /* !CONFIG_OPTPROBES */ 354 351 static inline void wait_for_kprobe_optimizer(void) { } 355 352 #endif /* CONFIG_OPTPROBES */ 353 + 356 354 #ifdef CONFIG_KPROBES_ON_FTRACE 357 355 extern void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, 358 356 struct ftrace_ops *ops, struct ftrace_regs *fregs); ··· 363 359 { 364 360 return -EINVAL; 365 361 } 366 - #endif 362 + #endif /* CONFIG_KPROBES_ON_FTRACE */ 367 363 368 364 /* Get the kprobe at this addr (if any) - called with preemption disabled */ 369 365 struct kprobe *get_kprobe(void *addr); ··· 371 367 /* kprobe_running() will just return the current_kprobe on this CPU */ 372 368 static inline struct kprobe *kprobe_running(void) 373 369 { 374 - return (__this_cpu_read(current_kprobe)); 370 + return __this_cpu_read(current_kprobe); 375 371 } 376 372 377 373 static inline void reset_current_kprobe(void) ··· 435 431 } 436 432 static inline int register_kprobe(struct kprobe *p) 437 433 { 438 - return -ENOSYS; 434 + return -EOPNOTSUPP; 439 435 } 440 436 static inline int register_kprobes(struct kprobe **kps, int num) 441 437 { 442 - return -ENOSYS; 438 + return -EOPNOTSUPP; 443 439 } 444 440 static inline void unregister_kprobe(struct kprobe *p) 445 441 { ··· 449 445 } 450 446 static inline int register_kretprobe(struct kretprobe *rp) 451 447 { 452 - return -ENOSYS; 448 + return -EOPNOTSUPP; 453 449 } 454 450 static inline int register_kretprobes(struct kretprobe **rps, int num) 455 451 { 456 - return -ENOSYS; 452 + return -EOPNOTSUPP; 457 453 } 458 454 static inline void unregister_kretprobe(struct kretprobe *rp) 459 455 { ··· 469 465 } 470 466 static inline int disable_kprobe(struct kprobe *kp) 471 467 { 472 - return -ENOSYS; 468 + return -EOPNOTSUPP; 473 469 } 474 470 static inline int enable_kprobe(struct kprobe *kp) 475 471 { 476 - return -ENOSYS; 472 + return -EOPNOTSUPP; 477 473 } 478 474 479 475 static inline bool within_kprobe_blacklist(unsigned long addr) ··· 486 482 return -ERANGE; 487 483 } 488 484 #endif /* CONFIG_KPROBES */ 485 + 489 486 static inline int disable_kretprobe(struct kretprobe *rp) 490 487 { 491 488 return disable_kprobe(&rp->kp); ··· 501 496 { 502 497 return false; 503 498 } 504 - #endif 499 + #endif /* !CONFIG_KPROBES */ 500 + 505 501 #ifndef CONFIG_OPTPROBES 506 502 static inline bool is_kprobe_optinsn_slot(unsigned long addr) 507 503 { 508 504 return false; 509 505 } 510 - #endif 506 + #endif /* !CONFIG_OPTPROBES */ 511 507 512 508 /* Returns true if kprobes handled the fault */ 513 509 static nokprobe_inline bool kprobe_page_fault(struct pt_regs *regs,
+122 -114
kernel/kprobes.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 2 /* 3 3 * Kernel Probes (KProbes) 4 - * kernel/kprobes.c 5 4 * 6 5 * Copyright (C) IBM Corporation, 2002, 2004 7 6 * ··· 51 52 52 53 static int kprobes_initialized; 53 54 /* kprobe_table can be accessed by 54 - * - Normal hlist traversal and RCU add/del under kprobe_mutex is held. 55 + * - Normal hlist traversal and RCU add/del under 'kprobe_mutex' is held. 55 56 * Or 56 57 * - RCU hlist traversal under disabling preempt (breakpoint handlers) 57 58 */ 58 59 static struct hlist_head kprobe_table[KPROBE_TABLE_SIZE]; 59 60 60 - /* NOTE: change this value only with kprobe_mutex held */ 61 + /* NOTE: change this value only with 'kprobe_mutex' held */ 61 62 static bool kprobes_all_disarmed; 62 63 63 - /* This protects kprobe_table and optimizing_list */ 64 + /* This protects 'kprobe_table' and 'optimizing_list' */ 64 65 static DEFINE_MUTEX(kprobe_mutex); 65 - static DEFINE_PER_CPU(struct kprobe *, kprobe_instance) = NULL; 66 + static DEFINE_PER_CPU(struct kprobe *, kprobe_instance); 66 67 67 68 kprobe_opcode_t * __weak kprobe_lookup_name(const char *name, 68 69 unsigned int __unused) ··· 70 71 return ((kprobe_opcode_t *)(kallsyms_lookup_name(name))); 71 72 } 72 73 73 - /* Blacklist -- list of struct kprobe_blacklist_entry */ 74 + /* 75 + * Blacklist -- list of 'struct kprobe_blacklist_entry' to store info where 76 + * kprobes can not probe. 77 + */ 74 78 static LIST_HEAD(kprobe_blacklist); 75 79 76 80 #ifdef __ARCH_WANT_KPROBES_INSN_SLOT 77 81 /* 78 - * kprobe->ainsn.insn points to the copy of the instruction to be 82 + * 'kprobe::ainsn.insn' points to the copy of the instruction to be 79 83 * single-stepped. x86_64, POWER4 and above have no-exec support and 80 84 * stepping on the instruction on a vmalloced/kmalloced/data page 81 85 * is a recipe for disaster ··· 109 107 110 108 void __weak *alloc_insn_page(void) 111 109 { 110 + /* 111 + * Use module_alloc() so this page is within +/- 2GB of where the 112 + * kernel image and loaded module images reside. This is required 113 + * for most of the architectures. 114 + * (e.g. x86-64 needs this to handle the %rip-relative fixups.) 115 + */ 112 116 return module_alloc(PAGE_SIZE); 113 117 } 114 118 ··· 150 142 list_for_each_entry_rcu(kip, &c->pages, list) { 151 143 if (kip->nused < slots_per_page(c)) { 152 144 int i; 145 + 153 146 for (i = 0; i < slots_per_page(c); i++) { 154 147 if (kip->slot_used[i] == SLOT_CLEAN) { 155 148 kip->slot_used[i] = SLOT_USED; ··· 176 167 if (!kip) 177 168 goto out; 178 169 179 - /* 180 - * Use module_alloc so this page is within +/- 2GB of where the 181 - * kernel image and loaded module images reside. This is required 182 - * so x86_64 can correctly handle the %rip-relative fixups. 183 - */ 184 170 kip->insns = c->alloc(); 185 171 if (!kip->insns) { 186 172 kfree(kip); ··· 237 233 238 234 list_for_each_entry_safe(kip, next, &c->pages, list) { 239 235 int i; 236 + 240 237 if (kip->ngarbage == 0) 241 238 continue; 242 239 kip->ngarbage = 0; /* we will collect all garbages */ ··· 318 313 list_for_each_entry_rcu(kip, &c->pages, list) { 319 314 if ((*symnum)--) 320 315 continue; 321 - strlcpy(sym, c->sym, KSYM_NAME_LEN); 316 + strscpy(sym, c->sym, KSYM_NAME_LEN); 322 317 *type = 't'; 323 318 *value = (unsigned long)kip->insns; 324 319 ret = 0; ··· 366 361 367 362 /* 368 363 * This routine is called either: 369 - * - under the kprobe_mutex - during kprobe_[un]register() 370 - * OR 371 - * - with preemption disabled - from arch/xxx/kernel/kprobes.c 364 + * - under the 'kprobe_mutex' - during kprobe_[un]register(). 365 + * OR 366 + * - with preemption disabled - from architecture specific code. 372 367 */ 373 368 struct kprobe *get_kprobe(void *addr) 374 369 { ··· 388 383 389 384 static int aggr_pre_handler(struct kprobe *p, struct pt_regs *regs); 390 385 391 - /* Return true if the kprobe is an aggregator */ 386 + /* Return true if 'p' is an aggregator */ 392 387 static inline int kprobe_aggrprobe(struct kprobe *p) 393 388 { 394 389 return p->pre_handler == aggr_pre_handler; 395 390 } 396 391 397 - /* Return true(!0) if the kprobe is unused */ 392 + /* Return true if 'p' is unused */ 398 393 static inline int kprobe_unused(struct kprobe *p) 399 394 { 400 395 return kprobe_aggrprobe(p) && kprobe_disabled(p) && 401 396 list_empty(&p->list); 402 397 } 403 398 404 - /* 405 - * Keep all fields in the kprobe consistent 406 - */ 399 + /* Keep all fields in the kprobe consistent. */ 407 400 static inline void copy_kprobe(struct kprobe *ap, struct kprobe *p) 408 401 { 409 402 memcpy(&p->opcode, &ap->opcode, sizeof(kprobe_opcode_t)); ··· 409 406 } 410 407 411 408 #ifdef CONFIG_OPTPROBES 412 - /* NOTE: change this value only with kprobe_mutex held */ 409 + /* NOTE: This is protected by 'kprobe_mutex'. */ 413 410 static bool kprobes_allow_optimization; 414 411 415 412 /* 416 - * Call all pre_handler on the list, but ignores its return value. 413 + * Call all 'kprobe::pre_handler' on the list, but ignores its return value. 417 414 * This must be called from arch-dep optimized caller. 418 415 */ 419 416 void opt_pre_handler(struct kprobe *p, struct pt_regs *regs) ··· 441 438 kfree(op); 442 439 } 443 440 444 - /* Return true(!0) if the kprobe is ready for optimization. */ 441 + /* Return true if the kprobe is ready for optimization. */ 445 442 static inline int kprobe_optready(struct kprobe *p) 446 443 { 447 444 struct optimized_kprobe *op; ··· 454 451 return 0; 455 452 } 456 453 457 - /* Return true(!0) if the kprobe is disarmed. Note: p must be on hash list */ 454 + /* Return true if the kprobe is disarmed. Note: p must be on hash list */ 458 455 static inline int kprobe_disarmed(struct kprobe *p) 459 456 { 460 457 struct optimized_kprobe *op; ··· 468 465 return kprobe_disabled(p) && list_empty(&op->list); 469 466 } 470 467 471 - /* Return true(!0) if the probe is queued on (un)optimizing lists */ 468 + /* Return true if the probe is queued on (un)optimizing lists */ 472 469 static int kprobe_queued(struct kprobe *p) 473 470 { 474 471 struct optimized_kprobe *op; ··· 483 480 484 481 /* 485 482 * Return an optimized kprobe whose optimizing code replaces 486 - * instructions including addr (exclude breakpoint). 483 + * instructions including 'addr' (exclude breakpoint). 487 484 */ 488 485 static struct kprobe *get_optimized_kprobe(unsigned long addr) 489 486 { ··· 504 501 return NULL; 505 502 } 506 503 507 - /* Optimization staging list, protected by kprobe_mutex */ 504 + /* Optimization staging list, protected by 'kprobe_mutex' */ 508 505 static LIST_HEAD(optimizing_list); 509 506 static LIST_HEAD(unoptimizing_list); 510 507 static LIST_HEAD(freeing_list); ··· 515 512 516 513 /* 517 514 * Optimize (replace a breakpoint with a jump) kprobes listed on 518 - * optimizing_list. 515 + * 'optimizing_list'. 519 516 */ 520 517 static void do_optimize_kprobes(void) 521 518 { 522 519 lockdep_assert_held(&text_mutex); 523 520 /* 524 - * The optimization/unoptimization refers online_cpus via 525 - * stop_machine() and cpu-hotplug modifies online_cpus. 526 - * And same time, text_mutex will be held in cpu-hotplug and here. 527 - * This combination can cause a deadlock (cpu-hotplug try to lock 528 - * text_mutex but stop_machine can not be done because online_cpus 529 - * has been changed) 530 - * To avoid this deadlock, caller must have locked cpu hotplug 531 - * for preventing cpu-hotplug outside of text_mutex locking. 521 + * The optimization/unoptimization refers 'online_cpus' via 522 + * stop_machine() and cpu-hotplug modifies the 'online_cpus'. 523 + * And same time, 'text_mutex' will be held in cpu-hotplug and here. 524 + * This combination can cause a deadlock (cpu-hotplug tries to lock 525 + * 'text_mutex' but stop_machine() can not be done because 526 + * the 'online_cpus' has been changed) 527 + * To avoid this deadlock, caller must have locked cpu-hotplug 528 + * for preventing cpu-hotplug outside of 'text_mutex' locking. 532 529 */ 533 530 lockdep_assert_cpus_held(); 534 531 ··· 542 539 543 540 /* 544 541 * Unoptimize (replace a jump with a breakpoint and remove the breakpoint 545 - * if need) kprobes listed on unoptimizing_list. 542 + * if need) kprobes listed on 'unoptimizing_list'. 546 543 */ 547 544 static void do_unoptimize_kprobes(void) 548 545 { ··· 557 554 return; 558 555 559 556 arch_unoptimize_kprobes(&unoptimizing_list, &freeing_list); 560 - /* Loop free_list for disarming */ 557 + /* Loop on 'freeing_list' for disarming */ 561 558 list_for_each_entry_safe(op, tmp, &freeing_list, list) { 562 559 /* Switching from detour code to origin */ 563 560 op->kp.flags &= ~KPROBE_FLAG_OPTIMIZED; ··· 568 565 /* 569 566 * Remove unused probes from hash list. After waiting 570 567 * for synchronization, these probes are reclaimed. 571 - * (reclaiming is done by do_free_cleaned_kprobes.) 568 + * (reclaiming is done by do_free_cleaned_kprobes().) 572 569 */ 573 570 hlist_del_rcu(&op->kp.hlist); 574 571 } else ··· 576 573 } 577 574 } 578 575 579 - /* Reclaim all kprobes on the free_list */ 576 + /* Reclaim all kprobes on the 'freeing_list' */ 580 577 static void do_free_cleaned_kprobes(void) 581 578 { 582 579 struct optimized_kprobe *op, *tmp; ··· 648 645 while (!list_empty(&optimizing_list) || !list_empty(&unoptimizing_list)) { 649 646 mutex_unlock(&kprobe_mutex); 650 647 651 - /* this will also make optimizing_work execute immmediately */ 648 + /* This will also make 'optimizing_work' execute immmediately */ 652 649 flush_delayed_work(&optimizing_work); 653 - /* @optimizing_work might not have been queued yet, relax */ 650 + /* 'optimizing_work' might not have been queued yet, relax */ 654 651 cpu_relax(); 655 652 656 653 mutex_lock(&kprobe_mutex); ··· 681 678 (kprobe_disabled(p) || kprobes_all_disarmed)) 682 679 return; 683 680 684 - /* kprobes with post_handler can not be optimized */ 681 + /* kprobes with 'post_handler' can not be optimized */ 685 682 if (p->post_handler) 686 683 return; 687 684 ··· 701 698 } 702 699 op->kp.flags |= KPROBE_FLAG_OPTIMIZED; 703 700 704 - /* On unoptimizing/optimizing_list, op must have OPTIMIZED flag */ 701 + /* 702 + * On the 'unoptimizing_list' and 'optimizing_list', 703 + * 'op' must have OPTIMIZED flag 704 + */ 705 705 if (WARN_ON_ONCE(!list_empty(&op->list))) 706 706 return; 707 707 ··· 774 768 WARN_ON_ONCE(list_empty(&op->list)); 775 769 /* Enable the probe again */ 776 770 ap->flags &= ~KPROBE_FLAG_DISABLED; 777 - /* Optimize it again (remove from op->list) */ 771 + /* Optimize it again. (remove from 'op->list') */ 778 772 if (!kprobe_optready(ap)) 779 773 return -EINVAL; 780 774 ··· 824 818 __prepare_optimized_kprobe(op, p); 825 819 } 826 820 827 - /* Allocate new optimized_kprobe and try to prepare optimized instructions */ 821 + /* Allocate new optimized_kprobe and try to prepare optimized instructions. */ 828 822 static struct kprobe *alloc_aggr_kprobe(struct kprobe *p) 829 823 { 830 824 struct optimized_kprobe *op; ··· 843 837 static void init_aggr_kprobe(struct kprobe *ap, struct kprobe *p); 844 838 845 839 /* 846 - * Prepare an optimized_kprobe and optimize it 847 - * NOTE: p must be a normal registered kprobe 840 + * Prepare an optimized_kprobe and optimize it. 841 + * NOTE: 'p' must be a normal registered kprobe. 848 842 */ 849 843 static void try_to_optimize_kprobe(struct kprobe *p) 850 844 { 851 845 struct kprobe *ap; 852 846 struct optimized_kprobe *op; 853 847 854 - /* Impossible to optimize ftrace-based kprobe */ 848 + /* Impossible to optimize ftrace-based kprobe. */ 855 849 if (kprobe_ftrace(p)) 856 850 return; 857 851 858 - /* For preparing optimization, jump_label_text_reserved() is called */ 852 + /* For preparing optimization, jump_label_text_reserved() is called. */ 859 853 cpus_read_lock(); 860 854 jump_label_lock(); 861 855 mutex_lock(&text_mutex); ··· 866 860 867 861 op = container_of(ap, struct optimized_kprobe, kp); 868 862 if (!arch_prepared_optinsn(&op->optinsn)) { 869 - /* If failed to setup optimizing, fallback to kprobe */ 863 + /* If failed to setup optimizing, fallback to kprobe. */ 870 864 arch_remove_optimized_kprobe(op); 871 865 kfree(op); 872 866 goto out; 873 867 } 874 868 875 869 init_aggr_kprobe(ap, p); 876 - optimize_kprobe(ap); /* This just kicks optimizer thread */ 870 + optimize_kprobe(ap); /* This just kicks optimizer thread. */ 877 871 878 872 out: 879 873 mutex_unlock(&text_mutex); ··· 888 882 unsigned int i; 889 883 890 884 mutex_lock(&kprobe_mutex); 891 - /* If optimization is already allowed, just return */ 885 + /* If optimization is already allowed, just return. */ 892 886 if (kprobes_allow_optimization) 893 887 goto out; 894 888 ··· 914 908 unsigned int i; 915 909 916 910 mutex_lock(&kprobe_mutex); 917 - /* If optimization is already prohibited, just return */ 911 + /* If optimization is already prohibited, just return. */ 918 912 if (!kprobes_allow_optimization) { 919 913 mutex_unlock(&kprobe_mutex); 920 914 return; ··· 932 926 cpus_read_unlock(); 933 927 mutex_unlock(&kprobe_mutex); 934 928 935 - /* Wait for unoptimizing completion */ 929 + /* Wait for unoptimizing completion. */ 936 930 wait_for_kprobe_optimizer(); 937 931 pr_info("kprobe jump-optimization is disabled. All kprobes are based on software breakpoint.\n"); 938 932 } ··· 959 953 } 960 954 #endif /* CONFIG_SYSCTL */ 961 955 962 - /* Put a breakpoint for a probe. Must be called with text_mutex locked */ 956 + /* Put a breakpoint for a probe. Must be called with 'text_mutex' locked. */ 963 957 static void __arm_kprobe(struct kprobe *p) 964 958 { 965 959 struct kprobe *_p; 966 960 967 - /* Check collision with other optimized kprobes */ 961 + /* Find the overlapping optimized kprobes. */ 968 962 _p = get_optimized_kprobe((unsigned long)p->addr); 969 963 if (unlikely(_p)) 970 964 /* Fallback to unoptimized kprobe */ ··· 974 968 optimize_kprobe(p); /* Try to optimize (add kprobe to a list) */ 975 969 } 976 970 977 - /* Remove the breakpoint of a probe. Must be called with text_mutex locked */ 971 + /* Remove the breakpoint of a probe. Must be called with 'text_mutex' locked. */ 978 972 static void __disarm_kprobe(struct kprobe *p, bool reopt) 979 973 { 980 974 struct kprobe *_p; ··· 984 978 985 979 if (!kprobe_queued(p)) { 986 980 arch_disarm_kprobe(p); 987 - /* If another kprobe was blocked, optimize it. */ 981 + /* If another kprobe was blocked, re-optimize it. */ 988 982 _p = get_optimized_kprobe((unsigned long)p->addr); 989 983 if (unlikely(_p) && reopt) 990 984 optimize_kprobe(_p); 991 985 } 992 - /* TODO: reoptimize others after unoptimized this probe */ 986 + /* 987 + * TODO: Since unoptimization and real disarming will be done by 988 + * the worker thread, we can not check whether another probe are 989 + * unoptimized because of this probe here. It should be re-optimized 990 + * by the worker thread. 991 + */ 993 992 } 994 993 995 994 #else /* !CONFIG_OPTPROBES */ ··· 1047 1036 static int kprobe_ipmodify_enabled; 1048 1037 static int kprobe_ftrace_enabled; 1049 1038 1050 - /* Caller must lock kprobe_mutex */ 1039 + /* Caller must lock 'kprobe_mutex' */ 1051 1040 static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, 1052 1041 int *cnt) 1053 1042 { ··· 1084 1073 ipmodify ? &kprobe_ipmodify_enabled : &kprobe_ftrace_enabled); 1085 1074 } 1086 1075 1087 - /* Caller must lock kprobe_mutex */ 1076 + /* Caller must lock 'kprobe_mutex'. */ 1088 1077 static int __disarm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, 1089 1078 int *cnt) 1090 1079 { ··· 1133 1122 return arch_prepare_kprobe(p); 1134 1123 } 1135 1124 1136 - /* Arm a kprobe with text_mutex */ 1125 + /* Arm a kprobe with 'text_mutex'. */ 1137 1126 static int arm_kprobe(struct kprobe *kp) 1138 1127 { 1139 1128 if (unlikely(kprobe_ftrace(kp))) ··· 1148 1137 return 0; 1149 1138 } 1150 1139 1151 - /* Disarm a kprobe with text_mutex */ 1140 + /* Disarm a kprobe with 'text_mutex'. */ 1152 1141 static int disarm_kprobe(struct kprobe *kp, bool reopt) 1153 1142 { 1154 1143 if (unlikely(kprobe_ftrace(kp))) ··· 1198 1187 } 1199 1188 NOKPROBE_SYMBOL(aggr_post_handler); 1200 1189 1201 - /* Walks the list and increments nmissed count for multiprobe case */ 1190 + /* Walks the list and increments 'nmissed' if 'p' has child probes. */ 1202 1191 void kprobes_inc_nmissed_count(struct kprobe *p) 1203 1192 { 1204 1193 struct kprobe *kp; 1194 + 1205 1195 if (!kprobe_aggrprobe(p)) { 1206 1196 p->nmissed++; 1207 1197 } else { 1208 1198 list_for_each_entry_rcu(kp, &p->list, list) 1209 1199 kp->nmissed++; 1210 1200 } 1211 - return; 1212 1201 } 1213 1202 NOKPROBE_SYMBOL(kprobes_inc_nmissed_count); 1214 1203 ··· 1226 1215 { 1227 1216 struct kretprobe *rp = get_kretprobe(ri); 1228 1217 1229 - if (likely(rp)) { 1218 + if (likely(rp)) 1230 1219 freelist_add(&ri->freelist, &rp->freelist); 1231 - } else 1220 + else 1232 1221 call_rcu(&ri->rcu, free_rp_inst_rcu); 1233 1222 } 1234 1223 NOKPROBE_SYMBOL(recycle_rp_inst); ··· 1254 1243 } 1255 1244 1256 1245 /* 1257 - * This function is called from finish_task_switch when task tk becomes dead, 1258 - * so that we can recycle any function-return probe instances associated 1246 + * This function is called from finish_task_switch() when task 'tk' becomes 1247 + * dead, so that we can recycle any kretprobe instances associated 1259 1248 * with this task. These left over instances represent probed functions 1260 1249 * that have been called but will never return. 1261 1250 */ ··· 1303 1292 } 1304 1293 } 1305 1294 1306 - /* Add the new probe to ap->list */ 1295 + /* Add the new probe to 'ap->list'. */ 1307 1296 static int add_new_kprobe(struct kprobe *ap, struct kprobe *p) 1308 1297 { 1309 1298 if (p->post_handler) ··· 1317 1306 } 1318 1307 1319 1308 /* 1320 - * Fill in the required fields of the "manager kprobe". Replace the 1321 - * earlier kprobe in the hlist with the manager kprobe 1309 + * Fill in the required fields of the aggregator kprobe. Replace the 1310 + * earlier kprobe in the hlist with the aggregator kprobe. 1322 1311 */ 1323 1312 static void init_aggr_kprobe(struct kprobe *ap, struct kprobe *p) 1324 1313 { 1325 - /* Copy p's insn slot to ap */ 1314 + /* Copy the insn slot of 'p' to 'ap'. */ 1326 1315 copy_kprobe(p, ap); 1327 1316 flush_insn_slot(ap); 1328 1317 ap->addr = p->addr; ··· 1340 1329 } 1341 1330 1342 1331 /* 1343 - * This is the second or subsequent kprobe at the address - handle 1344 - * the intricacies 1332 + * This registers the second or subsequent kprobe at the same address. 1345 1333 */ 1346 1334 static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p) 1347 1335 { ··· 1354 1344 mutex_lock(&text_mutex); 1355 1345 1356 1346 if (!kprobe_aggrprobe(orig_p)) { 1357 - /* If orig_p is not an aggr_kprobe, create new aggr_kprobe. */ 1347 + /* If 'orig_p' is not an 'aggr_kprobe', create new one. */ 1358 1348 ap = alloc_aggr_kprobe(orig_p); 1359 1349 if (!ap) { 1360 1350 ret = -ENOMEM; ··· 1379 1369 if (ret) 1380 1370 /* 1381 1371 * Even if fail to allocate new slot, don't need to 1382 - * free aggr_probe. It will be used next time, or 1383 - * freed by unregister_kprobe. 1372 + * free the 'ap'. It will be used next time, or 1373 + * freed by unregister_kprobe(). 1384 1374 */ 1385 1375 goto out; 1386 1376 ··· 1395 1385 | KPROBE_FLAG_DISABLED; 1396 1386 } 1397 1387 1398 - /* Copy ap's insn slot to p */ 1388 + /* Copy the insn slot of 'p' to 'ap'. */ 1399 1389 copy_kprobe(ap, p); 1400 1390 ret = add_new_kprobe(ap, p); 1401 1391 ··· 1421 1411 1422 1412 bool __weak arch_within_kprobe_blacklist(unsigned long addr) 1423 1413 { 1424 - /* The __kprobes marked functions and entry code must not be probed */ 1414 + /* The '__kprobes' functions and entry code must not be probed. */ 1425 1415 return addr >= (unsigned long)__kprobes_text_start && 1426 1416 addr < (unsigned long)__kprobes_text_end; 1427 1417 } ··· 1433 1423 if (arch_within_kprobe_blacklist(addr)) 1434 1424 return true; 1435 1425 /* 1436 - * If there exists a kprobe_blacklist, verify and 1437 - * fail any probe registration in the prohibited area 1426 + * If 'kprobe_blacklist' is defined, check the address and 1427 + * reject any probe registration in the prohibited area. 1438 1428 */ 1439 1429 list_for_each_entry(ent, &kprobe_blacklist, list) { 1440 1430 if (addr >= ent->start_addr && addr < ent->end_addr) ··· 1464 1454 } 1465 1455 1466 1456 /* 1467 - * If we have a symbol_name argument, look it up and add the offset field 1457 + * If 'symbol_name' is specified, look it up and add the 'offset' 1468 1458 * to it. This way, we can specify a relative address to a symbol. 1469 1459 * This returns encoded errors if it fails to look up symbol or invalid 1470 1460 * combination of parameters. ··· 1494 1484 return _kprobe_addr(p->addr, p->symbol_name, p->offset); 1495 1485 } 1496 1486 1497 - /* Check passed kprobe is valid and return kprobe in kprobe_table. */ 1487 + /* 1488 + * Check the 'p' is valid and return the aggregator kprobe 1489 + * at the same address. 1490 + */ 1498 1491 static struct kprobe *__get_valid_kprobe(struct kprobe *p) 1499 1492 { 1500 1493 struct kprobe *ap, *list_p; ··· 1574 1561 goto out; 1575 1562 } 1576 1563 1577 - /* Check if are we probing a module */ 1564 + /* Check if 'p' is probing a module. */ 1578 1565 *probed_mod = __module_text_address((unsigned long) p->addr); 1579 1566 if (*probed_mod) { 1580 1567 /* ··· 1587 1574 } 1588 1575 1589 1576 /* 1590 - * If the module freed .init.text, we couldn't insert 1577 + * If the module freed '.init.text', we couldn't insert 1591 1578 * kprobes in there. 1592 1579 */ 1593 1580 if (within_module_init((unsigned long)p->addr, *probed_mod) && ··· 1634 1621 1635 1622 old_p = get_kprobe(p->addr); 1636 1623 if (old_p) { 1637 - /* Since this may unoptimize old_p, locking text_mutex. */ 1624 + /* Since this may unoptimize 'old_p', locking 'text_mutex'. */ 1638 1625 ret = register_aggr_kprobe(old_p, p); 1639 1626 goto out; 1640 1627 } ··· 1673 1660 } 1674 1661 EXPORT_SYMBOL_GPL(register_kprobe); 1675 1662 1676 - /* Check if all probes on the aggrprobe are disabled */ 1663 + /* Check if all probes on the 'ap' are disabled. */ 1677 1664 static int aggr_kprobe_disabled(struct kprobe *ap) 1678 1665 { 1679 1666 struct kprobe *kp; ··· 1683 1670 list_for_each_entry(kp, &ap->list, list) 1684 1671 if (!kprobe_disabled(kp)) 1685 1672 /* 1686 - * There is an active probe on the list. 1687 - * We can't disable this ap. 1673 + * Since there is an active probe on the list, 1674 + * we can't disable this 'ap'. 1688 1675 */ 1689 1676 return 0; 1690 1677 1691 1678 return 1; 1692 1679 } 1693 1680 1694 - /* Disable one kprobe: Make sure called under kprobe_mutex is locked */ 1681 + /* Disable one kprobe: Make sure called under 'kprobe_mutex' is locked. */ 1695 1682 static struct kprobe *__disable_kprobe(struct kprobe *p) 1696 1683 { 1697 1684 struct kprobe *orig_p; ··· 1710 1697 /* Try to disarm and disable this/parent probe */ 1711 1698 if (p == orig_p || aggr_kprobe_disabled(orig_p)) { 1712 1699 /* 1713 - * If kprobes_all_disarmed is set, orig_p 1700 + * If 'kprobes_all_disarmed' is set, 'orig_p' 1714 1701 * should have already been disarmed, so 1715 1702 * skip unneed disarming process. 1716 1703 */ ··· 1997 1984 if (ret) 1998 1985 return ret; 1999 1986 2000 - /* If only rp->kp.addr is specified, check reregistering kprobes */ 1987 + /* If only 'rp->kp.addr' is specified, check reregistering kprobes */ 2001 1988 if (rp->kp.addr && warn_kprobe_rereg(&rp->kp)) 2002 1989 return -EINVAL; 2003 1990 ··· 2102 2089 #else /* CONFIG_KRETPROBES */ 2103 2090 int register_kretprobe(struct kretprobe *rp) 2104 2091 { 2105 - return -ENOSYS; 2092 + return -EOPNOTSUPP; 2106 2093 } 2107 2094 EXPORT_SYMBOL_GPL(register_kretprobe); 2108 2095 2109 2096 int register_kretprobes(struct kretprobe **rps, int num) 2110 2097 { 2111 - return -ENOSYS; 2098 + return -EOPNOTSUPP; 2112 2099 } 2113 2100 EXPORT_SYMBOL_GPL(register_kretprobes); 2114 2101 ··· 2157 2144 /* 2158 2145 * The module is going away. We should disarm the kprobe which 2159 2146 * is using ftrace, because ftrace framework is still available at 2160 - * MODULE_STATE_GOING notification. 2147 + * 'MODULE_STATE_GOING' notification. 2161 2148 */ 2162 2149 if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed) 2163 2150 disarm_kprobe_ftrace(p); ··· 2330 2317 return ret; 2331 2318 } 2332 2319 2333 - /* Symbols in __kprobes_text are blacklisted */ 2320 + /* Symbols in '__kprobes_text' are blacklisted */ 2334 2321 ret = kprobe_add_area_blacklist((unsigned long)__kprobes_text_start, 2335 2322 (unsigned long)__kprobes_text_end); 2336 2323 if (ret) 2337 2324 return ret; 2338 2325 2339 - /* Symbols in noinstr section are blacklisted */ 2326 + /* Symbols in 'noinstr' section are blacklisted */ 2340 2327 ret = kprobe_add_area_blacklist((unsigned long)__noinstr_text_start, 2341 2328 (unsigned long)__noinstr_text_end); 2342 2329 ··· 2408 2395 return NOTIFY_DONE; 2409 2396 2410 2397 /* 2411 - * When MODULE_STATE_GOING was notified, both of module .text and 2412 - * .init.text sections would be freed. When MODULE_STATE_LIVE was 2413 - * notified, only .init.text section would be freed. We need to 2398 + * When 'MODULE_STATE_GOING' was notified, both of module '.text' and 2399 + * '.init.text' sections would be freed. When 'MODULE_STATE_LIVE' was 2400 + * notified, only '.init.text' section would be freed. We need to 2414 2401 * disable kprobes which have been inserted in the sections. 2415 2402 */ 2416 2403 mutex_lock(&kprobe_mutex); ··· 2427 2414 * 2428 2415 * Note, this will also move any optimized probes 2429 2416 * that are pending to be removed from their 2430 - * corresponding lists to the freeing_list and 2417 + * corresponding lists to the 'freeing_list' and 2431 2418 * will not be touched by the delayed 2432 - * kprobe_optimizer work handler. 2419 + * kprobe_optimizer() work handler. 2433 2420 */ 2434 2421 kill_kprobe(p); 2435 2422 } ··· 2445 2432 .priority = 0 2446 2433 }; 2447 2434 2448 - /* Markers of _kprobe_blacklist section */ 2449 - extern unsigned long __start_kprobe_blacklist[]; 2450 - extern unsigned long __stop_kprobe_blacklist[]; 2451 - 2452 2435 void kprobe_free_init_mem(void) 2453 2436 { 2454 2437 void *start = (void *)(&__init_begin); ··· 2455 2446 2456 2447 mutex_lock(&kprobe_mutex); 2457 2448 2458 - /* Kill all kprobes on initmem */ 2449 + /* Kill all kprobes on initmem because the target code has been freed. */ 2459 2450 for (i = 0; i < KPROBE_TABLE_SIZE; i++) { 2460 2451 head = &kprobe_table[i]; 2461 2452 hlist_for_each_entry(p, head, hlist) { ··· 2478 2469 2479 2470 err = populate_kprobe_blacklist(__start_kprobe_blacklist, 2480 2471 __stop_kprobe_blacklist); 2481 - if (err) { 2472 + if (err) 2482 2473 pr_err("Failed to populate blacklist (error %d), kprobes not restricted, be careful using them!\n", err); 2483 - } 2484 2474 2485 2475 if (kretprobe_blacklist_size) { 2486 2476 /* lookup the function address from its name */ ··· 2496 2488 kprobes_all_disarmed = false; 2497 2489 2498 2490 #if defined(CONFIG_OPTPROBES) && defined(__ARCH_WANT_KPROBES_INSN_SLOT) 2499 - /* Init kprobe_optinsn_slots for allocation */ 2491 + /* Init 'kprobe_optinsn_slots' for allocation */ 2500 2492 kprobe_optinsn_slots.insn_size = MAX_OPTINSN_SIZE; 2501 2493 #endif 2502 2494 ··· 2630 2622 list_entry(v, struct kprobe_blacklist_entry, list); 2631 2623 2632 2624 /* 2633 - * If /proc/kallsyms is not showing kernel address, we won't 2625 + * If '/proc/kallsyms' is not showing kernel address, we won't 2634 2626 * show them here either. 2635 2627 */ 2636 2628 if (!kallsyms_show_value(m->file->f_cred))