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.

at master 226 lines 3.8 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2/* Copyright (c) 2026 Meta Platforms, Inc. and affiliates. */ 3 4#include <linux/bpf.h> 5#include <bpf/bpf_helpers.h> 6#include "bpf_misc.h" 7 8/* linear chain main -> A -> B */ 9__naked __noinline __used 10static unsigned long linear_b(void) 11{ 12 asm volatile ( 13 "r0 = 42;" 14 "exit;" 15 ); 16} 17 18__naked __noinline __used 19static unsigned long linear_a(void) 20{ 21 asm volatile ( 22 "call linear_b;" 23 "exit;" 24 ); 25} 26 27SEC("?raw_tp") 28__success __log_level(2) 29__msg("topo_order[0] = linear_b") 30__msg("topo_order[1] = linear_a") 31__msg("topo_order[2] = topo_linear") 32__naked int topo_linear(void) 33{ 34 asm volatile ( 35 "call linear_a;" 36 "exit;" 37 ); 38} 39 40/* diamond main -> A, main -> B, A -> C, B -> C */ 41__naked __noinline __used 42static unsigned long diamond_c(void) 43{ 44 asm volatile ( 45 "r0 = 1;" 46 "exit;" 47 ); 48} 49 50__naked __noinline __used 51static unsigned long diamond_b(void) 52{ 53 asm volatile ( 54 "call diamond_c;" 55 "exit;" 56 ); 57} 58 59__naked __noinline __used 60static unsigned long diamond_a(void) 61{ 62 asm volatile ( 63 "call diamond_c;" 64 "exit;" 65 ); 66} 67 68SEC("?raw_tp") 69__success __log_level(2) 70__msg("topo_order[0] = diamond_c") 71__msg("topo_order[3] = topo_diamond") 72__naked int topo_diamond(void) 73{ 74 asm volatile ( 75 "call diamond_a;" 76 "call diamond_b;" 77 "exit;" 78 ); 79} 80 81/* main -> global_a (global) -> static_leaf (static, leaf) */ 82__naked __noinline __used 83static unsigned long static_leaf(void) 84{ 85 asm volatile ( 86 "r0 = 7;" 87 "exit;" 88 ); 89} 90 91__noinline __used 92int global_a(int x) 93{ 94 return static_leaf(); 95} 96 97SEC("?raw_tp") 98__success __log_level(2) 99__msg("topo_order[0] = static_leaf") 100__msg("topo_order[1] = global_a") 101__msg("topo_order[2] = topo_mixed") 102__naked int topo_mixed(void) 103{ 104 asm volatile ( 105 "r1 = 0;" 106 "call global_a;" 107 "exit;" 108 ); 109} 110 111/* 112 * shared static callee from global and main: 113 * main -> shared_leaf (static) 114 * main -> global_b (global) -> shared_leaf (static) 115 */ 116__naked __noinline __used 117static unsigned long shared_leaf(void) 118{ 119 asm volatile ( 120 "r0 = 99;" 121 "exit;" 122 ); 123} 124 125__noinline __used 126int global_b(int x) 127{ 128 return shared_leaf(); 129} 130 131SEC("?raw_tp") 132__success __log_level(2) 133__msg("topo_order[0] = shared_leaf") 134__msg("topo_order[1] = global_b") 135__msg("topo_order[2] = topo_shared") 136__naked int topo_shared(void) 137{ 138 asm volatile ( 139 "call shared_leaf;" 140 "r1 = 0;" 141 "call global_b;" 142 "exit;" 143 ); 144} 145 146/* duplicate calls to the same subprog */ 147__naked __noinline __used 148static unsigned long dup_leaf(void) 149{ 150 asm volatile ( 151 "r0 = 0;" 152 "exit;" 153 ); 154} 155 156SEC("?raw_tp") 157__success __log_level(2) 158__msg("topo_order[0] = dup_leaf") 159__msg("topo_order[1] = topo_dup_calls") 160__naked int topo_dup_calls(void) 161{ 162 asm volatile ( 163 "call dup_leaf;" 164 "call dup_leaf;" 165 "exit;" 166 ); 167} 168 169/* main calls bpf_loop() with loop_cb as the callback */ 170static int loop_cb(int idx, void *ctx) 171{ 172 return 0; 173} 174 175SEC("?raw_tp") 176__success __log_level(2) 177__msg("topo_order[0] = loop_cb") 178__msg("topo_order[1] = topo_loop_cb") 179int topo_loop_cb(void) 180{ 181 bpf_loop(1, loop_cb, NULL, 0); 182 return 0; 183} 184 185/* 186 * bpf_loop callback calling another subprog 187 * main -> bpf_loop(callback=loop_cb2) -> loop_cb2 -> loop_cb2_leaf 188 */ 189__naked __noinline __used 190static unsigned long loop_cb2_leaf(void) 191{ 192 asm volatile ( 193 "r0 = 0;" 194 "exit;" 195 ); 196} 197 198static int loop_cb2(int idx, void *ctx) 199{ 200 return loop_cb2_leaf(); 201} 202 203SEC("?raw_tp") 204__success __log_level(2) 205__msg("topo_order[0] = loop_cb2_leaf") 206__msg("topo_order[1] = loop_cb2") 207__msg("topo_order[2] = topo_loop_cb_chain") 208int topo_loop_cb_chain(void) 209{ 210 bpf_loop(1, loop_cb2, NULL, 0); 211 return 0; 212} 213 214/* no calls (single subprog) */ 215SEC("?raw_tp") 216__success __log_level(2) 217__msg("topo_order[0] = topo_no_calls") 218__naked int topo_no_calls(void) 219{ 220 asm volatile ( 221 "r0 = 0;" 222 "exit;" 223 ); 224} 225 226char _license[] SEC("license") = "GPL";