2020#include "trace.h"
2121
2222u64 bpf_get_stackid (u64 r1 , u64 r2 , u64 r3 , u64 r4 , u64 r5 );
23+ u64 bpf_get_stack (u64 r1 , u64 r2 , u64 r3 , u64 r4 , u64 r5 );
2324
2425/**
2526 * trace_call_bpf - invoke BPF program
@@ -577,6 +578,8 @@ kprobe_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
577578 return & bpf_perf_event_output_proto ;
578579 case BPF_FUNC_get_stackid :
579580 return & bpf_get_stackid_proto ;
581+ case BPF_FUNC_get_stack :
582+ return & bpf_get_stack_proto ;
580583 case BPF_FUNC_perf_event_read_value :
581584 return & bpf_perf_event_read_value_proto ;
582585#ifdef CONFIG_BPF_KPROBE_OVERRIDE
@@ -664,6 +667,25 @@ static const struct bpf_func_proto bpf_get_stackid_proto_tp = {
664667 .arg3_type = ARG_ANYTHING ,
665668};
666669
670+ BPF_CALL_4 (bpf_get_stack_tp , void * , tp_buff , void * , buf , u32 , size ,
671+ u64 , flags )
672+ {
673+ struct pt_regs * regs = * (struct pt_regs * * )tp_buff ;
674+
675+ return bpf_get_stack ((unsigned long ) regs , (unsigned long ) buf ,
676+ (unsigned long ) size , flags , 0 );
677+ }
678+
679+ static const struct bpf_func_proto bpf_get_stack_proto_tp = {
680+ .func = bpf_get_stack_tp ,
681+ .gpl_only = true,
682+ .ret_type = RET_INTEGER ,
683+ .arg1_type = ARG_PTR_TO_CTX ,
684+ .arg2_type = ARG_PTR_TO_UNINIT_MEM ,
685+ .arg3_type = ARG_CONST_SIZE_OR_ZERO ,
686+ .arg4_type = ARG_ANYTHING ,
687+ };
688+
667689static const struct bpf_func_proto *
668690tp_prog_func_proto (enum bpf_func_id func_id , const struct bpf_prog * prog )
669691{
@@ -672,6 +694,8 @@ tp_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
672694 return & bpf_perf_event_output_proto_tp ;
673695 case BPF_FUNC_get_stackid :
674696 return & bpf_get_stackid_proto_tp ;
697+ case BPF_FUNC_get_stack :
698+ return & bpf_get_stack_proto_tp ;
675699 default :
676700 return tracing_func_proto (func_id , prog );
677701 }
@@ -734,6 +758,8 @@ pe_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
734758 return & bpf_perf_event_output_proto_tp ;
735759 case BPF_FUNC_get_stackid :
736760 return & bpf_get_stackid_proto_tp ;
761+ case BPF_FUNC_get_stack :
762+ return & bpf_get_stack_proto_tp ;
737763 case BPF_FUNC_perf_prog_read_value :
738764 return & bpf_perf_prog_read_value_proto ;
739765 default :
@@ -744,7 +770,7 @@ pe_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
744770/*
745771 * bpf_raw_tp_regs are separate from bpf_pt_regs used from skb/xdp
746772 * to avoid potential recursive reuse issue when/if tracepoints are added
747- * inside bpf_*_event_output and/or bpf_get_stack_id
773+ * inside bpf_*_event_output, bpf_get_stackid and/or bpf_get_stack
748774 */
749775static DEFINE_PER_CPU (struct pt_regs , bpf_raw_tp_regs );
750776BPF_CALL_5 (bpf_perf_event_output_raw_tp , struct bpf_raw_tracepoint_args * , args ,
@@ -787,6 +813,26 @@ static const struct bpf_func_proto bpf_get_stackid_proto_raw_tp = {
787813 .arg3_type = ARG_ANYTHING ,
788814};
789815
816+ BPF_CALL_4 (bpf_get_stack_raw_tp , struct bpf_raw_tracepoint_args * , args ,
817+ void * , buf , u32 , size , u64 , flags )
818+ {
819+ struct pt_regs * regs = this_cpu_ptr (& bpf_raw_tp_regs );
820+
821+ perf_fetch_caller_regs (regs );
822+ return bpf_get_stack ((unsigned long ) regs , (unsigned long ) buf ,
823+ (unsigned long ) size , flags , 0 );
824+ }
825+
826+ static const struct bpf_func_proto bpf_get_stack_proto_raw_tp = {
827+ .func = bpf_get_stack_raw_tp ,
828+ .gpl_only = true,
829+ .ret_type = RET_INTEGER ,
830+ .arg1_type = ARG_PTR_TO_CTX ,
831+ .arg2_type = ARG_PTR_TO_MEM ,
832+ .arg3_type = ARG_CONST_SIZE_OR_ZERO ,
833+ .arg4_type = ARG_ANYTHING ,
834+ };
835+
790836static const struct bpf_func_proto *
791837raw_tp_prog_func_proto (enum bpf_func_id func_id , const struct bpf_prog * prog )
792838{
@@ -795,6 +841,8 @@ raw_tp_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
795841 return & bpf_perf_event_output_proto_raw_tp ;
796842 case BPF_FUNC_get_stackid :
797843 return & bpf_get_stackid_proto_raw_tp ;
844+ case BPF_FUNC_get_stack :
845+ return & bpf_get_stack_proto_raw_tp ;
798846 default :
799847 return tracing_func_proto (func_id , prog );
800848 }
0 commit comments