bpf_trace.c (24a38b7c0c2c17f7b86c29f82beb7f2779704ca3) | bpf_trace.c (ac5a72ea5c8989871e61f6bb0852e0f91de51ebe) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* Copyright (c) 2011-2015 PLUMgrid, http://plumgrid.com 3 * Copyright (c) 2016 Facebook 4 */ 5#include <linux/kernel.h> 6#include <linux/types.h> 7#include <linux/slab.h> 8#include <linux/bpf.h> 9#include <linux/bpf_perf_event.h> 10#include <linux/filter.h> 11#include <linux/uaccess.h> 12#include <linux/ctype.h> 13#include <linux/kprobes.h> | 1// SPDX-License-Identifier: GPL-2.0 2/* Copyright (c) 2011-2015 PLUMgrid, http://plumgrid.com 3 * Copyright (c) 2016 Facebook 4 */ 5#include <linux/kernel.h> 6#include <linux/types.h> 7#include <linux/slab.h> 8#include <linux/bpf.h> 9#include <linux/bpf_perf_event.h> 10#include <linux/filter.h> 11#include <linux/uaccess.h> 12#include <linux/ctype.h> 13#include <linux/kprobes.h> |
14#include <linux/spinlock.h> |
|
14#include <linux/syscalls.h> 15#include <linux/error-injection.h> 16#include <linux/btf_ids.h> 17 18#include <asm/tlb.h> 19 20#include "trace_probe.h" 21#include "trace.h" 22 | 15#include <linux/syscalls.h> 16#include <linux/error-injection.h> 17#include <linux/btf_ids.h> 18 19#include <asm/tlb.h> 20 21#include "trace_probe.h" 22#include "trace.h" 23 |
24#define CREATE_TRACE_POINTS 25#include "bpf_trace.h" 26 |
|
23#define bpf_event_rcu_dereference(p) \ 24 rcu_dereference_protected(p, lockdep_is_held(&bpf_event_mutex)) 25 26#ifdef CONFIG_MODULES 27struct bpf_trace_module { 28 struct module *module; 29 struct list_head list; 30}; --- 339 unchanged lines hidden (view full) --- 370 strncpy_from_kernel_nofault(buf, unsafe_ptr, bufsz); 371 break; 372 case 'u': 373 strncpy_from_user_nofault(buf, user_ptr, bufsz); 374 break; 375 } 376} 377 | 27#define bpf_event_rcu_dereference(p) \ 28 rcu_dereference_protected(p, lockdep_is_held(&bpf_event_mutex)) 29 30#ifdef CONFIG_MODULES 31struct bpf_trace_module { 32 struct module *module; 33 struct list_head list; 34}; --- 339 unchanged lines hidden (view full) --- 374 strncpy_from_kernel_nofault(buf, unsafe_ptr, bufsz); 375 break; 376 case 'u': 377 strncpy_from_user_nofault(buf, user_ptr, bufsz); 378 break; 379 } 380} 381 |
382static DEFINE_RAW_SPINLOCK(trace_printk_lock); 383 384#define BPF_TRACE_PRINTK_SIZE 1024 385 386static inline __printf(1, 0) int bpf_do_trace_printk(const char *fmt, ...) 387{ 388 static char buf[BPF_TRACE_PRINTK_SIZE]; 389 unsigned long flags; 390 va_list ap; 391 int ret; 392 393 raw_spin_lock_irqsave(&trace_printk_lock, flags); 394 va_start(ap, fmt); 395 ret = vsnprintf(buf, sizeof(buf), fmt, ap); 396 va_end(ap); 397 /* vsnprintf() will not append null for zero-length strings */ 398 if (ret == 0) 399 buf[0] = '\0'; 400 trace_bpf_trace_printk(buf); 401 raw_spin_unlock_irqrestore(&trace_printk_lock, flags); 402 403 return ret; 404} 405 |
|
378/* 379 * Only limited trace_printk() conversion specifiers allowed: 380 * %d %i %u %x %ld %li %lu %lx %lld %lli %llu %llx %p %pB %pks %pus %s 381 */ 382BPF_CALL_5(bpf_trace_printk, char *, fmt, u32, fmt_size, u64, arg1, 383 u64, arg2, u64, arg3) 384{ 385 int i, mod[3] = {}, fmt_cnt = 0; --- 93 unchanged lines hidden (view full) --- 479 fmt_cnt++; 480 } 481 482/* Horrid workaround for getting va_list handling working with different 483 * argument type combinations generically for 32 and 64 bit archs. 484 */ 485#define __BPF_TP_EMIT() __BPF_ARG3_TP() 486#define __BPF_TP(...) \ | 406/* 407 * Only limited trace_printk() conversion specifiers allowed: 408 * %d %i %u %x %ld %li %lu %lx %lld %lli %llu %llx %p %pB %pks %pus %s 409 */ 410BPF_CALL_5(bpf_trace_printk, char *, fmt, u32, fmt_size, u64, arg1, 411 u64, arg2, u64, arg3) 412{ 413 int i, mod[3] = {}, fmt_cnt = 0; --- 93 unchanged lines hidden (view full) --- 507 fmt_cnt++; 508 } 509 510/* Horrid workaround for getting va_list handling working with different 511 * argument type combinations generically for 32 and 64 bit archs. 512 */ 513#define __BPF_TP_EMIT() __BPF_ARG3_TP() 514#define __BPF_TP(...) \ |
487 __trace_printk(0 /* Fake ip */, \ 488 fmt, ##__VA_ARGS__) | 515 bpf_do_trace_printk(fmt, ##__VA_ARGS__) |
489 490#define __BPF_ARG1_TP(...) \ 491 ((mod[0] == 2 || (mod[0] == 1 && __BITS_PER_LONG == 64)) \ 492 ? __BPF_TP(arg1, ##__VA_ARGS__) \ 493 : ((mod[0] == 1 || (mod[0] == 0 && __BITS_PER_LONG == 32)) \ 494 ? __BPF_TP((long)arg1, ##__VA_ARGS__) \ 495 : __BPF_TP((u32)arg1, ##__VA_ARGS__))) 496 --- 20 unchanged lines hidden (view full) --- 517 .ret_type = RET_INTEGER, 518 .arg1_type = ARG_PTR_TO_MEM, 519 .arg2_type = ARG_CONST_SIZE, 520}; 521 522const struct bpf_func_proto *bpf_get_trace_printk_proto(void) 523{ 524 /* | 516 517#define __BPF_ARG1_TP(...) \ 518 ((mod[0] == 2 || (mod[0] == 1 && __BITS_PER_LONG == 64)) \ 519 ? __BPF_TP(arg1, ##__VA_ARGS__) \ 520 : ((mod[0] == 1 || (mod[0] == 0 && __BITS_PER_LONG == 32)) \ 521 ? __BPF_TP((long)arg1, ##__VA_ARGS__) \ 522 : __BPF_TP((u32)arg1, ##__VA_ARGS__))) 523 --- 20 unchanged lines hidden (view full) --- 544 .ret_type = RET_INTEGER, 545 .arg1_type = ARG_PTR_TO_MEM, 546 .arg2_type = ARG_CONST_SIZE, 547}; 548 549const struct bpf_func_proto *bpf_get_trace_printk_proto(void) 550{ 551 /* |
525 * this program might be calling bpf_trace_printk, 526 * so allocate per-cpu printk buffers | 552 * This program might be calling bpf_trace_printk, 553 * so enable the associated bpf_trace/bpf_trace_printk event. 554 * Repeat this each time as it is possible a user has 555 * disabled bpf_trace_printk events. By loading a program 556 * calling bpf_trace_printk() however the user has expressed 557 * the intent to see such events. |
527 */ | 558 */ |
528 trace_printk_init_buffers(); | 559 if (trace_set_clr_event("bpf_trace", "bpf_trace_printk", 1)) 560 pr_warn_ratelimited("could not enable bpf_trace_printk events"); |
529 530 return &bpf_trace_printk_proto; 531} 532 533#define MAX_SEQ_PRINTF_VARARGS 12 534#define MAX_SEQ_PRINTF_MAX_MEMCPY 6 535#define MAX_SEQ_PRINTF_STR_LEN 128 536 --- 1504 unchanged lines hidden --- | 561 562 return &bpf_trace_printk_proto; 563} 564 565#define MAX_SEQ_PRINTF_VARARGS 12 566#define MAX_SEQ_PRINTF_MAX_MEMCPY 6 567#define MAX_SEQ_PRINTF_STR_LEN 128 568 --- 1504 unchanged lines hidden --- |