From e708c1488bca54b901c4c3e73462ab2decdb8209 Mon Sep 17 00:00:00 2001 From: Huang Shijie Date: Wed, 3 Aug 2016 13:46:03 -0700 Subject: samples/kprobe: convert the printk to pr_info/pr_err We prefer to use the pr_* to print out the log now, this patch converts the printk to pr_info. In the error path, use the pr_err to replace the printk. Link: http://lkml.kernel.org/r/1464143083-3877-1-git-send-email-shijie.huang@arm.com Signed-off-by: Huang Shijie Cc: Petr Mladek Cc: Steve Capper Cc: Ananth N Mavinakayanahalli Cc: Anil S Keshavamurthy Cc: Masami Hiramatsu Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- samples/kprobes/kprobe_example.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'samples') diff --git a/samples/kprobes/kprobe_example.c b/samples/kprobes/kprobe_example.c index f3b61b4ee09c..88b3e2d227ae 100644 --- a/samples/kprobes/kprobe_example.c +++ b/samples/kprobes/kprobe_example.c @@ -27,23 +27,19 @@ static struct kprobe kp = { static int handler_pre(struct kprobe *p, struct pt_regs *regs) { #ifdef CONFIG_X86 - printk(KERN_INFO "<%s> pre_handler: p->addr = 0x%p, ip = %lx," - " flags = 0x%lx\n", + pr_info("<%s> pre_handler: p->addr = 0x%p, ip = %lx, flags = 0x%lx\n", p->symbol_name, p->addr, regs->ip, regs->flags); #endif #ifdef CONFIG_PPC - printk(KERN_INFO "<%s> pre_handler: p->addr = 0x%p, nip = 0x%lx," - " msr = 0x%lx\n", + pr_info("<%s> pre_handler: p->addr = 0x%p, nip = 0x%lx, msr = 0x%lx\n", p->symbol_name, p->addr, regs->nip, regs->msr); #endif #ifdef CONFIG_MIPS - printk(KERN_INFO "<%s> pre_handler: p->addr = 0x%p, epc = 0x%lx," - " status = 0x%lx\n", + pr_info("<%s> pre_handler: p->addr = 0x%p, epc = 0x%lx, status = 0x%lx\n", p->symbol_name, p->addr, regs->cp0_epc, regs->cp0_status); #endif #ifdef CONFIG_TILEGX - printk(KERN_INFO "<%s> pre_handler: p->addr = 0x%p, pc = 0x%lx," - " ex1 = 0x%lx\n", + pr_info("<%s> pre_handler: p->addr = 0x%p, pc = 0x%lx, ex1 = 0x%lx\n", p->symbol_name, p->addr, regs->pc, regs->ex1); #endif #ifdef CONFIG_ARM64 @@ -61,19 +57,19 @@ static void handler_post(struct kprobe *p, struct pt_regs *regs, unsigned long flags) { #ifdef CONFIG_X86 - printk(KERN_INFO "<%s> post_handler: p->addr = 0x%p, flags = 0x%lx\n", + pr_info("<%s> post_handler: p->addr = 0x%p, flags = 0x%lx\n", p->symbol_name, p->addr, regs->flags); #endif #ifdef CONFIG_PPC - printk(KERN_INFO "<%s> post_handler: p->addr = 0x%p, msr = 0x%lx\n", + pr_info("<%s> post_handler: p->addr = 0x%p, msr = 0x%lx\n", p->symbol_name, p->addr, regs->msr); #endif #ifdef CONFIG_MIPS - printk(KERN_INFO "<%s> post_handler: p->addr = 0x%p, status = 0x%lx\n", + pr_info("<%s> post_handler: p->addr = 0x%p, status = 0x%lx\n", p->symbol_name, p->addr, regs->cp0_status); #endif #ifdef CONFIG_TILEGX - printk(KERN_INFO "<%s> post_handler: p->addr = 0x%p, ex1 = 0x%lx\n", + pr_info("<%s> post_handler: p->addr = 0x%p, ex1 = 0x%lx\n", p->symbol_name, p->addr, regs->ex1); #endif #ifdef CONFIG_ARM64 @@ -89,8 +85,7 @@ static void handler_post(struct kprobe *p, struct pt_regs *regs, */ static int handler_fault(struct kprobe *p, struct pt_regs *regs, int trapnr) { - printk(KERN_INFO "fault_handler: p->addr = 0x%p, trap #%dn", - p->addr, trapnr); + pr_info("fault_handler: p->addr = 0x%p, trap #%dn", p->addr, trapnr); /* Return 0 because we don't handle the fault. */ return 0; } @@ -104,17 +99,17 @@ static int __init kprobe_init(void) ret = register_kprobe(&kp); if (ret < 0) { - printk(KERN_INFO "register_kprobe failed, returned %d\n", ret); + pr_err("register_kprobe failed, returned %d\n", ret); return ret; } - printk(KERN_INFO "Planted kprobe at %p\n", kp.addr); + pr_info("Planted kprobe at %p\n", kp.addr); return 0; } static void __exit kprobe_exit(void) { unregister_kprobe(&kp); - printk(KERN_INFO "kprobe at %p unregistered\n", kp.addr); + pr_info("kprobe at %p unregistered\n", kp.addr); } module_init(kprobe_init) -- cgit v1.2.3 From 468b88956c3317de6cf2317374faf671f950724b Mon Sep 17 00:00:00 2001 From: Huang Shijie Date: Wed, 3 Aug 2016 13:46:06 -0700 Subject: samples/jprobe: convert the printk to pr_info/pr_err We prefer to use the pr_* to print out the log now, this patch converts the printk to pr_info. In the error path, use the pr_err to replace the printk. Link: http://lkml.kernel.org/r/1464143083-3877-2-git-send-email-shijie.huang@arm.com Signed-off-by: Huang Shijie Cc: Petr Mladek Cc: Steve Capper Cc: Ananth N Mavinakayanahalli Cc: Anil S Keshavamurthy Cc: Masami Hiramatsu Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- samples/kprobes/jprobe_example.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'samples') diff --git a/samples/kprobes/jprobe_example.c b/samples/kprobes/jprobe_example.c index c3108bb15789..e3c0a40909f7 100644 --- a/samples/kprobes/jprobe_example.c +++ b/samples/kprobes/jprobe_example.c @@ -48,10 +48,10 @@ static int __init jprobe_init(void) ret = register_jprobe(&my_jprobe); if (ret < 0) { - printk(KERN_INFO "register_jprobe failed, returned %d\n", ret); + pr_err("register_jprobe failed, returned %d\n", ret); return -1; } - printk(KERN_INFO "Planted jprobe at %p, handler addr %p\n", + pr_info("Planted jprobe at %p, handler addr %p\n", my_jprobe.kp.addr, my_jprobe.entry); return 0; } @@ -59,7 +59,7 @@ static int __init jprobe_init(void) static void __exit jprobe_exit(void) { unregister_jprobe(&my_jprobe); - printk(KERN_INFO "jprobe at %p unregistered\n", my_jprobe.kp.addr); + pr_info("jprobe at %p unregistered\n", my_jprobe.kp.addr); } module_init(jprobe_init) -- cgit v1.2.3 From 613413143faa3432e436674f1c2e57ad7d290ae1 Mon Sep 17 00:00:00 2001 From: Huang Shijie Date: Wed, 3 Aug 2016 13:46:09 -0700 Subject: samples/kretprobe: convert the printk to pr_info/pr_err We prefer to use the pr_* to print out the log now, this patch converts the printk to pr_info. In the error path, use the pr_err to replace the printk. Link: http://lkml.kernel.org/r/1464143083-3877-3-git-send-email-shijie.huang@arm.com Signed-off-by: Huang Shijie Cc: Petr Mladek Cc: Steve Capper Cc: Ananth N Mavinakayanahalli Cc: Anil S Keshavamurthy Cc: Masami Hiramatsu Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- samples/kprobes/kretprobe_example.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'samples') diff --git a/samples/kprobes/kretprobe_example.c b/samples/kprobes/kretprobe_example.c index ebb1d1aed547..adc83e9f59d0 100644 --- a/samples/kprobes/kretprobe_example.c +++ b/samples/kprobes/kretprobe_example.c @@ -62,7 +62,7 @@ static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs) now = ktime_get(); delta = ktime_to_ns(ktime_sub(now, data->entry_stamp)); - printk(KERN_INFO "%s returned %d and took %lld ns to execute\n", + pr_info("%s returned %d and took %lld ns to execute\n", func_name, retval, (long long)delta); return 0; } @@ -82,11 +82,10 @@ static int __init kretprobe_init(void) my_kretprobe.kp.symbol_name = func_name; ret = register_kretprobe(&my_kretprobe); if (ret < 0) { - printk(KERN_INFO "register_kretprobe failed, returned %d\n", - ret); + pr_err("register_kretprobe failed, returned %d\n", ret); return -1; } - printk(KERN_INFO "Planted return probe at %s: %p\n", + pr_info("Planted return probe at %s: %p\n", my_kretprobe.kp.symbol_name, my_kretprobe.kp.addr); return 0; } @@ -94,11 +93,10 @@ static int __init kretprobe_init(void) static void __exit kretprobe_exit(void) { unregister_kretprobe(&my_kretprobe); - printk(KERN_INFO "kretprobe at %p unregistered\n", - my_kretprobe.kp.addr); + pr_info("kretprobe at %p unregistered\n", my_kretprobe.kp.addr); /* nmissed > 0 suggests that maxactive was set too low. */ - printk(KERN_INFO "Missed probing %d instances of %s\n", + pr_info("Missed probing %d instances of %s\n", my_kretprobe.nmissed, my_kretprobe.kp.symbol_name); } -- cgit v1.2.3 From 57c24b2140437644f33eecdcc9c546bead0b5fbd Mon Sep 17 00:00:00 2001 From: Huang Shijie Date: Wed, 3 Aug 2016 13:46:12 -0700 Subject: samples/kretprobe: fix the wrong type The regs_return_value() returns "unsigned long" or "long" value. But the retval is int type now, it may cause overflow, the log may becomes: [ 2911.078869] do_brk returned -2003877888 and took 4620 ns to execute This patch converts the retval to "unsigned long" type, and fixes the overflow issue. Link: http://lkml.kernel.org/r/1464143083-3877-4-git-send-email-shijie.huang@arm.com Signed-off-by: Huang Shijie Cc: Petr Mladek Cc: Steve Capper Cc: Ananth N Mavinakayanahalli Cc: Anil S Keshavamurthy Cc: Masami Hiramatsu Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- samples/kprobes/kretprobe_example.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'samples') diff --git a/samples/kprobes/kretprobe_example.c b/samples/kprobes/kretprobe_example.c index adc83e9f59d0..7f9060f435cd 100644 --- a/samples/kprobes/kretprobe_example.c +++ b/samples/kprobes/kretprobe_example.c @@ -55,14 +55,14 @@ static int entry_handler(struct kretprobe_instance *ri, struct pt_regs *regs) */ static int ret_handler(struct kretprobe_instance *ri, struct pt_regs *regs) { - int retval = regs_return_value(regs); + unsigned long retval = regs_return_value(regs); struct my_data *data = (struct my_data *)ri->data; s64 delta; ktime_t now; now = ktime_get(); delta = ktime_to_ns(ktime_sub(now, data->entry_stamp)); - pr_info("%s returned %d and took %lld ns to execute\n", + pr_info("%s returned %lu and took %lld ns to execute\n", func_name, retval, (long long)delta); return 0; } -- cgit v1.2.3 From 747ea55e4f78fd980350c39570a986b8c1c3e4aa Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Fri, 12 Aug 2016 22:17:17 +0200 Subject: bpf: fix bpf_skb_in_cgroup helper naming While hashing out BPF's current_task_under_cgroup helper bits, it came to discussion that the skb_in_cgroup helper name was suboptimally chosen. Tejun says: So, I think in_cgroup should mean that the object is in that particular cgroup while under_cgroup in the subhierarchy of that cgroup. Let's rename the other subhierarchy test to under too. I think that'd be a lot less confusing going forward. [...] It's more intuitive and gives us the room to implement the real "in" test if ever necessary in the future. Since this touches uapi bits, we need to change this as long as v4.8 is not yet officially released. Thus, change the helper enum and rename related bits. Fixes: 4a482f34afcc ("cgroup: bpf: Add bpf_skb_in_cgroup_proto") Reference: http://patchwork.ozlabs.org/patch/658500/ Suggested-by: Sargun Dhillon Suggested-by: Tejun Heo Signed-off-by: Daniel Borkmann Acked-by: Alexei Starovoitov --- samples/bpf/bpf_helpers.h | 4 ++-- samples/bpf/test_cgrp2_tc_kern.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'samples') diff --git a/samples/bpf/bpf_helpers.h b/samples/bpf/bpf_helpers.h index 217c8d507f2e..7927a090fa0d 100644 --- a/samples/bpf/bpf_helpers.h +++ b/samples/bpf/bpf_helpers.h @@ -72,8 +72,8 @@ static int (*bpf_l3_csum_replace)(void *ctx, int off, int from, int to, int flag (void *) BPF_FUNC_l3_csum_replace; static int (*bpf_l4_csum_replace)(void *ctx, int off, int from, int to, int flags) = (void *) BPF_FUNC_l4_csum_replace; -static int (*bpf_skb_in_cgroup)(void *ctx, void *map, int index) = - (void *) BPF_FUNC_skb_in_cgroup; +static int (*bpf_skb_under_cgroup)(void *ctx, void *map, int index) = + (void *) BPF_FUNC_skb_under_cgroup; #if defined(__x86_64__) diff --git a/samples/bpf/test_cgrp2_tc_kern.c b/samples/bpf/test_cgrp2_tc_kern.c index 2732c37c8d5b..10ff73404e3a 100644 --- a/samples/bpf/test_cgrp2_tc_kern.c +++ b/samples/bpf/test_cgrp2_tc_kern.c @@ -57,7 +57,7 @@ int handle_egress(struct __sk_buff *skb) bpf_trace_printk(dont_care_msg, sizeof(dont_care_msg), eth->h_proto, ip6h->nexthdr); return TC_ACT_OK; - } else if (bpf_skb_in_cgroup(skb, &test_cgrp2_array_pin, 0) != 1) { + } else if (bpf_skb_under_cgroup(skb, &test_cgrp2_array_pin, 0) != 1) { bpf_trace_printk(pass_msg, sizeof(pass_msg)); return TC_ACT_OK; } else { -- cgit v1.2.3