1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */ 3 4 #include <vmlinux.h> 5 #include <bpf/bpf_tracing.h> 6 7 char _license[] SEC("license") = "GPL"; 8 9 int tid; 10 int i; 11 12 SEC("tp_btf/bpf_testmod_test_raw_tp_null") 13 int BPF_PROG(test_raw_tp_null, struct sk_buff *skb) 14 { 15 struct task_struct *task = bpf_get_current_task_btf(); 16 17 if (task->pid != tid) 18 return 0; 19 20 i = i + skb->mark + 1; 21 /* The compiler may move the NULL check before this deref, which causes 22 * the load to fail as deref of scalar. Prevent that by using a barrier. 23 */ 24 barrier(); 25 /* If dead code elimination kicks in, the increment below will 26 * be removed. For raw_tp programs, we mark input arguments as 27 * PTR_MAYBE_NULL, so branch prediction should never kick in. 28 */ 29 if (!skb) 30 i += 2; 31 return 0; 32 } 33